@animus-ui/next-plugin 0.1.1 → 0.1.3
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/README.md +83 -4
- package/dist/chunk-y_GBKt04.mjs +5 -0
- package/dist/extraction-session.d.ts +138 -0
- package/dist/extraction-session.d.ts.map +1 -0
- package/dist/index.cjs +766 -540
- package/dist/index.mjs +766 -539
- package/dist/loader-core-CbaYNhBu.cjs +71 -0
- package/dist/loader-core-D6Tm_b8F.mjs +66 -0
- package/dist/loader-core.d.ts +26 -0
- package/dist/loader-core.d.ts.map +1 -0
- package/dist/loader.cjs +12 -43
- package/dist/loader.d.ts +5 -9
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.mjs +12 -43
- package/dist/plugin.d.ts +24 -42
- package/dist/plugin.d.ts.map +1 -1
- package/dist/resolve-packages.d.ts +8 -0
- package/dist/resolve-packages.d.ts.map +1 -0
- package/dist/singleton-BKALu7Mk.mjs +108 -0
- package/dist/{singleton-CttvA4Rg.cjs → singleton-DH7yeWZa.cjs} +29 -60
- package/dist/singleton.d.ts +1 -8
- package/dist/singleton.d.ts.map +1 -1
- package/dist/timing.d.ts +7 -0
- package/dist/timing.d.ts.map +1 -0
- package/dist/turbopack-config.d.ts +55 -0
- package/dist/turbopack-config.d.ts.map +1 -0
- package/dist/turbopack-loader.cjs +90 -0
- package/dist/turbopack-loader.d.ts +16 -0
- package/dist/turbopack-loader.d.ts.map +1 -0
- package/dist/turbopack-loader.mjs +91 -0
- package/dist/turbopack-orchestrator.d.ts +31 -0
- package/dist/turbopack-orchestrator.d.ts.map +1 -0
- package/dist/types.d.ts +67 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/with-animus.d.ts +1 -1
- package/dist/with-animus.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/analyze-project-args.d.ts +0 -33
- package/dist/analyze-project-args.d.ts.map +0 -1
- package/dist/manifest-diagnostics.d.ts +0 -10
- package/dist/manifest-diagnostics.d.ts.map +0 -1
- package/dist/singleton-CmwFBCJ5.mjs +0 -136
package/dist/index.cjs
CHANGED
|
@@ -1,68 +1,161 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_singleton = require("./singleton-
|
|
2
|
+
const require_singleton = require("./singleton-DH7yeWZa.cjs");
|
|
3
|
+
let _animus_ui_extract_pipeline = require("@animus-ui/extract/pipeline");
|
|
3
4
|
let fs = require("fs");
|
|
4
5
|
let path = require("path");
|
|
5
6
|
let url = require("url");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
//#region src/resolve-packages.ts
|
|
8
|
+
/**
|
|
9
|
+
* Resolve external DS package specifiers to rootDir-relative entry paths.
|
|
10
|
+
* Node-generic (no webpack APIs): Pass 1 walks the consumer's workspaces for
|
|
11
|
+
* matching package names; Pass 2 falls back to `require.resolve`. Specifiers
|
|
12
|
+
* that resolve nowhere are simply omitted (spec: silent skip).
|
|
13
|
+
*/
|
|
14
|
+
function resolvePackagesByName(rootDir, names) {
|
|
15
|
+
if (names.length === 0) return {};
|
|
16
|
+
const nameSet = new Set(names);
|
|
17
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
18
|
+
const packageMap = {};
|
|
19
|
+
try {
|
|
20
|
+
const rootPkg = JSON.parse((0, fs.readFileSync)((0, path.join)(rootDir, "package.json"), "utf-8"));
|
|
21
|
+
const workspaces = Array.isArray(rootPkg.workspaces) ? rootPkg.workspaces : rootPkg.workspaces?.packages ?? [];
|
|
22
|
+
for (const ws of workspaces) {
|
|
23
|
+
const wsDir = (0, path.resolve)(rootDir, ws);
|
|
24
|
+
if (!(0, fs.existsSync)(wsDir)) continue;
|
|
25
|
+
try {
|
|
26
|
+
const pkg = JSON.parse((0, fs.readFileSync)((0, path.join)(wsDir, "package.json"), "utf-8"));
|
|
27
|
+
const name = pkg.name || "";
|
|
28
|
+
if (nameSet.has(name)) {
|
|
29
|
+
const entryPath = (0, path.resolve)(wsDir, pkg.main || pkg.module || "index.ts");
|
|
30
|
+
if ((0, fs.existsSync)(entryPath)) {
|
|
31
|
+
packageMap[name] = (0, path.relative)(rootDir, entryPath);
|
|
32
|
+
resolved.add(name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
} catch {}
|
|
38
|
+
for (const name of nameSet) {
|
|
39
|
+
if (resolved.has(name)) continue;
|
|
40
|
+
try {
|
|
41
|
+
packageMap[name] = (0, path.relative)(rootDir, require.resolve(name, { paths: [rootDir] }));
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
return packageMap;
|
|
32
45
|
}
|
|
33
46
|
//#endregion
|
|
34
|
-
//#region src/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
//#region src/timing.ts
|
|
48
|
+
/**
|
|
49
|
+
* Verbose build-timing waterfall: JS phases, analysis sub-phases, and the
|
|
50
|
+
* shared Rust phase table. `ANIMUS_TIMING_JSON=1` additionally dumps a
|
|
51
|
+
* machine-readable merged record.
|
|
52
|
+
*/
|
|
53
|
+
function logBuildTimings(bt, rustTiming, log, verbose) {
|
|
54
|
+
if (!verbose) return;
|
|
55
|
+
const pad = (label, width) => label + " ".repeat(Math.max(0, width - label.length));
|
|
56
|
+
for (const [key, label] of [
|
|
57
|
+
["systemLoad", "system-load"],
|
|
58
|
+
["fileDiscovery", "file-discovery"],
|
|
59
|
+
["fileRead", "file-read+hash"],
|
|
60
|
+
["packageResolve", "pkg-resolve"],
|
|
61
|
+
["analysis", "analysis"]
|
|
62
|
+
]) {
|
|
63
|
+
const ms = bt[key] ?? 0;
|
|
64
|
+
if (ms === 0 && !Object.hasOwn(bt, key)) continue;
|
|
65
|
+
log(` ${pad(label, 17)}${String(ms).padStart(5)}ms`);
|
|
66
|
+
if (key === "analysis") for (const [sk, sl] of [
|
|
67
|
+
["jsonSerialize", "json-serialize"],
|
|
68
|
+
["rustExtract", "rust-extract"],
|
|
69
|
+
["jsonParse", "json-parse"]
|
|
70
|
+
]) {
|
|
71
|
+
const sms = bt[sk] ?? 0;
|
|
72
|
+
log(` ${pad(sl, 15)}${String(sms).padStart(5)}ms`);
|
|
73
|
+
if (sk === "rustExtract" && rustTiming) for (const line of (0, _animus_ui_extract_pipeline.formatRustTimingWaterfall)(rustTiming, {
|
|
74
|
+
indent: " ",
|
|
75
|
+
labelWidth: 13
|
|
76
|
+
})) log(line);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
log(` total ${String(bt.total).padStart(5)}ms`);
|
|
80
|
+
if (process.env.ANIMUS_TIMING_JSON === "1") {
|
|
81
|
+
const merged = {};
|
|
82
|
+
for (const [k, v] of Object.entries(bt)) merged[`buildStart.${k}`] = v;
|
|
83
|
+
if (rustTiming) {
|
|
84
|
+
for (const [k, v] of Object.entries(rustTiming)) if (typeof v === "number") merged[`rust.${k}`] = v;
|
|
85
|
+
}
|
|
86
|
+
console.info(`[animus:timing] ${JSON.stringify(merged)}`);
|
|
39
87
|
}
|
|
40
88
|
}
|
|
41
89
|
//#endregion
|
|
42
|
-
//#region src/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
90
|
+
//#region src/extraction-session.ts
|
|
91
|
+
/**
|
|
92
|
+
* Module id the Rust emitter injects for the extracted stylesheet — also the
|
|
93
|
+
* exact resolve.alias key with-animus registers for it, which the adapter's
|
|
94
|
+
* alias harvesting must skip.
|
|
95
|
+
*/
|
|
96
|
+
const ANIMUS_CSS_MODULE_ID = ".animus/styles.css";
|
|
97
|
+
/** Default path fragments excluded from source discovery (full + watch). */
|
|
98
|
+
const DEFAULT_EXCLUDE = [
|
|
99
|
+
"node_modules",
|
|
100
|
+
"dist",
|
|
101
|
+
".test.",
|
|
102
|
+
".spec.",
|
|
103
|
+
".next",
|
|
104
|
+
".animus"
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* Bundler-agnostic extraction pipeline: system loading, source discovery
|
|
108
|
+
* and ingestion, external-package collection, analysis, stylesheet and
|
|
109
|
+
* system-props emission, and watch-cycle diffing.
|
|
110
|
+
*
|
|
111
|
+
* The webpack adapter (plugin.ts) owns only bundler wiring: hook
|
|
112
|
+
* registration, alias harvesting from the compiler config, in-memory asset
|
|
113
|
+
* replacement, and translating watch events into `handleWatchUpdate`
|
|
114
|
+
* change sets. Keeping this class free of webpack types is deliberate — a
|
|
115
|
+
* future Turbopack integration must drive the same session from outside
|
|
116
|
+
* the bundler (Turbopack has no compiler-hook surface), reusing everything
|
|
117
|
+
* here unchanged.
|
|
118
|
+
*
|
|
119
|
+
* Outputs are published through the package singleton (shared CSS,
|
|
120
|
+
* manifest, system props) and written to `.animus/` on disk.
|
|
121
|
+
*/
|
|
122
|
+
var ExtractionSession = class {
|
|
123
|
+
/** Set by the adapter before any pipeline run. */
|
|
46
124
|
rootDir = null;
|
|
47
|
-
|
|
48
|
-
groupRegistryJson = "";
|
|
49
|
-
themeJson = "";
|
|
50
|
-
variableMapJson = "";
|
|
51
|
-
variableCss = "";
|
|
52
|
-
contextualVarsJson = null;
|
|
53
|
-
selectorAliasesJson = null;
|
|
54
|
-
globalCss = "";
|
|
55
|
-
globalStyleBlocksJson = null;
|
|
56
|
-
keyframesBlocksJson = null;
|
|
125
|
+
/** Serialized path aliases, harvested by the adapter from bundler config. */
|
|
57
126
|
pathAliasesJson = null;
|
|
127
|
+
/** When set (Turbopack orchestration), every analysis also persists
|
|
128
|
+
* `.animus/analysis-inputs.json` so isolated loader workers can hydrate.
|
|
129
|
+
* Webpack mode leaves this off — its loader shares the process. */
|
|
130
|
+
persistAnalysisInputs = false;
|
|
131
|
+
/** Emitter identity override for the system-props module id. Webpack mode
|
|
132
|
+
* (null) injects the absolute `.animus/system-props.js` path, resolved by
|
|
133
|
+
* NormalModuleReplacement; Turbopack rejects absolute-path imports, so
|
|
134
|
+
* its driver sets the virtual id that `resolveAlias` maps to disk. */
|
|
135
|
+
systemPropsModuleId = null;
|
|
136
|
+
/** Absolute directory prefixes for external DS packages (loader allowlisting). */
|
|
137
|
+
externalPackageDirs = [];
|
|
138
|
+
/** External package specifier → absolute source entry path. */
|
|
139
|
+
externalSourceEntries = /* @__PURE__ */ new Map();
|
|
140
|
+
options;
|
|
141
|
+
staticCssJson;
|
|
142
|
+
system = null;
|
|
143
|
+
/** Full package-resolution map from the last full pipeline — replayed by
|
|
144
|
+
* incremental passes (sourceEntries alone omits dist-resolved packages). */
|
|
145
|
+
lastPackageMap = {};
|
|
58
146
|
fileCache = /* @__PURE__ */ new Map();
|
|
147
|
+
systemDependencyKeys = /* @__PURE__ */ new Set();
|
|
148
|
+
/** Loader-reported dependency paths for bundler watch registration. */
|
|
149
|
+
systemDependencyPaths = [];
|
|
150
|
+
systemDependencyHashes = /* @__PURE__ */ new Map();
|
|
59
151
|
lastCssHash = null;
|
|
60
152
|
lastSystemPropsHash = null;
|
|
61
|
-
|
|
62
|
-
|
|
153
|
+
lastManifestHash = null;
|
|
154
|
+
lastAnalysisInputsHash = null;
|
|
155
|
+
lcssTargets = null;
|
|
63
156
|
constructor(options) {
|
|
64
157
|
this.options = options;
|
|
65
|
-
|
|
158
|
+
this.staticCssJson = (0, _animus_ui_extract_pipeline.serializeStaticCss)(options.staticCss);
|
|
66
159
|
}
|
|
67
160
|
get verbose() {
|
|
68
161
|
return this.options.verbose === true || process.env.ANIMUS_DEBUG === "1" || process.env.ANIMUS_DEBUG === "true";
|
|
@@ -79,176 +172,82 @@ var AnimusWebpackPlugin = class {
|
|
|
79
172
|
elapsed(t) {
|
|
80
173
|
return this.verbose ? Math.round(performance.now() - t) : 0;
|
|
81
174
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const ms = bt[key] ?? 0;
|
|
92
|
-
if (ms === 0 && !Object.hasOwn(bt, key)) continue;
|
|
93
|
-
const pad = " ".repeat(Math.max(0, 17 - label.length));
|
|
94
|
-
this.log(` ${label}${pad}${String(ms).padStart(5)}ms`);
|
|
95
|
-
if (key === "analysis") for (const [sk, sl] of [
|
|
96
|
-
["jsonSerialize", "json-serialize"],
|
|
97
|
-
["rustExtract", "rust-extract"],
|
|
98
|
-
["jsonParse", "json-parse"]
|
|
99
|
-
]) {
|
|
100
|
-
const sms = bt[sk] ?? 0;
|
|
101
|
-
const spad = " ".repeat(Math.max(0, 15 - sl.length));
|
|
102
|
-
this.log(` ${sl}${spad}${String(sms).padStart(5)}ms`);
|
|
103
|
-
if (sk === "rustExtract" && rustTiming) for (const [rk, rl] of [
|
|
104
|
-
["parseAndWalk", "parse+walk"],
|
|
105
|
-
["importResolution", "imports"],
|
|
106
|
-
["extensionProvenance", "provenance"],
|
|
107
|
-
["topologicalSort", "topo-sort"],
|
|
108
|
-
["chainEvaluation", "chains"],
|
|
109
|
-
["jsxScanning", "jsx-scan"],
|
|
110
|
-
["systemPropAggregation", "sys-props"],
|
|
111
|
-
["usageLedger", "usage"],
|
|
112
|
-
["reconciliation", "reconcile"],
|
|
113
|
-
["cssGeneration", "css-gen"],
|
|
114
|
-
["manifestSerialization", "serialize"]
|
|
115
|
-
]) {
|
|
116
|
-
const rms = rustTiming[rk] ?? 0;
|
|
117
|
-
const rpad = " ".repeat(Math.max(0, 13 - rl.length));
|
|
118
|
-
const rextra = rk === "parseAndWalk" ? ` (${rustTiming.fileCount ?? 0} files, ${rustTiming.cacheHits ?? 0} cached)` : "";
|
|
119
|
-
this.log(` ${rl}${rpad}${String(rms).padStart(5)}ms${rextra}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
this.log(` total ${String(bt.total).padStart(5)}ms`);
|
|
124
|
-
if (process.env.ANIMUS_TIMING_JSON === "1") {
|
|
125
|
-
const merged = {};
|
|
126
|
-
for (const [k, v] of Object.entries(bt)) merged[`buildStart.${k}`] = v;
|
|
127
|
-
if (rustTiming) {
|
|
128
|
-
for (const [k, v] of Object.entries(rustTiming)) if (typeof v === "number") merged[`rust.${k}`] = v;
|
|
129
|
-
}
|
|
130
|
-
console.info(`[animus:timing] ${JSON.stringify(merged)}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
initialized = false;
|
|
134
|
-
/** Extract path aliases from webpack's resolve.alias config. */
|
|
135
|
-
extractAliases(compiler) {
|
|
136
|
-
const rootDir = compiler.context;
|
|
137
|
-
const rawAlias = compiler.options?.resolve?.alias;
|
|
138
|
-
if (!rawAlias || typeof rawAlias !== "object") return;
|
|
139
|
-
const entries = [];
|
|
140
|
-
for (const [key, value] of Object.entries(rawAlias)) {
|
|
141
|
-
const target = Array.isArray(value) ? value[0] : value;
|
|
142
|
-
if (typeof target !== "string") continue;
|
|
143
|
-
if (key.includes(".animus")) continue;
|
|
144
|
-
const replacement = target.startsWith(rootDir) ? target.slice(rootDir.length + 1) : target;
|
|
145
|
-
if (/\.\w+$/.test(replacement)) entries.push({
|
|
146
|
-
pattern: key,
|
|
147
|
-
replacement,
|
|
148
|
-
type: "exact"
|
|
149
|
-
});
|
|
150
|
-
else entries.push({
|
|
151
|
-
pattern: key.endsWith("/") ? key : key + "/",
|
|
152
|
-
replacement: replacement.endsWith("/") ? replacement : replacement + "/",
|
|
153
|
-
type: "prefix"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
entries.sort((a, b) => b.pattern.length - a.pattern.length);
|
|
157
|
-
if (entries.length > 0) this.pathAliasesJson = JSON.stringify({ aliases: entries });
|
|
158
|
-
}
|
|
159
|
-
apply(compiler) {
|
|
160
|
-
if (compiler.options?.name === "edge-server") return;
|
|
161
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
162
|
-
const stage = compiler.webpack?.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL ?? -2e3;
|
|
163
|
-
const RawSource = compiler.webpack?.sources.RawSource;
|
|
164
|
-
compilation.hooks.processAssets.tap({
|
|
165
|
-
name: PLUGIN_NAME,
|
|
166
|
-
stage
|
|
167
|
-
}, () => {
|
|
168
|
-
const css = require_singleton.getSharedCss();
|
|
169
|
-
if (!css || !RawSource) return;
|
|
170
|
-
const cssPath = (0, path.join)(this.rootDir || compiler.context, ".animus", "styles.css");
|
|
171
|
-
if (compilation.getAsset(cssPath)) {
|
|
172
|
-
compilation.updateAsset(cssPath, new RawSource(css));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const relPath = ".animus/styles.css";
|
|
176
|
-
if (compilation.getAsset(relPath)) compilation.updateAsset(relPath, new RawSource(css));
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
compiler.hooks.run.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
180
|
-
this.rootDir = _compiler.context;
|
|
181
|
-
this.extractAliases(_compiler);
|
|
182
|
-
const existing = require_singleton.getAnalysisPromise();
|
|
183
|
-
if (existing) {
|
|
184
|
-
await existing;
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const promise = this.runFullPipeline();
|
|
188
|
-
require_singleton.setAnalysisPromise(promise);
|
|
189
|
-
await promise;
|
|
190
|
-
});
|
|
191
|
-
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
192
|
-
this.rootDir = _compiler.context;
|
|
193
|
-
this.extractAliases(_compiler);
|
|
194
|
-
if (!this.initialized) {
|
|
195
|
-
const existing = require_singleton.getAnalysisPromise();
|
|
196
|
-
if (existing) {
|
|
197
|
-
await existing;
|
|
198
|
-
this.initialized = true;
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const promise = this.runFullPipeline();
|
|
202
|
-
require_singleton.setAnalysisPromise(promise);
|
|
203
|
-
await promise;
|
|
204
|
-
this.initialized = true;
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
await this.handleWatchUpdate();
|
|
208
|
-
});
|
|
175
|
+
/** Resolve the scan configuration from options — the single source of the
|
|
176
|
+
* exclude/extension policy shared by the full and incremental pipelines. */
|
|
177
|
+
resolveScanConfig() {
|
|
178
|
+
const extensionsSet = new Set(this.options.extensions ?? _animus_ui_extract_pipeline.DEFAULT_EXTENSIONS);
|
|
179
|
+
return {
|
|
180
|
+
excludePatterns: this.options.exclude ?? DEFAULT_EXCLUDE,
|
|
181
|
+
extensionsSet,
|
|
182
|
+
shouldHandleMdx: extensionsSet.has(".mdx")
|
|
183
|
+
};
|
|
209
184
|
}
|
|
210
|
-
|
|
211
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Incremental watch pass: geological reset when the system file changed,
|
|
187
|
+
* otherwise content-hash diffing restricted to the watcher's change sets
|
|
188
|
+
* (falling back to a full discovery walk when no sets are provided).
|
|
189
|
+
*/
|
|
190
|
+
async handleWatchUpdate(changes) {
|
|
191
|
+
if (!this.system) return;
|
|
212
192
|
const rootDir = this.rootDir;
|
|
213
|
-
const resolvedSystemPath = (0, path.resolve)(rootDir, this.options.system);
|
|
214
193
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
194
|
+
let systemHit;
|
|
195
|
+
if (!changes.modifiedFiles && !changes.removedFiles) for (const [dep, hash] of this.systemDependencyHashes) {
|
|
196
|
+
let current = "";
|
|
197
|
+
try {
|
|
198
|
+
current = (0, _animus_ui_extract_pipeline.contentHash)((0, fs.readFileSync)(dep, "utf-8"));
|
|
199
|
+
} catch {}
|
|
200
|
+
if (current !== hash) {
|
|
201
|
+
systemHit = dep;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else systemHit = [...changes.modifiedFiles ?? [], ...changes.removedFiles ?? []].find((path$2) => (0, _animus_ui_extract_pipeline.toWatchKeys)(path$2).some((key) => this.systemDependencyKeys.has(key)));
|
|
206
|
+
if (systemHit) {
|
|
207
|
+
this.log(`geological reset: system dependency changed (${(0, path.relative)(rootDir, systemHit)})`);
|
|
220
208
|
this.resetForHmr();
|
|
221
|
-
this.initialized = false;
|
|
222
209
|
const promise = this.runFullPipeline();
|
|
223
210
|
require_singleton.setAnalysisPromise(promise);
|
|
224
211
|
await promise;
|
|
225
|
-
this.initialized = true;
|
|
226
212
|
return;
|
|
227
213
|
}
|
|
228
|
-
} catch {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
".
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
214
|
+
} catch (err) {
|
|
215
|
+
this.warn(`HMR geological-reset check failed: ${String(err)}`);
|
|
216
|
+
}
|
|
217
|
+
const { excludePatterns, extensionsSet, shouldHandleMdx } = this.resolveScanConfig();
|
|
218
|
+
let removedAny = false;
|
|
219
|
+
if (changes.removedFiles) for (const removedPath of changes.removedFiles) {
|
|
220
|
+
const rel = (0, path.relative)(rootDir, removedPath);
|
|
221
|
+
if (this.fileCache.delete(rel) || this.fileCache.delete(rel + ".tsx")) removedAny = true;
|
|
222
|
+
}
|
|
223
|
+
let files;
|
|
224
|
+
if (changes.modifiedFiles) {
|
|
225
|
+
files = [];
|
|
226
|
+
for (const modifiedPath of changes.modifiedFiles) {
|
|
227
|
+
if (!extensionsSet.has((0, path.extname)(modifiedPath))) continue;
|
|
228
|
+
const rel = (0, path.relative)(rootDir, modifiedPath);
|
|
229
|
+
if (rel.startsWith("..")) continue;
|
|
230
|
+
if (excludePatterns.some((pattern) => modifiedPath.includes(pattern) || rel.includes(pattern))) continue;
|
|
231
|
+
files.push(modifiedPath);
|
|
232
|
+
}
|
|
233
|
+
} else files = (0, _animus_ui_extract_pipeline.discoverFiles)(rootDir, rootDir, excludePatterns, extensionsSet);
|
|
240
234
|
const changedPaths = [];
|
|
241
235
|
for (const filePath of files) {
|
|
242
236
|
let relPath = (0, path.relative)(rootDir, filePath);
|
|
243
|
-
let source
|
|
237
|
+
let source;
|
|
238
|
+
try {
|
|
239
|
+
source = (0, fs.readFileSync)(filePath, "utf-8");
|
|
240
|
+
} catch {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
244
243
|
if (shouldHandleMdx && (0, path.extname)(filePath) === ".mdx") {
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
source =
|
|
248
|
-
relPath = relPath
|
|
244
|
+
const processed = await this.preprocessMdxEntry(source, relPath, { warn: false });
|
|
245
|
+
if (!processed) continue;
|
|
246
|
+
source = processed.source;
|
|
247
|
+
relPath = processed.relPath;
|
|
249
248
|
}
|
|
250
249
|
const cached = this.fileCache.get(relPath);
|
|
251
|
-
const hash = (0,
|
|
250
|
+
const hash = (0, _animus_ui_extract_pipeline.contentHash)(source);
|
|
252
251
|
if (!cached || cached.hash !== hash) {
|
|
253
252
|
changedPaths.push(relPath);
|
|
254
253
|
this.fileCache.set(relPath, {
|
|
@@ -257,39 +256,74 @@ var AnimusWebpackPlugin = class {
|
|
|
257
256
|
});
|
|
258
257
|
}
|
|
259
258
|
}
|
|
260
|
-
if (changedPaths.length > 0) {
|
|
261
|
-
const fileEntries = this.buildFileEntriesFromCache(
|
|
259
|
+
if (changedPaths.length > 0 || removedAny) {
|
|
260
|
+
const fileEntries = this.buildFileEntriesFromCache();
|
|
262
261
|
require_singleton.resetAnalysisPromise();
|
|
263
262
|
const promise = this.runIncrementalPipeline(fileEntries);
|
|
264
263
|
require_singleton.setAnalysisPromise(promise);
|
|
265
264
|
await promise;
|
|
266
265
|
}
|
|
267
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Preprocess one `.mdx` entry into scanner-consumable tsx. Returns the
|
|
269
|
+
* rewritten source plus the `relPath + '.tsx'` path on success, or null
|
|
270
|
+
* when the file must be skipped.
|
|
271
|
+
*
|
|
272
|
+
* `warn: false` (incremental watch pass) skips silently — the full
|
|
273
|
+
* pipeline already surfaced the warning. `warn: true` (full pipeline)
|
|
274
|
+
* warns ONCE for a missing @mdx-js/mdx dependency via the shared
|
|
275
|
+
* `missingDepFlag` holder, and every time for a preprocessing error.
|
|
276
|
+
*/
|
|
277
|
+
async preprocessMdxEntry(source, relPath, opts) {
|
|
278
|
+
const result = await (0, _animus_ui_extract_pipeline.preprocessMdx)(source, relPath);
|
|
279
|
+
if (result.kind === "missing-dep") {
|
|
280
|
+
if (opts.warn && opts.missingDepFlag && !opts.missingDepFlag.warned) {
|
|
281
|
+
console.warn("[animus] ⚠ .mdx in extensions but @mdx-js/mdx not installed; MDX files skipped");
|
|
282
|
+
opts.missingDepFlag.warned = true;
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
if (result.kind === "error") {
|
|
287
|
+
if (opts.warn) console.warn(`[animus] ⚠ MDX preprocessing failed for ${relPath}: ${result.error}`);
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
source: result.source,
|
|
292
|
+
relPath: relPath + ".tsx"
|
|
293
|
+
};
|
|
294
|
+
}
|
|
268
295
|
async runFullPipeline() {
|
|
269
296
|
const pipelineStart = this.now();
|
|
270
297
|
const bt = {};
|
|
271
|
-
|
|
272
|
-
const { clearAnalysisCache } = require_singleton.engineApi();
|
|
273
|
-
clearAnalysisCache();
|
|
274
|
-
} catch {}
|
|
298
|
+
(0, _animus_ui_extract_pipeline.clearEngineCache)(require_singleton.engineApi);
|
|
275
299
|
const rootDir = this.rootDir;
|
|
276
300
|
const resolvedSystemPath = (0, path.resolve)(rootDir, this.options.system);
|
|
277
301
|
let t = this.now();
|
|
278
|
-
this.
|
|
302
|
+
this.system = (0, _animus_ui_extract_pipeline.loadSystemConfig)(require_singleton.engineApi, {
|
|
303
|
+
systemPath: resolvedSystemPath,
|
|
304
|
+
rootDir,
|
|
305
|
+
prefix: this.options.prefix
|
|
306
|
+
});
|
|
307
|
+
{
|
|
308
|
+
const deps = this.system.dependencies ?? [];
|
|
309
|
+
const keys = /* @__PURE__ */ new Set();
|
|
310
|
+
for (const key of (0, _animus_ui_extract_pipeline.toWatchKeys)(resolvedSystemPath)) keys.add(key);
|
|
311
|
+
for (const dep of deps) for (const key of (0, _animus_ui_extract_pipeline.toWatchKeys)(dep)) keys.add(key);
|
|
312
|
+
this.systemDependencyKeys = keys;
|
|
313
|
+
this.systemDependencyPaths = deps;
|
|
314
|
+
const hashes = /* @__PURE__ */ new Map();
|
|
315
|
+
for (const dep of deps.length > 0 ? deps : [resolvedSystemPath]) try {
|
|
316
|
+
hashes.set(dep, (0, _animus_ui_extract_pipeline.contentHash)((0, fs.readFileSync)(dep, "utf-8")));
|
|
317
|
+
} catch {
|
|
318
|
+
hashes.set(dep, "");
|
|
319
|
+
}
|
|
320
|
+
this.systemDependencyHashes = hashes;
|
|
321
|
+
}
|
|
279
322
|
bt.systemLoad = this.elapsed(t);
|
|
280
323
|
t = this.now();
|
|
281
|
-
const excludePatterns = this.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
".test.",
|
|
285
|
-
".spec.",
|
|
286
|
-
".next",
|
|
287
|
-
".animus"
|
|
288
|
-
];
|
|
289
|
-
const extensionsSet = new Set(this.options.extensions ?? _animus_ui_extract_pipeline.DEFAULT_EXTENSIONS);
|
|
290
|
-
const shouldHandleMdx = extensionsSet.has(".mdx");
|
|
291
|
-
let mdxMissingDepWarned = false;
|
|
292
|
-
const files = this.discoverFiles(rootDir, rootDir, excludePatterns, extensionsSet);
|
|
324
|
+
const { excludePatterns, extensionsSet, shouldHandleMdx } = this.resolveScanConfig();
|
|
325
|
+
const missingDepFlag = { warned: false };
|
|
326
|
+
const files = (0, _animus_ui_extract_pipeline.discoverFiles)(rootDir, rootDir, excludePatterns, extensionsSet);
|
|
293
327
|
bt.fileDiscovery = this.elapsed(t);
|
|
294
328
|
t = this.now();
|
|
295
329
|
const fileEntries = [];
|
|
@@ -297,22 +331,15 @@ var AnimusWebpackPlugin = class {
|
|
|
297
331
|
let source = (0, fs.readFileSync)(filePath, "utf-8");
|
|
298
332
|
let relPath = (0, path.relative)(rootDir, filePath);
|
|
299
333
|
if (shouldHandleMdx && (0, path.extname)(filePath) === ".mdx") {
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
if (result.kind === "error") {
|
|
309
|
-
console.warn(`[animus] ⚠ MDX preprocessing failed for ${relPath}: ${result.error}`);
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
source = result.source;
|
|
313
|
-
relPath = relPath + ".tsx";
|
|
334
|
+
const processed = await this.preprocessMdxEntry(source, relPath, {
|
|
335
|
+
warn: true,
|
|
336
|
+
missingDepFlag
|
|
337
|
+
});
|
|
338
|
+
if (!processed) continue;
|
|
339
|
+
source = processed.source;
|
|
340
|
+
relPath = processed.relPath;
|
|
314
341
|
}
|
|
315
|
-
const hash = (0,
|
|
342
|
+
const hash = (0, _animus_ui_extract_pipeline.contentHash)(source);
|
|
316
343
|
this.fileCache.set(relPath, {
|
|
317
344
|
hash,
|
|
318
345
|
source
|
|
@@ -327,216 +354,51 @@ var AnimusWebpackPlugin = class {
|
|
|
327
354
|
bt.fileCount = fileEntries.length;
|
|
328
355
|
t = this.now();
|
|
329
356
|
const packageNames = (0, _animus_ui_extract_pipeline.extractSystemFilePackages)(resolvedSystemPath);
|
|
330
|
-
const
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
this.externalSourceEntries.set(specifier, srcEntry);
|
|
349
|
-
}
|
|
350
|
-
const pkgFiles = this.discoverFiles(srcDir, rootDir, excludePatternsForPkgs, extensionsSet);
|
|
351
|
-
for (const pkgFile of pkgFiles) {
|
|
352
|
-
let pkgRelPath = (0, path.relative)(rootDir, pkgFile);
|
|
353
|
-
if (!fileEntries.some((e) => e.path === pkgRelPath)) try {
|
|
354
|
-
let pkgSource = (0, fs.readFileSync)(pkgFile, "utf-8");
|
|
355
|
-
if (shouldHandleMdx && (0, path.extname)(pkgFile) === ".mdx") {
|
|
356
|
-
const result = await (0, _animus_ui_extract_pipeline.preprocessMdx)(pkgSource, pkgRelPath);
|
|
357
|
-
if (result.kind === "missing-dep") {
|
|
358
|
-
if (!mdxMissingDepWarned) {
|
|
359
|
-
console.warn("[animus] ⚠ .mdx in extensions but @mdx-js/mdx not installed; MDX files skipped");
|
|
360
|
-
mdxMissingDepWarned = true;
|
|
361
|
-
}
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
if (result.kind === "error") {
|
|
365
|
-
console.warn(`[animus] ⚠ MDX preprocessing failed for ${pkgRelPath}: ${result.error}`);
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
pkgSource = result.source;
|
|
369
|
-
pkgRelPath = pkgRelPath + ".tsx";
|
|
370
|
-
}
|
|
371
|
-
const pkgHash = (0, crypto.createHash)("md5").update(pkgSource).digest("hex");
|
|
372
|
-
this.fileCache.set(pkgRelPath, {
|
|
373
|
-
hash: pkgHash,
|
|
374
|
-
source: pkgSource
|
|
375
|
-
});
|
|
376
|
-
fileEntries.push({
|
|
377
|
-
path: pkgRelPath,
|
|
378
|
-
source: pkgSource,
|
|
379
|
-
hash: pkgHash
|
|
380
|
-
});
|
|
381
|
-
} catch {}
|
|
382
|
-
}
|
|
383
|
-
} else collectedPkgDirs.push((0, path.dirname)(absEntry));
|
|
384
|
-
}
|
|
385
|
-
this.externalPackageDirs = collectedPkgDirs;
|
|
386
|
-
require_singleton.setSharedExternalDirs(collectedPkgDirs);
|
|
387
|
-
require_singleton.setSharedExternalEntries(this.externalSourceEntries);
|
|
388
|
-
bt.packageResolve = this.elapsed(t);
|
|
389
|
-
const { analyzeProject } = require_singleton.engineApi();
|
|
390
|
-
const animusDirPath = (0, path.join)(rootDir, ".animus");
|
|
391
|
-
const emitterConfig = JSON.stringify({
|
|
392
|
-
runtime_import: "@animus-ui/system/runtime",
|
|
393
|
-
css_module_id: ".animus/styles.css",
|
|
394
|
-
system_props_module_id: (0, path.join)(animusDirPath, "system-props.js")
|
|
395
|
-
});
|
|
396
|
-
t = this.now();
|
|
397
|
-
const fileEntriesJson = JSON.stringify(fileEntries);
|
|
398
|
-
const packageMapJson = JSON.stringify(packageMap);
|
|
399
|
-
bt.jsonSerialize = this.elapsed(t);
|
|
400
|
-
t = this.now();
|
|
401
|
-
const manifestJson = analyzeProject(...buildProductionAnalyzeProjectArgs({
|
|
402
|
-
filesJson: fileEntriesJson,
|
|
403
|
-
scalesJson: this.themeJson,
|
|
404
|
-
variableMapJson: this.variableMapJson,
|
|
405
|
-
contextualVarsJson: this.contextualVarsJson || null,
|
|
406
|
-
propConfigJson: this.configJson,
|
|
407
|
-
groupRegistryJson: this.groupRegistryJson,
|
|
408
|
-
packageResolutionJson: packageMapJson,
|
|
409
|
-
emitterConfigJson: emitterConfig,
|
|
410
|
-
selectorAliasesJson: this.selectorAliasesJson,
|
|
411
|
-
globalStyleBlocksJson: this.globalStyleBlocksJson,
|
|
412
|
-
pathAliasesJson: this.pathAliasesJson,
|
|
413
|
-
keyframesJson: this.keyframesBlocksJson
|
|
414
|
-
}));
|
|
415
|
-
bt.rustExtract = this.elapsed(t);
|
|
416
|
-
t = this.now();
|
|
417
|
-
const manifest = JSON.parse(manifestJson);
|
|
418
|
-
surfaceManifestDiagnostics(manifest, (message) => this.warn(message));
|
|
419
|
-
bt.jsonParse = this.elapsed(t);
|
|
420
|
-
bt.analysis = (bt.jsonSerialize ?? 0) + (bt.rustExtract ?? 0) + (bt.jsonParse ?? 0);
|
|
421
|
-
if (manifest?.report) this.log(`Extracted ${manifest.report.components_extracted ?? "?"}/${manifest.report.components_total ?? "?"} components (${bt.analysis}ms)`);
|
|
422
|
-
this.globalCss = manifest?.sheets?.global || "";
|
|
423
|
-
let componentCss = manifest?.css || "";
|
|
424
|
-
componentCss = (0, _animus_ui_extract_pipeline.applyUnitFallback)(componentCss);
|
|
425
|
-
const { declaration, variables, body } = (0, _animus_ui_extract_pipeline.assembleStylesheet)({
|
|
426
|
-
layers: this.options.layers,
|
|
427
|
-
variableCss: this.variableCss,
|
|
428
|
-
globalCss: this.globalCss,
|
|
429
|
-
componentCss,
|
|
430
|
-
split: true
|
|
357
|
+
const preResolved = resolvePackagesByName(rootDir, packageNames);
|
|
358
|
+
const collected = await (0, _animus_ui_extract_pipeline.collectExternalPackageSources)({
|
|
359
|
+
specifiers: packageNames,
|
|
360
|
+
resolveSpecifier: (name) => preResolved[name] ? (0, path.resolve)(rootDir, preResolved[name]) : null,
|
|
361
|
+
rootDir,
|
|
362
|
+
extensionsSet,
|
|
363
|
+
hasEntry: (relPath) => fileEntries.some((e) => e.path === relPath),
|
|
364
|
+
preprocessFile: async (source, relPath, absPath) => {
|
|
365
|
+
if (shouldHandleMdx && (0, path.extname)(absPath) === ".mdx") return this.preprocessMdxEntry(source, relPath, {
|
|
366
|
+
warn: true,
|
|
367
|
+
missingDepFlag
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
source,
|
|
371
|
+
relPath
|
|
372
|
+
};
|
|
373
|
+
},
|
|
374
|
+
onUnreadable: (relPath, err) => this.warn(`skipped unreadable package file ${relPath}: ${String(err)}`)
|
|
431
375
|
});
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
require_singleton.setSharedCss(fullCss);
|
|
438
|
-
const cssHash = (0, crypto.createHash)("md5").update(fullCss).digest("hex");
|
|
439
|
-
if (cssHash !== this.lastCssHash) {
|
|
440
|
-
const animusDir = (0, path.join)(rootDir, ".animus");
|
|
441
|
-
if (!(0, fs.existsSync)(animusDir)) (0, fs.mkdirSync)(animusDir, { recursive: true });
|
|
442
|
-
(0, fs.writeFileSync)((0, path.join)(animusDir, "styles.css"), fullCss);
|
|
443
|
-
this.lastCssHash = cssHash;
|
|
376
|
+
for (const record of collected.outcomes) if (record.outcome === "empty") this.warn(`include '${record.specifier}' resolved but discovered no component sources`);
|
|
377
|
+
const unresolvableMessage = (0, _animus_ui_extract_pipeline.unresolvableIncludesMessage)(collected.outcomes);
|
|
378
|
+
if (unresolvableMessage !== null) {
|
|
379
|
+
if (this.options.strict) throw new Error(unresolvableMessage);
|
|
380
|
+
this.warn(unresolvableMessage);
|
|
444
381
|
}
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
for (const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
(0, fs.writeFileSync)((0, path.join)(animusDir, "system-props.js"), systemPropsContent);
|
|
460
|
-
require_singleton.setManifestJson(manifestJson);
|
|
461
|
-
bt.total = this.elapsed(pipelineStart);
|
|
462
|
-
this.logBuildTimings(bt, manifest?.timing);
|
|
463
|
-
}
|
|
464
|
-
loadSystem(rootDir, systemPath) {
|
|
465
|
-
const { loadSystemModule } = require_singleton.engineApi();
|
|
466
|
-
const config = loadSystemModule(systemPath, rootDir);
|
|
467
|
-
this.configJson = config.propConfig;
|
|
468
|
-
this.groupRegistryJson = config.groupRegistry;
|
|
469
|
-
this.themeJson = config.scalesJson;
|
|
470
|
-
this.variableMapJson = config.variableMapJson;
|
|
471
|
-
this.variableCss = config.variableCss;
|
|
472
|
-
this.contextualVarsJson = config.contextualVarsJson;
|
|
473
|
-
this.selectorAliasesJson = config.selectorAliases || null;
|
|
474
|
-
if (this.options.prefix) {
|
|
475
|
-
const prefixed = (0, _animus_ui_extract_pipeline.applyPrefix)(this.options.prefix, this.variableMapJson, this.variableCss, this.themeJson, this.contextualVarsJson || void 0);
|
|
476
|
-
this.variableMapJson = prefixed.variableMapJson;
|
|
477
|
-
this.variableCss = prefixed.variableCss;
|
|
478
|
-
if (prefixed.themeJson) this.themeJson = prefixed.themeJson;
|
|
479
|
-
if (prefixed.contextualVarsJson) this.contextualVarsJson = prefixed.contextualVarsJson;
|
|
480
|
-
}
|
|
481
|
-
this.globalStyleBlocksJson = config.globalStyleBlocks || null;
|
|
482
|
-
this.keyframesBlocksJson = config.keyframesBlocks || null;
|
|
483
|
-
}
|
|
484
|
-
discoverFiles(dir, rootDir, excludePatterns, extensionsSet) {
|
|
485
|
-
const results = [];
|
|
486
|
-
const walk = (currentDir) => {
|
|
487
|
-
let entries;
|
|
488
|
-
try {
|
|
489
|
-
entries = (0, fs.readdirSync)(currentDir);
|
|
490
|
-
} catch {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
for (const entry of entries) {
|
|
494
|
-
const fullPath = (0, path.join)(currentDir, entry);
|
|
495
|
-
const relPath = (0, path.relative)(rootDir, fullPath);
|
|
496
|
-
if (excludePatterns.some((p) => relPath.includes(p))) continue;
|
|
497
|
-
let stat;
|
|
498
|
-
try {
|
|
499
|
-
stat = (0, fs.statSync)(fullPath);
|
|
500
|
-
} catch {
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
if (stat.isDirectory()) walk(fullPath);
|
|
504
|
-
else if (extensionsSet.has((0, path.extname)(entry))) results.push(fullPath);
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
walk(dir);
|
|
508
|
-
return results;
|
|
509
|
-
}
|
|
510
|
-
resolvePackagesByName(rootDir, names) {
|
|
511
|
-
if (names.length === 0) return {};
|
|
512
|
-
const nameSet = new Set(names);
|
|
513
|
-
const resolved = /* @__PURE__ */ new Set();
|
|
514
|
-
const packageMap = {};
|
|
515
|
-
try {
|
|
516
|
-
const workspaces = JSON.parse((0, fs.readFileSync)((0, path.join)(rootDir, "package.json"), "utf-8")).workspaces || [];
|
|
517
|
-
for (const ws of workspaces) {
|
|
518
|
-
const wsDir = (0, path.resolve)(rootDir, ws);
|
|
519
|
-
if (!(0, fs.existsSync)(wsDir)) continue;
|
|
520
|
-
try {
|
|
521
|
-
const pkg = JSON.parse((0, fs.readFileSync)((0, path.join)(wsDir, "package.json"), "utf-8"));
|
|
522
|
-
const name = pkg.name || "";
|
|
523
|
-
if (nameSet.has(name)) {
|
|
524
|
-
const entryPath = (0, path.resolve)(wsDir, pkg.main || pkg.module || "index.ts");
|
|
525
|
-
if ((0, fs.existsSync)(entryPath)) {
|
|
526
|
-
packageMap[name] = (0, path.relative)(rootDir, entryPath);
|
|
527
|
-
resolved.add(name);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
} catch {}
|
|
531
|
-
}
|
|
532
|
-
} catch {}
|
|
533
|
-
for (const name of nameSet) {
|
|
534
|
-
if (resolved.has(name)) continue;
|
|
535
|
-
try {
|
|
536
|
-
packageMap[name] = (0, path.relative)(rootDir, require.resolve(name, { paths: [rootDir] }));
|
|
537
|
-
} catch {}
|
|
382
|
+
const packageMap = collected.packageMap;
|
|
383
|
+
this.lastPackageMap = packageMap;
|
|
384
|
+
this.externalSourceEntries = collected.sourceEntries;
|
|
385
|
+
for (const entry of collected.entries) {
|
|
386
|
+
const hash = (0, _animus_ui_extract_pipeline.contentHash)(entry.source);
|
|
387
|
+
this.fileCache.set(entry.path, {
|
|
388
|
+
hash,
|
|
389
|
+
source: entry.source
|
|
390
|
+
});
|
|
391
|
+
fileEntries.push({
|
|
392
|
+
path: entry.path,
|
|
393
|
+
source: entry.source,
|
|
394
|
+
hash
|
|
395
|
+
});
|
|
538
396
|
}
|
|
539
|
-
|
|
397
|
+
this.externalPackageDirs = collected.packageDirs;
|
|
398
|
+
require_singleton.setSharedExternalDirs(collected.packageDirs);
|
|
399
|
+
require_singleton.setSharedExternalEntries(collected.sourceEntries);
|
|
400
|
+
bt.packageResolve = this.elapsed(t);
|
|
401
|
+
await this.analyzeAndEmit(fileEntries, packageMap, false, bt, pipelineStart);
|
|
540
402
|
}
|
|
541
403
|
/**
|
|
542
404
|
* Reset analysis state for HMR geological reset.
|
|
@@ -545,22 +407,21 @@ var AnimusWebpackPlugin = class {
|
|
|
545
407
|
require_singleton.resetAnalysisPromise();
|
|
546
408
|
this.lastCssHash = null;
|
|
547
409
|
this.lastSystemPropsHash = null;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
} catch {}
|
|
410
|
+
this.lastManifestHash = null;
|
|
411
|
+
this.lastAnalysisInputsHash = null;
|
|
412
|
+
(0, _animus_ui_extract_pipeline.clearEngineCache)(require_singleton.engineApi);
|
|
552
413
|
}
|
|
553
414
|
/**
|
|
554
|
-
* Build
|
|
555
|
-
*
|
|
415
|
+
* Build file entries from cache: every cached file rides with full source.
|
|
416
|
+
* The v2 engine has NO Rust-side cache (extract-v2-spine DEF-7: uncached
|
|
417
|
+
* re-analysis beats a cache-hit path), so it must always receive full sources
|
|
418
|
+
* (openspec: retire-extract-v1 removed the v1 empty-source cache contract).
|
|
556
419
|
*/
|
|
557
|
-
buildFileEntriesFromCache(
|
|
558
|
-
const changedSet = new Set(changedPaths);
|
|
559
|
-
const fullSources = require_singleton.getSharedEngine() === "v2";
|
|
420
|
+
buildFileEntriesFromCache() {
|
|
560
421
|
const entries = [];
|
|
561
|
-
for (const [path$
|
|
562
|
-
path: path$
|
|
563
|
-
source
|
|
422
|
+
for (const [path$3, { hash, source }] of this.fileCache) entries.push({
|
|
423
|
+
path: path$3,
|
|
424
|
+
source,
|
|
564
425
|
hash
|
|
565
426
|
});
|
|
566
427
|
return entries;
|
|
@@ -570,88 +431,238 @@ var AnimusWebpackPlugin = class {
|
|
|
570
431
|
* Reuses system config from the last full pipeline run.
|
|
571
432
|
*/
|
|
572
433
|
async runIncrementalPipeline(fileEntries) {
|
|
573
|
-
const rootDir = this.rootDir;
|
|
574
434
|
const bt = {};
|
|
575
435
|
const pipelineStart = this.now();
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
436
|
+
await this.analyzeAndEmit(fileEntries, this.lastPackageMap, true, bt, pipelineStart);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Shared analysis + emit core for both pipelines — the single call site
|
|
440
|
+
* that routes every manifest through the shared `runProjectAnalysis`,
|
|
441
|
+
* reachable from both runFullPipeline (production) and
|
|
442
|
+
* runIncrementalPipeline (HMR).
|
|
443
|
+
*
|
|
444
|
+
* Owns diagnostic surfacing, CSS assembly + styles.css write guard,
|
|
445
|
+
* system-props module emit, and the timing log. The `devMode` flag is the
|
|
446
|
+
* ONLY behavioral fork:
|
|
447
|
+
*
|
|
448
|
+
* - `false` (production): computes bt.analysis + logs the extraction
|
|
449
|
+
* report, and writes system-props.js UNCONDITIONALLY (no
|
|
450
|
+
* lastSystemPropsHash guard).
|
|
451
|
+
* - `true` (HMR): skips the report log, and guards the system-props.js
|
|
452
|
+
* write by lastSystemPropsHash.
|
|
453
|
+
*
|
|
454
|
+
* The styles.css write guard (lastCssHash) is identical on both paths.
|
|
455
|
+
*/
|
|
456
|
+
async analyzeAndEmit(fileEntries, packageMap, devMode, bt, pipelineStart) {
|
|
457
|
+
const system = this.system;
|
|
458
|
+
const result = (0, _animus_ui_extract_pipeline.runProjectAnalysis)(require_singleton.engineApi, {
|
|
459
|
+
fileEntries,
|
|
460
|
+
packageMap,
|
|
461
|
+
system,
|
|
462
|
+
emitter: {
|
|
463
|
+
runtimeImport: "@animus-ui/system/runtime",
|
|
464
|
+
cssModuleId: ANIMUS_CSS_MODULE_ID,
|
|
465
|
+
systemPropsModuleId: this.systemPropsModuleId ?? (0, path.join)(this.rootDir, ".animus", "system-props.js")
|
|
466
|
+
},
|
|
599
467
|
pathAliasesJson: this.pathAliasesJson,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
bt.jsonParse =
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
468
|
+
staticCssJson: this.staticCssJson,
|
|
469
|
+
devMode,
|
|
470
|
+
warn: (message) => this.warn(message)
|
|
471
|
+
});
|
|
472
|
+
bt.jsonSerialize = result.timings.serializeMs;
|
|
473
|
+
bt.rustExtract = result.timings.extractMs;
|
|
474
|
+
bt.jsonParse = result.timings.parseMs;
|
|
475
|
+
const manifest = result.manifest;
|
|
476
|
+
if (!devMode) {
|
|
477
|
+
bt.analysis = (bt.jsonSerialize ?? 0) + (bt.rustExtract ?? 0) + (bt.jsonParse ?? 0);
|
|
478
|
+
if (manifest?.report) this.log(`Extracted ${manifest.report.components_extracted ?? "?"}/${manifest.report.components_total ?? "?"} components (${bt.analysis}ms)`);
|
|
479
|
+
}
|
|
480
|
+
const { declaration, variables, body } = (0, _animus_ui_extract_pipeline.assembleStylesheet)({
|
|
611
481
|
layers: this.options.layers,
|
|
612
|
-
variableCss:
|
|
613
|
-
globalCss:
|
|
614
|
-
componentCss,
|
|
482
|
+
variableCss: system.variableCss,
|
|
483
|
+
globalCss: result.globalCss,
|
|
484
|
+
componentCss: result.componentCss,
|
|
615
485
|
split: true
|
|
616
486
|
});
|
|
487
|
+
if (this.lcssTargets === null) this.lcssTargets = (0, _animus_ui_extract_pipeline.resolveLightningTargets)(this.options.targets, this.rootDir);
|
|
617
488
|
const fullCss = [
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
489
|
+
declaration,
|
|
490
|
+
variables,
|
|
491
|
+
(0, _animus_ui_extract_pipeline.postProcessCss)(body, {
|
|
492
|
+
minify: this.options.minify ?? process.env.NODE_ENV === "production",
|
|
493
|
+
targets: this.lcssTargets,
|
|
494
|
+
warnFn: (msg) => this.warn(msg)
|
|
495
|
+
})
|
|
621
496
|
].filter(Boolean).join("\n");
|
|
622
497
|
require_singleton.setSharedCss(fullCss);
|
|
623
|
-
const cssHash = (0,
|
|
498
|
+
const cssHash = (0, _animus_ui_extract_pipeline.contentHash)(fullCss);
|
|
624
499
|
if (cssHash !== this.lastCssHash) {
|
|
625
|
-
|
|
626
|
-
if (!(0, fs.existsSync)(animusDir)) (0, fs.mkdirSync)(animusDir, { recursive: true });
|
|
627
|
-
(0, fs.writeFileSync)((0, path.join)(animusDir, "styles.css"), fullCss);
|
|
500
|
+
this.writeAnimusFile("styles.css", fullCss);
|
|
628
501
|
this.lastCssHash = cssHash;
|
|
629
502
|
}
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
slotClass: meta.slot_class,
|
|
636
|
-
...meta.transform_name ? { transformName: meta.transform_name } : {},
|
|
637
|
-
...meta.scale_values && Object.keys(meta.scale_values).length > 0 ? { scaleValues: meta.scale_values } : {}
|
|
638
|
-
};
|
|
639
|
-
const systemPropsContent = `export const systemPropMap = ${systemPropMap};\nexport const systemPropGroups = ${this.groupRegistryJson};\nexport const dynamicPropConfig = ${JSON.stringify(dynamicPropConfig)};\nexport const transforms = {};\n`;
|
|
503
|
+
const systemPropsContent = (0, _animus_ui_extract_pipeline.buildSystemPropsModule)({
|
|
504
|
+
systemPropMapJson: JSON.stringify(manifest?.system_prop_map ?? {}),
|
|
505
|
+
groupRegistryJson: system.groupRegistryJson,
|
|
506
|
+
dynamicProps: manifest?.dynamic_props ?? {}
|
|
507
|
+
});
|
|
640
508
|
require_singleton.setSharedSystemProps(systemPropsContent);
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
509
|
+
if (devMode) {
|
|
510
|
+
const systemPropsHash = (0, _animus_ui_extract_pipeline.contentHash)(systemPropsContent);
|
|
511
|
+
if (systemPropsHash !== this.lastSystemPropsHash) {
|
|
512
|
+
this.writeAnimusFile("system-props.js", systemPropsContent);
|
|
513
|
+
this.lastSystemPropsHash = systemPropsHash;
|
|
514
|
+
}
|
|
515
|
+
} else this.writeAnimusFile("system-props.js", systemPropsContent);
|
|
516
|
+
require_singleton.setManifestJson(result.manifestJson);
|
|
517
|
+
const manifestHash = (0, _animus_ui_extract_pipeline.contentHash)(result.manifestJson);
|
|
518
|
+
if (this.lastManifestHash === null) this.lastManifestHash = this.diskArtifactHash("manifest.json");
|
|
519
|
+
if (manifestHash !== this.lastManifestHash) {
|
|
520
|
+
this.writeAnimusFile("manifest.json", result.manifestJson);
|
|
521
|
+
this.lastManifestHash = manifestHash;
|
|
522
|
+
}
|
|
523
|
+
if (this.persistAnalysisInputs) {
|
|
524
|
+
const inputsJson = JSON.stringify(result.inputs);
|
|
525
|
+
const inputsHash = (0, _animus_ui_extract_pipeline.contentHash)(inputsJson);
|
|
526
|
+
if (this.lastAnalysisInputsHash === null) this.lastAnalysisInputsHash = this.diskArtifactHash("analysis-inputs.json");
|
|
527
|
+
if (inputsHash !== this.lastAnalysisInputsHash) {
|
|
528
|
+
this.writeAnimusFile("analysis-inputs.json", inputsJson);
|
|
529
|
+
this.lastAnalysisInputsHash = inputsHash;
|
|
530
|
+
}
|
|
647
531
|
}
|
|
648
|
-
require_singleton.setManifestJson(manifestJson);
|
|
649
532
|
bt.total = this.elapsed(pipelineStart);
|
|
650
|
-
|
|
533
|
+
logBuildTimings(bt, manifest?.timing, (msg) => this.log(msg), this.verbose);
|
|
534
|
+
}
|
|
535
|
+
/** Content hash of an existing `.animus/` artifact, or null when absent or
|
|
536
|
+
* unreadable. Seeds a null write guard so a FRESH session never rewrites a
|
|
537
|
+
* byte-identical artifact (spec: next-turbopack-integration — a rewrite
|
|
538
|
+
* changes mtime/inode and needlessly re-keys Turbopack loader-worker
|
|
539
|
+
* hydration). */
|
|
540
|
+
diskArtifactHash(name) {
|
|
541
|
+
try {
|
|
542
|
+
return (0, _animus_ui_extract_pipeline.contentHash)((0, fs.readFileSync)((0, path.join)(this.rootDir, ".animus", name), "utf-8"));
|
|
543
|
+
} catch {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/** Ensure `.animus/` exists and write one generated artifact into it.
|
|
548
|
+
* Write-then-rename so cross-process readers (Turbopack loader workers)
|
|
549
|
+
* can never observe a torn half-written file. The tmp name carries the
|
|
550
|
+
* pid — Next dev evaluates the config in more than one process, and two
|
|
551
|
+
* sessions writing the same artifact must not race on one tmp path. */
|
|
552
|
+
writeAnimusFile(name, content) {
|
|
553
|
+
const dir = (0, path.join)(this.rootDir, ".animus");
|
|
554
|
+
if (!(0, fs.existsSync)(dir)) (0, fs.mkdirSync)(dir, { recursive: true });
|
|
555
|
+
const tmpPath = (0, path.join)(dir, `.${name}.${process.pid}.tmp`);
|
|
556
|
+
(0, fs.writeFileSync)(tmpPath, content);
|
|
557
|
+
(0, fs.renameSync)(tmpPath, (0, path.join)(dir, name));
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/plugin.ts
|
|
562
|
+
const PLUGIN_NAME = "AnimusWebpackPlugin";
|
|
563
|
+
/**
|
|
564
|
+
* Webpack adapter for the extraction pipeline. All pipeline logic lives in
|
|
565
|
+
* the bundler-agnostic ExtractionSession — this class owns only the webpack
|
|
566
|
+
* wiring: hook registration, cross-compiler analysis dedup, alias
|
|
567
|
+
* harvesting from the compiler config, watch-event translation, and
|
|
568
|
+
* in-memory CSS asset replacement.
|
|
569
|
+
*/
|
|
570
|
+
var AnimusWebpackPlugin = class {
|
|
571
|
+
options;
|
|
572
|
+
session;
|
|
573
|
+
initialized = false;
|
|
574
|
+
aliasesExtracted = false;
|
|
575
|
+
constructor(options) {
|
|
576
|
+
this.options = options;
|
|
577
|
+
(0, _animus_ui_extract_pipeline.assertNoRetiredEngineSelection)(options.engine);
|
|
578
|
+
require_singleton.setSharedEngine(options.engine ?? "v2");
|
|
579
|
+
this.session = new ExtractionSession(options);
|
|
580
|
+
}
|
|
581
|
+
/** Extract path aliases from webpack's resolve.alias config. Runs once per
|
|
582
|
+
* plugin instance — the resolve config is immutable after apply. */
|
|
583
|
+
extractAliases(compiler) {
|
|
584
|
+
if (this.aliasesExtracted) return;
|
|
585
|
+
this.aliasesExtracted = true;
|
|
586
|
+
const rootDir = compiler.context;
|
|
587
|
+
const rawAlias = compiler.options?.resolve?.alias;
|
|
588
|
+
if (!rawAlias || typeof rawAlias !== "object") return;
|
|
589
|
+
const pairs = [];
|
|
590
|
+
for (const [key, value] of Object.entries(rawAlias)) {
|
|
591
|
+
const target = Array.isArray(value) ? value[0] : value;
|
|
592
|
+
if (typeof target !== "string") continue;
|
|
593
|
+
if (key === ".animus/styles.css") continue;
|
|
594
|
+
pairs.push({
|
|
595
|
+
pattern: key,
|
|
596
|
+
target
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
const built = (0, _animus_ui_extract_pipeline.buildPathAliasesJson)(pairs, rootDir);
|
|
600
|
+
if (built) this.session.pathAliasesJson = built.json;
|
|
601
|
+
}
|
|
602
|
+
apply(compiler) {
|
|
603
|
+
if (compiler.options?.name === "edge-server") return;
|
|
604
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
605
|
+
const registerSystemDependencies = () => {
|
|
606
|
+
for (const dep of this.session.systemDependencyPaths) if ((0, fs.existsSync)(dep)) compilation.fileDependencies.add(dep);
|
|
607
|
+
else compilation.missingDependencies.add(dep);
|
|
608
|
+
};
|
|
609
|
+
registerSystemDependencies();
|
|
610
|
+
const stage = compiler.webpack?.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL ?? -2e3;
|
|
611
|
+
const RawSource = compiler.webpack?.sources.RawSource;
|
|
612
|
+
compilation.hooks.processAssets.tap({
|
|
613
|
+
name: PLUGIN_NAME,
|
|
614
|
+
stage
|
|
615
|
+
}, () => {
|
|
616
|
+
registerSystemDependencies();
|
|
617
|
+
const css = require_singleton.getSharedCss();
|
|
618
|
+
if (!css || !RawSource) return;
|
|
619
|
+
const cssPath = (0, path.join)(this.session.rootDir || compiler.context, ".animus", "styles.css");
|
|
620
|
+
if (compilation.getAsset(cssPath)) {
|
|
621
|
+
compilation.updateAsset(cssPath, new RawSource(css));
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (compilation.getAsset(".animus/styles.css")) compilation.updateAsset(ANIMUS_CSS_MODULE_ID, new RawSource(css));
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
compiler.hooks.run.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
628
|
+
this.session.rootDir = _compiler.context;
|
|
629
|
+
this.extractAliases(_compiler);
|
|
630
|
+
const existing = require_singleton.getAnalysisPromise();
|
|
631
|
+
if (existing) {
|
|
632
|
+
await existing;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const promise = this.session.runFullPipeline();
|
|
636
|
+
require_singleton.setAnalysisPromise(promise);
|
|
637
|
+
await promise;
|
|
638
|
+
});
|
|
639
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
640
|
+
this.session.rootDir = _compiler.context;
|
|
641
|
+
this.extractAliases(_compiler);
|
|
642
|
+
if (!this.initialized) {
|
|
643
|
+
const existing = require_singleton.getAnalysisPromise();
|
|
644
|
+
if (existing) {
|
|
645
|
+
await existing;
|
|
646
|
+
this.initialized = true;
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const promise = this.session.runFullPipeline();
|
|
650
|
+
require_singleton.setAnalysisPromise(promise);
|
|
651
|
+
await promise;
|
|
652
|
+
this.initialized = true;
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
await this.session.handleWatchUpdate({
|
|
656
|
+
modifiedFiles: _compiler.modifiedFiles,
|
|
657
|
+
removedFiles: _compiler.removedFiles
|
|
658
|
+
});
|
|
659
|
+
});
|
|
651
660
|
}
|
|
652
|
-
/**
|
|
653
|
-
|
|
654
|
-
|
|
661
|
+
/**
|
|
662
|
+
* Reset analysis state for HMR geological reset.
|
|
663
|
+
*/
|
|
664
|
+
resetForHmr() {
|
|
665
|
+
this.session.resetForHmr();
|
|
655
666
|
}
|
|
656
667
|
/** Expose options for the loader */
|
|
657
668
|
getOptions() {
|
|
@@ -660,18 +671,187 @@ var AnimusWebpackPlugin = class {
|
|
|
660
671
|
/** Expose external package directories for webpack loader allowlisting.
|
|
661
672
|
* Falls back to shared globalThis state for non-owning compiler instances. */
|
|
662
673
|
getExternalPackageDirs() {
|
|
663
|
-
return this.externalPackageDirs.length > 0 ? this.externalPackageDirs : require_singleton.getSharedExternalDirs();
|
|
674
|
+
return this.session.externalPackageDirs.length > 0 ? this.session.externalPackageDirs : require_singleton.getSharedExternalDirs();
|
|
664
675
|
}
|
|
665
676
|
/** Expose external package source entries for webpack resolve alias.
|
|
666
677
|
* Falls back to shared globalThis state for non-owning compiler instances. */
|
|
667
678
|
getExternalSourceEntries() {
|
|
668
|
-
return this.externalSourceEntries.size > 0 ? this.externalSourceEntries : require_singleton.getSharedExternalEntries();
|
|
679
|
+
return this.session.externalSourceEntries.size > 0 ? this.session.externalSourceEntries : require_singleton.getSharedExternalEntries();
|
|
669
680
|
}
|
|
670
681
|
};
|
|
671
682
|
//#endregion
|
|
683
|
+
//#region src/turbopack-config.ts
|
|
684
|
+
/** The single glob the Animus loader registers under. `.mjs` is included
|
|
685
|
+
* for webpack parity: an external package without `src/` is ingested via
|
|
686
|
+
* its resolved dist entry (often `dist/index.mjs`) and must still reach
|
|
687
|
+
* the loader — manifest lookup remains the file-level gate. */
|
|
688
|
+
const ANIMUS_TURBOPACK_RULE_GLOB = "*.{ts,tsx,js,jsx,mjs}";
|
|
689
|
+
/** Virtual system-props id emitted into transformed sources under Turbopack
|
|
690
|
+
* (absolute-path imports are rejected there); resolveAlias maps it to the
|
|
691
|
+
* on-disk artifact. */
|
|
692
|
+
const TURBOPACK_SYSTEM_PROPS_ID = "virtual:animus/system-props";
|
|
693
|
+
/**
|
|
694
|
+
* Resolve whether Turbopack wiring is active for this process. Default is
|
|
695
|
+
* `'auto'`: active exactly when the TURBOPACK environment variable is set
|
|
696
|
+
* (Next sets it for every Turbopack dev/build). The stable `turbopack`
|
|
697
|
+
* option wins over the deprecated `unstable_turbopack` alias.
|
|
698
|
+
*/
|
|
699
|
+
function resolveTurbopackMode(options, env = process.env) {
|
|
700
|
+
const mode = options.turbopack?.mode ?? options.unstable_turbopack?.mode ?? "auto";
|
|
701
|
+
if (mode === "on") return true;
|
|
702
|
+
if (mode === "auto") return env.TURBOPACK !== void 0;
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Build the `turbopack` config fragment: one glob-keyed loader rule
|
|
707
|
+
* (file-level allowlisting lives in the loader via manifest lookup — Next 15
|
|
708
|
+
* rules have no condition algebra) plus resolve aliases for the virtual
|
|
709
|
+
* system-props id, the emitter's stylesheet id, and each collected external
|
|
710
|
+
* package specifier redirected to its source entry.
|
|
711
|
+
*/
|
|
712
|
+
function buildTurbopackConfig(args) {
|
|
713
|
+
const { rootDir, loaderPath, options, externalSourceEntries } = args;
|
|
714
|
+
const loaderOptions = {
|
|
715
|
+
rootDir,
|
|
716
|
+
...options.strict !== void 0 ? { strict: options.strict } : {},
|
|
717
|
+
...options.cssImportTarget !== void 0 ? { cssImportTarget: options.cssImportTarget } : {}
|
|
718
|
+
};
|
|
719
|
+
const resolveAlias = {
|
|
720
|
+
[TURBOPACK_SYSTEM_PROPS_ID]: "./.animus/system-props.js",
|
|
721
|
+
".animus/styles.css": "./.animus/styles.css"
|
|
722
|
+
};
|
|
723
|
+
for (const [specifier, srcEntry] of externalSourceEntries) resolveAlias[specifier] = `./${(0, path.relative)(rootDir, srcEntry).replace(/\\/g, "/")}`;
|
|
724
|
+
return {
|
|
725
|
+
rules: { [ANIMUS_TURBOPACK_RULE_GLOB]: { loaders: [{
|
|
726
|
+
loader: loaderPath,
|
|
727
|
+
options: loaderOptions
|
|
728
|
+
}] } },
|
|
729
|
+
resolveAlias
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Locate the Turbopack loader module: built dist first, source fallback for
|
|
734
|
+
* in-repo development. CJS preferred — Turbopack's loader-runner follows
|
|
735
|
+
* the webpack loader contract (`module.exports = fn`), and the .cjs build
|
|
736
|
+
* is loadable by every runner version; ESM default-export acceptance is
|
|
737
|
+
* not guaranteed.
|
|
738
|
+
*/
|
|
739
|
+
function resolveTurbopackLoaderPath(pluginDir) {
|
|
740
|
+
for (const candidate of ["turbopack-loader.cjs", "turbopack-loader.mjs"]) {
|
|
741
|
+
const distPath = (0, path.resolve)(pluginDir, candidate);
|
|
742
|
+
if ((0, fs.existsSync)(distPath)) return distPath;
|
|
743
|
+
}
|
|
744
|
+
return (0, path.resolve)(pluginDir, "turbopack-loader.ts");
|
|
745
|
+
}
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/turbopack-orchestrator.ts
|
|
748
|
+
/**
|
|
749
|
+
* Out-of-band pipeline orchestration for Turbopack (spec:
|
|
750
|
+
* next-turbopack-integration). Turbopack exposes no compiler hooks, so the
|
|
751
|
+
* pipeline runs during next.config resolution and, in dev, from a
|
|
752
|
+
* filesystem watcher — the bundler only ever sees the `.animus/` disk
|
|
753
|
+
* artifacts.
|
|
754
|
+
*/
|
|
755
|
+
/** Run the full pipeline with the Turbopack emitter identity: hydration
|
|
756
|
+
* artifacts persisted, and the virtual system-props id (Turbopack rejects
|
|
757
|
+
* the webpack path's absolute-path imports). */
|
|
758
|
+
async function runTurbopackPipeline(session) {
|
|
759
|
+
session.persistAnalysisInputs = true;
|
|
760
|
+
session.systemPropsModuleId = TURBOPACK_SYSTEM_PROPS_ID;
|
|
761
|
+
await session.runFullPipeline();
|
|
762
|
+
}
|
|
763
|
+
const activeWatcherRoots = /* @__PURE__ */ new Set();
|
|
764
|
+
const IGNORED_SEGMENTS = new Set([
|
|
765
|
+
".animus",
|
|
766
|
+
".next",
|
|
767
|
+
"node_modules"
|
|
768
|
+
]);
|
|
769
|
+
/**
|
|
770
|
+
* Start the dev watcher: fs.watch per eligible top-level directory (plus a
|
|
771
|
+
* non-recursive watch on the root itself), debounced into
|
|
772
|
+
* existence-partitioned modified/removed sets feeding
|
|
773
|
+
* `session.handleWatchUpdate` (serialized — updates never overlap).
|
|
774
|
+
* Generated and vendored trees (`.animus`, `.next`, node_modules) are never
|
|
775
|
+
* registered with the OS — recursive registration of those trees exhausts
|
|
776
|
+
* inotify/kqueue descriptors (EMFILE/ENOSPC) on large projects.
|
|
777
|
+
* Idempotent per project root; unref'd so it never holds the process open.
|
|
778
|
+
* Asynchronous FSWatcher errors degrade to no-watch with a warning instead
|
|
779
|
+
* of crashing the dev server. Returns a close handle, or null when this
|
|
780
|
+
* root is already watched or the platform lacks recursive fs.watch (Linux
|
|
781
|
+
* before Node 20 — degrades to no-watch with a warning).
|
|
782
|
+
*/
|
|
783
|
+
function startTurbopackWatcher(session, rootDir, debounceMs = 75, watchFn = fs.watch) {
|
|
784
|
+
if (activeWatcherRoots.has(rootDir)) return null;
|
|
785
|
+
activeWatcherRoots.add(rootDir);
|
|
786
|
+
const pendingPaths = /* @__PURE__ */ new Set();
|
|
787
|
+
const watchers = /* @__PURE__ */ new Map();
|
|
788
|
+
let timer = null;
|
|
789
|
+
let updateChain = Promise.resolve();
|
|
790
|
+
let closed = false;
|
|
791
|
+
const flush = () => {
|
|
792
|
+
timer = null;
|
|
793
|
+
const modifiedFiles = /* @__PURE__ */ new Set();
|
|
794
|
+
const removedFiles = /* @__PURE__ */ new Set();
|
|
795
|
+
for (const path$1 of pendingPaths) ((0, fs.existsSync)(path$1) ? modifiedFiles : removedFiles).add(path$1);
|
|
796
|
+
pendingPaths.clear();
|
|
797
|
+
updateChain = updateChain.then(() => session.handleWatchUpdate({
|
|
798
|
+
modifiedFiles,
|
|
799
|
+
removedFiles
|
|
800
|
+
}).catch((err) => {
|
|
801
|
+
console.warn(`[animus-extract] Turbopack watch update failed: ${String(err)}`);
|
|
802
|
+
}));
|
|
803
|
+
};
|
|
804
|
+
const closeAll = () => {
|
|
805
|
+
if (closed) return;
|
|
806
|
+
closed = true;
|
|
807
|
+
if (timer) clearTimeout(timer);
|
|
808
|
+
timer = null;
|
|
809
|
+
for (const watcher of watchers.values()) watcher.close();
|
|
810
|
+
watchers.clear();
|
|
811
|
+
activeWatcherRoots.delete(rootDir);
|
|
812
|
+
};
|
|
813
|
+
const onWatcherError = (err) => {
|
|
814
|
+
closeAll();
|
|
815
|
+
console.warn(`[animus-extract] Turbopack dev watcher failed (${String(err)}); source edits require a dev-server restart`);
|
|
816
|
+
};
|
|
817
|
+
const onEvent = (baseDir, filename) => {
|
|
818
|
+
if (closed || !filename) return;
|
|
819
|
+
const rel = filename.toString();
|
|
820
|
+
if (rel.split(/[\\/]/).some((segment) => IGNORED_SEGMENTS.has(segment))) return;
|
|
821
|
+
const abs = (0, path.join)(baseDir, rel);
|
|
822
|
+
if (baseDir === rootDir && !watchers.has(abs)) try {
|
|
823
|
+
if ((0, fs.statSync)(abs).isDirectory()) addWatcher(abs, true);
|
|
824
|
+
} catch {}
|
|
825
|
+
pendingPaths.add(abs);
|
|
826
|
+
if (!timer) {
|
|
827
|
+
timer = setTimeout(flush, debounceMs);
|
|
828
|
+
timer.unref?.();
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
const addWatcher = (dir, recursive) => {
|
|
832
|
+
const watcher = watchFn(dir, { recursive }, (_event, filename) => onEvent(dir, filename));
|
|
833
|
+
watcher.on("error", onWatcherError);
|
|
834
|
+
watcher.unref?.();
|
|
835
|
+
watchers.set(dir, watcher);
|
|
836
|
+
};
|
|
837
|
+
try {
|
|
838
|
+
addWatcher(rootDir, false);
|
|
839
|
+
for (const entry of (0, fs.readdirSync)(rootDir, { withFileTypes: true })) {
|
|
840
|
+
if (!entry.isDirectory() || IGNORED_SEGMENTS.has(entry.name)) continue;
|
|
841
|
+
addWatcher((0, path.join)(rootDir, entry.name), true);
|
|
842
|
+
}
|
|
843
|
+
} catch (err) {
|
|
844
|
+
closeAll();
|
|
845
|
+
console.warn(`[animus-extract] Turbopack dev watcher unavailable (${String(err)}); source edits require a dev-server restart`);
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
return { close: closeAll };
|
|
849
|
+
}
|
|
850
|
+
//#endregion
|
|
672
851
|
//#region src/with-animus.ts
|
|
673
852
|
const __dirname$1 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
674
853
|
let warnedGitignore = false;
|
|
854
|
+
let warnedUnstableTurbopack = false;
|
|
675
855
|
/**
|
|
676
856
|
* Wrap a Next.js config to enable Animus static CSS extraction.
|
|
677
857
|
*
|
|
@@ -683,16 +863,30 @@ let warnedGitignore = false;
|
|
|
683
863
|
*/
|
|
684
864
|
function withAnimus(options) {
|
|
685
865
|
if (!options.system) throw new Error("[animus-extract] Missing required option `system`. Provide the path to your SystemInstance module: withAnimus({ system: \"./src/ds.ts\" })");
|
|
866
|
+
if (options.unstable_turbopack && !options.turbopack && !warnedUnstableTurbopack) {
|
|
867
|
+
warnedUnstableTurbopack = true;
|
|
868
|
+
console.warn("[animus-extract] `unstable_turbopack` is deprecated — rename it to `turbopack` (same shape)");
|
|
869
|
+
}
|
|
686
870
|
return (nextConfig) => {
|
|
871
|
+
if (resolveTurbopackMode(options)) return wireTurbopack(nextConfig, options);
|
|
687
872
|
const existingWebpack = nextConfig.webpack;
|
|
688
873
|
return {
|
|
689
874
|
...nextConfig,
|
|
690
875
|
webpack(config, context) {
|
|
876
|
+
if (typeof existingWebpack === "function") config = existingWebpack(config, context);
|
|
691
877
|
const rootDir = process.cwd();
|
|
692
878
|
const animusDir = (0, path.join)(rootDir, ".animus");
|
|
693
879
|
if (!(0, fs.existsSync)(animusDir)) (0, fs.mkdirSync)(animusDir, { recursive: true });
|
|
694
880
|
const stubCssPath = (0, path.join)(animusDir, "styles.css");
|
|
695
|
-
if (!(0, fs.existsSync)(stubCssPath))
|
|
881
|
+
if (!(0, fs.existsSync)(stubCssPath)) {
|
|
882
|
+
const { declaration } = (0, _animus_ui_extract_pipeline.assembleStylesheet)({
|
|
883
|
+
layers: options.layers,
|
|
884
|
+
variableCss: "",
|
|
885
|
+
globalCss: "",
|
|
886
|
+
split: true
|
|
887
|
+
});
|
|
888
|
+
(0, fs.writeFileSync)(stubCssPath, declaration);
|
|
889
|
+
}
|
|
696
890
|
if (!warnedGitignore) {
|
|
697
891
|
warnedGitignore = true;
|
|
698
892
|
try {
|
|
@@ -702,19 +896,13 @@ function withAnimus(options) {
|
|
|
702
896
|
}
|
|
703
897
|
} catch {}
|
|
704
898
|
}
|
|
705
|
-
const plugin = new AnimusWebpackPlugin(
|
|
706
|
-
|
|
707
|
-
exclude: options.exclude,
|
|
708
|
-
strict: options.strict,
|
|
709
|
-
verbose: options.verbose,
|
|
710
|
-
prefix: options.prefix,
|
|
711
|
-
engine: options.engine
|
|
712
|
-
});
|
|
899
|
+
const plugin = new AnimusWebpackPlugin(options);
|
|
900
|
+
const isExternalPackageFile = (filePath) => plugin.getExternalPackageDirs().some((dir) => filePath.startsWith(dir + path.sep) || filePath === dir);
|
|
713
901
|
config.plugins = config.plugins || [];
|
|
714
902
|
config.plugins.push(plugin);
|
|
715
903
|
config.resolve = config.resolve || {};
|
|
716
904
|
config.resolve.alias = config.resolve.alias || {};
|
|
717
|
-
config.resolve.alias[
|
|
905
|
+
config.resolve.alias[ANIMUS_CSS_MODULE_ID] = (0, path.join)(rootDir, ".animus", "styles.css");
|
|
718
906
|
const systemPropsPath = (0, path.join)(rootDir, ".animus", "system-props.js");
|
|
719
907
|
config.plugins.push({ apply(compiler) {
|
|
720
908
|
compiler.hooks.normalModuleFactory.tap("AnimusVirtualResolve", (nmf) => {
|
|
@@ -733,24 +921,62 @@ function withAnimus(options) {
|
|
|
733
921
|
config.module.rules.push({
|
|
734
922
|
test: (filePath) => {
|
|
735
923
|
if (/\.[jt]sx?$/.test(filePath)) return true;
|
|
736
|
-
|
|
737
|
-
return false;
|
|
924
|
+
return /\.mjs$/.test(filePath) && isExternalPackageFile(filePath);
|
|
738
925
|
},
|
|
739
926
|
exclude: (filePath) => {
|
|
740
927
|
if (!filePath.includes("node_modules")) return false;
|
|
741
|
-
return !
|
|
928
|
+
return !isExternalPackageFile(filePath);
|
|
742
929
|
},
|
|
743
930
|
enforce: "pre",
|
|
744
931
|
use: [{
|
|
745
932
|
loader: actualLoaderPath,
|
|
746
|
-
options: {
|
|
933
|
+
options: {
|
|
934
|
+
strict: options.strict,
|
|
935
|
+
cssImportTarget: options.cssImportTarget
|
|
936
|
+
}
|
|
747
937
|
}]
|
|
748
938
|
});
|
|
749
|
-
if (typeof existingWebpack === "function") return existingWebpack(config, context);
|
|
750
939
|
return config;
|
|
751
940
|
}
|
|
752
941
|
};
|
|
753
942
|
};
|
|
754
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Turbopack wiring: run the full extraction now (artifacts on disk before
|
|
946
|
+
* bundling), start the dev watcher, and merge the generated rules/aliases
|
|
947
|
+
* into `nextConfig.turbopack`. Consumer-managed rules for the same glob are
|
|
948
|
+
* a hard error — silently stacking loaders would be undebuggable.
|
|
949
|
+
*/
|
|
950
|
+
async function wireTurbopack(nextConfig, options) {
|
|
951
|
+
const rootDir = process.cwd();
|
|
952
|
+
const session = new ExtractionSession(options);
|
|
953
|
+
session.rootDir = rootDir;
|
|
954
|
+
const builtAliases = (0, _animus_ui_extract_pipeline.buildPathAliasesJson)((0, _animus_ui_extract_pipeline.readTsconfigAliasPairs)(rootDir), rootDir);
|
|
955
|
+
if (builtAliases) session.pathAliasesJson = builtAliases.json;
|
|
956
|
+
await runTurbopackPipeline(session);
|
|
957
|
+
if (process.env.NODE_ENV === "development") startTurbopackWatcher(session, rootDir);
|
|
958
|
+
const fragment = buildTurbopackConfig({
|
|
959
|
+
rootDir,
|
|
960
|
+
loaderPath: resolveTurbopackLoaderPath(__dirname$1),
|
|
961
|
+
options,
|
|
962
|
+
externalSourceEntries: session.externalSourceEntries
|
|
963
|
+
});
|
|
964
|
+
const existing = nextConfig.turbopack ?? {};
|
|
965
|
+
if (existing.rules && "*.{ts,tsx,js,jsx,mjs}" in existing.rules) throw new Error(`[animus-extract] turbopack.rules['${ANIMUS_TURBOPACK_RULE_GLOB}'] is already configured — remove the consumer rule or disable unstable_turbopack`);
|
|
966
|
+
return {
|
|
967
|
+
...nextConfig,
|
|
968
|
+
turbopack: {
|
|
969
|
+
...existing,
|
|
970
|
+
rules: {
|
|
971
|
+
...existing.rules,
|
|
972
|
+
...fragment.rules
|
|
973
|
+
},
|
|
974
|
+
resolveAlias: {
|
|
975
|
+
...existing.resolveAlias,
|
|
976
|
+
...fragment.resolveAlias
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
}
|
|
755
981
|
//#endregion
|
|
756
982
|
exports.withAnimus = withAnimus;
|