Socket
Socket
Sign inDemoInstall

knifecycle

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knifecycle - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0

15

CHANGELOG.md

@@ -0,1 +1,16 @@

# [5.3.0](https://github.com/nfroidure/knifecycle/compare/v5.2.0...v5.3.0) (2019-03-03)
### Bug Fixes
* **Debug:** Fix the `$injector` debug message format ([ae8510d](https://github.com/nfroidure/knifecycle/commit/ae8510d))
* **Knifecycle:** Take in count more errors for optional failures ([6b5fab3](https://github.com/nfroidure/knifecycle/commit/6b5fab3)), closes [#83](https://github.com/nfroidure/knifecycle/issues/83)
### Features
* **alsoInject:** Dedupe injections when adding some ([10e9d4f](https://github.com/nfroidure/knifecycle/commit/10e9d4f))
# [5.2.0](https://github.com/nfroidure/knifecycle/compare/v5.1.6...v5.2.0) (2019-02-09)

@@ -2,0 +17,0 @@

20

dist/index.js

@@ -132,2 +132,14 @@ "use strict";

});
Object.defineProperty(exports, "parseDependencyDeclaration", {
enumerable: true,
get: function () {
return _util.parseDependencyDeclaration;
}
});
Object.defineProperty(exports, "stringifyDependencyDeclaration", {
enumerable: true,
get: function () {
return _util.stringifyDependencyDeclaration;
}
});
exports.Knifecycle = exports.default = void 0;

@@ -629,3 +641,3 @@

if (injectorContext) {
debug(['Warning: Instantiating a new service via the $injector. It may' + ' mean that you no longer need it if your worked around a circular' + ' dependency.']);
debug('Warning: Instantiating a new service via the $injector. It may' + ' mean that you no longer need it if your worked around a circular' + ' dependency.');
}

@@ -844,5 +856,5 @@

} catch (err) {
// Let pass syntax errors through to avoid running
// invalid code
if (optional && !(err instanceof SyntaxError)) {
// Let pass code errors through to avoid casting
// invalid code to an optional service
if (optional && !(err instanceof SyntaxError) && !(err instanceof TypeError) && !(err instanceof ReferenceError) && !(err instanceof EvalError) && !(err instanceof RangeError)) {
return;

@@ -849,0 +861,0 @@ }

39

dist/util.js

@@ -27,2 +27,3 @@ "use strict";

exports.parseDependencyDeclaration = parseDependencyDeclaration;
exports.stringifyDependencyDeclaration = stringifyDependencyDeclaration;
exports.ALLOWED_INITIALIZER_TYPES = exports.OPTIONAL_FLAG = exports.DECLARATION_SEPARATOR = exports.ALLOWED_SPECIAL_PROPS = exports.SPECIAL_PROPS = exports.SPECIAL_PROPS_PREFIX = void 0;

@@ -237,3 +238,18 @@

function alsoInject(dependencies, initializer) {
return inject((initializer[SPECIAL_PROPS.INJECT] || []).concat(dependencies), initializer);
const dedupedDependencies = (initializer[SPECIAL_PROPS.INJECT] || []).concat(dependencies).map(parseDependencyDeclaration).reduce((currentDedupedDepencencies, dependencyDeclaration) => {
const sameDependencyDeclaration = currentDedupedDepencencies.find(maybeSameDependencyDeclaration => maybeSameDependencyDeclaration.serviceName === dependencyDeclaration.serviceName);
if (!sameDependencyDeclaration) {
return currentDedupedDepencencies.concat(dependencyDeclaration);
}
if (sameDependencyDeclaration.mappedName !== dependencyDeclaration.mappedName) {
return currentDedupedDepencencies.concat(dependencyDeclaration);
}
sameDependencyDeclaration.optional = dependencyDeclaration.optional && sameDependencyDeclaration.optional ? true : false;
return currentDedupedDepencencies;
}, []).map(stringifyDependencyDeclaration); // dedupe
return inject(dedupedDependencies, initializer);
}

@@ -743,2 +759,23 @@ /**

};
}
/**
* Stringify a dependency declaration from its parts.
* @param {Object} dependencyDeclarationParts
* A dependency declaration string
* @return {String}
* The various parts of it
* @example
* stringifyDependencyDeclaration({
* serviceName: 'pgsql',
* mappedName: 'db',
* optional: false,
* });
*
* // Returns
* 'pgsql>db'
*/
function stringifyDependencyDeclaration(dependencyDeclarationParts) {
return `${dependencyDeclarationParts.optional ? '?' : ''}${dependencyDeclarationParts.serviceName}${dependencyDeclarationParts.mappedName !== dependencyDeclarationParts.serviceName ? '>' + dependencyDeclarationParts.mappedName : ''}`;
}

@@ -301,2 +301,9 @@ "use strict";

});
it('should dedupe dependencies', () => {
const newInitializer = (0, _util.alsoInject)(['ENV', '?NODE_ENV', '?TEST', 'mysql>db'], (0, _util.alsoInject)(['ENV', 'NODE_ENV', '?TEST', 'mysql'], aProvider));
_assert.default.notEqual(newInitializer, aProvider);
_assert.default.deepEqual(newInitializer[_util.SPECIAL_PROPS.INJECT], ['ENV', 'NODE_ENV', '?TEST', 'mysql', 'mysql>db']);
});
});

@@ -303,0 +310,0 @@ describe('parseInjections', () => {

{
"name": "knifecycle",
"version": "5.2.0",
"version": "5.3.0",
"description": "Manage your NodeJS processes's lifecycle automatically with an unobtrusive dependency injection implementation.",

@@ -101,8 +101,8 @@ "main": "dist/index.js",

"karma-sauce-launcher": "^2.0.2",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.0",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.6.2",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"prettier": "^1.16.3",
"sinon": "^7.2.3"
"sinon": "^7.2.6"
},

@@ -109,0 +109,0 @@ "dependencies": {

@@ -481,2 +481,5 @@ [//]: # ( )

</dd>
<dt><a href="#stringifyDependencyDeclaration">stringifyDependencyDeclaration(dependencyDeclarationParts)</a> ⇒ <code>String</code></dt>
<dd><p>Stringify a dependency declaration from its parts.</p>
</dd>
</dl>

@@ -1145,3 +1148,26 @@

```
<a name="stringifyDependencyDeclaration"></a>
## stringifyDependencyDeclaration(dependencyDeclarationParts) ⇒ <code>String</code>
Stringify a dependency declaration from its parts.
**Kind**: global function
**Returns**: <code>String</code> - The various parts of it
| Param | Type | Description |
| --- | --- | --- |
| dependencyDeclarationParts | <code>Object</code> | A dependency declaration string |
**Example**
```js
stringifyDependencyDeclaration({
serviceName: 'pgsql',
mappedName: 'db',
optional: false,
});
// Returns
'pgsql>db'
```
# Authors

@@ -1148,0 +1174,0 @@ - [Nicolas Froidure](http://insertafter.com/en/index.html)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc