@venizia/ignis-boot 0.3.6 → 0.4.1
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.
- package/LICENSE.md +1 -1
- package/dist/cjs/bun/auto-loader.js +3 -3
- package/dist/cjs/bun/auto-loader.js.map +1 -1
- package/dist/cjs/bun/group-resolver.js +1 -1
- package/dist/cjs/bun/group-resolver.js.map +1 -1
- package/dist/cjs/bun/plugin.js +10 -10
- package/dist/cjs/bun/plugin.js.map +1 -1
- package/dist/cjs/bun/scan-cache.js +1 -1
- package/dist/cjs/bun/scan-cache.js.map +1 -1
- package/dist/cjs/bun/sources.js +4 -4
- package/dist/cjs/bun/sources.js.map +1 -1
- package/dist/cjs/clis/artifacts.js +1 -1
- package/dist/cjs/clis/artifacts.js.map +1 -1
- package/dist/cjs/generator/emitter.d.ts +2 -2
- package/dist/cjs/generator/emitter.d.ts.map +1 -1
- package/dist/cjs/generator/emitter.js +8 -8
- package/dist/cjs/generator/emitter.js.map +1 -1
- package/dist/cjs/generator/scanner.d.ts.map +1 -1
- package/dist/cjs/generator/scanner.js +10 -8
- package/dist/cjs/generator/scanner.js.map +1 -1
- package/dist/cjs/vite/plugin.js +3 -3
- package/dist/cjs/vite/plugin.js.map +1 -1
- package/dist/esm/bun/auto-loader.js +3 -3
- package/dist/esm/bun/auto-loader.js.map +1 -1
- package/dist/esm/bun/group-resolver.js +1 -1
- package/dist/esm/bun/group-resolver.js.map +1 -1
- package/dist/esm/bun/plugin.js +10 -10
- package/dist/esm/bun/plugin.js.map +1 -1
- package/dist/esm/bun/scan-cache.js +1 -1
- package/dist/esm/bun/scan-cache.js.map +1 -1
- package/dist/esm/bun/sources.js +4 -4
- package/dist/esm/bun/sources.js.map +1 -1
- package/dist/esm/clis/artifacts.js +1 -1
- package/dist/esm/clis/artifacts.js.map +1 -1
- package/dist/esm/generator/emitter.d.ts +2 -2
- package/dist/esm/generator/emitter.d.ts.map +1 -1
- package/dist/esm/generator/emitter.js +8 -8
- package/dist/esm/generator/emitter.js.map +1 -1
- package/dist/esm/generator/scanner.d.ts.map +1 -1
- package/dist/esm/generator/scanner.js +10 -8
- package/dist/esm/generator/scanner.js.map +1 -1
- package/dist/esm/vite/plugin.js +3 -3
- package/dist/esm/vite/plugin.js.map +1 -1
- package/package.json +26 -27
|
@@ -5,7 +5,7 @@ const node_path_1 = require("node:path");
|
|
|
5
5
|
const common_1 = require("./common");
|
|
6
6
|
/** Renders the generated index: deterministic text, plain static imports, no IGNIS import - the object is type-checked where `registerArtifacts` receives it. */
|
|
7
7
|
class ArtifactIndexEmitter {
|
|
8
|
-
/** Mirrors `printWidth` in
|
|
8
|
+
/** Mirrors `printWidth` in the root bunfig.toml `[fmt]` table. */
|
|
9
9
|
static { this.PRINT_WIDTH = 100; }
|
|
10
10
|
static { this.DEFAULT_EXPORT_NAME = 'GeneratedArtifacts'; }
|
|
11
11
|
/** The `ignis-artifacts generate` command for these options - the header and the CLI's stale hint print the same one. */
|
|
@@ -29,9 +29,9 @@ class ArtifactIndexEmitter {
|
|
|
29
29
|
}
|
|
30
30
|
static render(opts) {
|
|
31
31
|
const { artifacts, outFile, exportName, command } = opts;
|
|
32
|
-
const emitted = artifacts.filter(artifact => artifact.type !== common_1.ArtifactTypes.MODEL);
|
|
32
|
+
const emitted = artifacts.filter((artifact) => artifact.type !== common_1.ArtifactTypes.MODEL);
|
|
33
33
|
const imports = emitted
|
|
34
|
-
.map(artifact => ({
|
|
34
|
+
.map((artifact) => ({
|
|
35
35
|
name: artifact.className,
|
|
36
36
|
path: ArtifactIndexEmitter.importPath({
|
|
37
37
|
from: outFile,
|
|
@@ -40,11 +40,11 @@ class ArtifactIndexEmitter {
|
|
|
40
40
|
}),
|
|
41
41
|
}))
|
|
42
42
|
.sort((a, b) => a.path.localeCompare(b.path) || a.name.localeCompare(b.name))
|
|
43
|
-
.map(entry => `import { ${entry.name} } from '${entry.path}';`);
|
|
43
|
+
.map((entry) => `import { ${entry.name} } from '${entry.path}';`);
|
|
44
44
|
const fields = common_1.ArtifactStereotypes.EMIT_ORDER.flatMap(({ type, field }) => {
|
|
45
45
|
const names = emitted
|
|
46
|
-
.filter(artifact => artifact.type === type)
|
|
47
|
-
.map(artifact => artifact.className)
|
|
46
|
+
.filter((artifact) => artifact.type === type)
|
|
47
|
+
.map((artifact) => artifact.className)
|
|
48
48
|
.sort((a, b) => a.localeCompare(b));
|
|
49
49
|
return ArtifactIndexEmitter.renderField({ field, names });
|
|
50
50
|
});
|
|
@@ -58,14 +58,14 @@ class ArtifactIndexEmitter {
|
|
|
58
58
|
'',
|
|
59
59
|
].join('\n');
|
|
60
60
|
}
|
|
61
|
-
/** One line while it fits the
|
|
61
|
+
/** One line while it fits the print width, else one name per line - so `bun fmt --check` on the generated file stays quiet. */
|
|
62
62
|
static renderField(opts) {
|
|
63
63
|
const { field, names } = opts;
|
|
64
64
|
const singleLine = ` ${field}: [${names.join(', ')}],`;
|
|
65
65
|
if (singleLine.length <= ArtifactIndexEmitter.PRINT_WIDTH) {
|
|
66
66
|
return [singleLine];
|
|
67
67
|
}
|
|
68
|
-
return [` ${field}: [`, ...names.map(name => ` ${name},`), ' ],'];
|
|
68
|
+
return [` ${field}: [`, ...names.map((name) => ` ${name},`), ' ],'];
|
|
69
69
|
}
|
|
70
70
|
static importPath(opts) {
|
|
71
71
|
if (opts.isAbsolute) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../../src/generator/emitter.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,qCAAqF;AAErF,iKAAiK;AACjK,MAAa,oBAAoB;IAC/B,
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../../src/generator/emitter.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,qCAAqF;AAErF,iKAAiK;AACjK,MAAa,oBAAoB;IAC/B,kEAAkE;aAClD,gBAAW,GAAG,GAAG,CAAC;aAElB,wBA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import { ArtifactStereotypes, ArtifactTypes, type IScannedArtifact } from './common';\n\n/** Renders the generated index: deterministic text, plain static imports, no IGNIS import - the object is type-checked where `registerArtifacts` receives it. */\nexport class ArtifactIndexEmitter {\n /** Mirrors `printWidth` in the root bunfig.toml `[fmt]` table. */\n static readonly PRINT_WIDTH = 100;\n\n static readonly DEFAULT_EXPORT_NAME = 'GeneratedArtifacts';\n\n /** The `ignis-artifacts generate` command for these options - the header and the CLI's stale hint print the same one. */\n static renderCommand(opts: {\n root: string;\n out: string;\n ignore?: string[];\n exportName?: string;\n sourceModules?: string[];\n }): string {\n const { root, out, ignore = [], exportName, sourceModules = [] } = opts;\n const flags = [`--root ${root}`, `--out ${out}`];\n if (ignore.length > 0) {\n flags.push(`--ignore ${ignore.join(',')}`);\n }\n if (exportName && exportName !== ArtifactIndexEmitter.DEFAULT_EXPORT_NAME) {\n flags.push(`--export ${exportName}`);\n }\n for (const sourceModule of sourceModules) {\n flags.push(`--source-module ${sourceModule}`);\n }\n return `ignis-artifacts generate ${flags.join(' ')}`;\n }\n\n /** The exact command that regenerates the file, so the header never points at another path than the one the build used. */\n static renderHeader(opts: {\n root: string;\n out: string;\n ignore?: string[];\n exportName?: string;\n sourceModules?: string[];\n }): string {\n return `// AUTO-GENERATED by @venizia/ignis-boot - do not edit. Regenerate: ${ArtifactIndexEmitter.renderCommand(opts)}`;\n }\n\n static render(opts: {\n artifacts: IScannedArtifact[];\n outFile: string;\n exportName: string;\n /** Absolute import paths - for a virtual module, which has no directory to resolve a relative one from. */\n absoluteImports?: boolean;\n /** The CLI arguments as given, for the header; `outFile` above is the resolved path used for import specifiers. */\n command: { root: string; out: string; ignore?: string[]; sourceModules?: string[] };\n }): string {\n const { artifacts, outFile, exportName, command } = opts;\n const emitted = artifacts.filter((artifact) => artifact.type !== ArtifactTypes.MODEL);\n\n const imports = emitted\n .map((artifact) => ({\n name: artifact.className,\n path: ArtifactIndexEmitter.importPath({\n from: outFile,\n to: artifact.filePath,\n isAbsolute: opts.absoluteImports ?? false,\n }),\n }))\n .sort((a, b) => a.path.localeCompare(b.path) || a.name.localeCompare(b.name))\n .map((entry) => `import { ${entry.name} } from '${entry.path}';`);\n\n const fields = ArtifactStereotypes.EMIT_ORDER.flatMap(({ type, field }) => {\n const names = emitted\n .filter((artifact) => artifact.type === type)\n .map((artifact) => artifact.className)\n .sort((a, b) => a.localeCompare(b));\n\n return ArtifactIndexEmitter.renderField({ field, names });\n });\n\n return [\n ArtifactIndexEmitter.renderHeader({ ...command, exportName }),\n ...imports,\n '',\n `export const ${exportName} = {`,\n ...fields,\n '};',\n '',\n ].join('\\n');\n }\n\n /** One line while it fits the print width, else one name per line - so `bun fmt --check` on the generated file stays quiet. */\n private static renderField(opts: { field: string; names: string[] }): string[] {\n const { field, names } = opts;\n const singleLine = ` ${field}: [${names.join(', ')}],`;\n\n if (singleLine.length <= ArtifactIndexEmitter.PRINT_WIDTH) {\n return [singleLine];\n }\n\n return [` ${field}: [`, ...names.map((name) => ` ${name},`), ' ],'];\n }\n\n private static importPath(opts: { from: string; to: string; isAbsolute: boolean }): string {\n if (opts.isAbsolute) {\n return opts.to.split(sep).join('/').replace(ArtifactStereotypes.SOURCE_EXTENSION, '');\n }\n const raw = relative(dirname(opts.from), opts.to)\n .split(sep)\n .join('/')\n .replace(ArtifactStereotypes.SOURCE_EXTENSION, '');\n return raw.startsWith('.') ? raw : `./${raw}`;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../../src/generator/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EAEtB,MAAM,UAAU,CAAC;AAGlB,yGAAyG;AACzG,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAkB;IAE1C,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,eAAe;IAIrC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,gBAAgB,EAAE;IAI5C,+JAA+J;IAC/J,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW;IA8B/C,oIAAoI;IACpI,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,aAAa;IAMrB,uJAAuJ;IACvJ,OAAO,CAAC,oBAAoB;
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../../src/generator/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EAEtB,MAAM,UAAU,CAAC;AAGlB,yGAAyG;AACzG,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAkB;IAE1C,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,eAAe;IAIrC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,gBAAgB,EAAE;IAI5C,+JAA+J;IAC/J,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW;IA8B/C,oIAAoI;IACpI,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,aAAa;IAMrB,uJAAuJ;IACvJ,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,QAAQ;IAgFhB,sIAAsI;IACtI,OAAO,CAAC,wBAAwB;IAkDhC,6HAA6H;IAC7H,OAAO,CAAC,0BAA0B;IAgBlC,OAAO,CAAC,wBAAwB;IAkBhC,OAAO,CAAC,eAAe;IA0CvB,OAAO,CAAC,oBAAoB;IA6B5B,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -34,8 +34,8 @@ class ArtifactScanner extends ignis_helpers_1.BaseHelper {
|
|
|
34
34
|
? new reexport_1.StereotypeReexportResolver({ root, sourceModules })
|
|
35
35
|
: undefined;
|
|
36
36
|
const skipped = [];
|
|
37
|
-
const artifacts = this.sortArtifacts(kept.flatMap(filePath => this.scanFile({ filePath, sourceModules, resolver, skipped })));
|
|
38
|
-
const ignored = this.sortArtifacts(hidden.flatMap(filePath => this.scanHiddenFile({ filePath, sourceModules, resolver })));
|
|
37
|
+
const artifacts = this.sortArtifacts(kept.flatMap((filePath) => this.scanFile({ filePath, sourceModules, resolver, skipped })));
|
|
38
|
+
const ignored = this.sortArtifacts(hidden.flatMap((filePath) => this.scanHiddenFile({ filePath, sourceModules, resolver })));
|
|
39
39
|
for (const artifact of ignored) {
|
|
40
40
|
skipped.push({
|
|
41
41
|
className: artifact.className,
|
|
@@ -66,10 +66,12 @@ class ArtifactScanner extends ignis_helpers_1.BaseHelper {
|
|
|
66
66
|
const sources = (0, node_fs_1.globSync)(common_1.ArtifactStereotypes.SOURCE_GLOB, { cwd: opts.root });
|
|
67
67
|
for (const relative of sources) {
|
|
68
68
|
if (relative.endsWith('.d.ts') ||
|
|
69
|
-
opts.defaultGlobs.some(pattern => (0, node_path_1.matchesGlob)(relative, pattern))) {
|
|
69
|
+
opts.defaultGlobs.some((pattern) => (0, node_path_1.matchesGlob)(relative, pattern))) {
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
|
-
const target = opts.userGlobs.some(pattern => (0, node_path_1.matchesGlob)(relative, pattern))
|
|
72
|
+
const target = opts.userGlobs.some((pattern) => (0, node_path_1.matchesGlob)(relative, pattern))
|
|
73
|
+
? hidden
|
|
74
|
+
: kept;
|
|
73
75
|
target.push((0, node_path_1.join)(opts.root, relative));
|
|
74
76
|
}
|
|
75
77
|
return { kept: kept.sort(), hidden: hidden.sort() };
|
|
@@ -87,7 +89,7 @@ class ArtifactScanner extends ignis_helpers_1.BaseHelper {
|
|
|
87
89
|
}
|
|
88
90
|
const exportedNames = this.collectExportClauseNames({ source });
|
|
89
91
|
const found = [];
|
|
90
|
-
typescript_1.default.forEachChild(source, node => {
|
|
92
|
+
typescript_1.default.forEachChild(source, (node) => {
|
|
91
93
|
if (!typescript_1.default.isClassDeclaration(node) || !node.name) {
|
|
92
94
|
return;
|
|
93
95
|
}
|
|
@@ -107,7 +109,7 @@ class ArtifactScanner extends ignis_helpers_1.BaseHelper {
|
|
|
107
109
|
});
|
|
108
110
|
}
|
|
109
111
|
const modifiers = typescript_1.default.getModifiers(node) ?? [];
|
|
110
|
-
const has = (kind) => modifiers.some(m => m.kind === kind);
|
|
112
|
+
const has = (kind) => modifiers.some((m) => m.kind === kind);
|
|
111
113
|
const isNamedExport = (has(typescript_1.default.SyntaxKind.ExportKeyword) && !has(typescript_1.default.SyntaxKind.DefaultKeyword)) ||
|
|
112
114
|
exportedNames.has(className);
|
|
113
115
|
const isAbstract = has(typescript_1.default.SyntaxKind.AbstractKeyword);
|
|
@@ -247,9 +249,9 @@ class ArtifactScanner extends ignis_helpers_1.BaseHelper {
|
|
|
247
249
|
}
|
|
248
250
|
asArtifactType(opts) {
|
|
249
251
|
const { raw } = opts;
|
|
250
|
-
return common_1.ArtifactStereotypes.EMIT_ORDER.map(entry => entry.type)
|
|
252
|
+
return common_1.ArtifactStereotypes.EMIT_ORDER.map((entry) => entry.type)
|
|
251
253
|
.concat(common_1.ArtifactTypes.MODEL)
|
|
252
|
-
.find(type => type === raw);
|
|
254
|
+
.find((type) => type === raw);
|
|
253
255
|
}
|
|
254
256
|
}
|
|
255
257
|
exports.ArtifactScanner = ArtifactScanner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../src/generator/scanner.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA8D;AAC9D,qCAAiD;AACjD,yCAAuD;AACvD,4DAA4B;AAC5B,qCASkB;AAClB,yCAAwD;AAExD,yGAAyG;AACzG,MAAa,eAAgB,SAAQ,0BAAU;IAG7C;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE,C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,MAAM,CAAC,sBAAa,CAAC,KAAK,CAAC;aAC3B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IAChC,CAAC;CACF;AA9UD,0CA8UC","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 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 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 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 const target = opts.userGlobs.some(pattern => matchesGlob(relative, pattern)) ? hidden : 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 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 if (types.length === 0) {\n return;\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 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 const specifier = statement.moduleSpecifier.text;\n const isSourceModule =\n ArtifactStereotypes.SOURCE_MODULES.test(specifier) || opts.sourceModules.has(specifier);\n if (!isSourceModule && !opts.resolver) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\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 if (!isSourceModule && !decoratorNames.has(element.name.text)) {\n continue;\n }\n const imported = isSourceModule\n ? name\n : opts.resolver?.originOf({ fromFile: opts.source.fileName, specifier, name });\n if (!imported) {\n continue;\n }\n const isStereotype =\n imported in ArtifactStereotypes.BY_DECORATOR ||\n imported === ArtifactStereotypes.ROOT_DECORATOR;\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 for (const statement of opts.source.statements) {\n if (!ts.isClassDeclaration(statement)) {\n continue;\n }\n for (const decorator of ts.getDecorators(statement) ?? []) {\n const expression = decorator.expression;\n if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {\n names.add(expression.expression.text);\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 for (const decorator of decorators) {\n const expression = decorator.expression;\n if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression)) {\n continue;\n }\n\n const stereotype = stereotypeByLocalName.get(expression.expression.text);\n if (!stereotype) {\n continue;\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 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 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 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 if (!property) {\n return undefined;\n }\n\n const value = property.initializer;\n if (ts.isStringLiteral(value)) {\n return this.asArtifactType({ raw: value.text });\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 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,0DAA8D;AAC9D,qCAAiD;AACjD,yCAAuD;AACvD,4DAA4B;AAC5B,qCASkB;AAClB,yCAAwD;AAExD,yGAAyG;AACzG,MAAa,eAAgB,SAAQ,0BAAU;IAG7C;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,eA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AC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IAClC,CAAC;CACF;AAhVD,0CAgVC","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 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 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 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 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 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 if (types.length === 0) {\n return;\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 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 const specifier = statement.moduleSpecifier.text;\n const isSourceModule =\n ArtifactStereotypes.SOURCE_MODULES.test(specifier) || opts.sourceModules.has(specifier);\n if (!isSourceModule && !opts.resolver) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\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 if (!isSourceModule && !decoratorNames.has(element.name.text)) {\n continue;\n }\n const imported = isSourceModule\n ? name\n : opts.resolver?.originOf({ fromFile: opts.source.fileName, specifier, name });\n if (!imported) {\n continue;\n }\n const isStereotype =\n imported in ArtifactStereotypes.BY_DECORATOR ||\n imported === ArtifactStereotypes.ROOT_DECORATOR;\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 for (const statement of opts.source.statements) {\n if (!ts.isClassDeclaration(statement)) {\n continue;\n }\n for (const decorator of ts.getDecorators(statement) ?? []) {\n const expression = decorator.expression;\n if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {\n names.add(expression.expression.text);\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 for (const decorator of decorators) {\n const expression = decorator.expression;\n if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression)) {\n continue;\n }\n\n const stereotype = stereotypeByLocalName.get(expression.expression.text);\n if (!stereotype) {\n continue;\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 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 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 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 if (!property) {\n return undefined;\n }\n\n const value = property.initializer;\n if (ts.isStringLiteral(value)) {\n return this.asArtifactType({ raw: value.text });\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 return ArtifactStereotypes.EMIT_ORDER.map((entry) => entry.type)\n .concat(ArtifactTypes.MODEL)\n .find((type) => type === raw);\n }\n}\n"]}
|
package/dist/cjs/vite/plugin.js
CHANGED
|
@@ -27,13 +27,13 @@ class IgnisArtifactsVitePlugin {
|
|
|
27
27
|
enforce: 'pre',
|
|
28
28
|
// Pre-bundling would hide `auto` inside a dependency chunk, out of reach of `load`.
|
|
29
29
|
config: () => ({ optimizeDeps: { exclude: ['@venizia/ignis-boot'] } }),
|
|
30
|
-
configResolved: config => {
|
|
30
|
+
configResolved: (config) => {
|
|
31
31
|
root ||= sources_1.ArtifactSources.packageSource({ from: config.root });
|
|
32
32
|
groupFiles = new Set(plugin_1.IgnisArtifactsPlugin.groupDefinitionFiles({ root }));
|
|
33
33
|
classesByFile = plugin_1.IgnisArtifactsPlugin.pinnedClasses({ root, groupFiles: [...groupFiles] });
|
|
34
34
|
},
|
|
35
|
-
resolveId: id => id === plugin_1.IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,
|
|
36
|
-
load: id => {
|
|
35
|
+
resolveId: (id) => id === plugin_1.IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,
|
|
36
|
+
load: (id) => {
|
|
37
37
|
if (id === IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL) {
|
|
38
38
|
return plugin_1.IgnisArtifactsPlugin.render({ root });
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,4CAA+C;AAC/C,0CAAqD;AACrD,4CAAiD;AAajD,mWAAmW;AACnW,MAAa,wBAAwB;aACnB,qBAAgB,GAAG,KAAK,6BAAoB,CAAC,OAAO,EAAE,CAAC;IAEvE;QACE,yBAAe,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,2BAAe,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,6FAA6F;IAC7F,wGAAwG;IACxG,MAAM,CAAC,UAAU,CAAC,IAAoB;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,OAA0B,EAAE;QACxC,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,IAAI,CA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AoB,CAAC,WAAW,CAAC,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBACvF,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,SAAS,CAAC;YAChB,CAAC;YACD,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBAC5B,MAAM,EAAE,GAAG,wBAAwB,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACjE,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;oBACvC,OAAO,SAAS,CAAC;gBACnB,CAAC;gBACD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,CAAC,CAAC,6BAAoB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oBACpE,CAAC,CAAC,IAAI,CAAC;gBACT,OAAO,UAAU;oBACf,CAAC,CAAC,6BAAoB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;oBACnF,CAAC,CAAC,OAAO,CAAC;YACd,CAAC;SACF,CAAC;IACJ,CAAC;;AAtDH,4DAuDC","sourcesContent":["import { resolve } from 'node:path';\nimport { ArtifactScanner } from '../generator';\nimport { IgnisArtifactsPlugin } from '../bun/plugin';\nimport { ArtifactSources } from '../bun/sources';\n\n/** The slice of Vite's plugin contract this plugin uses - typed here so `@venizia/ignis-boot` does not depend on `vite`. */\nexport interface IIgnisVitePlugin {\n name: string;\n enforce: 'pre';\n config: () => { optimizeDeps: { exclude: string[] } };\n configResolved: (config: { root: string }) => void;\n resolveId: (id: string) => string | undefined;\n load: (id: string) => string | undefined;\n transform: (code: string, id: string) => string | undefined;\n}\n\n/** `IgnisArtifactsPlugin` for Vite: serves `ignis:artifacts`, replaces `@venizia/ignis-boot/auto` with an eager import of it (a browser bundle is tree-shaken only when eager), inlines every `ArtifactGroup.define` / `application` call, and pins the name of every scanned class - binding keys are built from `Class.name`, and a minifier renames classes. */\nexport class IgnisArtifactsVitePlugin {\n static readonly RESOLVED_VIRTUAL = `\\0${IgnisArtifactsPlugin.VIRTUAL}`;\n\n static {\n ArtifactSources.useScanner({ scanner: ArtifactScanner.getInstance() });\n }\n\n /** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */\n /** The file a module id names: vite dev adds a query (`?v=<hash>`) to the id of a node_modules file. */\n static filePathOf(opts: { id: string }): string {\n const queryAt = opts.id.indexOf('?');\n return queryAt === -1 ? opts.id : opts.id.slice(0, queryAt);\n }\n\n static create(opts: { root?: string } = {}): IIgnisVitePlugin {\n let root = opts.root ? resolve(opts.root) : '';\n let groupFiles = new Set<string>();\n let classesByFile = new Map<string, Set<string>>();\n const autoModule = `import { ${IgnisArtifactsPlugin.EXPORT_NAME} } from '${IgnisArtifactsPlugin.VIRTUAL}';\\nimport { AutoArtifactGroup } from './auto-group';\\nexport default new AutoArtifactGroup({ content: ${IgnisArtifactsPlugin.EXPORT_NAME} });\\n`;\n\n return {\n name: IgnisArtifactsPlugin.NAME,\n enforce: 'pre',\n // Pre-bundling would hide `auto` inside a dependency chunk, out of reach of `load`.\n config: () => ({ optimizeDeps: { exclude: ['@venizia/ignis-boot'] } }),\n configResolved: (config) => {\n root ||= ArtifactSources.packageSource({ from: config.root });\n groupFiles = new Set(IgnisArtifactsPlugin.groupDefinitionFiles({ root }));\n classesByFile = IgnisArtifactsPlugin.pinnedClasses({ root, groupFiles: [...groupFiles] });\n },\n resolveId: (id) =>\n id === IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,\n load: (id) => {\n if (id === IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL) {\n return IgnisArtifactsPlugin.render({ root });\n }\n return IgnisArtifactsPlugin.AUTO_MODULE.test(IgnisArtifactsVitePlugin.filePathOf({ id }))\n ? autoModule\n : undefined;\n },\n transform: (code, moduleId) => {\n const id = IgnisArtifactsVitePlugin.filePathOf({ id: moduleId });\n const classNames = classesByFile.get(id);\n if (!groupFiles.has(id) && !classNames) {\n return undefined;\n }\n const grouped = groupFiles.has(id)\n ? IgnisArtifactsPlugin.rewriteGroups({ filePath: id, source: code })\n : code;\n return classNames\n ? IgnisArtifactsPlugin.pinClassNames({ filePath: id, source: grouped, classNames })\n : grouped;\n },\n };\n }\n}\n"]}
|
|
@@ -35,7 +35,7 @@ export class AutoArtifactsLoader {
|
|
|
35
35
|
/** The index the emitter would render for `artifacts`: modules imported in path order, each field sorted by class name. */
|
|
36
36
|
static async importIndex(opts) {
|
|
37
37
|
const emitted = opts.artifacts
|
|
38
|
-
.filter(artifact => artifact.type !== ArtifactTypes.MODEL)
|
|
38
|
+
.filter((artifact) => artifact.type !== ArtifactTypes.MODEL)
|
|
39
39
|
.sort((left, right) => left.filePath.localeCompare(right.filePath) ||
|
|
40
40
|
left.className.localeCompare(right.className));
|
|
41
41
|
const loaded = new Map();
|
|
@@ -46,9 +46,9 @@ export class AutoArtifactsLoader {
|
|
|
46
46
|
const index = {};
|
|
47
47
|
for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {
|
|
48
48
|
const classes = emitted
|
|
49
|
-
.filter(artifact => artifact.type === type)
|
|
49
|
+
.filter((artifact) => artifact.type === type)
|
|
50
50
|
.sort((left, right) => left.className.localeCompare(right.className))
|
|
51
|
-
.flatMap(artifact => loaded.get(artifact) ?? []);
|
|
51
|
+
.flatMap((artifact) => loaded.get(artifact) ?? []);
|
|
52
52
|
if (classes.length > 0) {
|
|
53
53
|
index[field] = classes;
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-loader.js","sourceRoot":"","sources":["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,CAAC;YAC/B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,KAAK,GAA2C,EAAE,CAAC;QACzD,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,mBAAmB,CAAC,UAAU,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,OAAO;iBACpB,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC;iBAC5C,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;iBACpE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;YACzB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers';\nimport type { AnyType, TClass } from '@venizia/ignis-helpers';\nimport { dirname } from 'node:path';\nimport {\n ArtifactStereotypes,\n ArtifactTypes,\n type IScannedArtifact,\n type TGeneratedArtifactIndex,\n} from '../generator/common';\nimport { ArtifactSources } from './sources';\n\n/** Loads the application's index for `@venizia/ignis-boot/auto` from source: registers the run-time plugin, then imports the virtual module. A binary never runs this - the build replaces the module. */\nexport class AutoArtifactsLoader {\n static assertRuntime(opts: { hasBun: boolean }): void {\n if (!opts.hasBun) {\n throw getError({\n message:\n '[@venizia/ignis-boot/auto] Auto artifacts need Bun (a Bun plugin builds the index) | On Node, generate the index with `ignis-artifacts generate --root src --out src/_artifacts.ts` and pass it to configs.artifacts',\n });\n }\n }\n\n static async load(): Promise<TGeneratedArtifactIndex> {\n AutoArtifactsLoader.assertRuntime({ hasBun: typeof Bun !== 'undefined' });\n\n // A warm scan cache needs neither the plugin nor TypeScript: import the listed classes directly.\n const entry = ArtifactSources.entry();\n const packageSource = ArtifactSources.packageSource({\n from: entry ? dirname(entry) : process.cwd(),\n });\n if (ArtifactSources.isCached({ packageSource })) {\n const artifacts = ArtifactSources.scan({ packageSource });\n return AutoArtifactsLoader.importIndex({\n artifacts: entry ? ArtifactSources.runningArtifacts({ artifacts, from: entry }) : artifacts,\n });\n }\n\n // A non-static specifier: a bundler must not pull the scanner (and TypeScript) into a binary.\n const pluginModule = './plugin';\n const { IgnisArtifactsPlugin } = await import(pluginModule);\n await IgnisArtifactsPlugin.registerRuntime();\n\n // A static specifier on purpose: a build without IgnisArtifactsPlugin then fails to resolve it, instead of shipping a binary with no classes.\n const { GeneratedArtifacts } = await import('ignis:artifacts');\n return GeneratedArtifacts;\n }\n\n /** The index the emitter would render for `artifacts`: modules imported in path order, each field sorted by class name. */\n static async importIndex(opts: {\n artifacts: IScannedArtifact[];\n }): Promise<TGeneratedArtifactIndex> {\n const emitted = opts.artifacts\n .filter((artifact) => artifact.type !== ArtifactTypes.MODEL)\n .sort(\n (left, right) =>\n left.filePath.localeCompare(right.filePath) ||\n left.className.localeCompare(right.className),\n );\n\n const loaded = new Map<IScannedArtifact, TClass<AnyType>>();\n for (const artifact of emitted) {\n const module = await import(artifact.filePath);\n loaded.set(artifact, module[artifact.className]);\n }\n\n const index: Record<string, Array<TClass<AnyType>>> = {};\n for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {\n const classes = emitted\n .filter((artifact) => artifact.type === type)\n .sort((left, right) => left.className.localeCompare(right.className))\n .flatMap((artifact) => loaded.get(artifact) ?? []);\n if (classes.length > 0) {\n index[field] = classes;\n }\n }\n return index;\n }\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export class GroupArtifactsResolver {
|
|
|
20
20
|
}
|
|
21
21
|
const index = {};
|
|
22
22
|
for (const artifact of ArtifactSources.folderArtifacts({ folder, site, ignore })) {
|
|
23
|
-
const field = ArtifactStereotypes.EMIT_ORDER.find(entry => entry.type === artifact.type)?.field;
|
|
23
|
+
const field = ArtifactStereotypes.EMIT_ORDER.find((entry) => entry.type === artifact.type)?.field;
|
|
24
24
|
if (!field) {
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-resolver.js","sourceRoot":"","sources":["../../../src/bun/group-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAgC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,2OAA2O;AAC3O,MAAM,OAAO,sBAAsB;IACjC,uGAAuG;aACvF,eAAU,GAAG,MAAM,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAEzF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAMpB;QACC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,oBAAoB,MAAM,IAAI,eAAe,6GAA6G;aACpK,CAAC,CAAC;QACL,CAAC;QAED,IACE,CAAC,eAAe,CAAC,QAAQ,CAAC;YACxB,aAAa,EAAE,eAAe,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;SACtE,CAAC,EACF,CAAC;YACD,MAAM,eAAe,CAAC,WAAW,EAAE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AE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YACjF,MAAM,KAAK,GAAG,mBAAmB,CAAC,UAAU,CAAC,IAAI,CAC/C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CACxC,EAAE,KAAK,CAAC;YACT,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,SAAS;YACX,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/C,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mIAAmI;IACnI,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;QACrF,MAAM,MAAM,GACV,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,CAAC,OAAO,GAAG,CAAC,WAMjB,EAAE,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,sBAAsB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC","sourcesContent":["import { getError } from '@venizia/ignis-helpers';\nimport type { AnyType, TClass } from '@venizia/ignis-helpers';\nimport { ArtifactStereotypes, type TGeneratedArtifactIndex } from '../generator/common';\nimport { dirname } from 'node:path';\nimport { ArtifactSources } from './sources';\n\n/** Fills an `ArtifactGroup` defined without content, from source: the defining package is the nearest `package.json` above the group's call site, and the group is every decorated class under a directory named `folder` in its `src`. */\nexport class GroupArtifactsResolver {\n /** The kernel's `SingletonRealm` slot for the group resolver (`ArtifactGroup.SINGLETON_REALM_KEY`). */\n static readonly REALM_SLOT = Symbol.for('@venizia/ignis-kernel:artifact-group-resolver');\n\n static async resolve(opts: {\n group: {\n folder: string | undefined;\n site: string | undefined;\n ignore?: ReadonlyArray<string>;\n };\n }): Promise<TGeneratedArtifactIndex> {\n const { folder, site, ignore } = opts.group;\n if (!site) {\n throw getError({\n message: `[ArtifactGroup] '${folder ?? '<application>'}' has no call site to resolve from | Define it with ArtifactGroup.define in the shared package's own source`,\n });\n }\n\n if (\n !ArtifactSources.isCached({\n packageSource: ArtifactSources.packageSource({ from: dirname(site) }),\n })\n ) {\n await ArtifactSources.loadScanner();\n }\n\n const index: Record<string, Array<TClass<AnyType>>> = {};\n for (const artifact of ArtifactSources.folderArtifacts({ folder, site, ignore })) {\n const field = ArtifactStereotypes.EMIT_ORDER.find(\n (entry) => entry.type === artifact.type,\n )?.field;\n if (!field) {\n continue;\n }\n const loaded = await import(artifact.filePath);\n index[field] = [...(index[field] ?? []), loaded[artifact.className]];\n }\n return index;\n }\n\n /** Fills the kernel's realm slot; the holder may already exist (the kernel created it empty), so it is mutated, never replaced. */\n static install(): void {\n const existing: unknown = Reflect.get(globalThis, GroupArtifactsResolver.REALM_SLOT);\n const holder: { resolve?: unknown } =\n typeof existing === 'object' && existing !== null ? existing : {};\n holder.resolve = (resolveOpts: {\n group: {\n folder: string | undefined;\n site: string | undefined;\n ignore?: ReadonlyArray<string>;\n };\n }) => GroupArtifactsResolver.resolve(resolveOpts);\n Reflect.set(globalThis, GroupArtifactsResolver.REALM_SLOT, holder);\n }\n}\n"]}
|
package/dist/esm/bun/plugin.js
CHANGED
|
@@ -84,8 +84,8 @@ export class IgnisArtifactsPlugin {
|
|
|
84
84
|
const fields = [];
|
|
85
85
|
for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {
|
|
86
86
|
const locals = artifacts
|
|
87
|
-
.filter(artifact => artifact.type === type)
|
|
88
|
-
.map(artifact => {
|
|
87
|
+
.filter((artifact) => artifact.type === type)
|
|
88
|
+
.map((artifact) => {
|
|
89
89
|
if (isCompiled) {
|
|
90
90
|
return `require(${JSON.stringify(artifact.filePath)}).${artifact.className}`;
|
|
91
91
|
}
|
|
@@ -137,7 +137,7 @@ export class IgnisArtifactsPlugin {
|
|
|
137
137
|
refuse(call, 'the argument is not an object literal');
|
|
138
138
|
}
|
|
139
139
|
const literal = argument;
|
|
140
|
-
const named = (name) => literal.properties.find(entry => entry.name !== undefined && ts.isIdentifier(entry.name) && entry.name.text === name);
|
|
140
|
+
const named = (name) => literal.properties.find((entry) => entry.name !== undefined && ts.isIdentifier(entry.name) && entry.name.text === name);
|
|
141
141
|
if (named('content')) {
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
@@ -157,8 +157,8 @@ export class IgnisArtifactsPlugin {
|
|
|
157
157
|
const ignoreList = ignoreProperty &&
|
|
158
158
|
ts.isPropertyAssignment(ignoreProperty) &&
|
|
159
159
|
ts.isArrayLiteralExpression(ignoreProperty.initializer) &&
|
|
160
|
-
ignoreProperty.initializer.elements.every(element => ts.isStringLiteral(element))
|
|
161
|
-
? ignoreProperty.initializer.elements.map(element => element.text)
|
|
160
|
+
ignoreProperty.initializer.elements.every((element) => ts.isStringLiteral(element))
|
|
161
|
+
? ignoreProperty.initializer.elements.map((element) => element.text)
|
|
162
162
|
: undefined;
|
|
163
163
|
if (ignoreProperty && ignoreList === undefined) {
|
|
164
164
|
refuse(call, 'ignore is not an array of string literals');
|
|
@@ -188,7 +188,7 @@ export class IgnisArtifactsPlugin {
|
|
|
188
188
|
const found = [];
|
|
189
189
|
const visit = (node) => {
|
|
190
190
|
if (ts.isClassDeclaration(node) && node.name) {
|
|
191
|
-
const isDecorated = (ts.getDecorators(node) ?? []).some(decorator => {
|
|
191
|
+
const isDecorated = (ts.getDecorators(node) ?? []).some((decorator) => {
|
|
192
192
|
const expression = ts.isCallExpression(decorator.expression)
|
|
193
193
|
? decorator.expression.expression
|
|
194
194
|
: decorator.expression;
|
|
@@ -240,7 +240,7 @@ export class IgnisArtifactsPlugin {
|
|
|
240
240
|
if (!IgnisArtifactsPlugin.DECORATED.test(source)) {
|
|
241
241
|
continue;
|
|
242
242
|
}
|
|
243
|
-
add(IgnisArtifactsPlugin.decoratedClasses({ filePath: file, source }).map(className => ({
|
|
243
|
+
add(IgnisArtifactsPlugin.decoratedClasses({ filePath: file, source }).map((className) => ({
|
|
244
244
|
filePath: file,
|
|
245
245
|
className,
|
|
246
246
|
})));
|
|
@@ -259,7 +259,7 @@ export class IgnisArtifactsPlugin {
|
|
|
259
259
|
}
|
|
260
260
|
/** The source files that define groups: the application's own `src` and the `src` of each workspace dependency (a dependency whose real path is outside every `node_modules`), found by walking up the `node_modules` chain as Node resolution does. */
|
|
261
261
|
static groupDefinitionFiles(opts) {
|
|
262
|
-
return IgnisArtifactsPlugin.workspaceSourceFiles(opts).filter(file => IgnisArtifactsPlugin.DEFINE_CALL.test(readFileSync(file, 'utf8')));
|
|
262
|
+
return IgnisArtifactsPlugin.workspaceSourceFiles(opts).filter((file) => IgnisArtifactsPlugin.DEFINE_CALL.test(readFileSync(file, 'utf8')));
|
|
263
263
|
}
|
|
264
264
|
/** The source files of the application and of each workspace dependency (a dependency whose real path is outside every `node_modules`), found by walking up the `node_modules` chain as Node resolution does - plus the compiled trees beside each `src`, for a package that runs from `dist`. Tests excluded. */
|
|
265
265
|
static workspaceSourceFiles(opts) {
|
|
@@ -345,8 +345,8 @@ export class IgnisArtifactsPlugin {
|
|
|
345
345
|
const pinned = IgnisArtifactsPlugin.pinnedClasses({ root, groupFiles, entry });
|
|
346
346
|
const loaded = [...new Set([...groupFiles, ...pinned.keys()])];
|
|
347
347
|
if (loaded.length > 0) {
|
|
348
|
-
const escaped = loaded.map(file => file.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'));
|
|
349
|
-
build.onLoad({ filter: new RegExp(`^(?:${escaped.join('|')})$`) }, args => {
|
|
348
|
+
const escaped = loaded.map((file) => file.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'));
|
|
349
|
+
build.onLoad({ filter: new RegExp(`^(?:${escaped.join('|')})$`) }, (args) => {
|
|
350
350
|
const source = readFileSync(args.path, 'utf8');
|
|
351
351
|
const grouped = groupFileSet.has(args.path)
|
|
352
352
|
? IgnisArtifactsPlugin.rewriteGroups({ filePath: args.path, source })
|