@venizia/ignis-boot 0.5.0-1 → 0.5.0-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 (37) hide show
  1. package/dist/esm/build-info/resolver.js +3 -3
  2. package/dist/esm/build-info/resolver.js.map +1 -1
  3. package/dist/esm/bun/auto-group.d.ts +1 -1
  4. package/dist/esm/bun/auto-group.js +8 -8
  5. package/dist/esm/bun/auto-group.js.map +1 -1
  6. package/dist/esm/bun/auto-loader.js +7 -0
  7. package/dist/esm/bun/auto-loader.js.map +1 -1
  8. package/dist/esm/bun/group-resolver.js +12 -2
  9. package/dist/esm/bun/group-resolver.js.map +1 -1
  10. package/dist/esm/bun/plugin.d.ts +1 -1
  11. package/dist/esm/bun/plugin.js +39 -32
  12. package/dist/esm/bun/plugin.js.map +1 -1
  13. package/dist/esm/bun/scan-cache.js +2 -2
  14. package/dist/esm/bun/scan-cache.js.map +1 -1
  15. package/dist/esm/clis/artifacts.js +15 -5
  16. package/dist/esm/clis/artifacts.js.map +1 -1
  17. package/dist/esm/clis/write-line.d.ts +9 -0
  18. package/dist/esm/clis/write-line.js +29 -0
  19. package/dist/esm/clis/write-line.js.map +1 -0
  20. package/dist/esm/common/quiet-logger.d.ts +1 -1
  21. package/dist/esm/common/quiet-logger.js +1 -1
  22. package/dist/esm/common/quiet-logger.js.map +1 -1
  23. package/dist/esm/generator/common/constants.d.ts +22 -9
  24. package/dist/esm/generator/common/constants.js +28 -30
  25. package/dist/esm/generator/common/constants.js.map +1 -1
  26. package/dist/esm/generator/common/types.d.ts +9 -4
  27. package/dist/esm/generator/common/types.js.map +1 -1
  28. package/dist/esm/generator/emitter.d.ts +4 -0
  29. package/dist/esm/generator/emitter.js +23 -0
  30. package/dist/esm/generator/emitter.js.map +1 -1
  31. package/dist/esm/generator/reexport.d.ts +33 -1
  32. package/dist/esm/generator/reexport.js +135 -5
  33. package/dist/esm/generator/reexport.js.map +1 -1
  34. package/dist/esm/generator/scanner.d.ts +5 -0
  35. package/dist/esm/generator/scanner.js +73 -10
  36. package/dist/esm/generator/scanner.js.map +1 -1
  37. package/package.json +9 -9
@@ -1,4 +1,11 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers';
2
+ import ts from 'typescript';
3
+ /** What `ArtifactTypes.define` stands for in a scan: its type, or why the scanner cannot read it. */
4
+ export type TDefinedType = {
5
+ type: string;
6
+ } | {
7
+ unreadable: string;
8
+ };
2
9
  /** Follows a named import through `export *` and renaming re-exports until it reaches a source module, so a framework that re-exports the kernel's decorators is recognised. Reads declarations only; never builds a type-checked program. */
3
10
  export declare class StereotypeReexportResolver extends BaseHelper {
4
11
  static readonly MAX_DEPTH = 10;
@@ -8,6 +15,7 @@ export declare class StereotypeReexportResolver extends BaseHelper {
8
15
  private readonly resolutions;
9
16
  private readonly sources;
10
17
  private readonly origins;
18
+ private readonly customTypes;
11
19
  constructor(opts: {
12
20
  root: string;
13
21
  sourceModules: Set<string>;
@@ -20,9 +28,33 @@ export declare class StereotypeReexportResolver extends BaseHelper {
20
28
  specifier: string;
21
29
  name: string;
22
30
  }): string | undefined;
31
+ /**
32
+ * What an application's own decorator stands for: `name`, exported by `specifier` as seen from `fromFile`, is followed
33
+ * through re-exports to `const name = ArtifactTypes.define({ type: '<literal>', ... })`. `undefined` when the chain ends
34
+ * anywhere else (a built-in stereotype, a function that is not a `define`); `unreadable` when it ends at something that
35
+ * looks like a `define` the scanner cannot read.
36
+ */
37
+ customTypeOf(opts: {
38
+ fromFile: string;
39
+ specifier: string;
40
+ name: string;
41
+ }): TDefinedType | undefined;
42
+ /** What `name` is among the top-level statements of `source`: a readable `ArtifactTypes.define`, one the scanner cannot read, or neither (`undefined`). */
43
+ definedTypeIn(opts: {
44
+ source: ts.SourceFile;
45
+ name: string;
46
+ }): TDefinedType | undefined;
47
+ /** `<something>.ArtifactTypes.define(...)` or `ArtifactTypes.define(...)` by shape alone, whatever `ArtifactTypes` is bound to. */
48
+ private isDefineCall;
49
+ /** The name `local` has in the module it is imported from (`import { ArtifactTypes as AT }` answers `ArtifactTypes` for `AT`). */
50
+ private importedNameOf;
51
+ /** `ArtifactTypes.define(...)` where `ArtifactTypes` is imported from a source module in this file. */
52
+ private isArtifactTypesDefine;
53
+ private literalTypeOf;
23
54
  private resolveFile;
24
55
  private parse;
25
56
  private isSourceModule;
26
- private follow;
57
+ /** The chain behind an import: a source-module name (a `string`) or, with `declaredIn`, what the declaring file says. */
58
+ private walk;
27
59
  }
28
60
  //# sourceMappingURL=reexport.d.ts.map
@@ -12,6 +12,7 @@ export class StereotypeReexportResolver extends BaseHelper {
12
12
  this.resolutions = new Map();
13
13
  this.sources = new Map();
14
14
  this.origins = new Map();
15
+ this.customTypes = new Map();
15
16
  this.sourceModules = opts.sourceModules;
16
17
  this.options = StereotypeReexportResolver.compilerOptionsFor({ root: opts.root });
17
18
  }
@@ -33,10 +34,134 @@ export class StereotypeReexportResolver extends BaseHelper {
33
34
  originOf(opts) {
34
35
  const key = `${dirname(opts.fromFile)}|${opts.specifier}|${opts.name}`;
35
36
  if (!this.origins.has(key)) {
36
- this.origins.set(key, this.follow({ ...opts, depth: 0, seen: new Set() }));
37
+ const found = this.walk({ ...opts, depth: 0, seen: new Set() });
38
+ this.origins.set(key, typeof found === 'string' ? found : undefined);
37
39
  }
38
40
  return this.origins.get(key);
39
41
  }
42
+ /**
43
+ * What an application's own decorator stands for: `name`, exported by `specifier` as seen from `fromFile`, is followed
44
+ * through re-exports to `const name = ArtifactTypes.define({ type: '<literal>', ... })`. `undefined` when the chain ends
45
+ * anywhere else (a built-in stereotype, a function that is not a `define`); `unreadable` when it ends at something that
46
+ * looks like a `define` the scanner cannot read.
47
+ */
48
+ customTypeOf(opts) {
49
+ const key = `${dirname(opts.fromFile)}|${opts.specifier}|${opts.name}`;
50
+ if (!this.customTypes.has(key)) {
51
+ const found = this.walk({
52
+ ...opts,
53
+ depth: 0,
54
+ seen: new Set(),
55
+ declaredIn: (declared) => this.definedTypeIn(declared),
56
+ });
57
+ this.customTypes.set(key, typeof found === 'object' ? found : undefined);
58
+ }
59
+ return this.customTypes.get(key);
60
+ }
61
+ /** What `name` is among the top-level statements of `source`: a readable `ArtifactTypes.define`, one the scanner cannot read, or neither (`undefined`). */
62
+ definedTypeIn(opts) {
63
+ const { source, name } = opts;
64
+ for (const statement of source.statements) {
65
+ if (!ts.isVariableStatement(statement)) {
66
+ continue;
67
+ }
68
+ for (const declaration of statement.declarationList.declarations) {
69
+ if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name) {
70
+ continue;
71
+ }
72
+ const call = declaration.initializer;
73
+ // A .d.ts carries no call. Only a declaration typed as what `define` returns (a decorator taking the registration options) is one.
74
+ if (!call &&
75
+ source.isDeclarationFile &&
76
+ declaration.type?.getText(source).includes('IArtifactRegistrationOptions')) {
77
+ return {
78
+ unreadable: 'it is declared in a built package (a .d.ts carries no define call) | scan the package source, or list the classes by hand',
79
+ };
80
+ }
81
+ if (!call || !ts.isCallExpression(call) || !this.isDefineCall({ source, call })) {
82
+ continue;
83
+ }
84
+ if (!this.isArtifactTypesDefine({ source, call })) {
85
+ return {
86
+ unreadable: 'ArtifactTypes is not imported by name from @venizia/ignis or @venizia/ignis-kernel in that file (a barrel, a namespace import or an alias of your own)',
87
+ };
88
+ }
89
+ const type = this.literalTypeOf({ call });
90
+ return type === undefined ? { unreadable: "its 'type' is not a string literal" } : { type };
91
+ }
92
+ }
93
+ return undefined;
94
+ }
95
+ /** `<something>.ArtifactTypes.define(...)` or `ArtifactTypes.define(...)` by shape alone, whatever `ArtifactTypes` is bound to. */
96
+ isDefineCall(opts) {
97
+ const { source, call } = opts;
98
+ const callee = call.expression;
99
+ if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'define') {
100
+ return false;
101
+ }
102
+ const receiver = callee.expression;
103
+ if (ts.isPropertyAccessExpression(receiver)) {
104
+ return receiver.name.text === 'ArtifactTypes';
105
+ }
106
+ return (ts.isIdentifier(receiver) &&
107
+ (receiver.text === 'ArtifactTypes' ||
108
+ this.importedNameOf({ source, local: receiver.text }) === 'ArtifactTypes'));
109
+ }
110
+ /** The name `local` has in the module it is imported from (`import { ArtifactTypes as AT }` answers `ArtifactTypes` for `AT`). */
111
+ importedNameOf(opts) {
112
+ for (const statement of opts.source.statements) {
113
+ const bindings = ts.isImportDeclaration(statement)
114
+ ? statement.importClause?.namedBindings
115
+ : undefined;
116
+ if (!bindings || !ts.isNamedImports(bindings)) {
117
+ continue;
118
+ }
119
+ const element = bindings.elements.find((entry) => entry.name.text === opts.local);
120
+ if (element) {
121
+ return (element.propertyName ?? element.name).text;
122
+ }
123
+ }
124
+ return undefined;
125
+ }
126
+ /** `ArtifactTypes.define(...)` where `ArtifactTypes` is imported from a source module in this file. */
127
+ isArtifactTypesDefine(opts) {
128
+ const { source, call } = opts;
129
+ const callee = call.expression;
130
+ if (!ts.isPropertyAccessExpression(callee) ||
131
+ callee.name.text !== 'define' ||
132
+ !ts.isIdentifier(callee.expression)) {
133
+ return false;
134
+ }
135
+ const local = callee.expression.text;
136
+ return source.statements.some((statement) => {
137
+ if (!ts.isImportDeclaration(statement) ||
138
+ !ts.isStringLiteral(statement.moduleSpecifier) ||
139
+ !this.isSourceModule({ specifier: statement.moduleSpecifier.text })) {
140
+ return false;
141
+ }
142
+ const bindings = statement.importClause?.namedBindings;
143
+ return (!!bindings &&
144
+ ts.isNamedImports(bindings) &&
145
+ bindings.elements.some((element) => element.name.text === local &&
146
+ (element.propertyName ?? element.name).text === 'ArtifactTypes'));
147
+ });
148
+ }
149
+ literalTypeOf(opts) {
150
+ const [argument] = opts.call.arguments;
151
+ if (!argument || !ts.isObjectLiteralExpression(argument)) {
152
+ return undefined;
153
+ }
154
+ for (const entry of argument.properties) {
155
+ if (ts.isPropertyAssignment(entry) &&
156
+ ts.isIdentifier(entry.name) &&
157
+ entry.name.text === 'type' &&
158
+ (ts.isStringLiteral(entry.initializer) ||
159
+ ts.isNoSubstitutionTemplateLiteral(entry.initializer))) {
160
+ return entry.initializer.text;
161
+ }
162
+ }
163
+ return undefined;
164
+ }
40
165
  resolveFile(opts) {
41
166
  const key = `${dirname(opts.fromFile)}|${opts.specifier}`;
42
167
  if (!this.resolutions.has(key)) {
@@ -57,10 +182,11 @@ export class StereotypeReexportResolver extends BaseHelper {
57
182
  return (ArtifactStereotypes.SOURCE_MODULES.test(opts.specifier) ||
58
183
  this.sourceModules.has(opts.specifier));
59
184
  }
60
- follow(opts) {
61
- const { fromFile, specifier, name, depth, seen } = opts;
185
+ /** The chain behind an import: a source-module name (a `string`) or, with `declaredIn`, what the declaring file says. */
186
+ walk(opts) {
187
+ const { fromFile, specifier, name, depth, seen, declaredIn } = opts;
62
188
  if (this.isSourceModule({ specifier })) {
63
- return name;
189
+ return declaredIn ? undefined : name;
64
190
  }
65
191
  if (depth >= StereotypeReexportResolver.MAX_DEPTH) {
66
192
  return undefined;
@@ -72,7 +198,11 @@ export class StereotypeReexportResolver extends BaseHelper {
72
198
  }
73
199
  seen.add(visit);
74
200
  const source = this.parse({ file: resolved });
75
- const next = (target) => this.follow({ fromFile: resolved, ...target, depth: depth + 1, seen });
201
+ const declared = declaredIn?.({ source, name });
202
+ if (declared !== undefined) {
203
+ return declared;
204
+ }
205
+ const next = (target) => this.walk({ fromFile: resolved, ...target, depth: depth + 1, seen, declaredIn });
76
206
  const importedBy = new Map();
77
207
  for (const statement of source.statements) {
78
208
  if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
@@ -1 +1 @@
1
- {"version":3,"file":"reexport.js","sourceRoot":"","sources":["../../../src/generator/reexport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,M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C,SAAS,CAAC;YAEhB,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;gBAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAEpF,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAED,SAAS;YACX,CAAC;YAED,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/C,SAAS;YACX,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;gBACtD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBAED,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;gBAE7D,IAAI,aAAa,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC5D,CAAC;gBAED,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAE1C,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { BaseHelper } from '@venizia/ignis-helpers';\nimport { readFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport ts from 'typescript';\nimport { ArtifactStereotypes } from './common';\n\n/** Follows a named import through `export *` and renaming re-exports until it reaches a source module, so a framework that re-exports the kernel's decorators is recognised. Reads declarations only; never builds a type-checked program. */\nexport class StereotypeReexportResolver extends BaseHelper {\n static readonly MAX_DEPTH = 10;\n\n private readonly options: ts.CompilerOptions;\n private readonly sourceModules: Set<string>;\n /** One scan reads the same barrels many times: resolutions, parsed files and answers are memoized per resolver. */\n private readonly resolutions = new Map<string, string | undefined>();\n private readonly sources = new Map<string, ts.SourceFile>();\n private readonly origins = new Map<string, string | undefined>();\n\n constructor(opts: { root: string; sourceModules: Set<string> }) {\n super({ scope: StereotypeReexportResolver.name });\n this.sourceModules = opts.sourceModules;\n this.options = StereotypeReexportResolver.compilerOptionsFor({ root: opts.root });\n }\n\n /** The nearest tsconfig's options (for `paths` aliases), with bundler resolution as the fallback. */\n private static compilerOptionsFor(opts: { root: string }): ts.CompilerOptions {\n const configPath = ts.findConfigFile(opts.root, ts.sys.fileExists);\n const fallback: ts.CompilerOptions = {\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n allowJs: true,\n };\n\n if (!configPath) {\n return fallback;\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n ts.readConfigFile(configPath, ts.sys.readFile).config,\n ts.sys,\n dirname(configPath),\n );\n\n return { ...fallback, ...parsed.options };\n }\n\n /** The kernel name `name` (exported by `specifier`, as seen from `fromFile`) originates as, or `undefined` when the chain never reaches a source module. */\n originOf(opts: { fromFile: string; specifier: string; name: string }): string | undefined {\n const key = `${dirname(opts.fromFile)}|${opts.specifier}|${opts.name}`;\n\n if (!this.origins.has(key)) {\n this.origins.set(key, this.follow({ ...opts, depth: 0, seen: new Set<string>() }));\n }\n\n return this.origins.get(key);\n }\n\n private resolveFile(opts: { fromFile: string; specifier: string }): string | undefined {\n const key = `${dirname(opts.fromFile)}|${opts.specifier}`;\n\n if (!this.resolutions.has(key)) {\n this.resolutions.set(\n key,\n ts.resolveModuleName(opts.specifier, opts.fromFile, this.options, ts.sys).resolvedModule\n ?.resolvedFileName,\n );\n }\n\n return this.resolutions.get(key);\n }\n\n private parse(opts: { file: string }): ts.SourceFile {\n let source = this.sources.get(opts.file);\n\n if (!source) {\n source = ts.createSourceFile(\n opts.file,\n readFileSync(opts.file, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n );\n this.sources.set(opts.file, source);\n }\n\n return source;\n }\n\n private isSourceModule(opts: { specifier: string }): boolean {\n return (\n ArtifactStereotypes.SOURCE_MODULES.test(opts.specifier) ||\n this.sourceModules.has(opts.specifier)\n );\n }\n\n private follow(opts: {\n fromFile: string;\n specifier: string;\n name: string;\n depth: number;\n seen: Set<string>;\n }): string | undefined {\n const { fromFile, specifier, name, depth, seen } = opts;\n\n if (this.isSourceModule({ specifier })) {\n return name;\n }\n\n if (depth >= StereotypeReexportResolver.MAX_DEPTH) {\n return undefined;\n }\n\n const resolved = this.resolveFile({ fromFile, specifier });\n const visit = `${resolved}#${name}`;\n\n if (!resolved || seen.has(visit)) {\n return undefined;\n }\n\n seen.add(visit);\n\n const source = this.parse({ file: resolved });\n const next = (target: { specifier: string; name: string }): string | undefined =>\n this.follow({ fromFile: resolved, ...target, depth: depth + 1, seen });\n\n const importedBy = new Map<string, { specifier: string; name: string }>();\n\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n importedBy.set(element.name.text, {\n specifier: statement.moduleSpecifier.text,\n name: (element.propertyName ?? element.name).text,\n });\n }\n }\n\n for (const statement of source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) {\n continue;\n }\n\n const fromSpecifier =\n statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)\n ? statement.moduleSpecifier.text\n : undefined;\n\n if (!statement.exportClause) {\n const origin = fromSpecifier ? next({ specifier: fromSpecifier, name }) : undefined;\n\n if (origin) {\n return origin;\n }\n\n continue;\n }\n\n if (!ts.isNamedExports(statement.exportClause)) {\n continue;\n }\n\n for (const element of statement.exportClause.elements) {\n if (element.name.text !== name) {\n continue;\n }\n\n const original = (element.propertyName ?? element.name).text;\n\n if (fromSpecifier) {\n return next({ specifier: fromSpecifier, name: original });\n }\n\n const imported = importedBy.get(original);\n\n return imported ? next(imported) : undefined;\n }\n }\n\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"reexport.js","sourceRoot":"","sources":["../../../src/generator/reexport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAK/C,8OAA8O;AAC9O,MAAM,OAAO,0BAA2B,SAAQ,UAAU;aACxC,cAAS,GAAG,EAAE,AAAL,CAAM;IAU/B,YAAY,IAAkD;QAC5D,KAAK,CAAC,EAAE,KAAK,EAAE,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC;QAPpD,mHAAmH;QAClG,gBAAW,GAAG,IAAI,GAAG,EAA8B,CAAC;QACpD,YAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC3C,YAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;QAChD,gBAAW,GAAG,IAAI,GAAG,EAAoC,CAAC;QAIzE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,0BAA0B,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,qGAAqG;IAC7F,MAAM,CAAC,kBAAkB,CAAC,IAAsB;QACtD,MAAM,UAAU,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAA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AC,SAAS,CAAC,eAAe,CAAC;gBACxE,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI;gBAChC,CAAC,CAAC,SAAS,CAAC;YAEhB,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;gBAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAEpF,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAED,SAAS;YACX,CAAC;YAED,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/C,SAAS;YACX,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;gBACtD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBAED,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;gBAE7D,IAAI,aAAa,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC5D,CAAC;gBAED,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAE1C,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { BaseHelper } from '@venizia/ignis-helpers';\nimport { readFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport ts from 'typescript';\nimport { ArtifactStereotypes } from './common';\n\n/** What `ArtifactTypes.define` stands for in a scan: its type, or why the scanner cannot read it. */\nexport type TDefinedType = { type: string } | { unreadable: string };\n\n/** Follows a named import through `export *` and renaming re-exports until it reaches a source module, so a framework that re-exports the kernel's decorators is recognised. Reads declarations only; never builds a type-checked program. */\nexport class StereotypeReexportResolver extends BaseHelper {\n static readonly MAX_DEPTH = 10;\n\n private readonly options: ts.CompilerOptions;\n private readonly sourceModules: Set<string>;\n /** One scan reads the same barrels many times: resolutions, parsed files and answers are memoized per resolver. */\n private readonly resolutions = new Map<string, string | undefined>();\n private readonly sources = new Map<string, ts.SourceFile>();\n private readonly origins = new Map<string, string | undefined>();\n private readonly customTypes = new Map<string, TDefinedType | undefined>();\n\n constructor(opts: { root: string; sourceModules: Set<string> }) {\n super({ scope: StereotypeReexportResolver.name });\n this.sourceModules = opts.sourceModules;\n this.options = StereotypeReexportResolver.compilerOptionsFor({ root: opts.root });\n }\n\n /** The nearest tsconfig's options (for `paths` aliases), with bundler resolution as the fallback. */\n private static compilerOptionsFor(opts: { root: string }): ts.CompilerOptions {\n const configPath = ts.findConfigFile(opts.root, ts.sys.fileExists);\n const fallback: ts.CompilerOptions = {\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n allowJs: true,\n };\n\n if (!configPath) {\n return fallback;\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n ts.readConfigFile(configPath, ts.sys.readFile).config,\n ts.sys,\n dirname(configPath),\n );\n\n return { ...fallback, ...parsed.options };\n }\n\n /** The kernel name `name` (exported by `specifier`, as seen from `fromFile`) originates as, or `undefined` when the chain never reaches a source module. */\n originOf(opts: { fromFile: string; specifier: string; name: string }): string | undefined {\n const key = `${dirname(opts.fromFile)}|${opts.specifier}|${opts.name}`;\n\n if (!this.origins.has(key)) {\n const found = this.walk({ ...opts, depth: 0, seen: new Set<string>() });\n this.origins.set(key, typeof found === 'string' ? found : undefined);\n }\n\n return this.origins.get(key);\n }\n\n /**\n * What an application's own decorator stands for: `name`, exported by `specifier` as seen from `fromFile`, is followed\n * through re-exports to `const name = ArtifactTypes.define({ type: '<literal>', ... })`. `undefined` when the chain ends\n * anywhere else (a built-in stereotype, a function that is not a `define`); `unreadable` when it ends at something that\n * looks like a `define` the scanner cannot read.\n */\n customTypeOf(opts: {\n fromFile: string;\n specifier: string;\n name: string;\n }): TDefinedType | undefined {\n const key = `${dirname(opts.fromFile)}|${opts.specifier}|${opts.name}`;\n\n if (!this.customTypes.has(key)) {\n const found = this.walk({\n ...opts,\n depth: 0,\n seen: new Set<string>(),\n declaredIn: (declared) => this.definedTypeIn(declared),\n });\n this.customTypes.set(key, typeof found === 'object' ? found : undefined);\n }\n\n return this.customTypes.get(key);\n }\n\n /** What `name` is among the top-level statements of `source`: a readable `ArtifactTypes.define`, one the scanner cannot read, or neither (`undefined`). */\n definedTypeIn(opts: { source: ts.SourceFile; name: string }): TDefinedType | undefined {\n const { source, name } = opts;\n\n for (const statement of source.statements) {\n if (!ts.isVariableStatement(statement)) {\n continue;\n }\n\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name) {\n continue;\n }\n\n const call = declaration.initializer;\n\n // A .d.ts carries no call. Only a declaration typed as what `define` returns (a decorator taking the registration options) is one.\n if (\n !call &&\n source.isDeclarationFile &&\n declaration.type?.getText(source).includes('IArtifactRegistrationOptions')\n ) {\n return {\n unreadable:\n 'it is declared in a built package (a .d.ts carries no define call) | scan the package source, or list the classes by hand',\n };\n }\n\n if (!call || !ts.isCallExpression(call) || !this.isDefineCall({ source, call })) {\n continue;\n }\n\n if (!this.isArtifactTypesDefine({ source, call })) {\n return {\n unreadable:\n 'ArtifactTypes is not imported by name from @venizia/ignis or @venizia/ignis-kernel in that file (a barrel, a namespace import or an alias of your own)',\n };\n }\n\n const type = this.literalTypeOf({ call });\n\n return type === undefined ? { unreadable: \"its 'type' is not a string literal\" } : { type };\n }\n }\n\n return undefined;\n }\n\n /** `<something>.ArtifactTypes.define(...)` or `ArtifactTypes.define(...)` by shape alone, whatever `ArtifactTypes` is bound to. */\n private isDefineCall(opts: { source: ts.SourceFile; call: ts.CallExpression }): boolean {\n const { source, call } = opts;\n const callee = call.expression;\n\n if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'define') {\n return false;\n }\n\n const receiver = callee.expression;\n\n if (ts.isPropertyAccessExpression(receiver)) {\n return receiver.name.text === 'ArtifactTypes';\n }\n\n return (\n ts.isIdentifier(receiver) &&\n (receiver.text === 'ArtifactTypes' ||\n this.importedNameOf({ source, local: receiver.text }) === 'ArtifactTypes')\n );\n }\n\n /** The name `local` has in the module it is imported from (`import { ArtifactTypes as AT }` answers `ArtifactTypes` for `AT`). */\n private importedNameOf(opts: { source: ts.SourceFile; local: string }): string | undefined {\n for (const statement of opts.source.statements) {\n const bindings = ts.isImportDeclaration(statement)\n ? statement.importClause?.namedBindings\n : undefined;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n const element = bindings.elements.find((entry) => entry.name.text === opts.local);\n\n if (element) {\n return (element.propertyName ?? element.name).text;\n }\n }\n\n return undefined;\n }\n\n /** `ArtifactTypes.define(...)` where `ArtifactTypes` is imported from a source module in this file. */\n private isArtifactTypesDefine(opts: { source: ts.SourceFile; call: ts.CallExpression }): boolean {\n const { source, call } = opts;\n const callee = call.expression;\n\n if (\n !ts.isPropertyAccessExpression(callee) ||\n callee.name.text !== 'define' ||\n !ts.isIdentifier(callee.expression)\n ) {\n return false;\n }\n\n const local = callee.expression.text;\n\n return source.statements.some((statement) => {\n if (\n !ts.isImportDeclaration(statement) ||\n !ts.isStringLiteral(statement.moduleSpecifier) ||\n !this.isSourceModule({ specifier: statement.moduleSpecifier.text })\n ) {\n return false;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n return (\n !!bindings &&\n ts.isNamedImports(bindings) &&\n bindings.elements.some(\n (element) =>\n element.name.text === local &&\n (element.propertyName ?? element.name).text === 'ArtifactTypes',\n )\n );\n });\n }\n\n private literalTypeOf(opts: { call: ts.CallExpression }): string | undefined {\n const [argument] = opts.call.arguments;\n\n if (!argument || !ts.isObjectLiteralExpression(argument)) {\n return undefined;\n }\n\n for (const entry of argument.properties) {\n if (\n ts.isPropertyAssignment(entry) &&\n ts.isIdentifier(entry.name) &&\n entry.name.text === 'type' &&\n (ts.isStringLiteral(entry.initializer) ||\n ts.isNoSubstitutionTemplateLiteral(entry.initializer))\n ) {\n return entry.initializer.text;\n }\n }\n\n return undefined;\n }\n\n private resolveFile(opts: { fromFile: string; specifier: string }): string | undefined {\n const key = `${dirname(opts.fromFile)}|${opts.specifier}`;\n\n if (!this.resolutions.has(key)) {\n this.resolutions.set(\n key,\n ts.resolveModuleName(opts.specifier, opts.fromFile, this.options, ts.sys).resolvedModule\n ?.resolvedFileName,\n );\n }\n\n return this.resolutions.get(key);\n }\n\n private parse(opts: { file: string }): ts.SourceFile {\n let source = this.sources.get(opts.file);\n\n if (!source) {\n source = ts.createSourceFile(\n opts.file,\n readFileSync(opts.file, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n );\n this.sources.set(opts.file, source);\n }\n\n return source;\n }\n\n private isSourceModule(opts: { specifier: string }): boolean {\n return (\n ArtifactStereotypes.SOURCE_MODULES.test(opts.specifier) ||\n this.sourceModules.has(opts.specifier)\n );\n }\n\n /** The chain behind an import: a source-module name (a `string`) or, with `declaredIn`, what the declaring file says. */\n private walk(opts: {\n fromFile: string;\n specifier: string;\n name: string;\n depth: number;\n seen: Set<string>;\n /** Reads what a file declares itself under `name`; set, the chain ends at a declaration, and a source module ends it with no answer. */\n declaredIn?: (opts: { source: ts.SourceFile; name: string }) => TDefinedType | undefined;\n }): string | TDefinedType | undefined {\n const { fromFile, specifier, name, depth, seen, declaredIn } = opts;\n\n if (this.isSourceModule({ specifier })) {\n return declaredIn ? undefined : name;\n }\n\n if (depth >= StereotypeReexportResolver.MAX_DEPTH) {\n return undefined;\n }\n\n const resolved = this.resolveFile({ fromFile, specifier });\n const visit = `${resolved}#${name}`;\n\n if (!resolved || seen.has(visit)) {\n return undefined;\n }\n\n seen.add(visit);\n\n const source = this.parse({ file: resolved });\n const declared = declaredIn?.({ source, name });\n\n if (declared !== undefined) {\n return declared;\n }\n\n const next = (target: { specifier: string; name: string }): string | TDefinedType | undefined =>\n this.walk({ fromFile: resolved, ...target, depth: depth + 1, seen, declaredIn });\n\n const importedBy = new Map<string, { specifier: string; name: string }>();\n\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n importedBy.set(element.name.text, {\n specifier: statement.moduleSpecifier.text,\n name: (element.propertyName ?? element.name).text,\n });\n }\n }\n\n for (const statement of source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) {\n continue;\n }\n\n const fromSpecifier =\n statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)\n ? statement.moduleSpecifier.text\n : undefined;\n\n if (!statement.exportClause) {\n const origin = fromSpecifier ? next({ specifier: fromSpecifier, name }) : undefined;\n\n if (origin) {\n return origin;\n }\n\n continue;\n }\n\n if (!ts.isNamedExports(statement.exportClause)) {\n continue;\n }\n\n for (const element of statement.exportClause.elements) {\n if (element.name.text !== name) {\n continue;\n }\n\n const original = (element.propertyName ?? element.name).text;\n\n if (fromSpecifier) {\n return next({ specifier: fromSpecifier, name: original });\n }\n\n const imported = importedBy.get(original);\n\n return imported ? next(imported) : undefined;\n }\n }\n\n return undefined;\n }\n}\n"]}
@@ -18,6 +18,11 @@ export declare class ArtifactScanner extends BaseHelper {
18
18
  private collectStereotypeImports;
19
19
  /** The identifiers called as decorators on the file's top-level classes (`@service()`, `@kit.service()` is not followed). */
20
20
  private collectClassDecoratorNames;
21
+ /**
22
+ * local identifier -> type, for the decorators this file's classes wear that an application defined with
23
+ * `ArtifactTypes.define`: declared in this file, or imported from a module whose chain of exports reaches the declaration.
24
+ */
25
+ private collectCustomDecorators;
21
26
  private collectExportClauseNames;
22
27
  private artifactTypesOf;
23
28
  private typeOfInjectableCall;
@@ -24,12 +24,12 @@ export class ArtifactScanner extends BaseHelper {
24
24
  userGlobs: opts.ignore ?? [],
25
25
  });
26
26
  const sourceModules = new Set(opts.sourceModules);
27
- const resolver = opts.followReexports
28
- ? new StereotypeReexportResolver({ root, sourceModules })
29
- : undefined;
27
+ // One resolver for both jobs: following re-exports to a stereotype is optional, finding the decorators an application defined is not.
28
+ const reader = new StereotypeReexportResolver({ root, sourceModules });
29
+ const resolver = opts.followReexports ? reader : undefined;
30
30
  const skipped = [];
31
- const artifacts = this.sortArtifacts(kept.flatMap((filePath) => this.scanFile({ filePath, sourceModules, resolver, skipped })));
32
- const ignored = this.sortArtifacts(hidden.flatMap((filePath) => this.scanHiddenFile({ filePath, sourceModules, resolver })));
31
+ const artifacts = this.sortArtifacts(kept.flatMap((filePath) => this.scanFile({ filePath, sourceModules, resolver, reader, skipped })));
32
+ const ignored = this.sortArtifacts(hidden.flatMap((filePath) => this.scanHiddenFile({ filePath, sourceModules, resolver, reader })));
33
33
  for (const artifact of ignored) {
34
34
  skipped.push({
35
35
  className: artifact.className,
@@ -71,14 +71,19 @@ export class ArtifactScanner extends BaseHelper {
71
71
  return { kept: kept.sort(), hidden: hidden.sort() };
72
72
  }
73
73
  scanFile(opts) {
74
- const { filePath, sourceModules, resolver, skipped, isHidden = false } = opts;
74
+ const { filePath, sourceModules, resolver, reader, skipped, isHidden = false } = opts;
75
75
  const source = ts.createSourceFile(filePath, readFileSync(filePath, 'utf8'), ts.ScriptTarget.Latest, true);
76
76
  const stereotypeByLocalName = this.collectStereotypeImports({
77
77
  source,
78
78
  sourceModules,
79
79
  resolver,
80
80
  });
81
- if (stereotypeByLocalName.size === 0) {
81
+ const customByLocalName = this.collectCustomDecorators({
82
+ source,
83
+ reader,
84
+ excluded: stereotypeByLocalName,
85
+ });
86
+ if (stereotypeByLocalName.size === 0 && customByLocalName.size === 0) {
82
87
  return [];
83
88
  }
84
89
  const exportedNames = this.collectExportClauseNames({ source });
@@ -88,12 +93,22 @@ export class ArtifactScanner extends BaseHelper {
88
93
  return;
89
94
  }
90
95
  const className = node.name.text;
91
- const types = this.artifactTypesOf({
96
+ const { types, unreadable } = this.artifactTypesOf({
92
97
  node,
93
98
  stereotypeByLocalName,
99
+ customByLocalName,
94
100
  filePath,
95
101
  className,
96
102
  });
103
+ if (types.length === 0 && unreadable.length > 0) {
104
+ if (!isHidden) {
105
+ skipped?.push({ className, filePath, reason: ScanSkipReasons.UNREADABLE_TYPE });
106
+ this.logger
107
+ .for('scanFile')
108
+ .warn('Skipped %s in %s | its decorator comes from an ArtifactTypes.define the scanner cannot read: %s', className, filePath, unreadable[0]);
109
+ }
110
+ return;
111
+ }
97
112
  if (types.length === 0) {
98
113
  return;
99
114
  }
@@ -180,6 +195,43 @@ export class ArtifactScanner extends BaseHelper {
180
195
  }
181
196
  return names;
182
197
  }
198
+ /**
199
+ * local identifier -> type, for the decorators this file's classes wear that an application defined with
200
+ * `ArtifactTypes.define`: declared in this file, or imported from a module whose chain of exports reaches the declaration.
201
+ */
202
+ collectCustomDecorators(opts) {
203
+ const { source, reader, excluded } = opts;
204
+ const result = new Map();
205
+ const imported = new Map();
206
+ for (const statement of source.statements) {
207
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
208
+ continue;
209
+ }
210
+ const bindings = statement.importClause?.namedBindings;
211
+ if (!bindings || !ts.isNamedImports(bindings)) {
212
+ continue;
213
+ }
214
+ for (const element of bindings.elements) {
215
+ imported.set(element.name.text, {
216
+ specifier: statement.moduleSpecifier.text,
217
+ name: (element.propertyName ?? element.name).text,
218
+ });
219
+ }
220
+ }
221
+ for (const local of this.collectClassDecoratorNames({ source })) {
222
+ if (excluded.has(local)) {
223
+ continue;
224
+ }
225
+ const origin = imported.get(local);
226
+ const type = origin
227
+ ? reader.customTypeOf({ fromFile: source.fileName, ...origin })
228
+ : reader.definedTypeIn({ source, name: local });
229
+ if (type) {
230
+ result.set(local, type);
231
+ }
232
+ }
233
+ return result;
234
+ }
183
235
  collectExportClauseNames(opts) {
184
236
  const names = new Set();
185
237
  for (const statement of opts.source.statements) {
@@ -194,14 +246,25 @@ export class ArtifactScanner extends BaseHelper {
194
246
  return names;
195
247
  }
196
248
  artifactTypesOf(opts) {
197
- const { node, stereotypeByLocalName, filePath, className } = opts;
249
+ const { node, stereotypeByLocalName, customByLocalName, filePath, className } = opts;
198
250
  const types = [];
251
+ const unreadable = [];
199
252
  const decorators = ts.getDecorators(node) ?? [];
200
253
  for (const decorator of decorators) {
201
254
  const expression = decorator.expression;
202
255
  if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression)) {
203
256
  continue;
204
257
  }
258
+ const custom = customByLocalName.get(expression.expression.text);
259
+ if (custom) {
260
+ if ('type' in custom) {
261
+ types.push(custom.type);
262
+ }
263
+ else {
264
+ unreadable.push(custom.unreadable);
265
+ }
266
+ continue;
267
+ }
205
268
  const stereotype = stereotypeByLocalName.get(expression.expression.text);
206
269
  if (!stereotype) {
207
270
  continue;
@@ -219,7 +282,7 @@ export class ArtifactScanner extends BaseHelper {
219
282
  }
220
283
  types.push(type);
221
284
  }
222
- return types;
285
+ return { types, unreadable };
223
286
  }
224
287
  typeOfInjectableCall(opts) {
225
288
  const [argument] = opts.call.arguments;
@@ -1 +1 @@
1
- {"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../src/generator/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,MAAM,YA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,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,cAAc,CAAC,IAAqB;QAC1C,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAErB,OAAO,mBAAmB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;aAC7D,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;aAC3B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers';\nimport { globSync, readFileSync } from 'node:fs';\nimport { join, matchesGlob, resolve } from 'node:path';\nimport ts from 'typescript';\nimport {\n ArtifactStereotypes,\n ArtifactTypes,\n ScanSkipReasons,\n type IScanOptions,\n type IScanReport,\n type IScanSkipped,\n type IScannedArtifact,\n type TArtifactType,\n} from './common';\nimport { StereotypeReexportResolver } from './reexport';\n\n/** Finds exported classes carrying a stereotype decorator by reading the source, never by running it. */\nexport class ArtifactScanner extends BaseHelper {\n private static instance?: ArtifactScanner;\n\n private constructor() {\n super({ scope: ArtifactScanner.name });\n }\n\n static getInstance(): ArtifactScanner {\n return (this.instance ??= new ArtifactScanner());\n }\n\n scan(opts: IScanOptions): IScannedArtifact[] {\n return this.scanWithReport(opts).artifacts;\n }\n\n /** `scan` plus the decorated classes a caller's own `ignore` pattern hid - the generator prints them so a stale pattern cannot drop an artifact in silence. */\n scanWithReport(opts: IScanOptions): IScanReport {\n const root = resolve(opts.root);\n const { kept, hidden } = this.partitionSourceFiles({\n root,\n defaultGlobs: ArtifactStereotypes.DEFAULT_IGNORE,\n userGlobs: opts.ignore ?? [],\n });\n const sourceModules = new Set(opts.sourceModules);\n const resolver = opts.followReexports\n ? new StereotypeReexportResolver({ root, sourceModules })\n : undefined;\n const skipped: IScanSkipped[] = [];\n\n const artifacts = this.sortArtifacts(\n kept.flatMap((filePath) => this.scanFile({ filePath, sourceModules, resolver, skipped })),\n );\n const ignored = this.sortArtifacts(\n hidden.flatMap((filePath) => this.scanHiddenFile({ filePath, sourceModules, resolver })),\n );\n\n for (const artifact of ignored) {\n skipped.push({\n className: artifact.className,\n filePath: artifact.filePath,\n reason: ScanSkipReasons.IGNORED,\n });\n }\n\n return { artifacts, ignored, skipped };\n }\n\n /** A hidden file is only reported on, never a reason to fail: a scan error becomes one warning and the file contributes nothing. */\n private scanHiddenFile(opts: {\n filePath: string;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n }): IScannedArtifact[] {\n try {\n return this.scanFile({ ...opts, isHidden: true });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.for('scanHiddenFile').warn('Skipped hidden file %s | %s', opts.filePath, reason);\n\n return [];\n }\n }\n\n private sortArtifacts(artifacts: IScannedArtifact[]): IScannedArtifact[] {\n return artifacts.sort(\n (a, b) => a.type.localeCompare(b.type) || a.className.localeCompare(b.className),\n );\n }\n\n /** `kept` feeds the index; `hidden` is what only a user pattern excluded (a default pattern wins, so tests and generated files are never reported). */\n private partitionSourceFiles(opts: {\n root: string;\n defaultGlobs: ReadonlyArray<string>;\n userGlobs: ReadonlyArray<string>;\n }): { kept: string[]; hidden: string[] } {\n const kept: string[] = [];\n const hidden: string[] = [];\n\n const sources = globSync(ArtifactStereotypes.SOURCE_GLOB, { cwd: opts.root });\n\n for (const relative of sources) {\n if (\n relative.endsWith('.d.ts') ||\n opts.defaultGlobs.some((pattern) => matchesGlob(relative, pattern))\n ) {\n continue;\n }\n\n const target = opts.userGlobs.some((pattern) => matchesGlob(relative, pattern))\n ? hidden\n : kept;\n target.push(join(opts.root, relative));\n }\n\n return { kept: kept.sort(), hidden: hidden.sort() };\n }\n\n private scanFile(opts: {\n filePath: string;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n skipped?: IScanSkipped[];\n isHidden?: boolean;\n }): IScannedArtifact[] {\n const { filePath, sourceModules, resolver, skipped, isHidden = false } = opts;\n const source = ts.createSourceFile(\n filePath,\n readFileSync(filePath, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n );\n\n const stereotypeByLocalName = this.collectStereotypeImports({\n source,\n sourceModules,\n resolver,\n });\n\n if (stereotypeByLocalName.size === 0) {\n return [];\n }\n\n const exportedNames = this.collectExportClauseNames({ source });\n const found: IScannedArtifact[] = [];\n\n ts.forEachChild(source, (node) => {\n if (!ts.isClassDeclaration(node) || !node.name) {\n return;\n }\n\n const className = node.name.text;\n const types = this.artifactTypesOf({\n node,\n stereotypeByLocalName,\n filePath,\n className,\n });\n\n if (types.length === 0) {\n return;\n }\n\n if (types.length > 1) {\n throw getError({\n message: `[ArtifactScanner] ${filePath} | class ${className} carries ${types.length} stereotypes (${types.join(', ')}) - one class is one artifact`,\n });\n }\n\n const modifiers = ts.getModifiers(node) ?? [];\n const has = (kind: ts.SyntaxKind): boolean => modifiers.some((m) => m.kind === kind);\n const isNamedExport =\n (has(ts.SyntaxKind.ExportKeyword) && !has(ts.SyntaxKind.DefaultKeyword)) ||\n exportedNames.has(className);\n const isAbstract = has(ts.SyntaxKind.AbstractKeyword);\n\n if (!isNamedExport || isAbstract) {\n if (!isHidden) {\n skipped?.push({\n className,\n filePath,\n reason: isAbstract ? ScanSkipReasons.ABSTRACT : ScanSkipReasons.NOT_EXPORTED,\n });\n this.logger\n .for('scanFile')\n .warn(\n 'Skipped %s in %s | %s',\n className,\n filePath,\n isAbstract ? 'abstract' : 'not a named export',\n );\n }\n\n return;\n }\n\n found.push({ className, filePath, type: types[0] });\n });\n\n return found;\n }\n\n /** local identifier -> stereotype name, for named imports from an IGNIS module or a caller-named source module (aliases resolved). */\n private collectStereotypeImports(opts: {\n source: ts.SourceFile;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n }): Map<string, string> {\n const result = new Map<string, string>();\n // Only a name a class actually wears as a decorator is worth following through re-exports.\n const decoratorNames = opts.resolver\n ? this.collectClassDecoratorNames({ source: opts.source })\n : new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const specifier = statement.moduleSpecifier.text;\n const isSourceModule =\n ArtifactStereotypes.SOURCE_MODULES.test(specifier) || opts.sourceModules.has(specifier);\n\n if (!isSourceModule && !opts.resolver) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n const name = (element.propertyName ?? element.name).text;\n\n if (!isSourceModule && !decoratorNames.has(element.name.text)) {\n continue;\n }\n\n const imported = isSourceModule\n ? name\n : opts.resolver?.originOf({ fromFile: opts.source.fileName, specifier, name });\n\n if (!imported) {\n continue;\n }\n\n const isStereotype =\n imported in ArtifactStereotypes.BY_DECORATOR ||\n imported === ArtifactStereotypes.ROOT_DECORATOR;\n\n if (isStereotype) {\n result.set(element.name.text, imported);\n }\n }\n }\n\n return result;\n }\n\n /** The identifiers called as decorators on the file's top-level classes (`@service()`, `@kit.service()` is not followed). */\n private collectClassDecoratorNames(opts: { source: ts.SourceFile }): Set<string> {\n const names = new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (!ts.isClassDeclaration(statement)) {\n continue;\n }\n\n for (const decorator of ts.getDecorators(statement) ?? []) {\n const expression = decorator.expression;\n\n if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {\n names.add(expression.expression.text);\n }\n }\n }\n\n return names;\n }\n\n private collectExportClauseNames(opts: { source: ts.SourceFile }): Set<string> {\n const names = new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (\n ts.isExportDeclaration(statement) &&\n statement.exportClause &&\n ts.isNamedExports(statement.exportClause)\n ) {\n for (const element of statement.exportClause.elements) {\n names.add((element.propertyName ?? element.name).text);\n }\n }\n }\n\n return names;\n }\n\n private artifactTypesOf(opts: {\n node: ts.ClassDeclaration;\n stereotypeByLocalName: Map<string, string>;\n filePath: string;\n className: string;\n }): TArtifactType[] {\n const { node, stereotypeByLocalName, filePath, className } = opts;\n const types: TArtifactType[] = [];\n\n const decorators = ts.getDecorators(node) ?? [];\n\n for (const decorator of decorators) {\n const expression = decorator.expression;\n\n if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression)) {\n continue;\n }\n\n const stereotype = stereotypeByLocalName.get(expression.expression.text);\n\n if (!stereotype) {\n continue;\n }\n\n if (stereotype !== ArtifactStereotypes.ROOT_DECORATOR) {\n types.push(ArtifactStereotypes.BY_DECORATOR[stereotype]);\n continue;\n }\n\n const type = this.typeOfInjectableCall({ call: expression });\n\n if (!type) {\n this.logger\n .for('artifactTypesOf')\n .warn(\n 'Skipped %s in %s | @injectable type is not a literal or ArtifactTypes.<NAME>',\n className,\n filePath,\n );\n continue;\n }\n\n types.push(type);\n }\n\n return types;\n }\n\n private typeOfInjectableCall(opts: { call: ts.CallExpression }): TArtifactType | undefined {\n const [argument] = opts.call.arguments;\n\n if (!argument || !ts.isObjectLiteralExpression(argument)) {\n return undefined;\n }\n\n const property = argument.properties.find(\n (entry): entry is ts.PropertyAssignment =>\n ts.isPropertyAssignment(entry) && ts.isIdentifier(entry.name) && entry.name.text === 'type',\n );\n\n if (!property) {\n return undefined;\n }\n\n const value = property.initializer;\n\n if (ts.isStringLiteral(value)) {\n return this.asArtifactType({ raw: value.text });\n }\n\n if (\n ts.isPropertyAccessExpression(value) &&\n ts.isIdentifier(value.expression) &&\n value.expression.text === 'ArtifactTypes'\n ) {\n return this.asArtifactType({ raw: value.name.text.toLowerCase() });\n }\n\n return undefined;\n }\n\n private asArtifactType(opts: { raw: string }): TArtifactType | undefined {\n const { raw } = opts;\n\n return ArtifactStereotypes.EMIT_ORDER.map((entry) => entry.type)\n .concat(ArtifactTypes.MODEL)\n .find((type) => type === raw);\n }\n}\n"]}
1
+ {"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../src/generator/scanner.ts"],"names":[],"mappings":"AAAA,OA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eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,IACE,EAAE,CAAC,0BAA0B,CAAC,KAAK,CAAC;YACpC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;YACjC,KAAK,CAAC,UAAU,CAAC,IAAI,KAAK,eAAe,EACzC,CAAC;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,cAAc,CAAC,IAAqB;QAC1C,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAErB,OAAO,mBAAmB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;aAC7D,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;aAC3B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers';\nimport { globSync, readFileSync } from 'node:fs';\nimport { join, matchesGlob, resolve } from 'node:path';\nimport ts from 'typescript';\nimport {\n ArtifactStereotypes,\n ArtifactTypes,\n ScanSkipReasons,\n type IScanOptions,\n type IScanReport,\n type IScanSkipped,\n type IScannedArtifact,\n type TArtifactType,\n} from './common';\nimport { StereotypeReexportResolver, type TDefinedType } from './reexport';\n\n/** Finds exported classes carrying a stereotype decorator by reading the source, never by running it. */\nexport class ArtifactScanner extends BaseHelper {\n private static instance?: ArtifactScanner;\n\n private constructor() {\n super({ scope: ArtifactScanner.name });\n }\n\n static getInstance(): ArtifactScanner {\n return (this.instance ??= new ArtifactScanner());\n }\n\n scan(opts: IScanOptions): IScannedArtifact[] {\n return this.scanWithReport(opts).artifacts;\n }\n\n /** `scan` plus the decorated classes a caller's own `ignore` pattern hid - the generator prints them so a stale pattern cannot drop an artifact in silence. */\n scanWithReport(opts: IScanOptions): IScanReport {\n const root = resolve(opts.root);\n const { kept, hidden } = this.partitionSourceFiles({\n root,\n defaultGlobs: ArtifactStereotypes.DEFAULT_IGNORE,\n userGlobs: opts.ignore ?? [],\n });\n const sourceModules = new Set(opts.sourceModules);\n // One resolver for both jobs: following re-exports to a stereotype is optional, finding the decorators an application defined is not.\n const reader = new StereotypeReexportResolver({ root, sourceModules });\n const resolver = opts.followReexports ? reader : undefined;\n const skipped: IScanSkipped[] = [];\n\n const artifacts = this.sortArtifacts(\n kept.flatMap((filePath) =>\n this.scanFile({ filePath, sourceModules, resolver, reader, skipped }),\n ),\n );\n const ignored = this.sortArtifacts(\n hidden.flatMap((filePath) =>\n this.scanHiddenFile({ filePath, sourceModules, resolver, reader }),\n ),\n );\n\n for (const artifact of ignored) {\n skipped.push({\n className: artifact.className,\n filePath: artifact.filePath,\n reason: ScanSkipReasons.IGNORED,\n });\n }\n\n return { artifacts, ignored, skipped };\n }\n\n /** A hidden file is only reported on, never a reason to fail: a scan error becomes one warning and the file contributes nothing. */\n private scanHiddenFile(opts: {\n filePath: string;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n reader: StereotypeReexportResolver;\n }): IScannedArtifact[] {\n try {\n return this.scanFile({ ...opts, isHidden: true });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.for('scanHiddenFile').warn('Skipped hidden file %s | %s', opts.filePath, reason);\n\n return [];\n }\n }\n\n private sortArtifacts(artifacts: IScannedArtifact[]): IScannedArtifact[] {\n return artifacts.sort(\n (a, b) => a.type.localeCompare(b.type) || a.className.localeCompare(b.className),\n );\n }\n\n /** `kept` feeds the index; `hidden` is what only a user pattern excluded (a default pattern wins, so tests and generated files are never reported). */\n private partitionSourceFiles(opts: {\n root: string;\n defaultGlobs: ReadonlyArray<string>;\n userGlobs: ReadonlyArray<string>;\n }): { kept: string[]; hidden: string[] } {\n const kept: string[] = [];\n const hidden: string[] = [];\n\n const sources = globSync(ArtifactStereotypes.SOURCE_GLOB, { cwd: opts.root });\n\n for (const relative of sources) {\n if (\n relative.endsWith('.d.ts') ||\n opts.defaultGlobs.some((pattern) => matchesGlob(relative, pattern))\n ) {\n continue;\n }\n\n const target = opts.userGlobs.some((pattern) => matchesGlob(relative, pattern))\n ? hidden\n : kept;\n target.push(join(opts.root, relative));\n }\n\n return { kept: kept.sort(), hidden: hidden.sort() };\n }\n\n private scanFile(opts: {\n filePath: string;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n reader: StereotypeReexportResolver;\n skipped?: IScanSkipped[];\n isHidden?: boolean;\n }): IScannedArtifact[] {\n const { filePath, sourceModules, resolver, reader, skipped, isHidden = false } = opts;\n const source = ts.createSourceFile(\n filePath,\n readFileSync(filePath, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n );\n\n const stereotypeByLocalName = this.collectStereotypeImports({\n source,\n sourceModules,\n resolver,\n });\n\n const customByLocalName = this.collectCustomDecorators({\n source,\n reader,\n excluded: stereotypeByLocalName,\n });\n\n if (stereotypeByLocalName.size === 0 && customByLocalName.size === 0) {\n return [];\n }\n\n const exportedNames = this.collectExportClauseNames({ source });\n const found: IScannedArtifact[] = [];\n\n ts.forEachChild(source, (node) => {\n if (!ts.isClassDeclaration(node) || !node.name) {\n return;\n }\n\n const className = node.name.text;\n const { types, unreadable } = this.artifactTypesOf({\n node,\n stereotypeByLocalName,\n customByLocalName,\n filePath,\n className,\n });\n\n if (types.length === 0 && unreadable.length > 0) {\n if (!isHidden) {\n skipped?.push({ className, filePath, reason: ScanSkipReasons.UNREADABLE_TYPE });\n this.logger\n .for('scanFile')\n .warn(\n 'Skipped %s in %s | its decorator comes from an ArtifactTypes.define the scanner cannot read: %s',\n className,\n filePath,\n unreadable[0],\n );\n }\n\n return;\n }\n\n if (types.length === 0) {\n return;\n }\n\n if (types.length > 1) {\n throw getError({\n message: `[ArtifactScanner] ${filePath} | class ${className} carries ${types.length} stereotypes (${types.join(', ')}) - one class is one artifact`,\n });\n }\n\n const modifiers = ts.getModifiers(node) ?? [];\n const has = (kind: ts.SyntaxKind): boolean => modifiers.some((m) => m.kind === kind);\n const isNamedExport =\n (has(ts.SyntaxKind.ExportKeyword) && !has(ts.SyntaxKind.DefaultKeyword)) ||\n exportedNames.has(className);\n const isAbstract = has(ts.SyntaxKind.AbstractKeyword);\n\n if (!isNamedExport || isAbstract) {\n if (!isHidden) {\n skipped?.push({\n className,\n filePath,\n reason: isAbstract ? ScanSkipReasons.ABSTRACT : ScanSkipReasons.NOT_EXPORTED,\n });\n this.logger\n .for('scanFile')\n .warn(\n 'Skipped %s in %s | %s',\n className,\n filePath,\n isAbstract ? 'abstract' : 'not a named export',\n );\n }\n\n return;\n }\n\n found.push({ className, filePath, type: types[0] });\n });\n\n return found;\n }\n\n /** local identifier -> stereotype name, for named imports from an IGNIS module or a caller-named source module (aliases resolved). */\n private collectStereotypeImports(opts: {\n source: ts.SourceFile;\n sourceModules: Set<string>;\n resolver?: StereotypeReexportResolver;\n }): Map<string, string> {\n const result = new Map<string, string>();\n // Only a name a class actually wears as a decorator is worth following through re-exports.\n const decoratorNames = opts.resolver\n ? this.collectClassDecoratorNames({ source: opts.source })\n : new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const specifier = statement.moduleSpecifier.text;\n const isSourceModule =\n ArtifactStereotypes.SOURCE_MODULES.test(specifier) || opts.sourceModules.has(specifier);\n\n if (!isSourceModule && !opts.resolver) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n const name = (element.propertyName ?? element.name).text;\n\n if (!isSourceModule && !decoratorNames.has(element.name.text)) {\n continue;\n }\n\n const imported = isSourceModule\n ? name\n : opts.resolver?.originOf({ fromFile: opts.source.fileName, specifier, name });\n\n if (!imported) {\n continue;\n }\n\n const isStereotype =\n imported in ArtifactStereotypes.BY_DECORATOR ||\n imported === ArtifactStereotypes.ROOT_DECORATOR;\n\n if (isStereotype) {\n result.set(element.name.text, imported);\n }\n }\n }\n\n return result;\n }\n\n /** The identifiers called as decorators on the file's top-level classes (`@service()`, `@kit.service()` is not followed). */\n private collectClassDecoratorNames(opts: { source: ts.SourceFile }): Set<string> {\n const names = new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (!ts.isClassDeclaration(statement)) {\n continue;\n }\n\n for (const decorator of ts.getDecorators(statement) ?? []) {\n const expression = decorator.expression;\n\n if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {\n names.add(expression.expression.text);\n }\n }\n }\n\n return names;\n }\n\n /**\n * local identifier -> type, for the decorators this file's classes wear that an application defined with\n * `ArtifactTypes.define`: declared in this file, or imported from a module whose chain of exports reaches the declaration.\n */\n private collectCustomDecorators(opts: {\n source: ts.SourceFile;\n reader: StereotypeReexportResolver;\n excluded: Map<string, string>;\n }): Map<string, TDefinedType> {\n const { source, reader, excluded } = opts;\n const result = new Map<string, TDefinedType>();\n const imported = new Map<string, { specifier: string; name: string }>();\n\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n imported.set(element.name.text, {\n specifier: statement.moduleSpecifier.text,\n name: (element.propertyName ?? element.name).text,\n });\n }\n }\n\n for (const local of this.collectClassDecoratorNames({ source })) {\n if (excluded.has(local)) {\n continue;\n }\n\n const origin = imported.get(local);\n const type = origin\n ? reader.customTypeOf({ fromFile: source.fileName, ...origin })\n : reader.definedTypeIn({ source, name: local });\n\n if (type) {\n result.set(local, type);\n }\n }\n\n return result;\n }\n\n private collectExportClauseNames(opts: { source: ts.SourceFile }): Set<string> {\n const names = new Set<string>();\n\n for (const statement of opts.source.statements) {\n if (\n ts.isExportDeclaration(statement) &&\n statement.exportClause &&\n ts.isNamedExports(statement.exportClause)\n ) {\n for (const element of statement.exportClause.elements) {\n names.add((element.propertyName ?? element.name).text);\n }\n }\n }\n\n return names;\n }\n\n private artifactTypesOf(opts: {\n node: ts.ClassDeclaration;\n stereotypeByLocalName: Map<string, string>;\n customByLocalName: Map<string, TDefinedType>;\n filePath: string;\n className: string;\n }): { types: string[]; unreadable: string[] } {\n const { node, stereotypeByLocalName, customByLocalName, filePath, className } = opts;\n const types: string[] = [];\n const unreadable: string[] = [];\n\n const decorators = ts.getDecorators(node) ?? [];\n\n for (const decorator of decorators) {\n const expression = decorator.expression;\n\n if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression)) {\n continue;\n }\n\n const custom = customByLocalName.get(expression.expression.text);\n\n if (custom) {\n if ('type' in custom) {\n types.push(custom.type);\n } else {\n unreadable.push(custom.unreadable);\n }\n\n continue;\n }\n\n const stereotype = stereotypeByLocalName.get(expression.expression.text);\n\n if (!stereotype) {\n continue;\n }\n\n if (stereotype !== ArtifactStereotypes.ROOT_DECORATOR) {\n types.push(ArtifactStereotypes.BY_DECORATOR[stereotype]);\n continue;\n }\n\n const type = this.typeOfInjectableCall({ call: expression });\n\n if (!type) {\n this.logger\n .for('artifactTypesOf')\n .warn(\n 'Skipped %s in %s | @injectable type is not a literal or ArtifactTypes.<NAME>',\n className,\n filePath,\n );\n continue;\n }\n\n types.push(type);\n }\n\n return { types, unreadable };\n }\n\n private typeOfInjectableCall(opts: { call: ts.CallExpression }): TArtifactType | undefined {\n const [argument] = opts.call.arguments;\n\n if (!argument || !ts.isObjectLiteralExpression(argument)) {\n return undefined;\n }\n\n const property = argument.properties.find(\n (entry): entry is ts.PropertyAssignment =>\n ts.isPropertyAssignment(entry) && ts.isIdentifier(entry.name) && entry.name.text === 'type',\n );\n\n if (!property) {\n return undefined;\n }\n\n const value = property.initializer;\n\n if (ts.isStringLiteral(value)) {\n return this.asArtifactType({ raw: value.text });\n }\n\n if (\n ts.isPropertyAccessExpression(value) &&\n ts.isIdentifier(value.expression) &&\n value.expression.text === 'ArtifactTypes'\n ) {\n return this.asArtifactType({ raw: value.name.text.toLowerCase() });\n }\n\n return undefined;\n }\n\n private asArtifactType(opts: { raw: string }): TArtifactType | undefined {\n const { raw } = opts;\n\n return ArtifactStereotypes.EMIT_ORDER.map((entry) => entry.type)\n .concat(ArtifactTypes.MODEL)\n .find((type) => type === raw);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ignis-boot",
3
- "version": "0.5.0-1",
3
+ "version": "0.5.0-11",
4
4
  "description": "Build-time artifact index generator for IGNIS applications: scans decorated classes with the TypeScript AST and emits one static registration file per package, so bun build --compile sees plain imports.",
5
5
  "keywords": [
6
6
  "artifact-index",
@@ -77,19 +77,19 @@
77
77
  },
78
78
  "scripts": {
79
79
  "force-update": "sh ../../scripts/build/force-update.sh",
80
- "test": "bun test ./src"
80
+ "test": "bun test --max-concurrency=6 ./src"
81
81
  },
82
82
  "dependencies": {
83
- "@venizia/ignis-helpers": "0.5.0-1",
84
- "@venizia/ignis-inversion": "0.5.0-0"
83
+ "@venizia/ignis-helpers": "0.5.0-11",
84
+ "@venizia/ignis-inversion": "0.5.0-5"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@types/bun": "^1.4.5",
88
- "@venizia/dev-configs": "0.5.0-2",
89
- "eslint": "^10.13.0",
90
- "oxlint": "1.89.0",
91
- "oxlint-tsgolint": "7.0.2004",
92
- "tsc-alias": "1.9.4",
88
+ "@venizia/dev-configs": "0.5.0-9",
89
+ "eslint": "^10.15.0",
90
+ "oxlint": "1.95.0",
91
+ "oxlint-tsgolint": "7.0.2009",
92
+ "tsc-alias": "1.9.12",
93
93
  "typescript": "^6.0.3"
94
94
  },
95
95
  "peerDependencies": {