node-dependency-injection 3.0.0-alpha.4 → 3.0.0-alpha.7
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 +39 -28
- package/package.json +2 -2
package/dist/lib/Autowire.js
CHANGED
|
@@ -19,7 +19,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
19
19
|
|
|
20
20
|
var _fs = _interopRequireDefault(require("fs"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _typescriptEstree = require("@typescript-eslint/typescript-estree");
|
|
23
23
|
|
|
24
24
|
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
25
25
|
|
|
@@ -189,7 +189,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
189
189
|
value: function _getClassDeclaration(filePath) {
|
|
190
190
|
var sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
|
|
191
191
|
|
|
192
|
-
var body = (0,
|
|
192
|
+
var body = (0, _typescriptEstree.parse)(sourceCode).body;
|
|
193
193
|
var classDeclaration = body.find(function (declaration) {
|
|
194
194
|
return declaration.type === 'ExportDefaultDeclaration';
|
|
195
195
|
});
|
|
@@ -215,7 +215,9 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
215
215
|
|
|
216
216
|
var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
if (parentId) {
|
|
219
|
+
definition.parent = parentId;
|
|
220
|
+
}
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
if (constructorDeclaration) {
|
|
@@ -225,11 +227,16 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
225
227
|
try {
|
|
226
228
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
227
229
|
var parameterDeclaration = _step3.value;
|
|
228
|
-
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
229
230
|
|
|
230
|
-
|
|
231
|
+
try {
|
|
232
|
+
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
233
|
+
|
|
234
|
+
var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
231
235
|
|
|
232
|
-
|
|
236
|
+
if (argumentId) {
|
|
237
|
+
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {}
|
|
233
240
|
}
|
|
234
241
|
} catch (err) {
|
|
235
242
|
_iterator3.e(err);
|
|
@@ -254,7 +261,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
254
261
|
|
|
255
262
|
var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
256
263
|
|
|
257
|
-
if (this.container.hasAlias(aliasId) === false) {
|
|
264
|
+
if (aliasId && this.container.hasAlias(aliasId) === false) {
|
|
258
265
|
this.container.setAlias(aliasId, serviceId);
|
|
259
266
|
}
|
|
260
267
|
}
|
|
@@ -268,36 +275,40 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
268
275
|
}, {
|
|
269
276
|
key: "_getIdentifierFromImports",
|
|
270
277
|
value: function _getIdentifierFromImports(type, body, parsedFile) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
278
|
+
try {
|
|
279
|
+
var rootDir = parsedFile.dir;
|
|
280
|
+
var relativeImportForImplement = body.find(function (declaration) {
|
|
281
|
+
if (declaration.specifiers) {
|
|
282
|
+
return declaration.specifiers.find(function (specifier) {
|
|
283
|
+
return specifier.local.name === type;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
278
286
|
|
|
279
|
-
|
|
280
|
-
|
|
287
|
+
return null;
|
|
288
|
+
}).source.value;
|
|
281
289
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
290
|
+
if (this._tsConfigPaths) {
|
|
291
|
+
for (var pathConfig in this._tsConfigPaths) {
|
|
292
|
+
var tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
293
|
+
var tsRelativePath = this._tsConfigPaths[pathConfig][0];
|
|
294
|
+
tsRelativePath = tsRelativePath.replace(/\*/g, '');
|
|
287
295
|
|
|
288
|
-
|
|
289
|
-
|
|
296
|
+
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
297
|
+
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
290
298
|
|
|
291
|
-
|
|
299
|
+
var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
292
300
|
|
|
293
|
-
|
|
301
|
+
rootDir = parsedTsConfigPath.dir;
|
|
302
|
+
}
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
|
-
}
|
|
297
305
|
|
|
298
|
-
|
|
306
|
+
var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
299
307
|
|
|
300
|
-
|
|
308
|
+
return this._getServiceIdFromPath(absolutePathImportForImplement, type);
|
|
309
|
+
} catch (e) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
301
312
|
}
|
|
302
313
|
}]);
|
|
303
314
|
return Autowire;
|
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.7",
|
|
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,7 +52,7 @@
|
|
|
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/typescript-estree": "^5.23.0",
|
|
56
56
|
"chalk": "^4.1.0",
|
|
57
57
|
"commander": "^8.3.0",
|
|
58
58
|
"console.table": "^0.10.0",
|