node-dependency-injection 3.0.0-alpha.6 → 3.0.0-alpha.9

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.
@@ -19,6 +19,8 @@ var _path = _interopRequireDefault(require("path"));
19
19
 
20
20
  var _fs = _interopRequireDefault(require("fs"));
21
21
 
22
+ var _json = _interopRequireDefault(require("json5"));
23
+
22
24
  var _typescriptEstree = require("@typescript-eslint/typescript-estree");
23
25
 
24
26
  var _Definition = _interopRequireDefault(require("./Definition"));
@@ -41,7 +43,7 @@ var Autowire = /*#__PURE__*/function () {
41
43
 
42
44
  try {
43
45
  this._tsConfigFullPath = tsConfigFullPath || _path["default"].join(process.cwd(), 'tsconfig.json');
44
- this._tsConfigPaths = require(this._tsConfigFullPath).compilerOptions.paths;
46
+ this._tsConfigPaths = _json["default"].parse(_fs["default"].readFileSync(this._tsConfigFullPath, 'utf-8')).compilerOptions.paths;
45
47
  } catch (e) {
46
48
  this._tsConfigPaths = null;
47
49
  }
@@ -157,10 +159,13 @@ var Autowire = /*#__PURE__*/function () {
157
159
 
158
160
  if (Class && classDeclaration) {
159
161
  definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
160
- serviceId = this._getServiceIdFromPath(filePath, Class.name);
161
- this.container.setDefinition(serviceId, definition);
162
162
 
163
- this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
163
+ if (definition) {
164
+ serviceId = this._getServiceIdFromPath(filePath, Class.name);
165
+ this.container.setDefinition(serviceId, definition);
166
+
167
+ this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
168
+ }
164
169
  }
165
170
  }
166
171
  }
@@ -201,47 +206,52 @@ var Autowire = /*#__PURE__*/function () {
201
206
  }, {
202
207
  key: "_getDefinition",
203
208
  value: function _getDefinition(classDeclaration, body, parsedFile, ServiceClass) {
204
- var definition = new _Definition["default"](ServiceClass);
205
- var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
206
- return method.key.name === 'constructor';
207
- });
208
-
209
- if (classDeclaration.declaration["abstract"]) {
210
- definition["abstract"] = true;
211
- }
209
+ try {
210
+ var definition = new _Definition["default"](ServiceClass);
211
+ var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
212
+ return method.key.name === 'constructor';
213
+ });
214
+
215
+ if (classDeclaration.declaration["abstract"]) {
216
+ definition["abstract"] = true;
217
+ }
212
218
 
213
- if (classDeclaration.declaration.superClass) {
214
- var typeParent = classDeclaration.declaration.superClass.name;
219
+ if (classDeclaration.declaration.superClass) {
220
+ var typeParent = classDeclaration.declaration.superClass.name;
215
221
 
216
- var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
222
+ var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
217
223
 
218
- definition.parent = parentId;
219
- }
220
-
221
- if (constructorDeclaration) {
222
- var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
223
- _step3;
224
+ if (parentId) {
225
+ definition.parent = parentId;
226
+ }
227
+ }
224
228
 
225
- try {
226
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
227
- var parameterDeclaration = _step3.value;
229
+ if (constructorDeclaration) {
230
+ var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
231
+ _step3;
228
232
 
229
- try {
233
+ try {
234
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
235
+ var parameterDeclaration = _step3.value;
230
236
  var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
231
237
 
232
238
  var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
233
239
 
234
- definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
235
- } catch (e) {}
240
+ if (argumentId) {
241
+ definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
242
+ }
243
+ }
244
+ } catch (err) {
245
+ _iterator3.e(err);
246
+ } finally {
247
+ _iterator3.f();
236
248
  }
237
- } catch (err) {
238
- _iterator3.e(err);
239
- } finally {
240
- _iterator3.f();
241
249
  }
242
- }
243
250
 
244
- return definition;
251
+ return definition;
252
+ } catch (e) {
253
+ return null;
254
+ }
245
255
  }
246
256
  }, {
247
257
  key: "_interfaceImplementations",
@@ -257,7 +267,7 @@ var Autowire = /*#__PURE__*/function () {
257
267
 
258
268
  var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
259
269
 
260
- if (this.container.hasAlias(aliasId) === false) {
270
+ if (aliasId && this.container.hasAlias(aliasId) === false) {
261
271
  this.container.setAlias(aliasId, serviceId);
262
272
  }
263
273
  }
@@ -271,36 +281,40 @@ var Autowire = /*#__PURE__*/function () {
271
281
  }, {
272
282
  key: "_getIdentifierFromImports",
273
283
  value: function _getIdentifierFromImports(type, body, parsedFile) {
274
- var rootDir = parsedFile.dir;
275
- var relativeImportForImplement = body.find(function (declaration) {
276
- if (declaration.specifiers) {
277
- return declaration.specifiers.find(function (specifier) {
278
- return specifier.local.name === type;
279
- });
280
- }
284
+ try {
285
+ var rootDir = parsedFile.dir;
286
+ var relativeImportForImplement = body.find(function (declaration) {
287
+ if (declaration.specifiers) {
288
+ return declaration.specifiers.find(function (specifier) {
289
+ return specifier.local.name === type;
290
+ });
291
+ }
281
292
 
282
- return null;
283
- }).source.value;
293
+ return null;
294
+ }).source.value;
284
295
 
285
- if (this._tsConfigPaths) {
286
- for (var pathConfig in this._tsConfigPaths) {
287
- var tsConfigPath = pathConfig.replace(/\*/g, '');
288
- var tsRelativePath = this._tsConfigPaths[pathConfig][0];
289
- tsRelativePath = tsRelativePath.replace(/\*/g, '');
296
+ if (this._tsConfigPaths) {
297
+ for (var pathConfig in this._tsConfigPaths) {
298
+ var tsConfigPath = pathConfig.replace(/\*/g, '');
299
+ var tsRelativePath = this._tsConfigPaths[pathConfig][0];
300
+ tsRelativePath = tsRelativePath.replace(/\*/g, '');
290
301
 
291
- if (relativeImportForImplement.includes(tsConfigPath)) {
292
- relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
302
+ if (relativeImportForImplement.includes(tsConfigPath)) {
303
+ relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
293
304
 
294
- var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
305
+ var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
295
306
 
296
- rootDir = parsedTsConfigPath.dir;
307
+ rootDir = parsedTsConfigPath.dir;
308
+ }
297
309
  }
298
310
  }
299
- }
300
311
 
301
- var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
312
+ var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
302
313
 
303
- return this._getServiceIdFromPath(absolutePathImportForImplement, type);
314
+ return this._getServiceIdFromPath(absolutePathImportForImplement, type);
315
+ } catch (e) {
316
+ return null;
317
+ }
304
318
  }
305
319
  }]);
306
320
  return Autowire;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-dependency-injection",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.9",
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": {
@@ -57,6 +57,7 @@
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",
60
61
  "validate-npm-package-name": "^3.0.0"
61
62
  },
62
63
  "devDependencies": {
package/tsconfig.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "target": "ES6",
3
4
  "lib": ["DOM", "ES7"],
4
5
  "baseUrl": ".",
5
6
  "paths": {
6
7
  "@app/*": [
7
- "./test/Resources-ts/AutowireModulePath/src/*"
8
+ "./test/Resources-ts/AutowireModulePath/src/*",
8
9
  ]
9
10
  }
10
11
  }