Skip to content

Commit

Permalink
7.0.0 (#70)
Browse files Browse the repository at this point in the history
* Update travis for new node version testing
Version 7.0.0 setup

* Added package-lock
Updated some npm modules due to npm audit report
Removed msngr.safe()
Removed msngr.asyncify()

* Build updates

* Reverted grunt minor update as the minor update updates many dependencies that are major and breaking in super old versions of node.
Revert npm audit fixes; they are just build dependencies and I went through them they are of no concern in our usage.

* Cleaned up tiny bit more code
Increased timeout on one weird test case (long explanation but it's fine for now)
Added clean option to grunt / npm scripts

* Minor tweaks

* Update changelog notes
  • Loading branch information
KrisSiegel authored Jan 11, 2019
1 parent 0f95ead commit c173dd2
Show file tree
Hide file tree
Showing 22 changed files with 1,907 additions and 366 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ src
node_modules
CHANGELOG.md
resources
package-lock.json
26 changes: 16 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
language: node_js
sudo: false
node_js:
- "8.2"
- "8.0"
- "7.10"
- "7.0"
- "6.11"
- "6.0"
- "5.12"
- "5.0"
- "4.8"
- "4.0"
- "11.6.0"
- "11.0.0"
- "10.15.0"
- "10.0.0"
- "9.11.2"
- "9.0.0"
- "8.15.0"
- "8.0.0"
- "7.10.1"
- "7.0.0"
- "6.16.0"
- "6.0.0"
- "5.12.0"
- "5.0.0"
- "4.9.1"
- "4.0.0"
- "0.12"
- "0.11"
- "0.10"
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Changelog
This is a roll-up of all release notes in order of release

## [Release 7.0.0 - January 11, 2019](https://github.com/KrisSiegel/msngr.js/releases/tag/7.0.0)
This release is a new major version due to some API deprecation / removal. Beyond that the API is effectively unchanged and should continue to work unless you used undocumented features that were just removed :)

***Breaking changes***
- Removed `msngr.asyncify`
- Removed `msngr.safe`

***Misc changes***
- Cleaned up dead code in build and testing scripts
- `msngr.min.js` size decrease from 11.7kb to 11.1kb
- Changed `npm test` behavior to no longer rebuild (only runs tests)
- Added `npm run clean` to clean the current build
- Added `package-lock.json` for better, reproducible builds

## [Release 6.0.0 - July 28, 2017](https://github.com/KrisSiegel/msngr.js/releases/tag/6.0.0)
This release is a re-focusing on what makes msngr.js great. It removes the mache cache, the global configuration object and the universal networking to focus only on messaging and processing of messages. Additional, internal refactoring was also done to further shrink the filesize to a gzipped size of roughly 3kb.

Expand Down
64 changes: 7 additions & 57 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = (function(grunt) {
tasks: {
options: {
filter: "include",
tasks: ["build", "test"]
tasks: ["build", "test", "clean"]
}
}
}
Expand Down Expand Up @@ -214,65 +214,15 @@ module.exports = (function(grunt) {
});

/*
The reflective server simply accepts JSON, parses it and echos what it received
back to the client. Pretty useful when testing sending and receiving data.
*/
grunt.registerTask("start-reflective-server", "Creates a test service with some dummy endpoints for testing", function() {
var http = require("http");
var server = http.createServer(function(request, response) {
var body = "";
request.on("data", function(chunk) {
body = body + chunk;
});

request.on("end", function() {
var result = {
method: request.method,
headers: request.headers,
path: request.url,
body: body
};

var headers = { };

try {
var objBody = JSON.parse(body);
if (objBody.headers != undefined && Object.keys(objBody.headers).length > 0) {
for (var key in objBody.headers) {
headers[key] = objBody.headers[key];
}
}

if (objBody.body != undefined) {
result.body = objBody.body;
}
} catch (ex) {
// Couldn't care less as opposed to the commonly misused "could care less"
// in which you actually do care a little. No, I couldn't care less because
// this error just means there are no commands to reflect :)
}

if (headers["content-type"] === undefined) {
headers["content-type"] = "application/json";
}

response.writeHead(200, headers);
response.end(JSON.stringify(result, null, 2));
});
});

server.listen("8009", "127.0.0.1", function(e) {
console.log("Reflective http server started");
});
});

/*
'build' and 'test' are roll-up tasks; they have specific descriptions and execute
'build' and 'test' are rolled-up tasks; they have specific descriptions and execute
multiple tasks each to accomplish their goals. These are the only intended tasks
to be run by the developer.
to be run by the developer.
build -> cleans then builds a new copy of `msngr.js` and `msngr.min.js`.
test -> executes tests against the `msngr.js` and `msngr.min.js` rolled-up builds.
*/
grunt.registerTask("build", "Cleans, sets version and builds msngr.js", ["header:building", "clean", "verisionify", "concat", "uglify:minify", "setRunner"]);

grunt.registerTask("test", "Cleans, sets version, builds and runs mocha unit tests through node.js and phantom.js", ["build", "header:nodeTesting", "start-reflective-server", "mochaTest", "header:clientTesting", "mocha_phantomjs"]);
grunt.registerTask("test", "Cleans, sets version, builds and runs mocha unit tests through node.js and phantom.js", ["header:nodeTesting", "mochaTest", "header:clientTesting", "mocha_phantomjs"]);

});
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2017 Kris Siegel
Copyright (c) 2014-2018 Kris Siegel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "msngr.js",
"main": "msngr.min.js",
"description": "msngr.js is an asynchronous messaging library, written in JavaScript, for node and browser use",
"version": "6.0.0",
"version": "7.0.0",
"homepage": "https://github.com/KrisSiegel/msngr.js",
"authors": [
"Kris Siegel"
Expand All @@ -17,6 +17,7 @@
"src",
"node_modules",
"CHANGELOG.md",
"resources"
"resources",
"package-lock.json"
]
}
106 changes: 13 additions & 93 deletions msngr.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var msngr = msngr || (function () {
};

// Built version of msngr.js for programatic access; this is auto generated
external.version = "6.0.0";
external.version = "7.0.0";

// Takes a function, executes it passing in the external and internal interfaces
external.extend = function (fn) {
Expand Down Expand Up @@ -226,7 +226,7 @@ msngr.extend(function (external, internal) {
Utils for handling and creating identifiers
*/

msngr.extend(function (external, internal) {
msngr.extend(function (external) {
"use strict";

var atomicCount = 0;
Expand Down Expand Up @@ -302,11 +302,10 @@ msngr.extend(function (external, internal) {
An implementation of the best-performing now() available
*/

msngr.extend(function (external, internal) {
msngr.extend(function (external) {
"use strict";

var nowExec = undefined;
var nowExecDebugLabel = "";
var lastNow = undefined;

var nowPerformance = function() {
Expand All @@ -325,13 +324,10 @@ msngr.extend(function (external, internal) {
if (nowExec === undefined) {
if (typeof performance !== "undefined") {
nowExec = nowPerformance;
nowExecDebugLabel = "performance";
} else if (typeof process !== "undefined") {
nowExec = nowNode;
nowExecDebugLabel = "node";
} else {
nowExec = nowLegacy;
nowExecDebugLabel = "legacy";
}
}
var now = nowExec();
Expand All @@ -344,44 +340,6 @@ msngr.extend(function (external, internal) {

});

/*
./src/mutators/asyncify.js
Takes a synchronous method and makes it work asynchronously
*/

msngr.extend(function (external, internal) {
"use strict";

/*
msngr.asyncify() accepts a single parameter and returns it with a new, async method.
fn -> the function, which should be synchronous, to add an async() method to.
*/
external.asyncify = function(fn) {
if (external.is(fn).function) {
fn.async = function () {
var args = [].slice.call(arguments);
var callback = args.pop();
if (external.is(callback).function) {
(function (a, c) {
external.immediate(function () {
try {
c.apply(null, [null, fn.apply(null, a)]);
} catch (e) {
c.apply(null, [e, null]);
}
});
}(args, callback));
}
};
}

return fn;
};

});

/*
./src/mutators/copy.js
Expand All @@ -399,10 +357,7 @@ msngr.extend(function (external, internal) {

// Mutable types that need to be specially handled
copyHandlers[internal.types.date] = function (d) {
var cdate = new Date();
cdate.setTime(d.getTime());

return cdate;
return new Date(d);
};

copyHandlers[internal.types.object] = function (obj) {
Expand Down Expand Up @@ -562,41 +517,6 @@ msngr.extend(function (external, internal) {

});

/*
./src/mutators/safe.js
Provides a safe way to access objects and functions
*/

msngr.extend(function (external, internal) {
"use strict";

/*
msngr.safe() accepts 2 required parameters and 1 optional.
obj -> the object to inspect.
path -> the json path to a specific property separated by dots; note that this will fail if an object key actually contains a dot.
def (optional) -> the default value to return should the requested property not exist.
*/
external.safe = function (obj, path, def) {
if (!external.is(obj).object || !external.is(path).string) {
throw new Error("msngr.safe() - invalid parameters");
}

var props = path.split(".");
var position = obj, prop = undefined;
while (prop = props.shift()) {
position = position[prop];
if (position === undefined) {
break;
}
}

return (external.is(position).there) ? position : def;
};

});

/*
./src/messaging/executer.js
Expand Down Expand Up @@ -721,8 +641,8 @@ msngr.extend(function (external, internal) {
"use strict";

// Wait, why are you re-implementing the functionality of msngr.is().there?
// Listen there boyscout. The memory indexer needs to be fast. Like very fast.
// So this simplifies and imlpements only what we need. This is slightly faster.
// Alright, here's the deal. The memory indexer needs to be fast. Like very fast.
// So this simplifies and implements only what we need. This is slightly faster.
var exists = function (input) {
return (input !== undefined && input !== null);
};
Expand Down Expand Up @@ -920,7 +840,7 @@ msngr.extend(function (external, internal) {
var ids = payloadIndex.query(msg);

if (ids.length === 0) {
return undefined;
return;
}

var payload = payloads[ids[0]];
Expand Down Expand Up @@ -961,7 +881,7 @@ msngr.extend(function (external, internal) {
// Executes middlewares
var executeMiddlewares = function (uses, payload, message, callback) {
var middles = getMiddlewares(uses, payload, message);
var execute = internal.executer(middles).series(function (result) {
internal.executer(middles).series(function (result) {
return callback(internal.merge.apply(this, [payload].concat(result)));
});
};
Expand Down Expand Up @@ -1119,10 +1039,10 @@ msngr.extend(function (external, internal) {
if (payload !== undefined) {
if (uses.length > 0 || forced.length > 0) {
settleMiddleware(uses, payload, msg, function (newPayload) {
explicitEmit([id], newPayload, undefined);
explicitEmit([id], newPayload);
});
} else {
explicitEmit([id], payload, undefined);
explicitEmit([id], payload);
}
}

Expand All @@ -1141,10 +1061,10 @@ msngr.extend(function (external, internal) {
if (payload !== undefined) {
if (uses.length > 0 || forced.length > 0) {
settleMiddleware(uses, payload, msg, function (newPayload) {
explicitEmit([id], newPayload, undefined);
explicitEmit([id], newPayload);
});
} else {
explicitEmit([id], payload, undefined);
explicitEmit([id], payload);
}
}

Expand Down Expand Up @@ -1267,7 +1187,7 @@ msngr.extend(function (external, internal) {
/*
module.exports.js
If we're running in a node.js.
If we're running in node.js.
*/
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
module.exports = msngr;
Expand Down
Loading

0 comments on commit c173dd2

Please sign in to comment.