@venizia/ignis-boot 0.4.3 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +17 -4
- package/dist/esm/build-info/resolver.d.ts +2 -2
- package/dist/esm/build-info/resolver.d.ts.map +1 -1
- package/dist/esm/build-info/resolver.js +17 -11
- package/dist/esm/build-info/resolver.js.map +1 -1
- package/dist/esm/bun/plugin.d.ts +1 -1
- package/dist/esm/bun/plugin.d.ts.map +1 -1
- package/dist/esm/bun/plugin.js +2 -2
- package/dist/esm/bun/plugin.js.map +1 -1
- package/dist/esm/clis/artifacts.js +0 -0
- package/package.json +19 -33
- package/dist/cjs/build-info/common/constants.d.ts +0 -12
- package/dist/cjs/build-info/common/constants.d.ts.map +0 -1
- package/dist/cjs/build-info/common/constants.js +0 -32
- package/dist/cjs/build-info/common/constants.js.map +0 -1
- package/dist/cjs/build-info/common/index.d.ts +0 -2
- package/dist/cjs/build-info/common/index.d.ts.map +0 -1
- package/dist/cjs/build-info/common/index.js +0 -18
- package/dist/cjs/build-info/common/index.js.map +0 -1
- package/dist/cjs/build-info/index.d.ts +0 -4
- package/dist/cjs/build-info/index.d.ts.map +0 -1
- package/dist/cjs/build-info/index.js +0 -20
- package/dist/cjs/build-info/index.js.map +0 -1
- package/dist/cjs/build-info/resolver.d.ts +0 -25
- package/dist/cjs/build-info/resolver.d.ts.map +0 -1
- package/dist/cjs/build-info/resolver.js +0 -105
- package/dist/cjs/build-info/resolver.js.map +0 -1
- package/dist/cjs/build-info/stamp.d.ts +0 -22
- package/dist/cjs/build-info/stamp.d.ts.map +0 -1
- package/dist/cjs/build-info/stamp.js +0 -36
- package/dist/cjs/build-info/stamp.js.map +0 -1
- package/dist/cjs/bun/auto-group.d.ts +0 -22
- package/dist/cjs/bun/auto-group.d.ts.map +0 -1
- package/dist/cjs/bun/auto-group.js +0 -51
- package/dist/cjs/bun/auto-group.js.map +0 -1
- package/dist/cjs/bun/auto-loader.d.ts +0 -13
- package/dist/cjs/bun/auto-loader.d.ts.map +0 -1
- package/dist/cjs/bun/auto-loader.js +0 -63
- package/dist/cjs/bun/auto-loader.js.map +0 -1
- package/dist/cjs/bun/auto.d.ts +0 -5
- package/dist/cjs/bun/auto.d.ts.map +0 -1
- package/dist/cjs/bun/auto.js +0 -11
- package/dist/cjs/bun/auto.js.map +0 -1
- package/dist/cjs/bun/group-resolver.d.ts +0 -16
- package/dist/cjs/bun/group-resolver.d.ts.map +0 -1
- package/dist/cjs/bun/group-resolver.js +0 -44
- package/dist/cjs/bun/group-resolver.js.map +0 -1
- package/dist/cjs/bun/index.d.ts +0 -7
- package/dist/cjs/bun/index.d.ts.map +0 -1
- package/dist/cjs/bun/index.js +0 -23
- package/dist/cjs/bun/index.js.map +0 -1
- package/dist/cjs/bun/plugin.d.ts +0 -67
- package/dist/cjs/bun/plugin.d.ts.map +0 -1
- package/dist/cjs/bun/plugin.js +0 -395
- package/dist/cjs/bun/plugin.js.map +0 -1
- package/dist/cjs/bun/scan-cache.d.ts +0 -22
- package/dist/cjs/bun/scan-cache.d.ts.map +0 -1
- package/dist/cjs/bun/scan-cache.js +0 -89
- package/dist/cjs/bun/scan-cache.js.map +0 -1
- package/dist/cjs/bun/sources.d.ts +0 -49
- package/dist/cjs/bun/sources.d.ts.map +0 -1
- package/dist/cjs/bun/sources.js +0 -115
- package/dist/cjs/bun/sources.js.map +0 -1
- package/dist/cjs/clis/artifacts.d.ts +0 -3
- package/dist/cjs/clis/artifacts.d.ts.map +0 -1
- package/dist/cjs/clis/artifacts.js +0 -62
- package/dist/cjs/clis/artifacts.js.map +0 -1
- package/dist/cjs/common/install-quiet-logger.d.ts +0 -2
- package/dist/cjs/common/install-quiet-logger.d.ts.map +0 -1
- package/dist/cjs/common/install-quiet-logger.js +0 -7
- package/dist/cjs/common/install-quiet-logger.js.map +0 -1
- package/dist/cjs/common/quiet-logger.d.ts +0 -18
- package/dist/cjs/common/quiet-logger.d.ts.map +0 -1
- package/dist/cjs/common/quiet-logger.js +0 -46
- package/dist/cjs/common/quiet-logger.js.map +0 -1
- package/dist/cjs/generator/common/constants.d.ts +0 -59
- package/dist/cjs/generator/common/constants.d.ts.map +0 -1
- package/dist/cjs/generator/common/constants.js +0 -102
- package/dist/cjs/generator/common/constants.js.map +0 -1
- package/dist/cjs/generator/common/index.d.ts +0 -3
- package/dist/cjs/generator/common/index.d.ts.map +0 -1
- package/dist/cjs/generator/common/index.js +0 -19
- package/dist/cjs/generator/common/index.js.map +0 -1
- package/dist/cjs/generator/common/types.d.ts +0 -33
- package/dist/cjs/generator/common/types.d.ts.map +0 -1
- package/dist/cjs/generator/common/types.js +0 -3
- package/dist/cjs/generator/common/types.js.map +0 -1
- package/dist/cjs/generator/emitter.d.ts +0 -41
- package/dist/cjs/generator/emitter.d.ts.map +0 -1
- package/dist/cjs/generator/emitter.js +0 -82
- package/dist/cjs/generator/emitter.js.map +0 -1
- package/dist/cjs/generator/index.d.ts +0 -26
- package/dist/cjs/generator/index.d.ts.map +0 -1
- package/dist/cjs/generator/index.js +0 -68
- package/dist/cjs/generator/index.js.map +0 -1
- package/dist/cjs/generator/reexport.d.ts +0 -28
- package/dist/cjs/generator/reexport.d.ts.map +0 -1
- package/dist/cjs/generator/reexport.js +0 -131
- package/dist/cjs/generator/reexport.js.map +0 -1
- package/dist/cjs/generator/scanner.d.ts +0 -26
- package/dist/cjs/generator/scanner.d.ts.map +0 -1
- package/dist/cjs/generator/scanner.js +0 -258
- package/dist/cjs/generator/scanner.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/vite/index.d.ts +0 -2
- package/dist/cjs/vite/index.d.ts.map +0 -1
- package/dist/cjs/vite/index.js +0 -18
- package/dist/cjs/vite/index.js.map +0 -1
- package/dist/cjs/vite/plugin.d.ts +0 -29
- package/dist/cjs/vite/plugin.d.ts.map +0 -1
- package/dist/cjs/vite/plugin.js +0 -61
- package/dist/cjs/vite/plugin.js.map +0 -1
package/dist/cjs/bun/plugin.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { BunPlugin } from 'bun';
|
|
2
|
-
/** Serves `ignis:artifacts` - the application's generated index, rendered in memory from the scanner. At run time it is a virtual module (`build.module`); in `Bun.build` it is resolved and loaded (`onResolve`/`onLoad`), so a binary carries the list and never scans. */
|
|
3
|
-
export declare class IgnisArtifactsPlugin {
|
|
4
|
-
static readonly NAME = "ignis-artifacts";
|
|
5
|
-
static readonly VIRTUAL = "ignis:artifacts";
|
|
6
|
-
static readonly EXPORT_NAME = "GeneratedArtifacts";
|
|
7
|
-
/** `@venizia/ignis-boot/auto`, from source or from either dist format - replaced at build time by a static re-export of the virtual module. */
|
|
8
|
-
static readonly AUTO_MODULE: RegExp;
|
|
9
|
-
/** A text test for a file worth parsing: `ArtifactGroup.define(`, with any spacing or line break around the dot. */
|
|
10
|
-
static readonly DEFINE_CALL: RegExp;
|
|
11
|
-
private static readonly RUNTIME_KEY;
|
|
12
|
-
/** The `src` beside the nearest `package.json` at or above `from` (default: the entry module's directory). */
|
|
13
|
-
static defaultRoot(opts?: {
|
|
14
|
-
from?: string;
|
|
15
|
-
}): string;
|
|
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`). */
|
|
19
|
-
static render(opts: {
|
|
20
|
-
root: string;
|
|
21
|
-
entry?: string;
|
|
22
|
-
}): string;
|
|
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. */
|
|
24
|
-
static rewriteGroups(opts: {
|
|
25
|
-
filePath: string;
|
|
26
|
-
source: string;
|
|
27
|
-
}): string;
|
|
28
|
-
/** A text test for a file worth parsing for decorated classes: an IGNIS stereotype decorator call. */
|
|
29
|
-
static readonly DECORATED: RegExp;
|
|
30
|
-
/** The classes of a source file that carry an IGNIS stereotype decorator (`@service()`, `@repository(...)`, `@injectable(...)`...). */
|
|
31
|
-
static decoratedClasses(opts: {
|
|
32
|
-
filePath: string;
|
|
33
|
-
source: string;
|
|
34
|
-
}): string[];
|
|
35
|
-
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`. Binding keys are built from `Class.name`, and a bundler renames classes - a minifier, or Bun's scope hoisting when a registered class shadows a same-name class it extends (`StockService` becomes `StockService2`). A string literal survives both, and a static block runs before the class's decorators. Only these classes are touched; the rest of the bundle is left alone. */
|
|
36
|
-
static pinClassNames(opts: {
|
|
37
|
-
filePath: string;
|
|
38
|
-
source: string;
|
|
39
|
-
classNames: ReadonlySet<string>;
|
|
40
|
-
}): string;
|
|
41
|
-
/** The classes whose names a build must pin, by the file the build loads: the app's own (from the tree `entry` runs, see `runningArtifacts`) and those of every package that defines a group the app can borrow (from the tree the group file sits in). */
|
|
42
|
-
static pinnedClasses(opts: {
|
|
43
|
-
root: string;
|
|
44
|
-
groupFiles?: ReadonlyArray<string>;
|
|
45
|
-
entry?: string;
|
|
46
|
-
}): Map<string, Set<string>>;
|
|
47
|
-
/** 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. */
|
|
48
|
-
static groupDefinitionFiles(opts: {
|
|
49
|
-
root: string;
|
|
50
|
-
}): string[];
|
|
51
|
-
/** 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. */
|
|
52
|
-
static workspaceSourceFiles(opts: {
|
|
53
|
-
root: string;
|
|
54
|
-
}): string[];
|
|
55
|
-
/** 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. */
|
|
56
|
-
static create(opts?: {
|
|
57
|
-
root?: string;
|
|
58
|
-
entry?: string;
|
|
59
|
-
isRuntime?: boolean;
|
|
60
|
-
lazyIndex?: boolean;
|
|
61
|
-
}): BunPlugin;
|
|
62
|
-
/** Registers the run-time plugin once per process; a second call is a no-op. */
|
|
63
|
-
static registerRuntime(opts?: {
|
|
64
|
-
root?: string;
|
|
65
|
-
}): Promise<void>;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,QAAQ,CAAC,OAAO,qBAAqB;IAC5C,MAAM,CAAC,QAAQ,CAAC,WAAW,wBAAwB;IAEnD,+IAA+I;IAC/I,MAAM,CAAC,QAAQ,CAAC,WAAW,SAC0F;IAErH,oHAAoH;IACpH,MAAM,CAAC,QAAQ,CAAC,WAAW,SAAsD;IAEjF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAA8D;IAMjG,8GAA8G;IAC9G,MAAM,CAAC,WAAW,CAAC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,MAAM;IAMxD,wLAAwL;IACxL,MAAM,CAAC,cAAc,IAAI,MAAM;IAK/B,+NAA+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C,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GACrF,SAAS;IAgEZ,gFAAgF;WACnE,eAAe,CAAC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAO1E"}
|
package/dist/cjs/bun/plugin.js
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IgnisArtifactsPlugin = void 0;
|
|
7
|
-
const ignis_helpers_1 = require("@venizia/ignis-helpers");
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
|
-
const node_path_1 = require("node:path");
|
|
10
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
-
const generator_1 = require("../generator");
|
|
12
|
-
const sources_1 = require("./sources");
|
|
13
|
-
/** Serves `ignis:artifacts` - the application's generated index, rendered in memory from the scanner. At run time it is a virtual module (`build.module`); in `Bun.build` it is resolved and loaded (`onResolve`/`onLoad`), so a binary carries the list and never scans. */
|
|
14
|
-
class IgnisArtifactsPlugin {
|
|
15
|
-
static { this.NAME = 'ignis-artifacts'; }
|
|
16
|
-
static { this.VIRTUAL = 'ignis:artifacts'; }
|
|
17
|
-
static { this.EXPORT_NAME = 'GeneratedArtifacts'; }
|
|
18
|
-
/** `@venizia/ignis-boot/auto`, from source or from either dist format - replaced at build time by a static re-export of the virtual module. */
|
|
19
|
-
static { this.AUTO_MODULE = /[\\/](?:@venizia[\\/]ignis-boot|packages[\\/]boot)[\\/](?:dist[\\/](?:esm|cjs)|src)[\\/]bun[\\/]auto\.(?:ts|js)$/; }
|
|
20
|
-
/** A text test for a file worth parsing: `ArtifactGroup.define(`, with any spacing or line break around the dot. */
|
|
21
|
-
static { this.DEFINE_CALL = /ArtifactGroup\s*\.\s*(?:define|application)\s*\(/; }
|
|
22
|
-
static { this.RUNTIME_KEY = Symbol.for('@venizia/ignis-boot:artifacts-runtime-plugin'); }
|
|
23
|
-
static {
|
|
24
|
-
sources_1.ArtifactSources.useScanner({ scanner: generator_1.ArtifactScanner.getInstance() });
|
|
25
|
-
}
|
|
26
|
-
/** The `src` beside the nearest `package.json` at or above `from` (default: the entry module's directory). */
|
|
27
|
-
static defaultRoot(opts = {}) {
|
|
28
|
-
return sources_1.ArtifactSources.packageSource({
|
|
29
|
-
from: opts.from ?? IgnisArtifactsPlugin.entryDirectory(),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/** 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). */
|
|
33
|
-
static entryDirectory() {
|
|
34
|
-
const entry = sources_1.ArtifactSources.entry();
|
|
35
|
-
return entry ? (0, node_path_1.dirname)(entry) : process.cwd();
|
|
36
|
-
}
|
|
37
|
-
/** 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`). */
|
|
38
|
-
static render(opts) {
|
|
39
|
-
const root = (0, node_path_1.resolve)(opts.root);
|
|
40
|
-
if (!(0, node_fs_1.existsSync)(root)) {
|
|
41
|
-
throw (0, ignis_helpers_1.getError)({
|
|
42
|
-
message: `[IgnisArtifactsPlugin] ${(0, node_path_1.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`,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const outFile = (0, node_path_1.join)(root, '__ignis_artifacts__.ts');
|
|
46
|
-
const artifacts = sources_1.ArtifactSources.scan({ packageSource: root });
|
|
47
|
-
return generator_1.ArtifactIndexEmitter.render({
|
|
48
|
-
artifacts: opts.entry
|
|
49
|
-
? sources_1.ArtifactSources.runningArtifacts({ artifacts, from: opts.entry })
|
|
50
|
-
: artifacts,
|
|
51
|
-
outFile,
|
|
52
|
-
exportName: IgnisArtifactsPlugin.EXPORT_NAME,
|
|
53
|
-
command: { root, out: outFile },
|
|
54
|
-
absoluteImports: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/** 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. */
|
|
58
|
-
static rewriteGroups(opts) {
|
|
59
|
-
const { filePath, source } = opts;
|
|
60
|
-
const sourceFile = typescript_1.default.createSourceFile(filePath, source, typescript_1.default.ScriptTarget.Latest, true);
|
|
61
|
-
const aliases = new Set();
|
|
62
|
-
for (const statement of sourceFile.statements) {
|
|
63
|
-
const bindings = typescript_1.default.isImportDeclaration(statement)
|
|
64
|
-
? statement.importClause?.namedBindings
|
|
65
|
-
: undefined;
|
|
66
|
-
for (const element of bindings && typescript_1.default.isNamedImports(bindings) ? bindings.elements : []) {
|
|
67
|
-
if ((element.propertyName ?? element.name).text === 'ArtifactGroup' &&
|
|
68
|
-
element.name.text !== 'ArtifactGroup') {
|
|
69
|
-
aliases.add(element.name.text);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const edits = [];
|
|
74
|
-
const imports = [];
|
|
75
|
-
let counter = 0;
|
|
76
|
-
const refuse = (node, reason) => {
|
|
77
|
-
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
78
|
-
throw (0, ignis_helpers_1.getError)({
|
|
79
|
-
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`,
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
const isCompiled = !generator_1.ArtifactStereotypes.SOURCE_EXTENSION.test(filePath);
|
|
83
|
-
const contentLiteral = (folder, ignore) => {
|
|
84
|
-
const artifacts = sources_1.ArtifactSources.folderArtifacts({ folder, site: filePath, ignore });
|
|
85
|
-
if (artifacts.length === 0) {
|
|
86
|
-
throw (0, ignis_helpers_1.getError)({
|
|
87
|
-
message: `[IgnisArtifactsPlugin] ArtifactGroup '${folder ?? '<application>'}' resolved to no class | ${filePath} - check the folder name and that its classes carry a stereotype decorator`,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const fields = [];
|
|
91
|
-
for (const { type, field } of generator_1.ArtifactStereotypes.EMIT_ORDER) {
|
|
92
|
-
const locals = artifacts
|
|
93
|
-
.filter((artifact) => artifact.type === type)
|
|
94
|
-
.map((artifact) => {
|
|
95
|
-
if (isCompiled) {
|
|
96
|
-
return `require(${JSON.stringify(artifact.filePath)}).${artifact.className}`;
|
|
97
|
-
}
|
|
98
|
-
counter += 1;
|
|
99
|
-
const local = `__ignis_group_${counter}`;
|
|
100
|
-
const path = artifact.filePath
|
|
101
|
-
.split(node_path_1.sep)
|
|
102
|
-
.join('/')
|
|
103
|
-
.replace(generator_1.ArtifactStereotypes.SOURCE_EXTENSION, '');
|
|
104
|
-
imports.push(`import { ${artifact.className} as ${local} } from '${path}';`);
|
|
105
|
-
return local;
|
|
106
|
-
});
|
|
107
|
-
if (locals.length > 0) {
|
|
108
|
-
fields.push(`${field}: [${locals.join(', ')}]`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return `{ ${fields.join(', ')} }`;
|
|
112
|
-
};
|
|
113
|
-
const visit = (node) => {
|
|
114
|
-
const isGroupCall = typescript_1.default.isCallExpression(node) &&
|
|
115
|
-
typescript_1.default.isPropertyAccessExpression(node.expression) &&
|
|
116
|
-
(typescript_1.default.isIdentifier(node.expression.expression) ||
|
|
117
|
-
typescript_1.default.isPropertyAccessExpression(node.expression.expression)) &&
|
|
118
|
-
(node.expression.name.text === 'define' || node.expression.name.text === 'application');
|
|
119
|
-
if (!isGroupCall) {
|
|
120
|
-
typescript_1.default.forEachChild(node, visit);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const call = node;
|
|
124
|
-
const access = call.expression;
|
|
125
|
-
const target = access.expression;
|
|
126
|
-
const callee = typescript_1.default.isIdentifier(target)
|
|
127
|
-
? target.text
|
|
128
|
-
: target.name.text;
|
|
129
|
-
const isApplication = access.name.text === 'application';
|
|
130
|
-
if (typescript_1.default.isIdentifier(target) && aliases.has(callee)) {
|
|
131
|
-
refuse(call, `ArtifactGroup is imported as ${callee}`);
|
|
132
|
-
}
|
|
133
|
-
if (callee !== 'ArtifactGroup') {
|
|
134
|
-
typescript_1.default.forEachChild(node, visit);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const [argument] = call.arguments;
|
|
138
|
-
if (isApplication && !argument) {
|
|
139
|
-
edits.push({ at: call.arguments.pos, text: `{ content: ${contentLiteral(undefined)} }` });
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (!argument || !typescript_1.default.isObjectLiteralExpression(argument)) {
|
|
143
|
-
refuse(call, 'the argument is not an object literal');
|
|
144
|
-
}
|
|
145
|
-
const literal = argument;
|
|
146
|
-
const named = (name) => literal.properties.find((entry) => entry.name !== undefined && typescript_1.default.isIdentifier(entry.name) && entry.name.text === name);
|
|
147
|
-
if (named('content')) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const folderProperty = named('folder');
|
|
151
|
-
if (isApplication && folderProperty) {
|
|
152
|
-
refuse(call, 'ArtifactGroup.application() takes no folder');
|
|
153
|
-
}
|
|
154
|
-
const folderLiteral = folderProperty &&
|
|
155
|
-
typescript_1.default.isPropertyAssignment(folderProperty) &&
|
|
156
|
-
typescript_1.default.isStringLiteral(folderProperty.initializer)
|
|
157
|
-
? folderProperty.initializer.text
|
|
158
|
-
: undefined;
|
|
159
|
-
if (!isApplication && folderLiteral === undefined) {
|
|
160
|
-
refuse(call, 'folder is not a string literal');
|
|
161
|
-
}
|
|
162
|
-
const ignoreProperty = named('ignore');
|
|
163
|
-
const ignoreList = ignoreProperty &&
|
|
164
|
-
typescript_1.default.isPropertyAssignment(ignoreProperty) &&
|
|
165
|
-
typescript_1.default.isArrayLiteralExpression(ignoreProperty.initializer) &&
|
|
166
|
-
ignoreProperty.initializer.elements.every((element) => typescript_1.default.isStringLiteral(element))
|
|
167
|
-
? ignoreProperty.initializer.elements.map((element) => element.text)
|
|
168
|
-
: undefined;
|
|
169
|
-
if (ignoreProperty && ignoreList === undefined) {
|
|
170
|
-
refuse(call, 'ignore is not an array of string literals');
|
|
171
|
-
}
|
|
172
|
-
const last = literal.properties[literal.properties.length - 1];
|
|
173
|
-
edits.push({
|
|
174
|
-
at: last ? last.getEnd() : literal.getStart() + 1,
|
|
175
|
-
text: `${last ? ', ' : ''}content: ${contentLiteral(folderLiteral, ignoreList)}`,
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
visit(sourceFile);
|
|
179
|
-
let rewritten = source;
|
|
180
|
-
for (const edit of [...edits].sort((left, right) => right.at - left.at)) {
|
|
181
|
-
rewritten = rewritten.slice(0, edit.at) + edit.text + rewritten.slice(edit.at);
|
|
182
|
-
}
|
|
183
|
-
return imports.length > 0 ? `${imports.join('\n')}\n${rewritten}` : rewritten;
|
|
184
|
-
}
|
|
185
|
-
/** A text test for a file worth parsing for decorated classes: an IGNIS stereotype decorator call. */
|
|
186
|
-
static { this.DECORATED = /@(?:configuration|component|controller|service|repository|datasource|model|injectable)\s*\(/; }
|
|
187
|
-
/** The classes of a source file that carry an IGNIS stereotype decorator (`@service()`, `@repository(...)`, `@injectable(...)`...). */
|
|
188
|
-
static decoratedClasses(opts) {
|
|
189
|
-
const names = new Set([
|
|
190
|
-
...Object.keys(generator_1.ArtifactStereotypes.BY_DECORATOR),
|
|
191
|
-
generator_1.ArtifactStereotypes.ROOT_DECORATOR,
|
|
192
|
-
]);
|
|
193
|
-
const sourceFile = typescript_1.default.createSourceFile(opts.filePath, opts.source, typescript_1.default.ScriptTarget.Latest, true);
|
|
194
|
-
const found = [];
|
|
195
|
-
const visit = (node) => {
|
|
196
|
-
if (typescript_1.default.isClassDeclaration(node) && node.name) {
|
|
197
|
-
const isDecorated = (typescript_1.default.getDecorators(node) ?? []).some((decorator) => {
|
|
198
|
-
const expression = typescript_1.default.isCallExpression(decorator.expression)
|
|
199
|
-
? decorator.expression.expression
|
|
200
|
-
: decorator.expression;
|
|
201
|
-
return typescript_1.default.isIdentifier(expression) && names.has(expression.text);
|
|
202
|
-
});
|
|
203
|
-
if (isDecorated) {
|
|
204
|
-
found.push(node.name.text);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
typescript_1.default.forEachChild(node, visit);
|
|
208
|
-
};
|
|
209
|
-
visit(sourceFile);
|
|
210
|
-
return found;
|
|
211
|
-
}
|
|
212
|
-
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`. Binding keys are built from `Class.name`, and a bundler renames classes - a minifier, or Bun's scope hoisting when a registered class shadows a same-name class it extends (`StockService` becomes `StockService2`). A string literal survives both, and a static block runs before the class's decorators. Only these classes are touched; the rest of the bundle is left alone. */
|
|
213
|
-
static pinClassNames(opts) {
|
|
214
|
-
const sourceFile = typescript_1.default.createSourceFile(opts.filePath, opts.source, typescript_1.default.ScriptTarget.Latest, true);
|
|
215
|
-
const positions = [];
|
|
216
|
-
const visit = (node) => {
|
|
217
|
-
if (typescript_1.default.isClassDeclaration(node) && node.name && opts.classNames.has(node.name.text)) {
|
|
218
|
-
positions.push({ at: node.members.pos, name: node.name.text });
|
|
219
|
-
}
|
|
220
|
-
typescript_1.default.forEachChild(node, visit);
|
|
221
|
-
};
|
|
222
|
-
visit(sourceFile);
|
|
223
|
-
let pinned = opts.source;
|
|
224
|
-
for (const { at, name } of positions.sort((left, right) => right.at - left.at)) {
|
|
225
|
-
const block = ` static { Object.defineProperty(this, 'name', { value: ${JSON.stringify(name)} }); }`;
|
|
226
|
-
pinned = pinned.slice(0, at) + block + pinned.slice(at);
|
|
227
|
-
}
|
|
228
|
-
return pinned;
|
|
229
|
-
}
|
|
230
|
-
/** The classes whose names a build must pin, by the file the build loads: the app's own (from the tree `entry` runs, see `runningArtifacts`) and those of every package that defines a group the app can borrow (from the tree the group file sits in). */
|
|
231
|
-
static pinnedClasses(opts) {
|
|
232
|
-
const byFile = new Map();
|
|
233
|
-
const add = (artifacts) => {
|
|
234
|
-
for (const { filePath, className } of artifacts) {
|
|
235
|
-
byFile.set(filePath, (byFile.get(filePath) ?? new Set()).add(className));
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
const own = sources_1.ArtifactSources.scan({ packageSource: opts.root });
|
|
239
|
-
add(opts.entry ? sources_1.ArtifactSources.runningArtifacts({ artifacts: own, from: opts.entry }) : own);
|
|
240
|
-
// Every class carrying an IGNIS decorator in the workspace sources: a class nothing scans (a library that defines no group) is still an injection target, and still renamed by a bundler when its name collides.
|
|
241
|
-
for (const file of IgnisArtifactsPlugin.workspaceSourceFiles({ root: opts.root })) {
|
|
242
|
-
if (!generator_1.ArtifactStereotypes.SOURCE_EXTENSION.test(file)) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
const source = (0, node_fs_1.readFileSync)(file, 'utf8');
|
|
246
|
-
if (!IgnisArtifactsPlugin.DECORATED.test(source)) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
add(IgnisArtifactsPlugin.decoratedClasses({ filePath: file, source }).map((className) => ({
|
|
250
|
-
filePath: file,
|
|
251
|
-
className,
|
|
252
|
-
})));
|
|
253
|
-
}
|
|
254
|
-
for (const groupFile of opts.groupFiles ?? []) {
|
|
255
|
-
const packageSource = sources_1.ArtifactSources.packageSource({ from: (0, node_path_1.dirname)(groupFile) });
|
|
256
|
-
if (packageSource === opts.root || !(0, node_fs_1.existsSync)(packageSource)) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
add(sources_1.ArtifactSources.runningArtifacts({
|
|
260
|
-
artifacts: sources_1.ArtifactSources.scan({ packageSource }),
|
|
261
|
-
from: groupFile,
|
|
262
|
-
}));
|
|
263
|
-
}
|
|
264
|
-
return byFile;
|
|
265
|
-
}
|
|
266
|
-
/** 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. */
|
|
267
|
-
static groupDefinitionFiles(opts) {
|
|
268
|
-
return IgnisArtifactsPlugin.workspaceSourceFiles(opts).filter((file) => IgnisArtifactsPlugin.DEFINE_CALL.test((0, node_fs_1.readFileSync)(file, 'utf8')));
|
|
269
|
-
}
|
|
270
|
-
/** 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. */
|
|
271
|
-
static workspaceSourceFiles(opts) {
|
|
272
|
-
const root = (0, node_path_1.resolve)(opts.root);
|
|
273
|
-
const packageDirectory = (0, node_path_1.dirname)(root);
|
|
274
|
-
const manifestPath = (0, node_path_1.join)(packageDirectory, 'package.json');
|
|
275
|
-
const manifest = (0, node_fs_1.existsSync)(manifestPath) ? JSON.parse((0, node_fs_1.readFileSync)(manifestPath, 'utf8')) : {};
|
|
276
|
-
const names = Object.keys({
|
|
277
|
-
...manifest.dependencies,
|
|
278
|
-
...manifest.devDependencies,
|
|
279
|
-
...manifest.peerDependencies,
|
|
280
|
-
});
|
|
281
|
-
const sources = new Set([root]);
|
|
282
|
-
for (const name of names) {
|
|
283
|
-
let directory = packageDirectory;
|
|
284
|
-
while (true) {
|
|
285
|
-
const linked = (0, node_path_1.join)(directory, 'node_modules', name);
|
|
286
|
-
if ((0, node_fs_1.existsSync)(linked)) {
|
|
287
|
-
const real = (0, node_fs_1.realpathSync)(linked);
|
|
288
|
-
if (!real.split(node_path_1.sep).includes('node_modules') && (0, node_fs_1.existsSync)((0, node_path_1.join)(real, 'src'))) {
|
|
289
|
-
sources.add((0, node_path_1.join)(real, 'src'));
|
|
290
|
-
}
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
const parent = (0, node_path_1.dirname)(directory);
|
|
294
|
-
if (parent === directory) {
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
directory = parent;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// A package that runs from its compiled tree (`main` in dist) defines its groups there too.
|
|
301
|
-
const trees = [];
|
|
302
|
-
for (const source of sources) {
|
|
303
|
-
if (!(0, node_fs_1.existsSync)(source)) {
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
trees.push({ directory: source, pattern: generator_1.ArtifactStereotypes.SOURCE_GLOB });
|
|
307
|
-
for (const entry of (0, node_fs_1.readdirSync)((0, node_path_1.dirname)(source), { withFileTypes: true })) {
|
|
308
|
-
if (entry.isDirectory() &&
|
|
309
|
-
!['src', 'node_modules'].includes(entry.name) &&
|
|
310
|
-
!entry.name.startsWith('.')) {
|
|
311
|
-
trees.push({ directory: (0, node_path_1.join)((0, node_path_1.dirname)(source), entry.name), pattern: '**/*.js' });
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
const files = [];
|
|
316
|
-
for (const { directory, pattern } of trees) {
|
|
317
|
-
for (const relativePath of (0, node_fs_1.globSync)(pattern, { cwd: directory })) {
|
|
318
|
-
if (!relativePath.includes('__tests__')) {
|
|
319
|
-
files.push((0, node_path_1.join)(directory, relativePath));
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return files;
|
|
324
|
-
}
|
|
325
|
-
/** 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. */
|
|
326
|
-
static create(opts = {}) {
|
|
327
|
-
const isRuntime = opts.isRuntime ?? false;
|
|
328
|
-
return {
|
|
329
|
-
name: IgnisArtifactsPlugin.NAME,
|
|
330
|
-
setup(build) {
|
|
331
|
-
const [entrypoint] = isRuntime ? [] : build.config.entrypoints;
|
|
332
|
-
const entry = opts.entry ?? (entrypoint ? (0, node_path_1.resolve)(entrypoint) : sources_1.ArtifactSources.entry());
|
|
333
|
-
const root = opts.root ??
|
|
334
|
-
sources_1.ArtifactSources.packageSource({ from: entry ? (0, node_path_1.dirname)(entry) : process.cwd() });
|
|
335
|
-
const contents = () => IgnisArtifactsPlugin.render({ root, entry });
|
|
336
|
-
if (isRuntime) {
|
|
337
|
-
build.module(IgnisArtifactsPlugin.VIRTUAL, () => ({
|
|
338
|
-
contents: contents(),
|
|
339
|
-
loader: 'ts',
|
|
340
|
-
}));
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
const virtualPath = (0, node_path_1.join)((0, node_path_1.resolve)(root), '__ignis_artifacts__.ts');
|
|
344
|
-
build.onResolve({ filter: /^ignis:artifacts$/ }, () => ({ path: virtualPath }));
|
|
345
|
-
build.onLoad({ filter: /__ignis_artifacts__\.ts$/ }, () => ({
|
|
346
|
-
contents: contents(),
|
|
347
|
-
loader: 'ts',
|
|
348
|
-
}));
|
|
349
|
-
const groupFiles = IgnisArtifactsPlugin.groupDefinitionFiles({ root });
|
|
350
|
-
const groupFileSet = new Set(groupFiles);
|
|
351
|
-
const pinned = IgnisArtifactsPlugin.pinnedClasses({ root, groupFiles, entry });
|
|
352
|
-
const loaded = [...new Set([...groupFiles, ...pinned.keys()])];
|
|
353
|
-
if (loaded.length > 0) {
|
|
354
|
-
const escaped = loaded.map((file) => file.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'));
|
|
355
|
-
build.onLoad({ filter: new RegExp(`^(?:${escaped.join('|')})$`) }, (args) => {
|
|
356
|
-
const source = (0, node_fs_1.readFileSync)(args.path, 'utf8');
|
|
357
|
-
const grouped = groupFileSet.has(args.path)
|
|
358
|
-
? IgnisArtifactsPlugin.rewriteGroups({ filePath: args.path, source })
|
|
359
|
-
: source;
|
|
360
|
-
const classNames = pinned.get(args.path);
|
|
361
|
-
return {
|
|
362
|
-
contents: classNames
|
|
363
|
-
? IgnisArtifactsPlugin.pinClassNames({
|
|
364
|
-
filePath: args.path,
|
|
365
|
-
source: grouped,
|
|
366
|
-
classNames,
|
|
367
|
-
})
|
|
368
|
-
: grouped,
|
|
369
|
-
loader: args.path.endsWith('.tsx') ? 'tsx' : args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
370
|
-
};
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
// 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.
|
|
374
|
-
const isLazy = opts.lazyIndex ?? build.config.target !== 'browser';
|
|
375
|
-
const autoModule = isLazy
|
|
376
|
-
? `import { AutoArtifactGroup } from './auto-group';\nexport default new AutoArtifactGroup({ resolve: async () => (await import('${IgnisArtifactsPlugin.VIRTUAL}')).${IgnisArtifactsPlugin.EXPORT_NAME} });\n`
|
|
377
|
-
: `import { ${IgnisArtifactsPlugin.EXPORT_NAME} } from '${IgnisArtifactsPlugin.VIRTUAL}';\nimport { AutoArtifactGroup } from './auto-group';\nexport default new AutoArtifactGroup({ content: ${IgnisArtifactsPlugin.EXPORT_NAME} });\n`;
|
|
378
|
-
build.onLoad({ filter: IgnisArtifactsPlugin.AUTO_MODULE }, () => ({
|
|
379
|
-
contents: autoModule,
|
|
380
|
-
loader: 'ts',
|
|
381
|
-
}));
|
|
382
|
-
},
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
/** Registers the run-time plugin once per process; a second call is a no-op. */
|
|
386
|
-
static async registerRuntime(opts = {}) {
|
|
387
|
-
if (Reflect.get(globalThis, IgnisArtifactsPlugin.RUNTIME_KEY) === true) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
await Bun.plugin(IgnisArtifactsPlugin.create({ ...opts, isRuntime: true }));
|
|
391
|
-
Reflect.set(globalThis, IgnisArtifactsPlugin.RUNTIME_KEY, true);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
exports.IgnisArtifactsPlugin = IgnisArtifactsPlugin;
|
|
395
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/bun/plugin.ts"],"names":[],"mappings":";;;;;;AACA,0DAAkD;AAClD,qCAAwF;AACxF,yCAAwD;AACxD,4DAA4B;AAC5B,4CAA0F;AAC1F,uCAA4C;AAE5C,6QAA6Q;AAC7Q,MAAa,oBAAoB;aACf,SAAI,GAAG,iBAAiB,CAAC;aACzB,YAAO,GAAG,iBAAiB,CAAC;aAC5B,gBAAW,GAAG,oBAAoB,CAAC;IAEnD,+IAA+I;aAC/H,gBAAW,GACzB,kHAAkH,CAAC;IAErH,oHAAoH;aACpG,gBAAW,GAAG,kDAAkD,CAAC;aAEzD,gBAAW,GAAG,MAAM,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAEjG;QACE,yBAAe,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,2BAAe,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,8GAA8G;IAC9G,MAAM,CAAC,WAAW,CAAC,OAA0B,EAAE;QAC7C,OAAO,yBAAe,CAAC,aAAa,CAAC;YACnC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,oBAAoB,CAAC,cAAc,EAAE;SACzD,CAAC,CAAC;IACL,CAAC;IAED,wLAAwL;IACxL,MAAM,CAAC,cAAc;QACnB,MAAM,KAAK,GAAG,yBAAe,CAAC,KAAK,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAA,mBAAO,EAA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AG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC;gBACnE,MAAM,UAAU,GAAG,MAAM;oBACvB,CAAC,CAAC,iIAAiI,oBAAoB,CAAC,OAAO,OAAO,oBAAoB,CAAC,WAAW,QAAQ;oBAC9M,CAAC,CAAC,YAAY,oBAAoB,CAAC,WAAW,YAAY,oBAAoB,CAAC,OAAO,0GAA0G,oBAAoB,CAAC,WAAW,QAAQ,CAAC;gBAC3O,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;oBAChE,QAAQ,EAAE,UAAU;oBACpB,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC,CAAC;YACN,CAAC;SACF,CAAC;IACJ,CAAC;IAED,gFAAgF;IAChF,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAA0B,EAAE;QACvD,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,oBAAoB,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC;YACvE,OAAO;QACT,CAAC;QACD,MAAM,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC5E,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;;AArcH,oDAscC","sourcesContent":["import type { BunPlugin } from 'bun';\nimport { getError } from '@venizia/ignis-helpers';\nimport { existsSync, globSync, readdirSync, readFileSync, realpathSync } from 'node:fs';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport ts from 'typescript';\nimport { ArtifactIndexEmitter, ArtifactScanner, ArtifactStereotypes } from '../generator';\nimport { ArtifactSources } from './sources';\n\n/** Serves `ignis:artifacts` - the application's generated index, rendered in memory from the scanner. At run time it is a virtual module (`build.module`); in `Bun.build` it is resolved and loaded (`onResolve`/`onLoad`), so a binary carries the list and never scans. */\nexport class IgnisArtifactsPlugin {\n static readonly NAME = 'ignis-artifacts';\n static readonly VIRTUAL = 'ignis:artifacts';\n static readonly EXPORT_NAME = 'GeneratedArtifacts';\n\n /** `@venizia/ignis-boot/auto`, from source or from either dist format - replaced at build time by a static re-export of the virtual module. */\n static readonly AUTO_MODULE =\n /[\\\\/](?:@venizia[\\\\/]ignis-boot|packages[\\\\/]boot)[\\\\/](?:dist[\\\\/](?:esm|cjs)|src)[\\\\/]bun[\\\\/]auto\\.(?:ts|js)$/;\n\n /** A text test for a file worth parsing: `ArtifactGroup.define(`, with any spacing or line break around the dot. */\n static readonly DEFINE_CALL = /ArtifactGroup\\s*\\.\\s*(?:define|application)\\s*\\(/;\n\n private static readonly RUNTIME_KEY = Symbol.for('@venizia/ignis-boot:artifacts-runtime-plugin');\n\n static {\n ArtifactSources.useScanner({ scanner: ArtifactScanner.getInstance() });\n }\n\n /** The `src` beside the nearest `package.json` at or above `from` (default: the entry module's directory). */\n static defaultRoot(opts: { from?: string } = {}): string {\n return ArtifactSources.packageSource({\n from: opts.from ?? IgnisArtifactsPlugin.entryDirectory(),\n });\n }\n\n /** 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). */\n static entryDirectory(): string {\n const entry = ArtifactSources.entry();\n return entry ? dirname(entry) : process.cwd();\n }\n\n /** 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`). */\n static render(opts: { root: string; entry?: string }): string {\n const root = resolve(opts.root);\n if (!existsSync(root)) {\n throw getError({\n 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`,\n });\n }\n const outFile = join(root, '__ignis_artifacts__.ts');\n const artifacts = ArtifactSources.scan({ packageSource: root });\n return ArtifactIndexEmitter.render({\n artifacts: opts.entry\n ? ArtifactSources.runningArtifacts({ artifacts, from: opts.entry })\n : artifacts,\n outFile,\n exportName: IgnisArtifactsPlugin.EXPORT_NAME,\n command: { root, out: outFile },\n absoluteImports: true,\n });\n }\n\n /** 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. */\n static rewriteGroups(opts: { filePath: string; source: string }): string {\n const { filePath, source } = opts;\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const aliases = new Set<string>();\n for (const statement of sourceFile.statements) {\n const bindings = ts.isImportDeclaration(statement)\n ? statement.importClause?.namedBindings\n : undefined;\n for (const element of bindings && ts.isNamedImports(bindings) ? bindings.elements : []) {\n if (\n (element.propertyName ?? element.name).text === 'ArtifactGroup' &&\n element.name.text !== 'ArtifactGroup'\n ) {\n aliases.add(element.name.text);\n }\n }\n }\n\n const edits: Array<{ at: number; text: string }> = [];\n const imports: string[] = [];\n let counter = 0;\n\n const refuse = (node: ts.Node, reason: string): never => {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n throw getError({\n 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`,\n });\n };\n\n const isCompiled = !ArtifactStereotypes.SOURCE_EXTENSION.test(filePath);\n const contentLiteral = (folder: string | undefined, ignore?: string[]): string => {\n const artifacts = ArtifactSources.folderArtifacts({ folder, site: filePath, ignore });\n if (artifacts.length === 0) {\n throw getError({\n message: `[IgnisArtifactsPlugin] ArtifactGroup '${folder ?? '<application>'}' resolved to no class | ${filePath} - check the folder name and that its classes carry a stereotype decorator`,\n });\n }\n\n const fields: string[] = [];\n for (const { type, field } of ArtifactStereotypes.EMIT_ORDER) {\n const locals = artifacts\n .filter((artifact) => artifact.type === type)\n .map((artifact) => {\n if (isCompiled) {\n return `require(${JSON.stringify(artifact.filePath)}).${artifact.className}`;\n }\n counter += 1;\n const local = `__ignis_group_${counter}`;\n const path = artifact.filePath\n .split(sep)\n .join('/')\n .replace(ArtifactStereotypes.SOURCE_EXTENSION, '');\n imports.push(`import { ${artifact.className} as ${local} } from '${path}';`);\n return local;\n });\n if (locals.length > 0) {\n fields.push(`${field}: [${locals.join(', ')}]`);\n }\n }\n return `{ ${fields.join(', ')} }`;\n };\n\n const visit = (node: ts.Node): void => {\n const isGroupCall =\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n (ts.isIdentifier(node.expression.expression) ||\n ts.isPropertyAccessExpression(node.expression.expression)) &&\n (node.expression.name.text === 'define' || node.expression.name.text === 'application');\n if (!isGroupCall) {\n ts.forEachChild(node, visit);\n return;\n }\n\n const call = node as ts.CallExpression;\n const access = call.expression as ts.PropertyAccessExpression;\n const target = access.expression;\n const callee = ts.isIdentifier(target)\n ? target.text\n : (target as ts.PropertyAccessExpression).name.text;\n const isApplication = access.name.text === 'application';\n if (ts.isIdentifier(target) && aliases.has(callee)) {\n refuse(call, `ArtifactGroup is imported as ${callee}`);\n }\n if (callee !== 'ArtifactGroup') {\n ts.forEachChild(node, visit);\n return;\n }\n\n const [argument] = call.arguments;\n if (isApplication && !argument) {\n edits.push({ at: call.arguments.pos, text: `{ content: ${contentLiteral(undefined)} }` });\n return;\n }\n if (!argument || !ts.isObjectLiteralExpression(argument)) {\n refuse(call, 'the argument is not an object literal');\n }\n\n const literal = argument as ts.ObjectLiteralExpression;\n const named = (name: string): ts.ObjectLiteralElementLike | undefined =>\n literal.properties.find(\n (entry) =>\n entry.name !== undefined && ts.isIdentifier(entry.name) && entry.name.text === name,\n );\n if (named('content')) {\n return;\n }\n\n const folderProperty = named('folder');\n if (isApplication && folderProperty) {\n refuse(call, 'ArtifactGroup.application() takes no folder');\n }\n const folderLiteral =\n folderProperty &&\n ts.isPropertyAssignment(folderProperty) &&\n ts.isStringLiteral(folderProperty.initializer)\n ? folderProperty.initializer.text\n : undefined;\n if (!isApplication && folderLiteral === undefined) {\n refuse(call, 'folder is not a string literal');\n }\n\n const ignoreProperty = named('ignore');\n const ignoreList =\n ignoreProperty &&\n ts.isPropertyAssignment(ignoreProperty) &&\n ts.isArrayLiteralExpression(ignoreProperty.initializer) &&\n ignoreProperty.initializer.elements.every((element) => ts.isStringLiteral(element))\n ? ignoreProperty.initializer.elements.map((element) => (element as ts.StringLiteral).text)\n : undefined;\n if (ignoreProperty && ignoreList === undefined) {\n refuse(call, 'ignore is not an array of string literals');\n }\n\n const last = literal.properties[literal.properties.length - 1];\n edits.push({\n at: last ? last.getEnd() : literal.getStart() + 1,\n text: `${last ? ', ' : ''}content: ${contentLiteral(folderLiteral, ignoreList)}`,\n });\n };\n visit(sourceFile);\n\n let rewritten = source;\n for (const edit of [...edits].sort((left, right) => right.at - left.at)) {\n rewritten = rewritten.slice(0, edit.at) + edit.text + rewritten.slice(edit.at);\n }\n return imports.length > 0 ? `${imports.join('\\n')}\\n${rewritten}` : rewritten;\n }\n\n /** A text test for a file worth parsing for decorated classes: an IGNIS stereotype decorator call. */\n static readonly DECORATED =\n /@(?:configuration|component|controller|service|repository|datasource|model|injectable)\\s*\\(/;\n\n /** The classes of a source file that carry an IGNIS stereotype decorator (`@service()`, `@repository(...)`, `@injectable(...)`...). */\n static decoratedClasses(opts: { filePath: string; source: string }): string[] {\n const names = new Set([\n ...Object.keys(ArtifactStereotypes.BY_DECORATOR),\n ArtifactStereotypes.ROOT_DECORATOR,\n ]);\n const sourceFile = ts.createSourceFile(\n opts.filePath,\n opts.source,\n ts.ScriptTarget.Latest,\n true,\n );\n const found: string[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node) && node.name) {\n const isDecorated = (ts.getDecorators(node) ?? []).some((decorator) => {\n const expression = ts.isCallExpression(decorator.expression)\n ? decorator.expression.expression\n : decorator.expression;\n return ts.isIdentifier(expression) && names.has(expression.text);\n });\n if (isDecorated) {\n found.push(node.name.text);\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return found;\n }\n\n /** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`. Binding keys are built from `Class.name`, and a bundler renames classes - a minifier, or Bun's scope hoisting when a registered class shadows a same-name class it extends (`StockService` becomes `StockService2`). A string literal survives both, and a static block runs before the class's decorators. Only these classes are touched; the rest of the bundle is left alone. */\n static pinClassNames(opts: {\n filePath: string;\n source: string;\n classNames: ReadonlySet<string>;\n }): string {\n const sourceFile = ts.createSourceFile(\n opts.filePath,\n opts.source,\n ts.ScriptTarget.Latest,\n true,\n );\n const positions: Array<{ at: number; name: string }> = [];\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node) && node.name && opts.classNames.has(node.name.text)) {\n positions.push({ at: node.members.pos, name: node.name.text });\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n let pinned = opts.source;\n for (const { at, name } of positions.sort((left, right) => right.at - left.at)) {\n const block = ` static { Object.defineProperty(this, 'name', { value: ${JSON.stringify(name)} }); }`;\n pinned = pinned.slice(0, at) + block + pinned.slice(at);\n }\n return pinned;\n }\n\n /** The classes whose names a build must pin, by the file the build loads: the app's own (from the tree `entry` runs, see `runningArtifacts`) and those of every package that defines a group the app can borrow (from the tree the group file sits in). */\n static pinnedClasses(opts: {\n root: string;\n groupFiles?: ReadonlyArray<string>;\n entry?: string;\n }): Map<string, Set<string>> {\n const byFile = new Map<string, Set<string>>();\n const add = (artifacts: ReadonlyArray<{ filePath: string; className: string }>): void => {\n for (const { filePath, className } of artifacts) {\n byFile.set(filePath, (byFile.get(filePath) ?? new Set()).add(className));\n }\n };\n const own = ArtifactSources.scan({ packageSource: opts.root });\n add(opts.entry ? ArtifactSources.runningArtifacts({ artifacts: own, from: opts.entry }) : own);\n // Every class carrying an IGNIS decorator in the workspace sources: a class nothing scans (a library that defines no group) is still an injection target, and still renamed by a bundler when its name collides.\n for (const file of IgnisArtifactsPlugin.workspaceSourceFiles({ root: opts.root })) {\n if (!ArtifactStereotypes.SOURCE_EXTENSION.test(file)) {\n continue;\n }\n const source = readFileSync(file, 'utf8');\n if (!IgnisArtifactsPlugin.DECORATED.test(source)) {\n continue;\n }\n add(\n IgnisArtifactsPlugin.decoratedClasses({ filePath: file, source }).map((className) => ({\n filePath: file,\n className,\n })),\n );\n }\n for (const groupFile of opts.groupFiles ?? []) {\n const packageSource = ArtifactSources.packageSource({ from: dirname(groupFile) });\n if (packageSource === opts.root || !existsSync(packageSource)) {\n continue;\n }\n add(\n ArtifactSources.runningArtifacts({\n artifacts: ArtifactSources.scan({ packageSource }),\n from: groupFile,\n }),\n );\n }\n return byFile;\n }\n\n /** 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. */\n static groupDefinitionFiles(opts: { root: string }): string[] {\n return IgnisArtifactsPlugin.workspaceSourceFiles(opts).filter((file) =>\n IgnisArtifactsPlugin.DEFINE_CALL.test(readFileSync(file, 'utf8')),\n );\n }\n\n /** 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. */\n static workspaceSourceFiles(opts: { root: string }): string[] {\n const root = resolve(opts.root);\n const packageDirectory = dirname(root);\n const manifestPath = join(packageDirectory, 'package.json');\n const manifest = existsSync(manifestPath) ? JSON.parse(readFileSync(manifestPath, 'utf8')) : {};\n const names = Object.keys({\n ...manifest.dependencies,\n ...manifest.devDependencies,\n ...manifest.peerDependencies,\n });\n\n const sources = new Set<string>([root]);\n for (const name of names) {\n let directory = packageDirectory;\n while (true) {\n const linked = join(directory, 'node_modules', name);\n if (existsSync(linked)) {\n const real = realpathSync(linked);\n if (!real.split(sep).includes('node_modules') && existsSync(join(real, 'src'))) {\n sources.add(join(real, 'src'));\n }\n break;\n }\n const parent = dirname(directory);\n if (parent === directory) {\n break;\n }\n directory = parent;\n }\n }\n\n // A package that runs from its compiled tree (`main` in dist) defines its groups there too.\n const trees: Array<{ directory: string; pattern: string }> = [];\n for (const source of sources) {\n if (!existsSync(source)) {\n continue;\n }\n trees.push({ directory: source, pattern: ArtifactStereotypes.SOURCE_GLOB });\n for (const entry of readdirSync(dirname(source), { withFileTypes: true })) {\n if (\n entry.isDirectory() &&\n !['src', 'node_modules'].includes(entry.name) &&\n !entry.name.startsWith('.')\n ) {\n trees.push({ directory: join(dirname(source), entry.name), pattern: '**/*.js' });\n }\n }\n }\n\n const files: string[] = [];\n for (const { directory, pattern } of trees) {\n for (const relativePath of globSync(pattern, { cwd: directory })) {\n if (!relativePath.includes('__tests__')) {\n files.push(join(directory, relativePath));\n }\n }\n }\n return files;\n }\n\n /** 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. */\n static create(\n opts: { root?: string; entry?: string; isRuntime?: boolean; lazyIndex?: boolean } = {},\n ): BunPlugin {\n const isRuntime = opts.isRuntime ?? false;\n\n return {\n name: IgnisArtifactsPlugin.NAME,\n setup(build) {\n const [entrypoint] = isRuntime ? [] : build.config.entrypoints;\n const entry = opts.entry ?? (entrypoint ? resolve(entrypoint) : ArtifactSources.entry());\n const root =\n opts.root ??\n ArtifactSources.packageSource({ from: entry ? dirname(entry) : process.cwd() });\n const contents = (): string => IgnisArtifactsPlugin.render({ root, entry });\n\n if (isRuntime) {\n build.module(IgnisArtifactsPlugin.VIRTUAL, () => ({\n contents: contents(),\n loader: 'ts',\n }));\n return;\n }\n\n const virtualPath = join(resolve(root), '__ignis_artifacts__.ts');\n build.onResolve({ filter: /^ignis:artifacts$/ }, () => ({ path: virtualPath }));\n build.onLoad({ filter: /__ignis_artifacts__\\.ts$/ }, () => ({\n contents: contents(),\n loader: 'ts',\n }));\n const groupFiles = IgnisArtifactsPlugin.groupDefinitionFiles({ root });\n const groupFileSet = new Set(groupFiles);\n const pinned = IgnisArtifactsPlugin.pinnedClasses({ root, groupFiles, entry });\n const loaded = [...new Set([...groupFiles, ...pinned.keys()])];\n if (loaded.length > 0) {\n const escaped = loaded.map((file) => file.replace(/[.*+?^${}()|[\\]\\\\/]/g, '\\\\$&'));\n build.onLoad({ filter: new RegExp(`^(?:${escaped.join('|')})$`) }, (args) => {\n const source = readFileSync(args.path, 'utf8');\n const grouped = groupFileSet.has(args.path)\n ? IgnisArtifactsPlugin.rewriteGroups({ filePath: args.path, source })\n : source;\n const classNames = pinned.get(args.path);\n return {\n contents: classNames\n ? IgnisArtifactsPlugin.pinClassNames({\n filePath: args.path,\n source: grouped,\n classNames,\n })\n : grouped,\n loader: args.path.endsWith('.tsx') ? 'tsx' : args.path.endsWith('.ts') ? 'ts' : 'js',\n };\n });\n }\n // 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.\n const isLazy = opts.lazyIndex ?? build.config.target !== 'browser';\n const autoModule = isLazy\n ? `import { AutoArtifactGroup } from './auto-group';\\nexport default new AutoArtifactGroup({ resolve: async () => (await import('${IgnisArtifactsPlugin.VIRTUAL}')).${IgnisArtifactsPlugin.EXPORT_NAME} });\\n`\n : `import { ${IgnisArtifactsPlugin.EXPORT_NAME} } from '${IgnisArtifactsPlugin.VIRTUAL}';\\nimport { AutoArtifactGroup } from './auto-group';\\nexport default new AutoArtifactGroup({ content: ${IgnisArtifactsPlugin.EXPORT_NAME} });\\n`;\n build.onLoad({ filter: IgnisArtifactsPlugin.AUTO_MODULE }, () => ({\n contents: autoModule,\n loader: 'ts',\n }));\n },\n };\n }\n\n /** Registers the run-time plugin once per process; a second call is a no-op. */\n static async registerRuntime(opts: { root?: string } = {}): Promise<void> {\n if (Reflect.get(globalThis, IgnisArtifactsPlugin.RUNTIME_KEY) === true) {\n return;\n }\n await Bun.plugin(IgnisArtifactsPlugin.create({ ...opts, isRuntime: true }));\n Reflect.set(globalThis, IgnisArtifactsPlugin.RUNTIME_KEY, true);\n }\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type IScannedArtifact } from '../generator/common';
|
|
2
|
-
/** The scanner's answer for one `src`, kept under the package's `node_modules/.cache` and valid while no `.ts` file under `src`, the package manifest or the lockfile changed - a hit skips TypeScript entirely. */
|
|
3
|
-
export declare class ArtifactScanCache {
|
|
4
|
-
static readonly VERSION = 2;
|
|
5
|
-
static location(opts: {
|
|
6
|
-
root: string;
|
|
7
|
-
}): string;
|
|
8
|
-
/** Path, size and mtime of every `.ts`/`.tsx` under `root`, plus the package manifest and the nearest lockfile (a dependency upgrade can change which decorators count). */
|
|
9
|
-
static fingerprint(opts: {
|
|
10
|
-
root: string;
|
|
11
|
-
}): string;
|
|
12
|
-
/** The cached scan, or `undefined` for a missing, stale or unreadable cache - never an error. */
|
|
13
|
-
static read(opts: {
|
|
14
|
-
root: string;
|
|
15
|
-
}): IScannedArtifact[] | undefined;
|
|
16
|
-
/** Stores a scan; `false` when the cache directory cannot be written (a read-only install), which only costs the next start a scan. */
|
|
17
|
-
static write(opts: {
|
|
18
|
-
root: string;
|
|
19
|
-
artifacts: IScannedArtifact[];
|
|
20
|
-
}): boolean;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=scan-cache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scan-cache.d.ts","sourceRoot":"","sources":["../../../src/bun/scan-cache.ts"],"names":[],"mappings":"AAWA,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,oNAAoN;AACpN,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,QAAQ,CAAC,OAAO,KAAK;IAE5B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAM/C,4KAA4K;IAC5K,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAmClD,iGAAiG;IACjG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,gBAAgB,EAAE,GAAG,SAAS;IAqBnE,uIAAuI;IACvI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,gBAAgB,EAAE,CAAA;KAAE,GAAG,OAAO;CAmB7E"}
|