@tsed/components-scan 7.0.0-alpha.2 → 7.0.0-beta.11

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 (96) hide show
  1. package/lib/cjs/__mock__/Test1.js +8 -0
  2. package/lib/cjs/__mock__/Test1.js.map +1 -0
  3. package/lib/cjs/__mock__/Test2.js +8 -0
  4. package/lib/cjs/__mock__/Test2.js.map +1 -0
  5. package/lib/cjs/__mock__/controllers/rest/TestCtrl.js +12 -0
  6. package/lib/cjs/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  7. package/lib/cjs/__mock__/module1/Module1.js +19 -0
  8. package/lib/cjs/__mock__/module1/Module1.js.map +1 -0
  9. package/lib/cjs/__mock__/module1/controllers/M1Ctrl1.js +17 -0
  10. package/lib/cjs/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  11. package/lib/cjs/__mock__/module1/services/M1Service.js +17 -0
  12. package/lib/cjs/__mock__/module1/services/M1Service.js.map +1 -0
  13. package/lib/cjs/__mock__/module1/submodule/SubModule.js +15 -0
  14. package/lib/cjs/__mock__/module1/submodule/SubModule.js.map +1 -0
  15. package/lib/cjs/__mock__/module1/submodule/SubService.js +12 -0
  16. package/lib/cjs/__mock__/module1/submodule/SubService.js.map +1 -0
  17. package/lib/cjs/__mock__/module2/Module2.js +18 -0
  18. package/lib/cjs/__mock__/module2/Module2.js.map +1 -0
  19. package/lib/cjs/__mock__/module2/controllers/M2Ctrl.js +12 -0
  20. package/lib/cjs/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  21. package/lib/cjs/cleanGlobPatterns.js +25 -0
  22. package/lib/cjs/cleanGlobPatterns.js.map +1 -0
  23. package/lib/cjs/importComponents.js +59 -0
  24. package/lib/cjs/importComponents.js.map +1 -0
  25. package/lib/cjs/importFiles.js +51 -0
  26. package/lib/cjs/importFiles.js.map +1 -0
  27. package/lib/cjs/importProviders.js +50 -0
  28. package/lib/cjs/importProviders.js.map +1 -0
  29. package/lib/cjs/index.js +13 -0
  30. package/lib/cjs/index.js.map +1 -0
  31. package/lib/cjs/isTsEnv.js +19 -0
  32. package/lib/cjs/isTsEnv.js.map +1 -0
  33. package/lib/cjs/normalizePath.js +19 -0
  34. package/lib/cjs/normalizePath.js.map +1 -0
  35. package/lib/cjs/package.json +3 -0
  36. package/lib/esm/__mock__/Test1.js +4 -0
  37. package/lib/esm/__mock__/Test1.js.map +1 -0
  38. package/lib/esm/__mock__/Test2.js +4 -0
  39. package/lib/esm/__mock__/Test2.js.map +1 -0
  40. package/lib/esm/__mock__/controllers/rest/TestCtrl.js +9 -0
  41. package/lib/esm/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  42. package/lib/esm/__mock__/module1/Module1.js +16 -0
  43. package/lib/esm/__mock__/module1/Module1.js.map +1 -0
  44. package/lib/esm/__mock__/module1/controllers/M1Ctrl1.js +14 -0
  45. package/lib/esm/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  46. package/lib/esm/__mock__/module1/services/M1Service.js +14 -0
  47. package/lib/esm/__mock__/module1/services/M1Service.js.map +1 -0
  48. package/lib/esm/__mock__/module1/submodule/SubModule.js +12 -0
  49. package/lib/esm/__mock__/module1/submodule/SubModule.js.map +1 -0
  50. package/lib/esm/__mock__/module1/submodule/SubService.js +9 -0
  51. package/lib/esm/__mock__/module1/submodule/SubService.js.map +1 -0
  52. package/lib/esm/__mock__/module2/Module2.js +15 -0
  53. package/lib/esm/__mock__/module2/Module2.js.map +1 -0
  54. package/lib/esm/__mock__/module2/controllers/M2Ctrl.js +9 -0
  55. package/lib/esm/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  56. package/lib/esm/cleanGlobPatterns.js +21 -0
  57. package/lib/esm/cleanGlobPatterns.js.map +1 -0
  58. package/lib/esm/importComponents.js +54 -0
  59. package/lib/esm/importComponents.js.map +1 -0
  60. package/lib/esm/importFiles.js +24 -0
  61. package/lib/esm/importFiles.js.map +1 -0
  62. package/lib/esm/importProviders.js +46 -0
  63. package/lib/esm/importProviders.js.map +1 -0
  64. package/lib/esm/index.js +10 -0
  65. package/lib/esm/index.js.map +1 -0
  66. package/lib/esm/isTsEnv.js +15 -0
  67. package/lib/esm/isTsEnv.js.map +1 -0
  68. package/lib/esm/normalizePath.js +14 -0
  69. package/lib/esm/normalizePath.js.map +1 -0
  70. package/lib/esm/package.json +3 -0
  71. package/lib/types/__mock__/Test1.d.ts +3 -0
  72. package/lib/types/__mock__/Test2.d.ts +3 -0
  73. package/lib/types/__mock__/controllers/rest/TestCtrl.d.ts +2 -0
  74. package/lib/types/__mock__/module1/Module1.d.ts +2 -0
  75. package/lib/types/__mock__/module1/controllers/M1Ctrl1.d.ts +5 -0
  76. package/lib/types/__mock__/module1/services/M1Service.d.ts +5 -0
  77. package/lib/types/__mock__/module1/submodule/SubModule.d.ts +2 -0
  78. package/lib/types/__mock__/module1/submodule/SubService.d.ts +2 -0
  79. package/lib/types/__mock__/module2/Module2.d.ts +2 -0
  80. package/lib/types/__mock__/module2/controllers/M2Ctrl.d.ts +2 -0
  81. package/lib/{cleanGlobPatterns.d.ts → types/cleanGlobPatterns.d.ts} +0 -0
  82. package/lib/{importComponents.d.ts → types/importComponents.d.ts} +7 -1
  83. package/lib/{importFiles.d.ts → types/importFiles.d.ts} +0 -0
  84. package/lib/types/importProviders.d.ts +6 -0
  85. package/lib/{index.d.ts → types/index.d.ts} +6 -2
  86. package/lib/types/isTsEnv.d.ts +1 -0
  87. package/lib/{normalizePath.d.ts → types/normalizePath.d.ts} +0 -0
  88. package/package.json +19 -18
  89. package/readme.md +0 -2
  90. package/tsconfig.compile.esm.json +12 -0
  91. package/lib/importProviders.d.ts +0 -10
  92. package/lib/index.js +0 -193
  93. package/lib/index.js.map +0 -1
  94. package/lib/index.modern.js +0 -168
  95. package/lib/index.modern.js.map +0 -1
  96. package/lib/isTsEnv.d.ts +0 -2
@@ -0,0 +1,15 @@
1
+ import { __decorate } from "tslib";
2
+ import { Module } from "@tsed/di";
3
+ import { M2Ctrl } from "./controllers/M2Ctrl.js";
4
+ let Module2 = class Module2 {
5
+ };
6
+ Module2 = __decorate([
7
+ Module({
8
+ mount: {
9
+ "/mod2": [M2Ctrl]
10
+ },
11
+ imports: []
12
+ })
13
+ ], Module2);
14
+ export { Module2 };
15
+ //# sourceMappingURL=Module2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Module2.js","sourceRoot":"","sources":["../../../../src/__mock__/module2/Module2.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAQ5C,IAAa,OAAO,GAApB,MAAa,OAAO;CAAG,CAAA;AAAV,OAAO;IANnB,MAAM,CAAC;QACN,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,MAAM,CAAC;SAClB;QACD,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,OAAO,CAAG;SAAV,OAAO","sourcesContent":["import {Module} from \"@tsed/di\";\nimport {M2Ctrl} from \"./controllers/M2Ctrl\";\n\n@Module({\n mount: {\n \"/mod2\": [M2Ctrl]\n },\n imports: []\n})\nexport class Module2 {}\n"]}
@@ -0,0 +1,9 @@
1
+ import { __decorate } from "tslib";
2
+ import { Controller } from "@tsed/di";
3
+ let M2Ctrl = class M2Ctrl {
4
+ };
5
+ M2Ctrl = __decorate([
6
+ Controller("/m2")
7
+ ], M2Ctrl);
8
+ export { M2Ctrl };
9
+ //# sourceMappingURL=M2Ctrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"M2Ctrl.js","sourceRoot":"","sources":["../../../../../src/__mock__/module2/controllers/M2Ctrl.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,IAAa,MAAM,GAAnB,MAAa,MAAM;CAAG,CAAA;AAAT,MAAM;IADlB,UAAU,CAAC,KAAK,CAAC;GACL,MAAM,CAAG;SAAT,MAAM","sourcesContent":["import {Controller} from \"@tsed/di\";\n\n@Controller(\"/m2\")\nexport class M2Ctrl {}\n"]}
@@ -0,0 +1,21 @@
1
+ import { resolve } from "path";
2
+ import { isTsEnv } from "./isTsEnv.js";
3
+ import { normalizePath } from "./normalizePath.js";
4
+ function mapExcludes(excludes) {
5
+ return excludes.map((s) => `!${s.replace(/!/gi, "")}`);
6
+ }
7
+ function mapExtensions(file) {
8
+ if (!isTsEnv()) {
9
+ file = file.replace(/\.ts$/i, ".js").replace(/{\.ts,\.js}$/i, ".js");
10
+ }
11
+ return file;
12
+ }
13
+ export function cleanGlobPatterns(files, excludes) {
14
+ return []
15
+ .concat(files)
16
+ .map((s) => resolve(s))
17
+ .concat(mapExcludes(excludes))
18
+ .map(mapExtensions)
19
+ .map((s) => normalizePath(s));
20
+ }
21
+ //# sourceMappingURL=cleanGlobPatterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanGlobPatterns.js","sourceRoot":"","sources":["../../src/cleanGlobPatterns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,SAAS,WAAW,CAAC,QAAkB;IACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC,OAAO,EAAE,EAAE;QACd,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;KACtE;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAwB,EAAE,QAAkB;IAC5E,OAAO,EAAE;SACN,MAAM,CAAC,KAAc,CAAC;SACtB,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SAC9B,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAU,CAAC;SACtC,GAAG,CAAC,aAAa,CAAC;SAClB,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import {resolve} from \"path\";\nimport {isTsEnv} from \"./isTsEnv\";\nimport {normalizePath} from \"./normalizePath\";\n\nfunction mapExcludes(excludes: string[]) {\n return excludes.map((s: string) => `!${s.replace(/!/gi, \"\")}`);\n}\n\nfunction mapExtensions(file: string): string {\n if (!isTsEnv()) {\n file = file.replace(/\\.ts$/i, \".js\").replace(/{\\.ts,\\.js}$/i, \".js\");\n }\n\n return file;\n}\n\nexport function cleanGlobPatterns(files: string | string[], excludes: string[]): string[] {\n return []\n .concat(files as never)\n .map((s: string) => resolve(s))\n .concat(mapExcludes(excludes) as never)\n .map(mapExtensions)\n .map((s: string) => normalizePath(s));\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import { isArray, isClass } from "@tsed/core";
2
+ import { importFiles } from "./importFiles.js";
3
+ /**
4
+ * @deprecated
5
+ */
6
+ async function resolveSymbols(item, excludes, disableComponentsScan = false) {
7
+ if (isClass(item)) {
8
+ return [item];
9
+ }
10
+ /* istanbul ignore else */
11
+ if (!disableComponentsScan) {
12
+ return importFiles(item, excludes);
13
+ }
14
+ /* istanbul ignore next */
15
+ return [];
16
+ }
17
+ /**
18
+ * @deprecated
19
+ */
20
+ export function mapConfiguration(config) {
21
+ if (isArray(config)) {
22
+ return config.map((value) => {
23
+ return {
24
+ values: [].concat(value)
25
+ };
26
+ });
27
+ }
28
+ return Object.keys(config).reduce((list, key) => {
29
+ list.push({
30
+ endpoint: key,
31
+ values: [].concat(config[key])
32
+ });
33
+ return list;
34
+ }, []);
35
+ }
36
+ /**
37
+ * @deprecated
38
+ */
39
+ export async function importComponents(config, excludes, disableComponentsScan = false) {
40
+ if (!config) {
41
+ return [];
42
+ }
43
+ config = mapConfiguration(config);
44
+ const promises = [];
45
+ for (const option of config) {
46
+ promises.push(...option.values.map(async (value) => {
47
+ const symbols = await resolveSymbols(value, excludes, disableComponentsScan);
48
+ return symbols.filter(isClass).map((symbol) => ({ token: symbol, route: option.endpoint }));
49
+ }));
50
+ }
51
+ const result = await Promise.all(promises);
52
+ return result.flat();
53
+ }
54
+ //# sourceMappingURL=importComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importComponents.js","sourceRoot":"","sources":["../../src/importComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,KAAK,UAAU,cAAc,CAAC,IAAS,EAAE,QAAkB,EAAE,qBAAqB,GAAG,KAAK;IACxF,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IACD,0BAA0B;IAC1B,IAAI,CAAC,qBAAqB,EAAE;QAC1B,OAAO,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KACpC;IAED,0BAA0B;IAC1B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAW;IAC1C,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE;QACnB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAC/B,OAAO;gBACL,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;aACzB,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAW,EAAE,GAAW,EAAE,EAAE;QAC7D,IAAI,CAAC,IAAI,CAAC;YACR,QAAQ,EAAE,GAAG;YACb,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SAC/B,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAW,EACX,QAAkB,EAClB,qBAAqB,GAAG,KAAK;IAE7B,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAElC,MAAM,QAAQ,GAAQ,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE;QAC3B,QAAQ,CAAC,IAAI,CACX,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAU,EAAE,EAAE;YACxC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,qBAAqB,CAAC,CAAC;YAE7E,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAC,CAAC,CAAC,CAAC;QAC5F,CAAC,CAAC,CACH,CAAC;KACH;IAED,MAAM,MAAM,GAAwC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC","sourcesContent":["import {isArray, isClass} from \"@tsed/core\";\nimport {importFiles} from \"./importFiles\";\n\n/**\n * @deprecated\n */\nasync function resolveSymbols(item: any, excludes: string[], disableComponentsScan = false) {\n if (isClass(item)) {\n return [item];\n }\n /* istanbul ignore else */\n if (!disableComponentsScan) {\n return importFiles(item, excludes);\n }\n\n /* istanbul ignore next */\n return [];\n}\n\n/**\n * @deprecated\n */\nexport function mapConfiguration(config: any): {endpoint?: string; values: any[]}[] {\n if (isArray(config)) {\n return config.map((value: any) => {\n return {\n values: [].concat(value)\n };\n });\n }\n\n return Object.keys(config).reduce((list: any[], key: string) => {\n list.push({\n endpoint: key,\n values: [].concat(config[key])\n });\n\n return list;\n }, []);\n}\n\n/**\n * @deprecated\n */\nexport async function importComponents(\n config: any,\n excludes: string[],\n disableComponentsScan = false\n): Promise<{token: string; route?: string}[]> {\n if (!config) {\n return [];\n }\n\n config = mapConfiguration(config);\n\n const promises: any = [];\n\n for (const option of config) {\n promises.push(\n ...option.values.map(async (value: any) => {\n const symbols = await resolveSymbols(value, excludes, disableComponentsScan);\n\n return symbols.filter(isClass).map((symbol) => ({token: symbol, route: option.endpoint}));\n })\n );\n }\n\n const result: {token: string; route?: string}[][] = await Promise.all(promises);\n\n return result.flat();\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { importPackage } from "@tsed/core";
2
+ import { cleanGlobPatterns } from "./cleanGlobPatterns.js";
3
+ export async function importFiles(patterns, exclude) {
4
+ const { default: globby } = await import("globby");
5
+ const files = await globby(cleanGlobPatterns(patterns, exclude));
6
+ const symbols = [];
7
+ for (const file of files.sort((a, b) => (a < b ? -1 : 1))) {
8
+ if (!file.endsWith(".d.ts")) {
9
+ // prevent .d.ts import if the global pattern isn't correctly configured
10
+ try {
11
+ const exports = await importPackage(file);
12
+ Object.keys(exports).forEach((key) => symbols.push(exports[key]));
13
+ }
14
+ catch (er) {
15
+ // istanbul ignore next
16
+ console.error(er);
17
+ // istanbul ignore next
18
+ process.exit(1);
19
+ }
20
+ }
21
+ }
22
+ return symbols;
23
+ }
24
+ //# sourceMappingURL=importFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importFiles.js","sourceRoot":"","sources":["../../src/importFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAA2B,EAAE,OAAiB;IAC9E,MAAM,EAAC,OAAO,EAAE,MAAM,EAAC,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEjD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,MAAM,OAAO,GAAU,EAAE,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QACzD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3B,wEAAwE;YACxE,IAAI;gBACF,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACnE;YAAC,OAAO,EAAE,EAAE;gBACX,uBAAuB;gBACvB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBAClB,uBAAuB;gBACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {importPackage} from \"@tsed/core\";\nimport {cleanGlobPatterns} from \"./cleanGlobPatterns\";\n\nexport async function importFiles(patterns: string | string[], exclude: string[]): Promise<any[]> {\n const {default: globby} = await import(\"globby\");\n\n const files = await globby(cleanGlobPatterns(patterns, exclude));\n const symbols: any[] = [];\n\n for (const file of files.sort((a, b) => (a < b ? -1 : 1))) {\n if (!file.endsWith(\".d.ts\")) {\n // prevent .d.ts import if the global pattern isn't correctly configured\n try {\n const exports = await importPackage(file);\n Object.keys(exports).forEach((key) => symbols.push(exports[key]));\n } catch (er) {\n // istanbul ignore next\n console.error(er);\n // istanbul ignore next\n process.exit(1);\n }\n }\n }\n\n return symbols;\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { GlobalProviders, ProviderType } from "@tsed/di";
2
+ import { isArray, isClass, isString } from "@tsed/core";
3
+ import { importFiles } from "./importFiles.js";
4
+ const lookup = ["imports", "componentsScan", "mount"];
5
+ async function resolveRecursively(items, exclude, rootDir) {
6
+ for (const index in items) {
7
+ if (isString(items[index])) {
8
+ items[index] = await importFiles(items[index].replace("${rootDir}", rootDir), exclude);
9
+ }
10
+ }
11
+ const providers = items.flat().filter(isClass);
12
+ for (const token of providers) {
13
+ const provider = GlobalProviders.get(token);
14
+ if ((provider === null || provider === void 0 ? void 0 : provider.type) === ProviderType.MODULE && provider.configuration) {
15
+ provider.configuration.exclude = exclude;
16
+ provider.configuration.rootDir = provider.configuration.rootDir || rootDir;
17
+ provider.configuration = await importProviders(provider.configuration);
18
+ }
19
+ }
20
+ return providers;
21
+ }
22
+ /**
23
+ * Lookup settings and replace glob pattern by the resolved providers
24
+ *
25
+ * @param settings
26
+ */
27
+ export async function importProviders(settings) {
28
+ const { exclude = [], rootDir } = settings;
29
+ for (const property of lookup) {
30
+ if (settings[property]) {
31
+ if (!isArray(settings[property])) {
32
+ const current = settings[property];
33
+ const promises = Object.entries(current).map(async ([key, items]) => {
34
+ current[key] = await resolveRecursively([].concat(items), exclude, rootDir);
35
+ });
36
+ await Promise.all(promises);
37
+ }
38
+ else {
39
+ settings[property] = await resolveRecursively(settings[property], exclude, rootDir);
40
+ }
41
+ }
42
+ }
43
+ settings.disableComponentsScan = true;
44
+ return settings;
45
+ }
46
+ //# sourceMappingURL=importProviders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importProviders.js","sourceRoot":"","sources":["../../src/importProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AACvD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAEtD,KAAK,UAAU,kBAAkB,CAAC,KAAY,EAAE,OAAiB,EAAE,OAAe;IAChF,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;QACzB,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;YAC1B,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;SACxF;KACF;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE/C,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;QAC7B,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE5C,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,YAAY,CAAC,MAAM,IAAI,QAAQ,CAAC,aAAa,EAAE;YACpE,QAAQ,CAAC,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;YACzC,QAAQ,CAAC,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,IAAI,OAAO,CAAC;YAE3E,QAAQ,CAAC,aAAa,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;SACxE;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAqC;IACzE,MAAM,EAAC,OAAO,GAAG,EAAE,EAAE,OAAO,EAAC,GAAG,QAAQ,CAAC;IAEzC,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE;QAC7B,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE;gBAChC,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,CAAgB,EAAE,EAAE;oBACjF,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,kBAAkB,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC9E,CAAC,CAAC,CAAC;gBAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aAC7B;iBAAM;gBACL,QAAQ,CAAC,QAAQ,CAAC,GAAG,MAAM,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;aACrF;SACF;KACF;IAED,QAAQ,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAEtC,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {GlobalProviders, ProviderType} from \"@tsed/di\";\nimport {isArray, isClass, isString} from \"@tsed/core\";\nimport {importFiles} from \"./importFiles\";\n\nconst lookup = [\"imports\", \"componentsScan\", \"mount\"];\n\nasync function resolveRecursively(items: any[], exclude: string[], rootDir: string) {\n for (const index in items) {\n if (isString(items[index])) {\n items[index] = await importFiles(items[index].replace(\"${rootDir}\", rootDir), exclude);\n }\n }\n\n const providers = items.flat().filter(isClass);\n\n for (const token of providers) {\n const provider = GlobalProviders.get(token);\n\n if (provider?.type === ProviderType.MODULE && provider.configuration) {\n provider.configuration.exclude = exclude;\n provider.configuration.rootDir = provider.configuration.rootDir || rootDir;\n\n provider.configuration = await importProviders(provider.configuration);\n }\n }\n\n return providers;\n}\n\n/**\n * Lookup settings and replace glob pattern by the resolved providers\n *\n * @param settings\n */\nexport async function importProviders(settings: Partial<TsED.Configuration>): Promise<Partial<TsED.Configuration>> {\n const {exclude = [], rootDir} = settings;\n\n for (const property of lookup) {\n if (settings[property]) {\n if (!isArray(settings[property])) {\n const current = settings[property];\n const promises = Object.entries(current).map(async ([key, items]: [string, any]) => {\n current[key] = await resolveRecursively([].concat(items), exclude, rootDir);\n });\n\n await Promise.all(promises);\n } else {\n settings[property] = await resolveRecursively(settings[property], exclude, rootDir);\n }\n }\n }\n\n settings.disableComponentsScan = true;\n\n return settings;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./cleanGlobPatterns.js";
5
+ export * from "./importComponents.js";
6
+ export * from "./importFiles.js";
7
+ export * from "./importProviders.js";
8
+ export * from "./isTsEnv.js";
9
+ export * from "./normalizePath.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./cleanGlobPatterns\";\nexport * from \"./importComponents\";\nexport * from \"./importFiles\";\nexport * from \"./importProviders\";\nexport * from \"./isTsEnv\";\nexport * from \"./normalizePath\";\n"]}
@@ -0,0 +1,15 @@
1
+ export function isTsEnv() {
2
+ var _a;
3
+ try {
4
+ if (require && require.extensions && require.extensions[".ts"]) {
5
+ return true;
6
+ }
7
+ }
8
+ catch (er) { }
9
+ return (process.env["TS_NODE_DEV"] ||
10
+ ((_a = process.env["_"]) === null || _a === void 0 ? void 0 : _a.includes("ts-node")) ||
11
+ process.env["TS_TEST"] ||
12
+ process.env.JEST_WORKER_ID !== undefined ||
13
+ process.env.NODE_ENV === "test");
14
+ }
15
+ //# sourceMappingURL=isTsEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isTsEnv.js","sourceRoot":"","sources":["../../src/isTsEnv.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO;;IACrB,IAAI;QACF,IAAI,OAAO,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;KACF;IAAC,OAAO,EAAE,EAAE,GAAE;IACf,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;SAC1B,MAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,0CAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;QACrC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,SAAS;QACxC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAChC,CAAC;AACJ,CAAC","sourcesContent":["export function isTsEnv() {\n try {\n if (require && require.extensions && require.extensions[\".ts\"]) {\n return true;\n }\n } catch (er) {}\n return (\n process.env[\"TS_NODE_DEV\"] ||\n process.env[\"_\"]?.includes(\"ts-node\") ||\n process.env[\"TS_TEST\"] ||\n process.env.JEST_WORKER_ID !== undefined ||\n process.env.NODE_ENV === \"test\"\n );\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { isArray, isString } from "@tsed/core";
2
+ import { join } from "path";
3
+ import fixPath from "normalize-path";
4
+ export function normalizePath(item, ...paths) {
5
+ if (isString(item)) {
6
+ const path = join(item, ...paths);
7
+ return fixPath(path);
8
+ }
9
+ if (isArray(item)) {
10
+ return item.map((item) => normalizePath(item));
11
+ }
12
+ return item;
13
+ }
14
+ //# sourceMappingURL=normalizePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizePath.js","sourceRoot":"","sources":["../../src/normalizePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAIrC,MAAM,UAAU,aAAa,CAAC,IAAS,EAAE,GAAG,KAAe;IACzD,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE;QAClB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;KACtB;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;KACrD;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {isArray, isString} from \"@tsed/core\";\nimport {join} from \"path\";\nimport fixPath from \"normalize-path\";\n\nexport function normalizePath(item: string, ...paths: string[]): string;\nexport function normalizePath(item: (string | any)[]): (string | any)[];\nexport function normalizePath(item: any, ...paths: string[]) {\n if (isString(item)) {\n const path = join(item, ...paths);\n return fixPath(path);\n }\n\n if (isArray(item)) {\n return item.map((item: any) => normalizePath(item));\n }\n\n return item;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,3 @@
1
+ export declare const value1 = "value";
2
+ export declare class Test1 {
3
+ }
@@ -0,0 +1,3 @@
1
+ export declare const value2 = "value";
2
+ export declare class Test2 {
3
+ }
@@ -0,0 +1,2 @@
1
+ export declare class TestCtrl {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class Module1 {
2
+ }
@@ -0,0 +1,5 @@
1
+ import { M1Service } from "../services/M1Service";
2
+ export declare class M1Ctrl1 {
3
+ service: M1Service;
4
+ constructor(service: M1Service);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { SubService } from "../submodule/SubService";
2
+ export declare class M1Service {
3
+ subService: SubService;
4
+ constructor(subService: SubService);
5
+ }
@@ -0,0 +1,2 @@
1
+ export declare class SubModule {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class SubService {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class Module2 {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class M2Ctrl {
2
+ }
@@ -1,8 +1,14 @@
1
+ /**
2
+ * @deprecated
3
+ */
1
4
  export declare function mapConfiguration(config: any): {
2
5
  endpoint?: string;
3
6
  values: any[];
4
7
  }[];
5
- export declare function importComponents(config: any, excludes: string[]): Promise<{
8
+ /**
9
+ * @deprecated
10
+ */
11
+ export declare function importComponents(config: any, excludes: string[], disableComponentsScan?: boolean): Promise<{
6
12
  token: string;
7
13
  route?: string;
8
14
  }[]>;
File without changes
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Lookup settings and replace glob pattern by the resolved providers
3
+ *
4
+ * @param settings
5
+ */
6
+ export declare function importProviders(settings: Partial<TsED.Configuration>): Promise<Partial<TsED.Configuration>>;
@@ -1,5 +1,9 @@
1
- export * from "./importFiles";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./cleanGlobPatterns";
2
5
  export * from "./importComponents";
6
+ export * from "./importFiles";
3
7
  export * from "./importProviders";
4
- export * from "./cleanGlobPatterns";
8
+ export * from "./isTsEnv";
5
9
  export * from "./normalizePath";
@@ -0,0 +1 @@
1
+ export declare function isTsEnv(): string | boolean;
package/package.json CHANGED
@@ -1,40 +1,41 @@
1
1
  {
2
2
  "name": "@tsed/components-scan",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0-beta.11",
4
4
  "description": "Components scan utilities for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/index.js",
8
- "typings": "./lib/index.d.ts",
7
+ "main": "./lib/cjs/index.js",
8
+ "module": "./lib/esm/index.js",
9
+ "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
11
+ "types": "./lib/types/index.d.ts",
12
+ "import": "./lib/esm/index.js",
13
+ "require": "./lib/cjs/index.js",
14
+ "default": "./lib/esm/index.js"
12
15
  },
13
16
  "scripts": {
14
- "build": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json",
17
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
+ "build:cjs": "tsc --build tsconfig.compile.json",
19
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
15
21
  "test": "cross-env NODE_ENV=test jest"
16
22
  },
17
23
  "dependencies": {
18
- "@tsed/core": "7.0.0-alpha.2",
19
- "@tsed/di": "7.0.0-alpha.2",
20
24
  "globby": "11.0.3",
21
25
  "normalize-path": "3.0.0",
22
- "tslib": "2.2.0"
26
+ "tslib": "2.3.1"
23
27
  },
24
28
  "devDependencies": {
25
- "@tsed/logger": "^5.16.0"
26
- },
27
- "peerDependencies": {
28
- "@tsed/logger": "^5.16.0"
29
+ "@tsed/core": "7.0.0-beta.11",
30
+ "@tsed/di": "7.0.0-beta.11",
31
+ "@types/normalize-path": "^3.0.0"
29
32
  },
33
+ "peerDependencies": {},
30
34
  "repository": "https://github.com/tsedio/tsed",
31
35
  "bugs": {
32
36
  "url": "https://github.com/tsedio/tsed/issues"
33
37
  },
34
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/utils/components-scan",
38
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/components-scan",
35
39
  "author": "Romain Lenzotti",
36
- "license": "MIT",
37
- "publishConfig": {
38
- "tag": "alpha"
39
- }
40
+ "license": "MIT"
40
41
  }
package/readme.md CHANGED
@@ -35,14 +35,12 @@ A package of Ts.ED framework. See website: https://tsed.io/
35
35
  npm install --save @tsed/components-scan
36
36
  ```
37
37
 
38
-
39
38
  ## Backers
40
39
 
41
40
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
42
41
 
43
42
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
44
43
 
45
-
46
44
  ## Sponsors
47
45
 
48
46
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "./",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
12
+ }
@@ -1,10 +0,0 @@
1
- /**
2
- * Import providers from given patterns.
3
- *
4
- * @param settings
5
- * @param properties
6
- */
7
- export declare function importProviders(settings: Partial<TsED.Configuration>, properties?: string[]): Promise<{
8
- token: string;
9
- route?: string;
10
- }[]>;