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

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.
Files changed (64) hide show
  1. package/.nyc_output/65e34a77-efb9-4bcf-803d-282fd660b5a8.json +1 -0
  2. package/.nyc_output/f2f58129-8a27-4ea1-94b2-d5913ef6944d.json +1 -0
  3. package/.nyc_output/processinfo/65e34a77-efb9-4bcf-803d-282fd660b5a8.json +1 -0
  4. package/.nyc_output/processinfo/f2f58129-8a27-4ea1-94b2-d5913ef6944d.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/bin/Services/File/BaseAdapter.js.html +158 -0
  8. package/coverage/lcov-report/bin/Services/File/FileManager.js.html +176 -0
  9. package/coverage/lcov-report/bin/Services/File/JsAdapter.js.html +140 -0
  10. package/coverage/lcov-report/bin/Services/File/JsonAdapter.js.html +131 -0
  11. package/coverage/lcov-report/bin/Services/File/YamlAdapter.js.html +155 -0
  12. package/coverage/lcov-report/bin/Services/File/index.html +171 -0
  13. package/coverage/lcov-report/block-navigation.js +79 -0
  14. package/coverage/lcov-report/favicon.png +0 -0
  15. package/coverage/lcov-report/index.html +171 -0
  16. package/coverage/lcov-report/lib/Autowire.js.html +506 -0
  17. package/coverage/lcov-report/lib/Compiler.js.html +239 -0
  18. package/coverage/lcov-report/lib/CompilerPass/DecoratePass.js.html +248 -0
  19. package/coverage/lcov-report/lib/CompilerPass/OptimizePass.js.html +128 -0
  20. package/coverage/lcov-report/lib/CompilerPass/RemovePass.js.html +116 -0
  21. package/coverage/lcov-report/lib/CompilerPass/index.html +156 -0
  22. package/coverage/lcov-report/lib/CompilerPass/index.js.html +326 -0
  23. package/coverage/lcov-report/lib/ContainerBuilder.js.html +1115 -0
  24. package/coverage/lcov-report/lib/Definition.js.html +962 -0
  25. package/coverage/lcov-report/lib/Exception/AbstractServiceException.js.html +110 -0
  26. package/coverage/lcov-report/lib/Exception/AttributesMapException.js.html +101 -0
  27. package/coverage/lcov-report/lib/Exception/ConfigurationFileNotFoundException.js.html +110 -0
  28. package/coverage/lcov-report/lib/Exception/DefinitionNotFoundException.js.html +110 -0
  29. package/coverage/lcov-report/lib/Exception/FrozenContainerException.js.html +101 -0
  30. package/coverage/lcov-report/lib/Exception/LoadMethodNotFoundException.js.html +110 -0
  31. package/coverage/lcov-report/lib/Exception/LoggerWarnMethodNotFoundException.js.html +101 -0
  32. package/coverage/lcov-report/lib/Exception/MethodCallEmptyException.js.html +101 -0
  33. package/coverage/lcov-report/lib/Exception/MethodCallNotFoundException.js.html +110 -0
  34. package/coverage/lcov-report/lib/Exception/NotAbstractServiceException.js.html +110 -0
  35. package/coverage/lcov-report/lib/Exception/PrivateServiceException.js.html +110 -0
  36. package/coverage/lcov-report/lib/Exception/ProcessMethodNotFoundException.js.html +110 -0
  37. package/coverage/lcov-report/lib/Exception/ServiceCircularReferenceException.js.html +101 -0
  38. package/coverage/lcov-report/lib/Exception/ServiceFileNotFoundException.js.html +110 -0
  39. package/coverage/lcov-report/lib/Exception/ServiceFileNotLoadedException.js.html +110 -0
  40. package/coverage/lcov-report/lib/Exception/ServiceNotFoundException.js.html +113 -0
  41. package/coverage/lcov-report/lib/Exception/WrongCompilerPassTypeException.js.html +110 -0
  42. package/coverage/lcov-report/lib/Exception/WrongDefinitionException.js.html +101 -0
  43. package/coverage/lcov-report/lib/Exception/index.html +366 -0
  44. package/coverage/lcov-report/lib/InstanceManager.js.html +839 -0
  45. package/coverage/lcov-report/lib/Loader/FileLoader.js.html +1034 -0
  46. package/coverage/lcov-report/lib/Loader/JsFileLoader.js.html +155 -0
  47. package/coverage/lcov-report/lib/Loader/JsonFileLoader.js.html +98 -0
  48. package/coverage/lcov-report/lib/Loader/YamlFileLoader.js.html +188 -0
  49. package/coverage/lcov-report/lib/Loader/index.html +156 -0
  50. package/coverage/lcov-report/lib/PackageReference.js.html +131 -0
  51. package/coverage/lcov-report/lib/PassConfig.js.html +230 -0
  52. package/coverage/lcov-report/lib/Reference.js.html +158 -0
  53. package/coverage/lcov-report/lib/TagReference.js.html +131 -0
  54. package/coverage/lcov-report/lib/index.html +231 -0
  55. package/coverage/lcov-report/prettify.css +1 -0
  56. package/coverage/lcov-report/prettify.js +2 -0
  57. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  58. package/coverage/lcov-report/sorter.js +170 -0
  59. package/coverage/lcov.info +1516 -0
  60. package/dist/lib/Autowire.js +29 -4
  61. package/dist/lib/index.js +9 -1
  62. package/dist/lib/types/index.d.ts +9 -1
  63. package/package.json +7 -4
  64. package/tsconfig.json +7 -1
@@ -19,7 +19,7 @@ var _path = _interopRequireDefault(require("path"));
19
19
 
20
20
  var _fs = _interopRequireDefault(require("fs"));
21
21
 
22
- var _parser = require("@typescript-eslint/parser");
22
+ var _typescriptEstree = require("@typescript-eslint/typescript-estree");
23
23
 
24
24
  var _Definition = _interopRequireDefault(require("./Definition"));
25
25
 
@@ -33,10 +33,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
33
33
 
34
34
  var Autowire = /*#__PURE__*/function () {
35
35
  function Autowire(container) {
36
+ var tsConfigFullPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
36
37
  (0, _classCallCheck2["default"])(this, Autowire);
37
38
  this._interfaceImplementation = new Map();
38
39
  this._rootDirectory = container.defaultDir;
39
40
  this._container = container;
41
+
42
+ try {
43
+ this._tsConfigFullPath = tsConfigFullPath || _path["default"].join(process.cwd(), 'tsconfig.json');
44
+ this._tsConfigPaths = require(this._tsConfigFullPath).compilerOptions.paths;
45
+ } catch (e) {
46
+ this._tsConfigPaths = null;
47
+ }
40
48
  }
41
49
  /**
42
50
  * @return {ContainerBuilder}
@@ -120,7 +128,7 @@ var Autowire = /*#__PURE__*/function () {
120
128
  key: "_getServiceIdFromPath",
121
129
  value: function _getServiceIdFromPath(path, type) {
122
130
  var extension = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.ts';
123
- return path.replace(/\//g, '_').replace(extension, '').concat("_".concat(type));
131
+ return path.replace(/\//g, '_').replace(extension, '').replace('@', '_').concat("_".concat(type));
124
132
  }
125
133
  /**
126
134
  * @returns {void}
@@ -181,7 +189,7 @@ var Autowire = /*#__PURE__*/function () {
181
189
  value: function _getClassDeclaration(filePath) {
182
190
  var sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
183
191
 
184
- var body = (0, _parser.parse)(sourceCode).body;
192
+ var body = (0, _typescriptEstree.parse)(sourceCode).body;
185
193
  var classDeclaration = body.find(function (declaration) {
186
194
  return declaration.type === 'ExportDefaultDeclaration';
187
195
  });
@@ -260,6 +268,7 @@ var Autowire = /*#__PURE__*/function () {
260
268
  }, {
261
269
  key: "_getIdentifierFromImports",
262
270
  value: function _getIdentifierFromImports(type, body, parsedFile) {
271
+ var rootDir = parsedFile.dir;
263
272
  var relativeImportForImplement = body.find(function (declaration) {
264
273
  if (declaration.specifiers) {
265
274
  return declaration.specifiers.find(function (specifier) {
@@ -270,7 +279,23 @@ var Autowire = /*#__PURE__*/function () {
270
279
  return null;
271
280
  }).source.value;
272
281
 
273
- var absolutePathImportForImplement = _path["default"].join(parsedFile.dir, relativeImportForImplement);
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, '');
287
+
288
+ if (relativeImportForImplement.includes(tsConfigPath)) {
289
+ relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
290
+
291
+ var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
292
+
293
+ rootDir = parsedTsConfigPath.dir;
294
+ }
295
+ }
296
+ }
297
+
298
+ var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
274
299
 
275
300
  return this._getServiceIdFromPath(absolutePathImportForImplement, type);
276
301
  }
package/dist/lib/index.js CHANGED
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ Object.defineProperty(exports, "Autowire", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _Autowire["default"];
12
+ }
13
+ });
8
14
  Object.defineProperty(exports, "ContainerBuilder", {
9
15
  enumerable: true,
10
16
  get: function get() {
@@ -76,4 +82,6 @@ var _PassConfig = _interopRequireDefault(require("./PassConfig"));
76
82
 
77
83
  var _Definition = _interopRequireDefault(require("./Definition"));
78
84
 
79
- var _TagReference = _interopRequireDefault(require("./TagReference"));
85
+ var _TagReference = _interopRequireDefault(require("./TagReference"));
86
+
87
+ var _Autowire = _interopRequireDefault(require("./Autowire"));
@@ -62,7 +62,7 @@ export class ContainerBuilder {
62
62
 
63
63
  findTaggedServiceIds(name: string): Map<any, any>;
64
64
 
65
- get<T = any>(id: string): T;
65
+ get<T = any>(id: string|any): T;
66
66
 
67
67
  getDefinition(key: string): Definition;
68
68
 
@@ -171,3 +171,11 @@ export class JsFileLoader extends FileLoader {
171
171
 
172
172
  export class JsonFileLoader extends JsFileLoader {
173
173
  }
174
+
175
+ export class Autowire {
176
+ constructor (container: ContainerBuilder);
177
+
178
+ get container (): ContainerBuilder;
179
+
180
+ process (): Promise<void>;
181
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-dependency-injection",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.5",
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": {
@@ -11,8 +11,8 @@
11
11
  "ndi": "dist/bin/ndi.js"
12
12
  },
13
13
  "scripts": {
14
- "test": "cross-env NODE_ENV=test mocha -r ts-node/register",
15
- "test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha",
14
+ "test": "cross-env NODE_ENV=test ts-mocha --paths",
15
+ "test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ts-mocha --paths",
16
16
  "test:standard": "standard",
17
17
  "test:standard:fix": "standard --fix",
18
18
  "build:lib": "rm -rf dist/lib/* && babel lib -d dist/lib -D",
@@ -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/parser": "^5.22.0",
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",
@@ -65,6 +65,7 @@
65
65
  "@babel/preset-env": "^7.17.10",
66
66
  "@babel/register": "^7.17.7",
67
67
  "@types/chai": "^4.3.1",
68
+ "@types/expect": "^24.3.0",
68
69
  "@types/mocha": "^9.1.1",
69
70
  "babel-plugin-istanbul": "^6.1.1",
70
71
  "chai": "^4.3.6",
@@ -75,7 +76,9 @@
75
76
  "nyc": "^15.1.0",
76
77
  "sinon": "^11.1.2",
77
78
  "standard": "^16.0.4",
79
+ "ts-mocha": "^10.0.0",
78
80
  "ts-node": "^10.7.0",
81
+ "tsconfig-paths": "^4.0.0",
79
82
  "typescript": "^4.6.4"
80
83
  },
81
84
  "babel": {
package/tsconfig.json CHANGED
@@ -1,5 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": ["DOM", "ES7"]
3
+ "lib": ["DOM", "ES7"],
4
+ "baseUrl": ".",
5
+ "paths": {
6
+ "@app/*": [
7
+ "./test/Resources-ts/AutowireModulePath/src/*"
8
+ ]
9
+ }
4
10
  }
5
11
  }