@venizia/ignis-boot 0.2.1-1 → 0.2.1-10
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/dist/cjs/bun/auto-group.d.ts.map +1 -1
- package/dist/cjs/bun/auto-group.js +4 -3
- package/dist/cjs/bun/auto-group.js.map +1 -1
- package/dist/cjs/bun/auto-loader.d.ts +5 -1
- package/dist/cjs/bun/auto-loader.d.ts.map +1 -1
- package/dist/cjs/bun/auto-loader.js +37 -0
- package/dist/cjs/bun/auto-loader.js.map +1 -1
- package/dist/cjs/bun/group-resolver.d.ts +2 -1
- package/dist/cjs/bun/group-resolver.d.ts.map +1 -1
- package/dist/cjs/bun/group-resolver.js +11 -5
- package/dist/cjs/bun/group-resolver.js.map +1 -1
- package/dist/cjs/bun/index.d.ts +1 -0
- package/dist/cjs/bun/index.d.ts.map +1 -1
- package/dist/cjs/bun/index.js +1 -0
- package/dist/cjs/bun/index.js.map +1 -1
- package/dist/cjs/bun/plugin.d.ts +9 -4
- package/dist/cjs/bun/plugin.d.ts.map +1 -1
- package/dist/cjs/bun/plugin.js +145 -70
- package/dist/cjs/bun/plugin.js.map +1 -1
- package/dist/cjs/bun/scan-cache.d.ts +22 -0
- package/dist/cjs/bun/scan-cache.d.ts.map +1 -0
- package/dist/cjs/bun/scan-cache.js +89 -0
- package/dist/cjs/bun/scan-cache.js.map +1 -0
- package/dist/cjs/bun/sources.d.ts +36 -4
- package/dist/cjs/bun/sources.d.ts.map +1 -1
- package/dist/cjs/bun/sources.js +83 -16
- package/dist/cjs/bun/sources.js.map +1 -1
- package/dist/cjs/generator/common/constants.d.ts +4 -0
- package/dist/cjs/generator/common/constants.d.ts.map +1 -1
- package/dist/cjs/generator/common/constants.js +6 -2
- package/dist/cjs/generator/common/constants.js.map +1 -1
- package/dist/cjs/generator/emitter.d.ts.map +1 -1
- package/dist/cjs/generator/emitter.js +5 -2
- 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 -7
- package/dist/cjs/generator/scanner.js.map +1 -1
- package/dist/cjs/vite/index.d.ts +2 -0
- package/dist/cjs/vite/index.d.ts.map +1 -0
- package/dist/cjs/vite/index.js +18 -0
- package/dist/cjs/vite/index.js.map +1 -0
- package/dist/cjs/vite/plugin.d.ts +33 -0
- package/dist/cjs/vite/plugin.d.ts.map +1 -0
- package/dist/cjs/vite/plugin.js +51 -0
- package/dist/cjs/vite/plugin.js.map +1 -0
- package/dist/esm/bun/auto-group.d.ts.map +1 -1
- package/dist/esm/bun/auto-group.js +2 -1
- package/dist/esm/bun/auto-group.js.map +1 -1
- package/dist/esm/bun/auto-loader.d.ts +5 -1
- package/dist/esm/bun/auto-loader.d.ts.map +1 -1
- package/dist/esm/bun/auto-loader.js +37 -0
- package/dist/esm/bun/auto-loader.js.map +1 -1
- package/dist/esm/bun/group-resolver.d.ts +2 -1
- package/dist/esm/bun/group-resolver.d.ts.map +1 -1
- package/dist/esm/bun/group-resolver.js +10 -4
- package/dist/esm/bun/group-resolver.js.map +1 -1
- package/dist/esm/bun/index.d.ts +1 -0
- package/dist/esm/bun/index.d.ts.map +1 -1
- package/dist/esm/bun/index.js +1 -0
- package/dist/esm/bun/index.js.map +1 -1
- package/dist/esm/bun/plugin.d.ts +9 -4
- package/dist/esm/bun/plugin.d.ts.map +1 -1
- package/dist/esm/bun/plugin.js +146 -71
- package/dist/esm/bun/plugin.js.map +1 -1
- package/dist/esm/bun/scan-cache.d.ts +22 -0
- package/dist/esm/bun/scan-cache.d.ts.map +1 -0
- package/dist/esm/bun/scan-cache.js +85 -0
- package/dist/esm/bun/scan-cache.js.map +1 -0
- package/dist/esm/bun/sources.d.ts +36 -4
- package/dist/esm/bun/sources.d.ts.map +1 -1
- package/dist/esm/bun/sources.js +84 -17
- package/dist/esm/bun/sources.js.map +1 -1
- package/dist/esm/generator/common/constants.d.ts +4 -0
- package/dist/esm/generator/common/constants.d.ts.map +1 -1
- package/dist/esm/generator/common/constants.js +6 -2
- package/dist/esm/generator/common/constants.js.map +1 -1
- package/dist/esm/generator/emitter.d.ts.map +1 -1
- package/dist/esm/generator/emitter.js +5 -2
- 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 +12 -9
- package/dist/esm/generator/scanner.js.map +1 -1
- package/dist/esm/vite/index.d.ts +2 -0
- package/dist/esm/vite/index.d.ts.map +1 -0
- package/dist/esm/vite/index.js +2 -0
- package/dist/esm/vite/index.js.map +1 -0
- package/dist/esm/vite/plugin.d.ts +33 -0
- package/dist/esm/vite/plugin.d.ts.map +1 -0
- package/dist/esm/vite/plugin.js +47 -0
- package/dist/esm/vite/plugin.js.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IgnisArtifactsVitePlugin = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const generator_1 = require("../generator");
|
|
6
|
+
const plugin_1 = require("../bun/plugin");
|
|
7
|
+
const sources_1 = require("../bun/sources");
|
|
8
|
+
/** `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), and inlines every `ArtifactGroup.define` / `application` call. Names are kept in the build, because binding keys are built from `Class.name` and a minifier renames classes. */
|
|
9
|
+
class IgnisArtifactsVitePlugin {
|
|
10
|
+
static { this.RESOLVED_VIRTUAL = `\0${plugin_1.IgnisArtifactsPlugin.VIRTUAL}`; }
|
|
11
|
+
static {
|
|
12
|
+
sources_1.ArtifactSources.useScanner({ scanner: generator_1.ArtifactScanner.getInstance() });
|
|
13
|
+
}
|
|
14
|
+
/** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */
|
|
15
|
+
static create(opts = {}) {
|
|
16
|
+
let root = opts.root ? (0, node_path_1.resolve)(opts.root) : '';
|
|
17
|
+
let groupFiles = new Set();
|
|
18
|
+
const autoModule = `import { ${plugin_1.IgnisArtifactsPlugin.EXPORT_NAME} } from '${plugin_1.IgnisArtifactsPlugin.VIRTUAL}';\nimport { AutoArtifactGroup } from './auto-group';\nexport default new AutoArtifactGroup({ content: ${plugin_1.IgnisArtifactsPlugin.EXPORT_NAME} });\n`;
|
|
19
|
+
return {
|
|
20
|
+
name: plugin_1.IgnisArtifactsPlugin.NAME,
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
// Pre-bundling would hide `auto` inside a dependency chunk, out of reach of `load`.
|
|
23
|
+
config: () => ({
|
|
24
|
+
optimizeDeps: { exclude: ['@venizia/ignis-boot'] },
|
|
25
|
+
build: { rolldownOptions: { output: { keepNames: true } } },
|
|
26
|
+
}),
|
|
27
|
+
configResolved: config => {
|
|
28
|
+
root ||= sources_1.ArtifactSources.packageSource({ from: config.root });
|
|
29
|
+
groupFiles = new Set(plugin_1.IgnisArtifactsPlugin.groupDefinitionFiles({ root }));
|
|
30
|
+
},
|
|
31
|
+
resolveId: id => id === plugin_1.IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,
|
|
32
|
+
load: id => {
|
|
33
|
+
if (id === IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL) {
|
|
34
|
+
return plugin_1.IgnisArtifactsPlugin.render({ root });
|
|
35
|
+
}
|
|
36
|
+
return plugin_1.IgnisArtifactsPlugin.AUTO_MODULE.test(id) ? autoModule : undefined;
|
|
37
|
+
},
|
|
38
|
+
transform: (code, id) => groupFiles.has(id)
|
|
39
|
+
? plugin_1.IgnisArtifactsPlugin.rewriteGroups({ filePath: id, source: code })
|
|
40
|
+
: undefined,
|
|
41
|
+
// A file added, removed or edited under the root can change the index: rescan on the next load.
|
|
42
|
+
watchChange: id => {
|
|
43
|
+
if (id.startsWith(root)) {
|
|
44
|
+
sources_1.ArtifactSources.clear();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.IgnisArtifactsVitePlugin = IgnisArtifactsVitePlugin;
|
|
51
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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;AAiBjD,gWAAgW;AAChW,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,MAAM,CAAC,MAAM,CAAC,OAA0B,EAAE;QACxC,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,IAAI,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;QACnC,MAAM,UAAU,GAAG,YAAY,6BAAoB,CAAC,WAAW,YAAY,6BAAoB,CAAC,OAAO,0GAA0G,6BAAoB,CAAC,WAAW,QAAQ,CAAC;QAE1P,OAAO;YACL,IAAI,EAAE,6BAAoB,CAAC,IAAI;YAC/B,OAAO,EAAE,KAAK;YACd,oFAAoF;YACpF,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;gBACb,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE;gBAClD,KAAK,EAAE,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;aAC5D,CAAC;YACF,cAAc,EAAE,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
|
|
1
|
+
{"version":3,"file":"auto-group.d.ts","sourceRoot":"","sources":["../../../src/bun/auto-group.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,+RAA+R;AAC/R,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,eAAe,EAAG,IAAI,CAAU;IACzC,QAAQ,CAAC,MAAM,YAAa;IAC5B,QAAQ,CAAC,IAAI,YAAa;IAC1B,QAAQ,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAAC;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuD;gBAEpE,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,uBAAuB,CAAC;QAClC,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,uBAAuB,CAAC,CAAC;KAClD;IAKK,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAYjD,OAAO,CAAC,MAAM,CAAC,UAAU;IAOzB,IAAI,cAAc,IAAI,KAAK,CAE1B;IAED,IAAI,WAAW,IAAI,KAAK,CAEvB;IAED,IAAI,UAAU,IAAI,KAAK,CAEtB;IAED,IAAI,YAAY,IAAI,KAAK,CAExB;IAED,IAAI,QAAQ,IAAI,KAAK,CAEpB;IAED,IAAI,WAAW,IAAI,KAAK,CAEvB;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// The inversion package, not the helpers barrel: a browser bundle reaches this module, and the barrel loads node builtins.
|
|
2
|
+
import { getError } from '@venizia/ignis-inversion';
|
|
2
3
|
/** The application's own artifacts as the kernel's group protocol (`isArtifactGroup`), built without depending on the kernel: inlined `content` in a binary, `resolve()` from source. Reading a kind throws, so a function that walks `configs.artifacts` cannot drop it as an empty index. */
|
|
3
4
|
export class AutoArtifactGroup {
|
|
4
5
|
constructor(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-group.js","sourceRoot":"","sources":["../../../src/bun/auto-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auto-group.js","sourceRoot":"","sources":["../../../src/bun/auto-group.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,+RAA+R;AAC/R,MAAM,OAAO,iBAAiB;IAO5B,YAAY,IAGX;QATQ,oBAAe,GAAG,IAAa,CAAC;QAChC,WAAM,GAAG,SAAS,CAAC;QACnB,SAAI,GAAG,SAAS,CAAC;QAQxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,8EAA8E;aACxF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAEO,MAAM,CAAC,UAAU;QACvB,MAAM,QAAQ,CAAC;YACb,OAAO,EACL,sOAAsO;SACzO,CAAC,CAAC;IACL,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;CACF"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IScannedArtifact, type TGeneratedArtifactIndex } from '../generator/common/index.js';
|
|
2
2
|
/** 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. */
|
|
3
3
|
export declare class AutoArtifactsLoader {
|
|
4
4
|
static assertRuntime(opts: {
|
|
5
5
|
hasBun: boolean;
|
|
6
6
|
}): void;
|
|
7
7
|
static load(): Promise<TGeneratedArtifactIndex>;
|
|
8
|
+
/** The index the emitter would render for `artifacts`: modules imported in path order, each field sorted by class name. */
|
|
9
|
+
static importIndex(opts: {
|
|
10
|
+
artifacts: IScannedArtifact[];
|
|
11
|
+
}): Promise<TGeneratedArtifactIndex>;
|
|
8
12
|
}
|
|
9
13
|
//# sourceMappingURL=auto-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-loader.d.ts","sourceRoot":"","sources":["../../../src/bun/auto-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-loader.d.ts","sourceRoot":"","sources":["../../../src/bun/auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,0MAA0M;AAC1M,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;WASxC,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAyBrD,2HAA2H;WAC9G,WAAW,CAAC,IAAI,EAAE;QAC7B,SAAS,EAAE,gBAAgB,EAAE,CAAC;KAC/B,GAAG,OAAO,CAAC,uBAAuB,CAAC;CA2BrC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-helpers';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { ArtifactStereotypes, ArtifactTypes, } from '../generator/common/index.js';
|
|
4
|
+
import { ArtifactSources } from './sources.js';
|
|
2
5
|
/** 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. */
|
|
3
6
|
export class AutoArtifactsLoader {
|
|
4
7
|
static assertRuntime(opts) {
|
|
@@ -10,6 +13,17 @@ export class AutoArtifactsLoader {
|
|
|
10
13
|
}
|
|
11
14
|
static async load() {
|
|
12
15
|
AutoArtifactsLoader.assertRuntime({ hasBun: typeof Bun !== 'undefined' });
|
|
16
|
+
// A warm scan cache needs neither the plugin nor TypeScript: import the listed classes directly.
|
|
17
|
+
const entry = ArtifactSources.entry();
|
|
18
|
+
const packageSource = ArtifactSources.packageSource({
|
|
19
|
+
from: entry ? dirname(entry) : process.cwd(),
|
|
20
|
+
});
|
|
21
|
+
if (ArtifactSources.isCached({ packageSource })) {
|
|
22
|
+
const artifacts = ArtifactSources.scan({ packageSource });
|
|
23
|
+
return AutoArtifactsLoader.importIndex({
|
|
24
|
+
artifacts: entry ? ArtifactSources.runningArtifacts({ artifacts, from: entry }) : artifacts,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
13
27
|
// A non-static specifier: a bundler must not pull the scanner (and TypeScript) into a binary.
|
|
14
28
|
const pluginModule = './plugin';
|
|
15
29
|
const { IgnisArtifactsPlugin } = await import(pluginModule);
|
|
@@ -18,5 +32,28 @@ export class AutoArtifactsLoader {
|
|
|
18
32
|
const { GeneratedArtifacts } = await import('ignis:artifacts');
|
|
19
33
|
return GeneratedArtifacts;
|
|
20
34
|
}
|
|
35
|
+
/** The index the emitter would render for `artifacts`: modules imported in path order, each field sorted by class name. */
|
|
36
|
+
static async importIndex(opts) {
|
|
37
|
+
const emitted = opts.artifacts
|
|
38
|
+
.filter(artifact => artifact.type !== ArtifactTypes.MODEL)
|
|
39
|
+
.sort((left, right) => left.filePath.localeCompare(right.filePath) ||
|
|
40
|
+
left.className.localeCompare(right.className));
|
|
41
|
+
const loaded = new Map();
|
|
42
|
+
for (const artifact of emitted) {
|
|
43
|
+
const module = await import(artifact.filePath);
|
|
44
|
+
loaded.set(artifact, module[artifact.className]);
|
|
45
|
+
}
|
|
46
|
+
const index = {};
|
|
47
|
+
for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {
|
|
48
|
+
const classes = emitted
|
|
49
|
+
.filter(artifact => artifact.type === type)
|
|
50
|
+
.sort((left, right) => left.className.localeCompare(right.className))
|
|
51
|
+
.flatMap(artifact => loaded.get(artifact) ?? []);
|
|
52
|
+
if (classes.length > 0) {
|
|
53
|
+
index[field] = classes;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return index;
|
|
57
|
+
}
|
|
21
58
|
}
|
|
22
59
|
//# sourceMappingURL=auto-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-loader.js","sourceRoot":"","sources":["../../../src/bun/auto-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"auto-loader.js","sourceRoot":"","sources":["../../../src/bun/auto-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,mBAAmB,EACnB,aAAa,GAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,0MAA0M;AAC1M,MAAM,OAAO,mBAAmB;IAC9B,MAAM,CAAC,aAAa,CAAC,IAAyB;QAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,QAAQ,CAAC;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TGeneratedArtifactIndex } from '../generator/index.js';
|
|
1
|
+
import { type TGeneratedArtifactIndex } from '../generator/common/index.js';
|
|
2
2
|
/** 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`. */
|
|
3
3
|
export declare class GroupArtifactsResolver {
|
|
4
4
|
/** The kernel's `SingletonRealm` slot for the group resolver (`ArtifactGroup.SINGLETON_REALM_KEY`). */
|
|
@@ -7,6 +7,7 @@ export declare class GroupArtifactsResolver {
|
|
|
7
7
|
group: {
|
|
8
8
|
folder: string | undefined;
|
|
9
9
|
site: string | undefined;
|
|
10
|
+
ignore?: ReadonlyArray<string>;
|
|
10
11
|
};
|
|
11
12
|
}): Promise<TGeneratedArtifactIndex>;
|
|
12
13
|
/** Fills the kernel's realm slot; the holder may already exist (the kernel created it empty), so it is mutated, never replaced. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-resolver.d.ts","sourceRoot":"","sources":["../../../src/bun/group-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"group-resolver.d.ts","sourceRoot":"","sources":["../../../src/bun/group-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAIxF,2OAA2O;AAC3O,qBAAa,sBAAsB;IACjC,uGAAuG;IACvG,MAAM,CAAC,QAAQ,CAAC,UAAU,gBAA+D;WAE5E,OAAO,CAAC,IAAI,EAAE;QACzB,KAAK,EAAE;YACL,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;YAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;YACzB,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;SAChC,CAAC;KACH,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA8BpC,mIAAmI;IACnI,MAAM,CAAC,OAAO,IAAI,IAAI;CAavB"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-helpers';
|
|
2
|
-
import { ArtifactStereotypes } from '../generator/index.js';
|
|
2
|
+
import { ArtifactStereotypes } from '../generator/common/index.js';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
3
4
|
import { ArtifactSources } from './sources.js';
|
|
4
5
|
/** 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`. */
|
|
5
6
|
export class GroupArtifactsResolver {
|
|
6
7
|
/** The kernel's `SingletonRealm` slot for the group resolver (`ArtifactGroup.SINGLETON_REALM_KEY`). */
|
|
7
8
|
static { this.REALM_SLOT = Symbol.for('@venizia/ignis-kernel:artifact-group-resolver'); }
|
|
8
9
|
static async resolve(opts) {
|
|
9
|
-
const { folder, site } = opts.group;
|
|
10
|
-
if (!
|
|
10
|
+
const { folder, site, ignore } = opts.group;
|
|
11
|
+
if (!site) {
|
|
11
12
|
throw getError({
|
|
12
13
|
message: `[ArtifactGroup] '${folder ?? '<application>'}' has no call site to resolve from | Define it with ArtifactGroup.define in the shared package's own source`,
|
|
13
14
|
});
|
|
14
15
|
}
|
|
16
|
+
if (!ArtifactSources.isCached({
|
|
17
|
+
packageSource: ArtifactSources.packageSource({ from: dirname(site) }),
|
|
18
|
+
})) {
|
|
19
|
+
await ArtifactSources.loadScanner();
|
|
20
|
+
}
|
|
15
21
|
const index = {};
|
|
16
|
-
for (const artifact of ArtifactSources.folderArtifacts({ folder, site })) {
|
|
22
|
+
for (const artifact of ArtifactSources.folderArtifacts({ folder, site, ignore })) {
|
|
17
23
|
const field = ArtifactStereotypes.EMIT_ORDER.find(entry => entry.type === artifact.type)?.field;
|
|
18
24
|
if (!field) {
|
|
19
25
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-resolver.js","sourceRoot":"","sources":["../../../src/bun/group-resolver.ts"],"names":[],"mapp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KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CACtC,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"}
|
package/dist/esm/bun/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bun/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bun/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/esm/bun/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bun/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bun/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/esm/bun/plugin.d.ts
CHANGED
|
@@ -9,15 +9,18 @@ export declare class IgnisArtifactsPlugin {
|
|
|
9
9
|
/** A text test for a file worth parsing: `ArtifactGroup.define(`, with any spacing or line break around the dot. */
|
|
10
10
|
static readonly DEFINE_CALL: RegExp;
|
|
11
11
|
private static readonly RUNTIME_KEY;
|
|
12
|
-
/** The `src` beside the nearest `package.json` at or above `from` (default: the
|
|
12
|
+
/** The `src` beside the nearest `package.json` at or above `from` (default: the entry module's directory). */
|
|
13
13
|
static defaultRoot(opts?: {
|
|
14
14
|
from?: string;
|
|
15
15
|
}): string;
|
|
16
|
-
/** The
|
|
16
|
+
/** The entry module's directory (`Bun.main`), so the root never depends on where the process was started; the working directory only when there is no entry file (`bun -e`, a REPL). */
|
|
17
|
+
static entryDirectory(): string;
|
|
18
|
+
/** The index as module source: every import absolute, since a virtual module has no directory to resolve from. With `entry` in a compiled tree, each class is imported from that tree (`ArtifactSources.runningArtifacts`). */
|
|
17
19
|
static render(opts: {
|
|
18
20
|
root: string;
|
|
21
|
+
entry?: string;
|
|
19
22
|
}): string;
|
|
20
|
-
/** Rewrites every `ArtifactGroup.define({ folder: '<literal>' })` in a source file to carry its classes as `content`, imported by absolute path - a binary then holds each group's list and never scans. A
|
|
23
|
+
/** Rewrites every `ArtifactGroup.define({ folder: '<literal>' })` and `ArtifactGroup.application()` in a source file to carry its classes as `content`, imported by absolute path - a binary then holds each group's list and never scans. A group with no decorated class, or a call the plugin cannot read (an aliased `ArtifactGroup`, a folder that is not a string literal), fails the build. */
|
|
21
24
|
static rewriteGroups(opts: {
|
|
22
25
|
filePath: string;
|
|
23
26
|
source: string;
|
|
@@ -26,10 +29,12 @@ export declare class IgnisArtifactsPlugin {
|
|
|
26
29
|
static groupDefinitionFiles(opts: {
|
|
27
30
|
root: string;
|
|
28
31
|
}): string[];
|
|
29
|
-
/** For `Bun.build({ plugins: [IgnisArtifactsPlugin.create()] })`; `isRuntime` is set by `registerRuntime`, which serves a virtual module instead. */
|
|
32
|
+
/** For `Bun.build({ plugins: [IgnisArtifactsPlugin.create()] })`; `isRuntime` is set by `registerRuntime`, which serves a virtual module instead. `entry` (default: the build's first entrypoint, or `Bun.main` at run time) decides which tree the classes are imported from. */
|
|
30
33
|
static create(opts?: {
|
|
31
34
|
root?: string;
|
|
35
|
+
entry?: string;
|
|
32
36
|
isRuntime?: boolean;
|
|
37
|
+
lazyIndex?: boolean;
|
|
33
38
|
}): BunPlugin;
|
|
34
39
|
/** Registers the run-time plugin once per process; a second call is a no-op. */
|
|
35
40
|
static registerRuntime(opts?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/bun/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAQrC,6QAA6Q;AAC7Q,qBAAa,oBAAoB;IAC/B,MAAM,CAAC,QAAQ,CAAC,IAAI,qBAAqB;IACzC,MAAM,CAAC,QAA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AAM,EAAE;IAgE7D,kRAAkR;IAClR,MAAM,CAAC,MAAM,CACX,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GACrF,SAAS;IAmDZ,gFAAgF;WACnE,eAAe,CAAC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAO1E"}
|
package/dist/esm/bun/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-helpers';
|
|
2
|
-
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { existsSync, globSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
3
|
import { dirname, join, resolve, sep } from 'node:path';
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { ArtifactIndexEmitter, ArtifactScanner, ArtifactStereotypes } from '../generator/index.js';
|
|
@@ -12,29 +12,43 @@ export class IgnisArtifactsPlugin {
|
|
|
12
12
|
/** `@venizia/ignis-boot/auto`, from source or from either dist format - replaced at build time by a static re-export of the virtual module. */
|
|
13
13
|
static { this.AUTO_MODULE = /[\\/](?:@venizia[\\/]ignis-boot|packages[\\/]boot)[\\/](?:dist[\\/](?:esm|cjs)|src)[\\/]bun[\\/]auto\.(?:ts|js)$/; }
|
|
14
14
|
/** A text test for a file worth parsing: `ArtifactGroup.define(`, with any spacing or line break around the dot. */
|
|
15
|
-
static { this.DEFINE_CALL = /ArtifactGroup\s*\.\s*define\s*\(/; }
|
|
15
|
+
static { this.DEFINE_CALL = /ArtifactGroup\s*\.\s*(?:define|application)\s*\(/; }
|
|
16
16
|
static { this.RUNTIME_KEY = Symbol.for('@venizia/ignis-boot:artifacts-runtime-plugin'); }
|
|
17
|
-
|
|
17
|
+
static {
|
|
18
|
+
ArtifactSources.useScanner({ scanner: ArtifactScanner.getInstance() });
|
|
19
|
+
}
|
|
20
|
+
/** The `src` beside the nearest `package.json` at or above `from` (default: the entry module's directory). */
|
|
18
21
|
static defaultRoot(opts = {}) {
|
|
19
|
-
return ArtifactSources.packageSource(
|
|
22
|
+
return ArtifactSources.packageSource({
|
|
23
|
+
from: opts.from ?? IgnisArtifactsPlugin.entryDirectory(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** The entry module's directory (`Bun.main`), so the root never depends on where the process was started; the working directory only when there is no entry file (`bun -e`, a REPL). */
|
|
27
|
+
static entryDirectory() {
|
|
28
|
+
const entry = ArtifactSources.entry();
|
|
29
|
+
return entry ? dirname(entry) : process.cwd();
|
|
20
30
|
}
|
|
21
|
-
/** The index as module source: every import absolute, since a virtual module has no directory to resolve from. */
|
|
31
|
+
/** The index as module source: every import absolute, since a virtual module has no directory to resolve from. With `entry` in a compiled tree, each class is imported from that tree (`ArtifactSources.runningArtifacts`). */
|
|
22
32
|
static render(opts) {
|
|
23
33
|
const root = resolve(opts.root);
|
|
34
|
+
if (!existsSync(root)) {
|
|
35
|
+
throw getError({
|
|
36
|
+
message: `[IgnisArtifactsPlugin] ${dirname(root)} has no src directory (${root}) | Auto artifacts scan the src beside the package.json of the entry module; pass IgnisArtifactsPlugin.create({ root }), or use ArtifactGroup.application() in the application's own source`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
24
39
|
const outFile = join(root, '__ignis_artifacts__.ts');
|
|
25
|
-
const
|
|
26
|
-
root,
|
|
27
|
-
followReexports: true,
|
|
28
|
-
});
|
|
40
|
+
const artifacts = ArtifactSources.scan({ packageSource: root });
|
|
29
41
|
return ArtifactIndexEmitter.render({
|
|
30
|
-
artifacts
|
|
42
|
+
artifacts: opts.entry
|
|
43
|
+
? ArtifactSources.runningArtifacts({ artifacts, from: opts.entry })
|
|
44
|
+
: artifacts,
|
|
31
45
|
outFile,
|
|
32
46
|
exportName: IgnisArtifactsPlugin.EXPORT_NAME,
|
|
33
47
|
command: { root, out: outFile },
|
|
34
48
|
absoluteImports: true,
|
|
35
49
|
});
|
|
36
50
|
}
|
|
37
|
-
/** Rewrites every `ArtifactGroup.define({ folder: '<literal>' })` in a source file to carry its classes as `content`, imported by absolute path - a binary then holds each group's list and never scans. A
|
|
51
|
+
/** Rewrites every `ArtifactGroup.define({ folder: '<literal>' })` and `ArtifactGroup.application()` in a source file to carry its classes as `content`, imported by absolute path - a binary then holds each group's list and never scans. A group with no decorated class, or a call the plugin cannot read (an aliased `ArtifactGroup`, a folder that is not a string literal), fails the build. */
|
|
38
52
|
static rewriteGroups(opts) {
|
|
39
53
|
const { filePath, source } = opts;
|
|
40
54
|
const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);
|
|
@@ -56,63 +70,104 @@ export class IgnisArtifactsPlugin {
|
|
|
56
70
|
const refuse = (node, reason) => {
|
|
57
71
|
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
58
72
|
throw getError({
|
|
59
|
-
message: `[IgnisArtifactsPlugin] An ArtifactGroup
|
|
73
|
+
message: `[IgnisArtifactsPlugin] An ArtifactGroup call at ${filePath}:${line + 1} cannot be rewritten | ${reason} - write ArtifactGroup.define({ folder: '<name>' }) or ArtifactGroup.application() with the class imported under its own name`,
|
|
60
74
|
});
|
|
61
75
|
};
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const named = (name) => literal.properties.find(entry => entry.name && ts.isIdentifier(entry.name) && entry.name.text === name);
|
|
78
|
-
const folderProperty = named('folder');
|
|
79
|
-
if (!named('content')) {
|
|
80
|
-
if (!folderProperty ||
|
|
81
|
-
!ts.isPropertyAssignment(folderProperty) ||
|
|
82
|
-
!ts.isStringLiteral(folderProperty.initializer)) {
|
|
83
|
-
refuse(node, 'folder is not a string literal');
|
|
84
|
-
}
|
|
85
|
-
const folder = folderProperty.initializer.text;
|
|
86
|
-
const artifacts = ArtifactSources.folderArtifacts({ folder, site: filePath });
|
|
87
|
-
if (artifacts.length === 0) {
|
|
88
|
-
throw getError({
|
|
89
|
-
message: `[IgnisArtifactsPlugin] ArtifactGroup '${folder}' resolved to no class | ${filePath} - check the folder name and that its classes carry a stereotype decorator`,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const fields = [];
|
|
93
|
-
for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {
|
|
94
|
-
const locals = artifacts
|
|
95
|
-
.filter(artifact => artifact.type === type)
|
|
96
|
-
.map(artifact => {
|
|
97
|
-
counter += 1;
|
|
98
|
-
const local = `__ignis_group_${counter}`;
|
|
99
|
-
const path = artifact.filePath.split(sep).join('/').replace(/\.ts$/, '');
|
|
100
|
-
imports.push(`import { ${artifact.className} as ${local} } from '${path}';`);
|
|
101
|
-
return local;
|
|
102
|
-
});
|
|
103
|
-
if (locals.length > 0) {
|
|
104
|
-
fields.push(`${field}: [${locals.join(', ')}]`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const last = literal.properties[literal.properties.length - 1];
|
|
108
|
-
edits.push({
|
|
109
|
-
at: last ? last.getEnd() : literal.getStart() + 1,
|
|
110
|
-
text: `${last ? ', ' : ''}content: { ${fields.join(', ')} }`,
|
|
111
|
-
});
|
|
76
|
+
const isCompiled = !ArtifactStereotypes.SOURCE_EXTENSION.test(filePath);
|
|
77
|
+
const contentLiteral = (folder, ignore) => {
|
|
78
|
+
const artifacts = ArtifactSources.folderArtifacts({ folder, site: filePath, ignore });
|
|
79
|
+
if (artifacts.length === 0) {
|
|
80
|
+
throw getError({
|
|
81
|
+
message: `[IgnisArtifactsPlugin] ArtifactGroup '${folder ?? '<application>'}' resolved to no class | ${filePath} - check the folder name and that its classes carry a stereotype decorator`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const fields = [];
|
|
85
|
+
for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {
|
|
86
|
+
const locals = artifacts
|
|
87
|
+
.filter(artifact => artifact.type === type)
|
|
88
|
+
.map(artifact => {
|
|
89
|
+
if (isCompiled) {
|
|
90
|
+
return `require(${JSON.stringify(artifact.filePath)}).${artifact.className}`;
|
|
112
91
|
}
|
|
92
|
+
counter += 1;
|
|
93
|
+
const local = `__ignis_group_${counter}`;
|
|
94
|
+
const path = artifact.filePath
|
|
95
|
+
.split(sep)
|
|
96
|
+
.join('/')
|
|
97
|
+
.replace(ArtifactStereotypes.SOURCE_EXTENSION, '');
|
|
98
|
+
imports.push(`import { ${artifact.className} as ${local} } from '${path}';`);
|
|
99
|
+
return local;
|
|
100
|
+
});
|
|
101
|
+
if (locals.length > 0) {
|
|
102
|
+
fields.push(`${field}: [${locals.join(', ')}]`);
|
|
113
103
|
}
|
|
114
104
|
}
|
|
115
|
-
|
|
105
|
+
return `{ ${fields.join(', ')} }`;
|
|
106
|
+
};
|
|
107
|
+
const visit = (node) => {
|
|
108
|
+
const isGroupCall = ts.isCallExpression(node) &&
|
|
109
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
110
|
+
(ts.isIdentifier(node.expression.expression) ||
|
|
111
|
+
ts.isPropertyAccessExpression(node.expression.expression)) &&
|
|
112
|
+
(node.expression.name.text === 'define' || node.expression.name.text === 'application');
|
|
113
|
+
if (!isGroupCall) {
|
|
114
|
+
ts.forEachChild(node, visit);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const call = node;
|
|
118
|
+
const access = call.expression;
|
|
119
|
+
const target = access.expression;
|
|
120
|
+
const callee = ts.isIdentifier(target)
|
|
121
|
+
? target.text
|
|
122
|
+
: target.name.text;
|
|
123
|
+
const isApplication = access.name.text === 'application';
|
|
124
|
+
if (ts.isIdentifier(target) && aliases.has(callee)) {
|
|
125
|
+
refuse(call, `ArtifactGroup is imported as ${callee}`);
|
|
126
|
+
}
|
|
127
|
+
if (callee !== 'ArtifactGroup') {
|
|
128
|
+
ts.forEachChild(node, visit);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const [argument] = call.arguments;
|
|
132
|
+
if (isApplication && !argument) {
|
|
133
|
+
edits.push({ at: call.arguments.pos, text: `{ content: ${contentLiteral(undefined)} }` });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!argument || !ts.isObjectLiteralExpression(argument)) {
|
|
137
|
+
refuse(call, 'the argument is not an object literal');
|
|
138
|
+
}
|
|
139
|
+
const literal = argument;
|
|
140
|
+
const named = (name) => literal.properties.find(entry => entry.name !== undefined && ts.isIdentifier(entry.name) && entry.name.text === name);
|
|
141
|
+
if (named('content')) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const folderProperty = named('folder');
|
|
145
|
+
if (isApplication && folderProperty) {
|
|
146
|
+
refuse(call, 'ArtifactGroup.application() takes no folder');
|
|
147
|
+
}
|
|
148
|
+
const folderLiteral = folderProperty &&
|
|
149
|
+
ts.isPropertyAssignment(folderProperty) &&
|
|
150
|
+
ts.isStringLiteral(folderProperty.initializer)
|
|
151
|
+
? folderProperty.initializer.text
|
|
152
|
+
: undefined;
|
|
153
|
+
if (!isApplication && folderLiteral === undefined) {
|
|
154
|
+
refuse(call, 'folder is not a string literal');
|
|
155
|
+
}
|
|
156
|
+
const ignoreProperty = named('ignore');
|
|
157
|
+
const ignoreList = ignoreProperty &&
|
|
158
|
+
ts.isPropertyAssignment(ignoreProperty) &&
|
|
159
|
+
ts.isArrayLiteralExpression(ignoreProperty.initializer) &&
|
|
160
|
+
ignoreProperty.initializer.elements.every(element => ts.isStringLiteral(element))
|
|
161
|
+
? ignoreProperty.initializer.elements.map(element => element.text)
|
|
162
|
+
: undefined;
|
|
163
|
+
if (ignoreProperty && ignoreList === undefined) {
|
|
164
|
+
refuse(call, 'ignore is not an array of string literals');
|
|
165
|
+
}
|
|
166
|
+
const last = literal.properties[literal.properties.length - 1];
|
|
167
|
+
edits.push({
|
|
168
|
+
at: last ? last.getEnd() : literal.getStart() + 1,
|
|
169
|
+
text: `${last ? ', ' : ''}content: ${contentLiteral(folderLiteral, ignoreList)}`,
|
|
170
|
+
});
|
|
116
171
|
};
|
|
117
172
|
visit(sourceFile);
|
|
118
173
|
let rewritten = source;
|
|
@@ -151,13 +206,25 @@ export class IgnisArtifactsPlugin {
|
|
|
151
206
|
directory = parent;
|
|
152
207
|
}
|
|
153
208
|
}
|
|
154
|
-
|
|
209
|
+
// A package that runs from its compiled tree (`main` in dist) defines its groups there too.
|
|
210
|
+
const trees = [];
|
|
155
211
|
for (const source of sources) {
|
|
156
212
|
if (!existsSync(source)) {
|
|
157
213
|
continue;
|
|
158
214
|
}
|
|
159
|
-
|
|
160
|
-
|
|
215
|
+
trees.push({ directory: source, pattern: ArtifactStereotypes.SOURCE_GLOB });
|
|
216
|
+
for (const entry of readdirSync(dirname(source), { withFileTypes: true })) {
|
|
217
|
+
if (entry.isDirectory() &&
|
|
218
|
+
!['src', 'node_modules'].includes(entry.name) &&
|
|
219
|
+
!entry.name.startsWith('.')) {
|
|
220
|
+
trees.push({ directory: join(dirname(source), entry.name), pattern: '**/*.js' });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const files = [];
|
|
225
|
+
for (const { directory, pattern } of trees) {
|
|
226
|
+
for (const relativePath of globSync(pattern, { cwd: directory })) {
|
|
227
|
+
const file = join(directory, relativePath);
|
|
161
228
|
if (!relativePath.includes('__tests__') &&
|
|
162
229
|
IgnisArtifactsPlugin.DEFINE_CALL.test(readFileSync(file, 'utf8'))) {
|
|
163
230
|
files.push(file);
|
|
@@ -166,14 +233,17 @@ export class IgnisArtifactsPlugin {
|
|
|
166
233
|
}
|
|
167
234
|
return files;
|
|
168
235
|
}
|
|
169
|
-
/** For `Bun.build({ plugins: [IgnisArtifactsPlugin.create()] })`; `isRuntime` is set by `registerRuntime`, which serves a virtual module instead. */
|
|
236
|
+
/** For `Bun.build({ plugins: [IgnisArtifactsPlugin.create()] })`; `isRuntime` is set by `registerRuntime`, which serves a virtual module instead. `entry` (default: the build's first entrypoint, or `Bun.main` at run time) decides which tree the classes are imported from. */
|
|
170
237
|
static create(opts = {}) {
|
|
171
|
-
const root = opts.root ?? IgnisArtifactsPlugin.defaultRoot();
|
|
172
238
|
const isRuntime = opts.isRuntime ?? false;
|
|
173
|
-
const contents = () => IgnisArtifactsPlugin.render({ root });
|
|
174
239
|
return {
|
|
175
240
|
name: IgnisArtifactsPlugin.NAME,
|
|
176
241
|
setup(build) {
|
|
242
|
+
const [entrypoint] = isRuntime ? [] : build.config.entrypoints;
|
|
243
|
+
const entry = opts.entry ?? (entrypoint ? resolve(entrypoint) : ArtifactSources.entry());
|
|
244
|
+
const root = opts.root ??
|
|
245
|
+
ArtifactSources.packageSource({ from: entry ? dirname(entry) : process.cwd() });
|
|
246
|
+
const contents = () => IgnisArtifactsPlugin.render({ root, entry });
|
|
177
247
|
if (isRuntime) {
|
|
178
248
|
build.module(IgnisArtifactsPlugin.VIRTUAL, () => ({
|
|
179
249
|
contents: contents(),
|
|
@@ -195,11 +265,16 @@ export class IgnisArtifactsPlugin {
|
|
|
195
265
|
filePath: args.path,
|
|
196
266
|
source: readFileSync(args.path, 'utf8'),
|
|
197
267
|
}),
|
|
198
|
-
loader: 'ts',
|
|
268
|
+
loader: args.path.endsWith('.tsx') ? 'tsx' : args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
199
269
|
}));
|
|
200
270
|
}
|
|
271
|
+
// Lazy (a dynamic import on the first resolve) for a server: a library importing this module must not evaluate the app's classes inside its own half-loaded graph. Eager for a browser bundle: a lazily evaluated graph is not tree-shaken, which doubled a measured frontend bundle.
|
|
272
|
+
const isLazy = opts.lazyIndex ?? build.config.target !== 'browser';
|
|
273
|
+
const autoModule = isLazy
|
|
274
|
+
? `import { AutoArtifactGroup } from './auto-group.js';\nexport default new AutoArtifactGroup({ resolve: async () => (await import('${IgnisArtifactsPlugin.VIRTUAL}')).${IgnisArtifactsPlugin.EXPORT_NAME} });\n`
|
|
275
|
+
: `import { ${IgnisArtifactsPlugin.EXPORT_NAME} } from '${IgnisArtifactsPlugin.VIRTUAL}';\nimport { AutoArtifactGroup } from './auto-group.js';\nexport default new AutoArtifactGroup({ content: ${IgnisArtifactsPlugin.EXPORT_NAME} });\n`;
|
|
201
276
|
build.onLoad({ filter: IgnisArtifactsPlugin.AUTO_MODULE }, () => ({
|
|
202
|
-
contents:
|
|
277
|
+
contents: autoModule,
|
|
203
278
|
loader: 'ts',
|
|
204
279
|
}));
|
|
205
280
|
},
|