knifecycle
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -0,1 +1,6 @@ | ||
<a name="2.5.1"></a> | ||
## [2.5.1](https://github.com/nfroidure/knifecycle/compare/v2.5.0...v2.5.1) (2018-04-13) | ||
<a name="2.5.0"></a> | ||
@@ -2,0 +7,0 @@ # [2.5.0](https://github.com/nfroidure/knifecycle/compare/v2.4.2...v2.5.0) (2018-03-21) |
@@ -64,11 +64,23 @@ 'use strict'; | ||
export async function initialize(services = {}) {${batches.map((batch, index) => ` | ||
// Initialization batch #${index}${batch.map(name => { | ||
// Initialization batch #${index} | ||
const batch${index} = {${batch.map(name => { | ||
if (!dependenciesHash[name].__initializer) { | ||
return ` | ||
services['${name}'] = ${name};`; | ||
${name}: Promise.resolve(${name}),`; | ||
} | ||
return ` | ||
services['${name}'] = (await ${dependenciesHash[name].__initializerName}({${dependenciesHash[name].__inject ? `${dependenciesHash[name].__inject.map(_util.parseDependencyDeclaration).map(({ serviceName, mappedName }) => ` | ||
${serviceName}: services['${mappedName}'],`).join('')}\n ` : ''}}))${'provider' === dependenciesHash[name].__type ? '.service' : ''};`; | ||
${name}: ${dependenciesHash[name].__initializerName}({${dependenciesHash[name].__inject ? `${dependenciesHash[name].__inject.map(_util.parseDependencyDeclaration).map(({ serviceName, mappedName }) => ` | ||
${serviceName}: services['${mappedName}'],`).join('')}` : ''} | ||
})${'provider' === dependenciesHash[name].__type ? '.then(provider => provider.service)' : ''},`; | ||
}).join('')} | ||
}; | ||
await Promise.all( | ||
Object.keys(batch${index}) | ||
.map(key => batch${index}[key]) | ||
); | ||
${batch.map(name => { | ||
return ` | ||
services['${name}'] = await batch${index}['${name}'];`; | ||
}).join('')} | ||
`).join('')} | ||
@@ -75,0 +87,0 @@ return {${dependencies.map(_util.parseDependencyDeclaration).map(({ serviceName, mappedName }) => ` |
@@ -65,19 +65,47 @@ 'use strict'; | ||
// Initialization batch #0 | ||
services['dep1'] = (await initDep1({ | ||
})); | ||
services['NODE_ENV'] = NODE_ENV; | ||
const batch0 = { | ||
dep1: initDep1({ | ||
}), | ||
NODE_ENV: Promise.resolve(NODE_ENV), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch0) | ||
.map(key => batch0[key]) | ||
); | ||
services['dep1'] = await batch0['dep1']; | ||
services['NODE_ENV'] = await batch0['NODE_ENV']; | ||
// Initialization batch #1 | ||
services['dep2'] = (await initDep2({ | ||
dep1: services['dep1'], | ||
NODE_ENV: services['NODE_ENV'], | ||
})).service; | ||
const batch1 = { | ||
dep2: initDep2({ | ||
dep1: services['dep1'], | ||
NODE_ENV: services['NODE_ENV'], | ||
}).then(provider => provider.service), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch1) | ||
.map(key => batch1[key]) | ||
); | ||
services['dep2'] = await batch1['dep2']; | ||
// Initialization batch #2 | ||
services['dep3'] = (await initDep3({ | ||
dep2: services['dep2'], | ||
dep1: services['dep1'], | ||
depOpt: services['depOpt'], | ||
})); | ||
const batch2 = { | ||
dep3: initDep3({ | ||
dep2: services['dep2'], | ||
dep1: services['dep1'], | ||
depOpt: services['depOpt'], | ||
}), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch2) | ||
.map(key => batch2[key]) | ||
); | ||
services['dep3'] = await batch2['dep3']; | ||
return { | ||
@@ -84,0 +112,0 @@ dep1: services['dep1'], |
{ | ||
"name": "knifecycle", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"description": "Manage your NodeJS processes's lifecycle.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -77,10 +77,11 @@ import { SPECIAL_PROPS, parseDependencyDeclaration } from './util'; | ||
(batch, index) => ` | ||
// Initialization batch #${index}${batch | ||
// Initialization batch #${index} | ||
const batch${index} = {${batch | ||
.map(name => { | ||
if (!dependenciesHash[name].__initializer) { | ||
return ` | ||
services['${name}'] = ${name};`; | ||
${name}: Promise.resolve(${name}),`; | ||
} | ||
return ` | ||
services['${name}'] = (await ${dependenciesHash[name].__initializerName}({${ | ||
${name}: ${dependenciesHash[name].__initializerName}({${ | ||
dependenciesHash[name].__inject | ||
@@ -92,11 +93,26 @@ ? `${dependenciesHash[name].__inject | ||
` | ||
${serviceName}: services['${mappedName}'],`, | ||
${serviceName}: services['${mappedName}'],`, | ||
) | ||
.join('')}\n ` | ||
.join('')}` | ||
: '' | ||
}}))${ | ||
'provider' === dependenciesHash[name].__type ? '.service' : '' | ||
};`; | ||
} | ||
})${ | ||
'provider' === dependenciesHash[name].__type | ||
? '.then(provider => provider.service)' | ||
: '' | ||
},`; | ||
}) | ||
.join('')} | ||
}; | ||
await Promise.all( | ||
Object.keys(batch${index}) | ||
.map(key => batch${index}[key]) | ||
); | ||
${batch | ||
.map(name => { | ||
return ` | ||
services['${name}'] = await batch${index}['${name}'];`; | ||
}) | ||
.join('')} | ||
`, | ||
@@ -103,0 +119,0 @@ ) |
@@ -69,19 +69,47 @@ import assert from 'assert'; | ||
// Initialization batch #0 | ||
services['dep1'] = (await initDep1({ | ||
})); | ||
services['NODE_ENV'] = NODE_ENV; | ||
const batch0 = { | ||
dep1: initDep1({ | ||
}), | ||
NODE_ENV: Promise.resolve(NODE_ENV), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch0) | ||
.map(key => batch0[key]) | ||
); | ||
services['dep1'] = await batch0['dep1']; | ||
services['NODE_ENV'] = await batch0['NODE_ENV']; | ||
// Initialization batch #1 | ||
services['dep2'] = (await initDep2({ | ||
dep1: services['dep1'], | ||
NODE_ENV: services['NODE_ENV'], | ||
})).service; | ||
const batch1 = { | ||
dep2: initDep2({ | ||
dep1: services['dep1'], | ||
NODE_ENV: services['NODE_ENV'], | ||
}).then(provider => provider.service), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch1) | ||
.map(key => batch1[key]) | ||
); | ||
services['dep2'] = await batch1['dep2']; | ||
// Initialization batch #2 | ||
services['dep3'] = (await initDep3({ | ||
dep2: services['dep2'], | ||
dep1: services['dep1'], | ||
depOpt: services['depOpt'], | ||
})); | ||
const batch2 = { | ||
dep3: initDep3({ | ||
dep2: services['dep2'], | ||
dep1: services['dep1'], | ||
depOpt: services['depOpt'], | ||
}), | ||
}; | ||
await Promise.all( | ||
Object.keys(batch2) | ||
.map(key => batch2[key]) | ||
); | ||
services['dep3'] = await batch2['dep3']; | ||
return { | ||
@@ -88,0 +116,0 @@ dep1: services['dep1'], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
226448
4965