@venizia/ignis-boot 0.2.1-10 → 0.2.1-11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/vite/plugin.d.ts +7 -8
- package/dist/cjs/vite/plugin.d.ts.map +1 -1
- package/dist/cjs/vite/plugin.js +45 -8
- package/dist/cjs/vite/plugin.js.map +1 -1
- package/dist/esm/vite/plugin.d.ts +7 -8
- package/dist/esm/vite/plugin.d.ts.map +1 -1
- package/dist/esm/vite/plugin.js +42 -8
- package/dist/esm/vite/plugin.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,13 +6,6 @@ export interface IIgnisVitePlugin {
|
|
|
6
6
|
optimizeDeps: {
|
|
7
7
|
exclude: string[];
|
|
8
8
|
};
|
|
9
|
-
build: {
|
|
10
|
-
rolldownOptions: {
|
|
11
|
-
output: {
|
|
12
|
-
keepNames: boolean;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
9
|
};
|
|
17
10
|
configResolved: (config: {
|
|
18
11
|
root: string;
|
|
@@ -22,9 +15,15 @@ export interface IIgnisVitePlugin {
|
|
|
22
15
|
transform: (code: string, id: string) => string | undefined;
|
|
23
16
|
watchChange: (id: string) => void;
|
|
24
17
|
}
|
|
25
|
-
/** `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),
|
|
18
|
+
/** `IgnisArtifactsPlugin` for Vite: serves `ignis:artifacts`, replaces `@venizia/ignis-boot/auto` with an eager import of it (a browser bundle is tree-shaken only when eager), inlines every `ArtifactGroup.define` / `application` call, and pins the name of every scanned class - binding keys are built from `Class.name`, and a minifier renames classes. */
|
|
26
19
|
export declare class IgnisArtifactsVitePlugin {
|
|
27
20
|
static readonly RESOLVED_VIRTUAL: string;
|
|
21
|
+
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`: a string literal survives minification, and a static block runs before the class's decorators read the name. Only these classes keep their names; the rest of the bundle minifies as usual. */
|
|
22
|
+
static pinClassNames(opts: {
|
|
23
|
+
filePath: string;
|
|
24
|
+
source: string;
|
|
25
|
+
classNames: ReadonlySet<string>;
|
|
26
|
+
}): string;
|
|
28
27
|
/** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */
|
|
29
28
|
static create(opts?: {
|
|
30
29
|
root?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"AAMA,4HAA4H;AAC5H,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM;QAAE,YAAY,EAAE;YAAE,OAAO,EAAE,MAAM,EAAE,CAAA;SAAE,CAAA;KAAE,CAAC;IACtD,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnD,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC5D,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,mWAAmW;AACnW,qBAAa,wBAAwB;IACnC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,SAAuC;IAMvE,qRAAqR;IACrR,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QACzB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;KACjC,GAAG,MAAM;IAwBV,6FAA6F;IAC7F,MAAM,CAAC,MAAM,CAAC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,gBAAgB;CAmD9D"}
|
package/dist/cjs/vite/plugin.js
CHANGED
|
@@ -1,32 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.IgnisArtifactsVitePlugin = void 0;
|
|
4
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
5
9
|
const generator_1 = require("../generator");
|
|
6
10
|
const plugin_1 = require("../bun/plugin");
|
|
7
11
|
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),
|
|
12
|
+
/** `IgnisArtifactsPlugin` for Vite: serves `ignis:artifacts`, replaces `@venizia/ignis-boot/auto` with an eager import of it (a browser bundle is tree-shaken only when eager), inlines every `ArtifactGroup.define` / `application` call, and pins the name of every scanned class - binding keys are built from `Class.name`, and a minifier renames classes. */
|
|
9
13
|
class IgnisArtifactsVitePlugin {
|
|
10
14
|
static { this.RESOLVED_VIRTUAL = `\0${plugin_1.IgnisArtifactsPlugin.VIRTUAL}`; }
|
|
11
15
|
static {
|
|
12
16
|
sources_1.ArtifactSources.useScanner({ scanner: generator_1.ArtifactScanner.getInstance() });
|
|
13
17
|
}
|
|
18
|
+
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`: a string literal survives minification, and a static block runs before the class's decorators read the name. Only these classes keep their names; the rest of the bundle minifies as usual. */
|
|
19
|
+
static pinClassNames(opts) {
|
|
20
|
+
const sourceFile = typescript_1.default.createSourceFile(opts.filePath, opts.source, typescript_1.default.ScriptTarget.Latest, true);
|
|
21
|
+
const positions = [];
|
|
22
|
+
const visit = (node) => {
|
|
23
|
+
if (typescript_1.default.isClassDeclaration(node) && node.name && opts.classNames.has(node.name.text)) {
|
|
24
|
+
positions.push({ at: node.members.pos, name: node.name.text });
|
|
25
|
+
}
|
|
26
|
+
typescript_1.default.forEachChild(node, visit);
|
|
27
|
+
};
|
|
28
|
+
visit(sourceFile);
|
|
29
|
+
let pinned = opts.source;
|
|
30
|
+
for (const { at, name } of positions.sort((left, right) => right.at - left.at)) {
|
|
31
|
+
const block = ` static { Object.defineProperty(this, 'name', { value: ${JSON.stringify(name)} }); }`;
|
|
32
|
+
pinned = pinned.slice(0, at) + block + pinned.slice(at);
|
|
33
|
+
}
|
|
34
|
+
return pinned;
|
|
35
|
+
}
|
|
14
36
|
/** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */
|
|
15
37
|
static create(opts = {}) {
|
|
16
38
|
let root = opts.root ? (0, node_path_1.resolve)(opts.root) : '';
|
|
17
39
|
let groupFiles = new Set();
|
|
40
|
+
let classesByFile = new Map();
|
|
41
|
+
const scan = () => {
|
|
42
|
+
classesByFile = new Map();
|
|
43
|
+
for (const { filePath, className } of sources_1.ArtifactSources.scan({ packageSource: root })) {
|
|
44
|
+
classesByFile.set(filePath, (classesByFile.get(filePath) ?? new Set()).add(className));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
18
47
|
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
48
|
return {
|
|
20
49
|
name: plugin_1.IgnisArtifactsPlugin.NAME,
|
|
21
50
|
enforce: 'pre',
|
|
22
51
|
// 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
|
-
}),
|
|
52
|
+
config: () => ({ optimizeDeps: { exclude: ['@venizia/ignis-boot'] } }),
|
|
27
53
|
configResolved: config => {
|
|
28
54
|
root ||= sources_1.ArtifactSources.packageSource({ from: config.root });
|
|
29
55
|
groupFiles = new Set(plugin_1.IgnisArtifactsPlugin.groupDefinitionFiles({ root }));
|
|
56
|
+
scan();
|
|
30
57
|
},
|
|
31
58
|
resolveId: id => id === plugin_1.IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,
|
|
32
59
|
load: id => {
|
|
@@ -35,13 +62,23 @@ class IgnisArtifactsVitePlugin {
|
|
|
35
62
|
}
|
|
36
63
|
return plugin_1.IgnisArtifactsPlugin.AUTO_MODULE.test(id) ? autoModule : undefined;
|
|
37
64
|
},
|
|
38
|
-
transform: (code, id) =>
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
transform: (code, id) => {
|
|
66
|
+
const classNames = classesByFile.get(id);
|
|
67
|
+
if (!groupFiles.has(id) && !classNames) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const grouped = groupFiles.has(id)
|
|
71
|
+
? plugin_1.IgnisArtifactsPlugin.rewriteGroups({ filePath: id, source: code })
|
|
72
|
+
: code;
|
|
73
|
+
return classNames
|
|
74
|
+
? IgnisArtifactsVitePlugin.pinClassNames({ filePath: id, source: grouped, classNames })
|
|
75
|
+
: grouped;
|
|
76
|
+
},
|
|
41
77
|
// A file added, removed or edited under the root can change the index: rescan on the next load.
|
|
42
78
|
watchChange: id => {
|
|
43
79
|
if (id.startsWith(root)) {
|
|
44
80
|
sources_1.ArtifactSources.clear();
|
|
81
|
+
scan();
|
|
45
82
|
}
|
|
46
83
|
},
|
|
47
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,4DAA4B;AAC5B,4CAA+C;AAC/C,0CAAqD;AACrD,4CAAiD;AAcjD,mWAAmW;AACnW,MAAa,wBAAwB;aACnB,qBAAgB,GAAG,KAAK,6BAAoB,CAAC,OAAO,EAAE,CAAC;IAEvE;QACE,yBAAe,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,2BAAe,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,qRAAqR;IACrR,MAAM,CAAC,aAAa,CAAC,IAIpB;QACC,MAAM,UAAU,GAAG,oBAAE,CAAC,gBAAgB,CACpC,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,oBAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;QACF,MAAM,SAAS,GAAwC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;YACpC,IAAI,oBAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpF,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,oBAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC,CAAC;QACF,KAAK,CAAC,UAAU,C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ACnB,CAAC;gBACD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,CAAC,CAAC,6BAAoB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oBACpE,CAAC,CAAC,IAAI,CAAC;gBACT,OAAO,UAAU;oBACf,CAAC,CAAC,wBAAwB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;oBACvF,CAAC,CAAC,OAAO,CAAC;YACd,CAAC;YACD,gGAAgG;YAChG,WAAW,EAAE,EAAE,CAAC,EAAE;gBAChB,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,yBAAe,CAAC,KAAK,EAAE,CAAC;oBACxB,IAAI,EAAE,CAAC;gBACT,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;;AAvFH,4DAwFC"}
|
|
@@ -6,13 +6,6 @@ export interface IIgnisVitePlugin {
|
|
|
6
6
|
optimizeDeps: {
|
|
7
7
|
exclude: string[];
|
|
8
8
|
};
|
|
9
|
-
build: {
|
|
10
|
-
rolldownOptions: {
|
|
11
|
-
output: {
|
|
12
|
-
keepNames: boolean;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
9
|
};
|
|
17
10
|
configResolved: (config: {
|
|
18
11
|
root: string;
|
|
@@ -22,9 +15,15 @@ export interface IIgnisVitePlugin {
|
|
|
22
15
|
transform: (code: string, id: string) => string | undefined;
|
|
23
16
|
watchChange: (id: string) => void;
|
|
24
17
|
}
|
|
25
|
-
/** `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),
|
|
18
|
+
/** `IgnisArtifactsPlugin` for Vite: serves `ignis:artifacts`, replaces `@venizia/ignis-boot/auto` with an eager import of it (a browser bundle is tree-shaken only when eager), inlines every `ArtifactGroup.define` / `application` call, and pins the name of every scanned class - binding keys are built from `Class.name`, and a minifier renames classes. */
|
|
26
19
|
export declare class IgnisArtifactsVitePlugin {
|
|
27
20
|
static readonly RESOLVED_VIRTUAL: string;
|
|
21
|
+
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`: a string literal survives minification, and a static block runs before the class's decorators read the name. Only these classes keep their names; the rest of the bundle minifies as usual. */
|
|
22
|
+
static pinClassNames(opts: {
|
|
23
|
+
filePath: string;
|
|
24
|
+
source: string;
|
|
25
|
+
classNames: ReadonlySet<string>;
|
|
26
|
+
}): string;
|
|
28
27
|
/** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */
|
|
29
28
|
static create(opts?: {
|
|
30
29
|
root?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"AAMA,4HAA4H;AAC5H,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM;QAAE,YAAY,EAAE;YAAE,OAAO,EAAE,MAAM,EAAE,CAAA;SAAE,CAAA;KAAE,CAAC;IACtD,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnD,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC5D,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,mWAAmW;AACnW,qBAAa,wBAAwB;IACnC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,SAAuC;IAMvE,qRAAqR;IACrR,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QACzB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;KACjC,GAAG,MAAM;IAwBV,6FAA6F;IAC7F,MAAM,CAAC,MAAM,CAAC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,gBAAgB;CAmD9D"}
|
package/dist/esm/vite/plugin.js
CHANGED
|
@@ -1,29 +1,53 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
|
+
import ts from 'typescript';
|
|
2
3
|
import { ArtifactScanner } from '../generator/index.js';
|
|
3
4
|
import { IgnisArtifactsPlugin } from '../bun/plugin.js';
|
|
4
5
|
import { ArtifactSources } from '../bun/sources.js';
|
|
5
|
-
/** `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),
|
|
6
|
+
/** `IgnisArtifactsPlugin` for Vite: serves `ignis:artifacts`, replaces `@venizia/ignis-boot/auto` with an eager import of it (a browser bundle is tree-shaken only when eager), inlines every `ArtifactGroup.define` / `application` call, and pins the name of every scanned class - binding keys are built from `Class.name`, and a minifier renames classes. */
|
|
6
7
|
export class IgnisArtifactsVitePlugin {
|
|
7
8
|
static { this.RESOLVED_VIRTUAL = `\0${IgnisArtifactsPlugin.VIRTUAL}`; }
|
|
8
9
|
static {
|
|
9
10
|
ArtifactSources.useScanner({ scanner: ArtifactScanner.getInstance() });
|
|
10
11
|
}
|
|
12
|
+
/** Opens each named class with `static { Object.defineProperty(this, 'name', ...) }`: a string literal survives minification, and a static block runs before the class's decorators read the name. Only these classes keep their names; the rest of the bundle minifies as usual. */
|
|
13
|
+
static pinClassNames(opts) {
|
|
14
|
+
const sourceFile = ts.createSourceFile(opts.filePath, opts.source, ts.ScriptTarget.Latest, true);
|
|
15
|
+
const positions = [];
|
|
16
|
+
const visit = (node) => {
|
|
17
|
+
if (ts.isClassDeclaration(node) && node.name && opts.classNames.has(node.name.text)) {
|
|
18
|
+
positions.push({ at: node.members.pos, name: node.name.text });
|
|
19
|
+
}
|
|
20
|
+
ts.forEachChild(node, visit);
|
|
21
|
+
};
|
|
22
|
+
visit(sourceFile);
|
|
23
|
+
let pinned = opts.source;
|
|
24
|
+
for (const { at, name } of positions.sort((left, right) => right.at - left.at)) {
|
|
25
|
+
const block = ` static { Object.defineProperty(this, 'name', { value: ${JSON.stringify(name)} }); }`;
|
|
26
|
+
pinned = pinned.slice(0, at) + block + pinned.slice(at);
|
|
27
|
+
}
|
|
28
|
+
return pinned;
|
|
29
|
+
}
|
|
11
30
|
/** `root`: the `src` to scan (default: the one beside the `package.json` of Vite's root). */
|
|
12
31
|
static create(opts = {}) {
|
|
13
32
|
let root = opts.root ? resolve(opts.root) : '';
|
|
14
33
|
let groupFiles = new Set();
|
|
34
|
+
let classesByFile = new Map();
|
|
35
|
+
const scan = () => {
|
|
36
|
+
classesByFile = new Map();
|
|
37
|
+
for (const { filePath, className } of ArtifactSources.scan({ packageSource: root })) {
|
|
38
|
+
classesByFile.set(filePath, (classesByFile.get(filePath) ?? new Set()).add(className));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
15
41
|
const autoModule = `import { ${IgnisArtifactsPlugin.EXPORT_NAME} } from '${IgnisArtifactsPlugin.VIRTUAL}';\nimport { AutoArtifactGroup } from './auto-group';\nexport default new AutoArtifactGroup({ content: ${IgnisArtifactsPlugin.EXPORT_NAME} });\n`;
|
|
16
42
|
return {
|
|
17
43
|
name: IgnisArtifactsPlugin.NAME,
|
|
18
44
|
enforce: 'pre',
|
|
19
45
|
// Pre-bundling would hide `auto` inside a dependency chunk, out of reach of `load`.
|
|
20
|
-
config: () => ({
|
|
21
|
-
optimizeDeps: { exclude: ['@venizia/ignis-boot'] },
|
|
22
|
-
build: { rolldownOptions: { output: { keepNames: true } } },
|
|
23
|
-
}),
|
|
46
|
+
config: () => ({ optimizeDeps: { exclude: ['@venizia/ignis-boot'] } }),
|
|
24
47
|
configResolved: config => {
|
|
25
48
|
root ||= ArtifactSources.packageSource({ from: config.root });
|
|
26
49
|
groupFiles = new Set(IgnisArtifactsPlugin.groupDefinitionFiles({ root }));
|
|
50
|
+
scan();
|
|
27
51
|
},
|
|
28
52
|
resolveId: id => id === IgnisArtifactsPlugin.VIRTUAL ? IgnisArtifactsVitePlugin.RESOLVED_VIRTUAL : undefined,
|
|
29
53
|
load: id => {
|
|
@@ -32,13 +56,23 @@ export class IgnisArtifactsVitePlugin {
|
|
|
32
56
|
}
|
|
33
57
|
return IgnisArtifactsPlugin.AUTO_MODULE.test(id) ? autoModule : undefined;
|
|
34
58
|
},
|
|
35
|
-
transform: (code, id) =>
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
transform: (code, id) => {
|
|
60
|
+
const classNames = classesByFile.get(id);
|
|
61
|
+
if (!groupFiles.has(id) && !classNames) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const grouped = groupFiles.has(id)
|
|
65
|
+
? IgnisArtifactsPlugin.rewriteGroups({ filePath: id, source: code })
|
|
66
|
+
: code;
|
|
67
|
+
return classNames
|
|
68
|
+
? IgnisArtifactsVitePlugin.pinClassNames({ filePath: id, source: grouped, classNames })
|
|
69
|
+
: grouped;
|
|
70
|
+
},
|
|
38
71
|
// A file added, removed or edited under the root can change the index: rescan on the next load.
|
|
39
72
|
watchChange: id => {
|
|
40
73
|
if (id.startsWith(root)) {
|
|
41
74
|
ArtifactSources.clear();
|
|
75
|
+
scan();
|
|
42
76
|
}
|
|
43
77
|
},
|
|
44
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAcjD,mWAAmW;AACnW,MAAM,OAAO,wBAAwB;aACnB,qBAAgB,GAAG,KAAK,oBAAoB,CAAC,OAAO,EAAE,CAAC;IAEvE;QACE,eAAe,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,qRAAqR;IACrR,MAAM,CAAC,aAAa,CAAC,IAIpB;QACC,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;QACF,MAAM,SAAS,GAAwC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;YACpC,IAAI,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI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AAC,CAAC,SAAS,CAAC;YAC5E,CAAC;YACD,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE;gBACtB,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;oBACvC,OAAO,SAAS,CAAC;gBACnB,CAAC;gBACD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,CAAC,CAAC,oBAAoB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oBACpE,CAAC,CAAC,IAAI,CAAC;gBACT,OAAO,UAAU;oBACf,CAAC,CAAC,wBAAwB,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;oBACvF,CAAC,CAAC,OAAO,CAAC;YACd,CAAC;YACD,gGAAgG;YAChG,WAAW,EAAE,EAAE,CAAC,EAAE;gBAChB,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,eAAe,CAAC,KAAK,EAAE,CAAC;oBACxB,IAAI,EAAE,CAAC;gBACT,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-boot",
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-11",
|
|
4
4
|
"description": "Build-time artifact index generator for IGNIS applications: scans decorated classes with the TypeScript AST and emits one static registration file per package, so bun build --compile sees plain imports.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"artifact-index",
|