node-dependency-injection 3.0.0-alpha.11 → 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/Autowire.js +56 -73
- package/dist/lib/Compiler.js +2 -0
- package/dist/lib/InstanceManager.js +2 -10
- package/package.json +2 -3
- package/tsconfig.json +1 -2
package/dist/lib/Autowire.js
CHANGED
|
@@ -19,9 +19,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
19
19
|
|
|
20
20
|
var _fs = _interopRequireDefault(require("fs"));
|
|
21
21
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _typescriptEstree = require("@typescript-eslint/typescript-estree");
|
|
22
|
+
var _parser = require("@typescript-eslint/parser");
|
|
25
23
|
|
|
26
24
|
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
27
25
|
|
|
@@ -43,7 +41,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
43
41
|
|
|
44
42
|
try {
|
|
45
43
|
this._tsConfigFullPath = tsConfigFullPath || _path["default"].join(process.cwd(), 'tsconfig.json');
|
|
46
|
-
this._tsConfigPaths =
|
|
44
|
+
this._tsConfigPaths = require(this._tsConfigFullPath).compilerOptions.paths;
|
|
47
45
|
} catch (e) {
|
|
48
46
|
this._tsConfigPaths = null;
|
|
49
47
|
}
|
|
@@ -159,13 +157,10 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
159
157
|
|
|
160
158
|
if (Class && classDeclaration) {
|
|
161
159
|
definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
160
|
+
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
161
|
+
this.container.setDefinition(serviceId, definition);
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
165
|
-
this.container.setDefinition(serviceId, definition);
|
|
166
|
-
|
|
167
|
-
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
168
|
-
}
|
|
163
|
+
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
169
164
|
}
|
|
170
165
|
}
|
|
171
166
|
}
|
|
@@ -194,7 +189,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
194
189
|
value: function _getClassDeclaration(filePath) {
|
|
195
190
|
var sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
|
|
196
191
|
|
|
197
|
-
var body = (0,
|
|
192
|
+
var body = (0, _parser.parse)(sourceCode).body;
|
|
198
193
|
var classDeclaration = body.find(function (declaration) {
|
|
199
194
|
return declaration.type === 'ExportDefaultDeclaration';
|
|
200
195
|
});
|
|
@@ -206,52 +201,44 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
206
201
|
}, {
|
|
207
202
|
key: "_getDefinition",
|
|
208
203
|
value: function _getDefinition(classDeclaration, body, parsedFile, ServiceClass) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (classDeclaration.declaration["abstract"]) {
|
|
216
|
-
definition["abstract"] = true;
|
|
217
|
-
}
|
|
204
|
+
var definition = new _Definition["default"](ServiceClass);
|
|
205
|
+
var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
|
|
206
|
+
return method.key.name === 'constructor';
|
|
207
|
+
});
|
|
218
208
|
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
if (classDeclaration.declaration["abstract"]) {
|
|
210
|
+
definition["abstract"] = true;
|
|
211
|
+
}
|
|
221
212
|
|
|
222
|
-
|
|
213
|
+
if (classDeclaration.declaration.superClass) {
|
|
214
|
+
var typeParent = classDeclaration.declaration.superClass.name;
|
|
223
215
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
216
|
+
var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
217
|
+
|
|
218
|
+
definition.parent = parentId;
|
|
219
|
+
}
|
|
228
220
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
if (constructorDeclaration) {
|
|
222
|
+
var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
|
|
223
|
+
_step3;
|
|
232
224
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
225
|
+
try {
|
|
226
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
227
|
+
var parameterDeclaration = _step3.value;
|
|
228
|
+
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
237
229
|
|
|
238
|
-
|
|
230
|
+
var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
239
231
|
|
|
240
|
-
|
|
241
|
-
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} catch (err) {
|
|
245
|
-
_iterator3.e(err);
|
|
246
|
-
} finally {
|
|
247
|
-
_iterator3.f();
|
|
232
|
+
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
248
233
|
}
|
|
234
|
+
} catch (err) {
|
|
235
|
+
_iterator3.e(err);
|
|
236
|
+
} finally {
|
|
237
|
+
_iterator3.f();
|
|
249
238
|
}
|
|
250
|
-
|
|
251
|
-
return definition;
|
|
252
|
-
} catch (e) {
|
|
253
|
-
return null;
|
|
254
239
|
}
|
|
240
|
+
|
|
241
|
+
return definition;
|
|
255
242
|
}
|
|
256
243
|
}, {
|
|
257
244
|
key: "_interfaceImplementations",
|
|
@@ -267,7 +254,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
267
254
|
|
|
268
255
|
var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
269
256
|
|
|
270
|
-
if (
|
|
257
|
+
if (this.container.hasAlias(aliasId) === false) {
|
|
271
258
|
this.container.setAlias(aliasId, serviceId);
|
|
272
259
|
}
|
|
273
260
|
}
|
|
@@ -281,40 +268,36 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
281
268
|
}, {
|
|
282
269
|
key: "_getIdentifierFromImports",
|
|
283
270
|
value: function _getIdentifierFromImports(type, body, parsedFile) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
271
|
+
var rootDir = parsedFile.dir;
|
|
272
|
+
var relativeImportForImplement = body.find(function (declaration) {
|
|
273
|
+
if (declaration.specifiers) {
|
|
274
|
+
return declaration.specifiers.find(function (specifier) {
|
|
275
|
+
return specifier.local.name === type;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
292
278
|
|
|
293
|
-
|
|
294
|
-
|
|
279
|
+
return null;
|
|
280
|
+
}).source.value;
|
|
295
281
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
282
|
+
if (this._tsConfigPaths) {
|
|
283
|
+
for (var pathConfig in this._tsConfigPaths) {
|
|
284
|
+
var tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
285
|
+
var tsRelativePath = this._tsConfigPaths[pathConfig][0];
|
|
286
|
+
tsRelativePath = tsRelativePath.replace(/\*/g, '');
|
|
301
287
|
|
|
302
|
-
|
|
303
|
-
|
|
288
|
+
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
289
|
+
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
304
290
|
|
|
305
|
-
|
|
291
|
+
var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
306
292
|
|
|
307
|
-
|
|
308
|
-
}
|
|
293
|
+
rootDir = parsedTsConfigPath.dir;
|
|
309
294
|
}
|
|
310
295
|
}
|
|
296
|
+
}
|
|
311
297
|
|
|
312
|
-
|
|
298
|
+
var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
313
299
|
|
|
314
|
-
|
|
315
|
-
} catch (e) {
|
|
316
|
-
return null;
|
|
317
|
-
}
|
|
300
|
+
return this._getServiceIdFromPath(absolutePathImportForImplement, type);
|
|
318
301
|
}
|
|
319
302
|
}]);
|
|
320
303
|
return Autowire;
|
package/dist/lib/Compiler.js
CHANGED
|
@@ -89,7 +89,7 @@ var InstanceManager = /*#__PURE__*/function () {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
this._containerBuilder.logger.warn("The service ".concat(
|
|
92
|
+
this._containerBuilder.logger.warn("The service ".concat(id, " is not registered"));
|
|
93
93
|
|
|
94
94
|
throw new _ServiceNotFoundException["default"](id);
|
|
95
95
|
}
|
|
@@ -183,15 +183,7 @@ var InstanceManager = /*#__PURE__*/function () {
|
|
|
183
183
|
var args = this._resolveArguments(definition.args);
|
|
184
184
|
|
|
185
185
|
if (definition.parent) {
|
|
186
|
-
|
|
187
|
-
args = this._appendParentArgumentsFromDefinition(definition, args);
|
|
188
|
-
} catch (e) {
|
|
189
|
-
if (e instanceof _NotAbstractServiceException["default"]) {
|
|
190
|
-
throw e;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
args = [];
|
|
194
|
-
}
|
|
186
|
+
args = this._appendParentArgumentsFromDefinition(definition, args);
|
|
195
187
|
}
|
|
196
188
|
|
|
197
189
|
var instance = (0, _construct2["default"])(definition.Object, (0, _toConsumableArray2["default"])(args));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-dependency-injection",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
4
4
|
"description": "The NodeDependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.",
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"directories": {
|
|
@@ -52,12 +52,11 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
54
54
|
"@babel/runtime": "^7.17.9",
|
|
55
|
-
"@typescript-eslint/
|
|
55
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
56
56
|
"chalk": "^4.1.0",
|
|
57
57
|
"commander": "^8.3.0",
|
|
58
58
|
"console.table": "^0.10.0",
|
|
59
59
|
"js-yaml": "^4.0.0",
|
|
60
|
-
"json5": "^2.2.1",
|
|
61
60
|
"validate-npm-package-name": "^3.0.0"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
package/tsconfig.json
CHANGED