node-dependency-injection 3.0.0-alpha.5 → 3.0.0-alpha.8

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.
@@ -157,10 +157,13 @@ var Autowire = /*#__PURE__*/function () {
157
157
 
158
158
  if (Class && classDeclaration) {
159
159
  definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
160
- serviceId = this._getServiceIdFromPath(filePath, Class.name);
161
- this.container.setDefinition(serviceId, definition);
162
160
 
163
- this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
161
+ if (definition) {
162
+ serviceId = this._getServiceIdFromPath(filePath, Class.name);
163
+ this.container.setDefinition(serviceId, definition);
164
+
165
+ this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
166
+ }
164
167
  }
165
168
  }
166
169
  }
@@ -201,44 +204,52 @@ var Autowire = /*#__PURE__*/function () {
201
204
  }, {
202
205
  key: "_getDefinition",
203
206
  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
- }
207
+ try {
208
+ var definition = new _Definition["default"](ServiceClass);
209
+ var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
210
+ return method.key.name === 'constructor';
211
+ });
212
+
213
+ if (classDeclaration.declaration["abstract"]) {
214
+ definition["abstract"] = true;
215
+ }
212
216
 
213
- if (classDeclaration.declaration.superClass) {
214
- var typeParent = classDeclaration.declaration.superClass.name;
217
+ if (classDeclaration.declaration.superClass) {
218
+ var typeParent = classDeclaration.declaration.superClass.name;
215
219
 
216
- var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
220
+ var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
217
221
 
218
- definition.parent = parentId;
219
- }
222
+ if (parentId) {
223
+ definition.parent = parentId;
224
+ }
225
+ }
220
226
 
221
- if (constructorDeclaration) {
222
- var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
223
- _step3;
227
+ if (constructorDeclaration) {
228
+ var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
229
+ _step3;
224
230
 
225
- try {
226
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
227
- var parameterDeclaration = _step3.value;
228
- var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
231
+ try {
232
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
233
+ var parameterDeclaration = _step3.value;
234
+ var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
229
235
 
230
- var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
236
+ var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
231
237
 
232
- definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
238
+ if (argumentId) {
239
+ definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
240
+ }
241
+ }
242
+ } catch (err) {
243
+ _iterator3.e(err);
244
+ } finally {
245
+ _iterator3.f();
233
246
  }
234
- } catch (err) {
235
- _iterator3.e(err);
236
- } finally {
237
- _iterator3.f();
238
247
  }
239
- }
240
248
 
241
- return definition;
249
+ return definition;
250
+ } catch (e) {
251
+ return null;
252
+ }
242
253
  }
243
254
  }, {
244
255
  key: "_interfaceImplementations",
@@ -254,7 +265,7 @@ var Autowire = /*#__PURE__*/function () {
254
265
 
255
266
  var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
256
267
 
257
- if (this.container.hasAlias(aliasId) === false) {
268
+ if (aliasId && this.container.hasAlias(aliasId) === false) {
258
269
  this.container.setAlias(aliasId, serviceId);
259
270
  }
260
271
  }
@@ -268,36 +279,40 @@ var Autowire = /*#__PURE__*/function () {
268
279
  }, {
269
280
  key: "_getIdentifierFromImports",
270
281
  value: function _getIdentifierFromImports(type, body, parsedFile) {
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
- }
282
+ try {
283
+ var rootDir = parsedFile.dir;
284
+ var relativeImportForImplement = body.find(function (declaration) {
285
+ if (declaration.specifiers) {
286
+ return declaration.specifiers.find(function (specifier) {
287
+ return specifier.local.name === type;
288
+ });
289
+ }
278
290
 
279
- return null;
280
- }).source.value;
291
+ return null;
292
+ }).source.value;
281
293
 
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, '');
294
+ if (this._tsConfigPaths) {
295
+ for (var pathConfig in this._tsConfigPaths) {
296
+ var tsConfigPath = pathConfig.replace(/\*/g, '');
297
+ var tsRelativePath = this._tsConfigPaths[pathConfig][0];
298
+ tsRelativePath = tsRelativePath.replace(/\*/g, '');
287
299
 
288
- if (relativeImportForImplement.includes(tsConfigPath)) {
289
- relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
300
+ if (relativeImportForImplement.includes(tsConfigPath)) {
301
+ relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
290
302
 
291
- var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
303
+ var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
292
304
 
293
- rootDir = parsedTsConfigPath.dir;
305
+ rootDir = parsedTsConfigPath.dir;
306
+ }
294
307
  }
295
308
  }
296
- }
297
309
 
298
- var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
310
+ var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
299
311
 
300
- return this._getServiceIdFromPath(absolutePathImportForImplement, type);
312
+ return this._getServiceIdFromPath(absolutePathImportForImplement, type);
313
+ } catch (e) {
314
+ return null;
315
+ }
301
316
  }
302
317
  }]);
303
318
  return Autowire;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-dependency-injection",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.8",
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": {