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.
@@ -19,9 +19,7 @@ var _path = _interopRequireDefault(require("path"));
19
19
 
20
20
  var _fs = _interopRequireDefault(require("fs"));
21
21
 
22
- var _json = _interopRequireDefault(require("json5"));
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 = _json["default"].parse(_fs["default"].readFileSync(this._tsConfigFullPath, 'utf-8')).compilerOptions.paths;
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
- if (definition) {
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, _typescriptEstree.parse)(sourceCode).body;
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
- 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
- }
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
- if (classDeclaration.declaration.superClass) {
220
- var typeParent = classDeclaration.declaration.superClass.name;
209
+ if (classDeclaration.declaration["abstract"]) {
210
+ definition["abstract"] = true;
211
+ }
221
212
 
222
- var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
213
+ if (classDeclaration.declaration.superClass) {
214
+ var typeParent = classDeclaration.declaration.superClass.name;
223
215
 
224
- if (parentId) {
225
- definition.parent = parentId;
226
- }
227
- }
216
+ var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
217
+
218
+ definition.parent = parentId;
219
+ }
228
220
 
229
- if (constructorDeclaration) {
230
- var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
231
- _step3;
221
+ if (constructorDeclaration) {
222
+ var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
223
+ _step3;
232
224
 
233
- try {
234
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
235
- var parameterDeclaration = _step3.value;
236
- var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
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
- var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
230
+ var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
239
231
 
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();
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 (aliasId && this.container.hasAlias(aliasId) === false) {
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
- 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
- }
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
- return null;
294
- }).source.value;
279
+ return null;
280
+ }).source.value;
295
281
 
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, '');
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
- if (relativeImportForImplement.includes(tsConfigPath)) {
303
- relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
288
+ if (relativeImportForImplement.includes(tsConfigPath)) {
289
+ relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
304
290
 
305
- var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
291
+ var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
306
292
 
307
- rootDir = parsedTsConfigPath.dir;
308
- }
293
+ rootDir = parsedTsConfigPath.dir;
309
294
  }
310
295
  }
296
+ }
311
297
 
312
- var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
298
+ var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
313
299
 
314
- return this._getServiceIdFromPath(absolutePathImportForImplement, type);
315
- } catch (e) {
316
- return null;
317
- }
300
+ return this._getServiceIdFromPath(absolutePathImportForImplement, type);
318
301
  }
319
302
  }]);
320
303
  return Autowire;
@@ -45,6 +45,8 @@ var Compiler = /*#__PURE__*/function () {
45
45
  if (error instanceof RangeError) {
46
46
  throw new _ServiceCircularReferenceException["default"]();
47
47
  }
48
+
49
+ throw error;
48
50
  }
49
51
  }
50
52
  /**
@@ -89,7 +89,7 @@ var InstanceManager = /*#__PURE__*/function () {
89
89
  }
90
90
  }
91
91
 
92
- this._containerBuilder.logger.warn("The service ".concat(typeof id === 'function' ? id.name : id, " is not registered"));
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
- try {
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.11",
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/typescript-estree": "^5.23.0",
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
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES6",
4
3
  "lib": ["DOM", "ES7"],
5
4
  "baseUrl": ".",
6
5
  "paths": {
7
6
  "@app/*": [
8
- "./test/Resources-ts/AutowireModulePath/src/*",
7
+ "./test/Resources-ts/AutowireModulePath/src/*"
9
8
  ]
10
9
  }
11
10
  }