@animus-ui/next-plugin 0.1.11 → 0.1.12
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/index.cjs +58 -152
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +60 -153
- package/dist/loader-core-BthLSJQF.cjs +47 -0
- package/dist/loader-core-x6cOzF9v.mjs +42 -0
- package/dist/loader-core.d.ts +6 -13
- package/dist/loader-core.d.ts.map +1 -1
- package/dist/loader-path.d.ts +0 -13
- package/dist/loader-path.d.ts.map +1 -1
- package/dist/loader.cjs +2 -25
- package/dist/loader.d.ts +2 -24
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.mjs +2 -24
- package/dist/plugin.d.ts +17 -69
- package/dist/plugin.d.ts.map +1 -1
- package/dist/turbopack-config.d.ts +8 -35
- package/dist/turbopack-config.d.ts.map +1 -1
- package/dist/turbopack-loader.cjs +34 -54
- package/dist/turbopack-loader.d.ts +12 -24
- package/dist/turbopack-loader.d.ts.map +1 -1
- package/dist/turbopack-loader.mjs +35 -55
- package/dist/types.d.ts +24 -90
- package/dist/types.d.ts.map +1 -1
- package/dist/with-animus.d.ts +39 -24
- package/dist/with-animus.d.ts.map +1 -1
- package/package.json +5 -2
- package/dist/loader-core-D2rh--tX.cjs +0 -71
- package/dist/loader-core-DwiidYBi.mjs +0 -66
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./turbopack-loader.cjs");
|
|
3
2
|
let _animus_ui_extract_pipeline = require("@animus-ui/extract/pipeline");
|
|
4
3
|
let _animus_ui_extract_session = require("@animus-ui/extract/session");
|
|
5
4
|
let fs = require("fs");
|
|
6
5
|
let path = require("path");
|
|
7
6
|
let url = require("url");
|
|
8
7
|
//#region src/loader-path.ts
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
* The one loader-path derivation: first existing dist candidate under the
|
|
12
|
-
* plugin dir, else the in-repo source fallback. Both loader resolvers below
|
|
13
|
-
* are thin wrappers, so rule registration and any loader-chain predicate
|
|
14
|
-
* can never drift (openspec: next-webpack-served-transform-coherence,
|
|
15
|
-
* design D1).
|
|
16
|
-
*/
|
|
8
|
+
const __filename$2 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
9
|
+
const __dirname$2 = (0, path.dirname)(__filename$2);
|
|
17
10
|
function resolveLoaderPath(pluginDir, distCandidates, sourceFallback) {
|
|
18
11
|
for (const candidate of distCandidates) {
|
|
19
12
|
const distPath = (0, path.resolve)(pluginDir, candidate);
|
|
@@ -21,69 +14,38 @@ function resolveLoaderPath(pluginDir, distCandidates, sourceFallback) {
|
|
|
21
14
|
}
|
|
22
15
|
return (0, path.resolve)(pluginDir, sourceFallback);
|
|
23
16
|
}
|
|
24
|
-
/**
|
|
25
|
-
* This package's webpack loader path, shared by the rule registration
|
|
26
|
-
* (with-animus) and the needBuild loader-chain predicate (plugin). Compiled
|
|
27
|
-
* dist ships `loader.mjs` next to this module; running from source falls
|
|
28
|
-
* back to the TypeScript loader.
|
|
29
|
-
*/
|
|
30
17
|
function resolveAnimusLoaderPath() {
|
|
31
18
|
return resolveLoaderPath(__dirname$2, ["loader.mjs"], "loader.ts");
|
|
32
19
|
}
|
|
33
20
|
//#endregion
|
|
34
21
|
//#region src/plugin.ts
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
const
|
|
22
|
+
/** The value arrives from a consumer's `next.config`, so the union above is a
|
|
23
|
+
* model of what webpack accepts, not a proof about the value in hand. */
|
|
24
|
+
const isWatchIgnoreString = (ignored) => Object.prototype.toString.call(ignored) === "[object String]";
|
|
25
|
+
const isWatchIgnoreMatcher = (ignored) => Object.prototype.toString.call(ignored) === "[object Function]";
|
|
26
|
+
const UNSUPPORTED_WEBPACK_MESSAGE = "[animus-extract] Unsupported webpack: NormalModule.getCompilationHooks(compilation).needBuild is required for dev transform coherence and this webpack does not expose it. Use a Next.js version whose webpack exposes this hook.";
|
|
39
27
|
const PLUGIN_NAME = "AnimusWebpackPlugin";
|
|
40
|
-
/**
|
|
41
|
-
* Webpack adapter for the extraction pipeline. All pipeline logic lives in
|
|
42
|
-
* the bundler-agnostic ExtractionSession — this class owns only the webpack
|
|
43
|
-
* wiring: hook registration, cross-compiler analysis dedup, alias
|
|
44
|
-
* harvesting from the compiler config, watch-event translation, and
|
|
45
|
-
* in-memory CSS asset replacement.
|
|
46
|
-
*/
|
|
47
28
|
var AnimusWebpackPlugin = class {
|
|
48
29
|
options;
|
|
49
30
|
session;
|
|
50
31
|
initialized = false;
|
|
51
32
|
aliasesExtracted = false;
|
|
52
|
-
/** Loader paths counting as "the animus loader" in a module's chain —
|
|
53
|
-
* this package's own loader plus an optional harness override. */
|
|
54
33
|
animusLoaderPaths;
|
|
55
|
-
/** Epoch THIS compiler last proceeded with (set after every awaited
|
|
56
|
-
* watchRun transaction — including joined ones). Null until the
|
|
57
|
-
* initialization pipeline publishes. */
|
|
58
34
|
lastBuiltEpoch = null;
|
|
59
|
-
/** Armed by watchRun when the transaction moved the epoch; captured and
|
|
60
|
-
* disarmed by the next compilation's needBuild wiring (design D1). */
|
|
61
35
|
epochMovedForNextCompilation = false;
|
|
62
36
|
constructor(options) {
|
|
63
37
|
this.options = options;
|
|
64
38
|
(0, _animus_ui_extract_pipeline.assertNoRetiredEngineSelection)(options.engine);
|
|
65
39
|
(0, _animus_ui_extract_session.setSharedEngine)(options.engine ?? "v2");
|
|
66
40
|
this.session = new _animus_ui_extract_session.ExtractionSession(options);
|
|
67
|
-
this.animusLoaderPaths = new Set([resolveAnimusLoaderPath()]);
|
|
41
|
+
this.animusLoaderPaths = /* @__PURE__ */ new Set([resolveAnimusLoaderPath()]);
|
|
68
42
|
if (options.loaderPath) this.animusLoaderPaths.add(options.loaderPath);
|
|
69
43
|
}
|
|
70
|
-
/** True when the module's loader chain contains the animus loader — the
|
|
71
|
-
* needBuild fan-out predicate (design D1: no historical records; covers
|
|
72
|
-
* restored persistent-cache modules and raw passthroughs alike). */
|
|
73
44
|
moduleUsesAnimusLoader(module) {
|
|
74
45
|
const loaders = module?.loaders;
|
|
75
46
|
if (!Array.isArray(loaders)) return false;
|
|
76
|
-
return loaders.some((entry) =>
|
|
47
|
+
return loaders.some((entry) => entry?.loader !== void 0 && this.animusLoaderPaths.has(entry.loader));
|
|
77
48
|
}
|
|
78
|
-
/** Append the exact epoch artifact path to `watchOptions.ignored`,
|
|
79
|
-
* preserving the user's shape (design D2: the artifact participates in
|
|
80
|
-
* module snapshots via addDependency but never triggers live watch
|
|
81
|
-
* turns — no echo compilations). Session identity is process-claimed,
|
|
82
|
-
* so every compiler's plugin instance derives the SAME session-scoped
|
|
83
|
-
* path here regardless of which instance ends up owning the pipeline.
|
|
84
|
-
* Derived from the ONE root (session.rootDir, set at config time by
|
|
85
|
-
* with-animus); compiler.context is the fallback for bare-apply
|
|
86
|
-
* harnesses — identical when compiler.context === cwd. */
|
|
87
49
|
appendEpochWatchIgnore(compiler) {
|
|
88
50
|
const options = compiler.options;
|
|
89
51
|
if (!options) return;
|
|
@@ -94,25 +56,22 @@ var AnimusWebpackPlugin = class {
|
|
|
94
56
|
if (ignored === void 0 || ignored === null) watchOptions.ignored = [epochPath];
|
|
95
57
|
else if (Array.isArray(ignored)) {
|
|
96
58
|
if (!ignored.includes(epochPath)) ignored.push(epochPath);
|
|
97
|
-
} else if (
|
|
59
|
+
} else if (isWatchIgnoreString(ignored)) watchOptions.ignored = [ignored, epochPath];
|
|
98
60
|
else if (ignored instanceof RegExp) watchOptions.ignored = (path) => path === epochPath || ignored.test(path);
|
|
99
|
-
else if (
|
|
100
|
-
const original = ignored;
|
|
101
|
-
watchOptions.ignored = (path) => path === epochPath || Boolean(original(path));
|
|
102
|
-
}
|
|
61
|
+
else if (isWatchIgnoreMatcher(ignored)) watchOptions.ignored = (path) => path === epochPath || Boolean(ignored(path));
|
|
103
62
|
}
|
|
104
|
-
/** Extract path aliases from webpack's resolve.alias config. Runs once per
|
|
105
|
-
* plugin instance — the resolve config is immutable after apply. */
|
|
106
63
|
extractAliases(compiler) {
|
|
107
64
|
if (this.aliasesExtracted) return;
|
|
108
65
|
this.aliasesExtracted = true;
|
|
109
66
|
const rootDir = compiler.context;
|
|
110
67
|
const rawAlias = compiler.options?.resolve?.alias;
|
|
111
|
-
if (
|
|
68
|
+
if (rawAlias === void 0) return;
|
|
69
|
+
if (Object.prototype.toString.call(rawAlias) !== "[object Object]") return;
|
|
112
70
|
const pairs = [];
|
|
113
71
|
for (const [key, value] of Object.entries(rawAlias)) {
|
|
114
|
-
|
|
115
|
-
|
|
72
|
+
if (value === false) continue;
|
|
73
|
+
const target = Array.isArray(value) ? value.at(0) : value;
|
|
74
|
+
if (target === void 0) continue;
|
|
116
75
|
if (key === _animus_ui_extract_session.ANIMUS_CSS_MODULE_ID) continue;
|
|
117
76
|
pairs.push({
|
|
118
77
|
pattern: key,
|
|
@@ -125,13 +84,13 @@ var AnimusWebpackPlugin = class {
|
|
|
125
84
|
apply(compiler) {
|
|
126
85
|
if (compiler.options?.name === "edge-server") return;
|
|
127
86
|
const NormalModule = compiler.webpack?.NormalModule;
|
|
128
|
-
if (
|
|
87
|
+
if (NormalModule?.getCompilationHooks === void 0) throw new Error(UNSUPPORTED_WEBPACK_MESSAGE);
|
|
129
88
|
this.appendEpochWatchIgnore(compiler);
|
|
130
89
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
131
90
|
const epochMoved = this.epochMovedForNextCompilation;
|
|
132
91
|
this.epochMovedForNextCompilation = false;
|
|
133
92
|
const needBuild = NormalModule.getCompilationHooks(compilation).needBuild;
|
|
134
|
-
if (
|
|
93
|
+
if (needBuild === void 0) throw new Error(UNSUPPORTED_WEBPACK_MESSAGE);
|
|
135
94
|
needBuild.tapAsync(PLUGIN_NAME, (module, _context, callback) => {
|
|
136
95
|
if (epochMoved && this.moduleUsesAnimusLoader(module)) {
|
|
137
96
|
callback(null, true);
|
|
@@ -158,7 +117,8 @@ var AnimusWebpackPlugin = class {
|
|
|
158
117
|
registerSystemDependencies();
|
|
159
118
|
const css = (0, _animus_ui_extract_session.getSharedCss)();
|
|
160
119
|
if (!css || !RawSource) return;
|
|
161
|
-
const
|
|
120
|
+
const rootDir = this.session.rootDir || compiler.context;
|
|
121
|
+
const cssPath = (0, _animus_ui_extract_session.stylesPath)((0, _animus_ui_extract_session.sessionArtifactDir)(rootDir, this.session.sessionId));
|
|
162
122
|
if (compilation.getAsset(cssPath)) {
|
|
163
123
|
compilation.updateAsset(cssPath, new RawSource(css));
|
|
164
124
|
return;
|
|
@@ -169,24 +129,24 @@ var AnimusWebpackPlugin = class {
|
|
|
169
129
|
compiler.hooks.run.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
170
130
|
this.adoptCompilerContext(_compiler);
|
|
171
131
|
this.extractAliases(_compiler);
|
|
172
|
-
const existing = (0, _animus_ui_extract_session.
|
|
132
|
+
const existing = (0, _animus_ui_extract_session.getAnalysisStartedPromise)();
|
|
173
133
|
if (existing) {
|
|
174
134
|
await existing;
|
|
175
135
|
return;
|
|
176
136
|
}
|
|
177
137
|
const promise = this.session.runFullPipeline();
|
|
178
|
-
(0, _animus_ui_extract_session.
|
|
138
|
+
(0, _animus_ui_extract_session.setAnalysisStartedPromise)(promise);
|
|
179
139
|
await promise;
|
|
180
140
|
});
|
|
181
141
|
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (_compiler) => {
|
|
182
142
|
this.adoptCompilerContext(_compiler);
|
|
183
143
|
this.extractAliases(_compiler);
|
|
184
144
|
if (!this.initialized) {
|
|
185
|
-
const existing = (0, _animus_ui_extract_session.
|
|
145
|
+
const existing = (0, _animus_ui_extract_session.getAnalysisStartedPromise)();
|
|
186
146
|
if (existing) await existing;
|
|
187
147
|
else {
|
|
188
148
|
const promise = this.session.runFullPipeline();
|
|
189
|
-
(0, _animus_ui_extract_session.
|
|
149
|
+
(0, _animus_ui_extract_session.setAnalysisStartedPromise)(promise);
|
|
190
150
|
await promise;
|
|
191
151
|
}
|
|
192
152
|
this.initialized = true;
|
|
@@ -202,35 +162,20 @@ var AnimusWebpackPlugin = class {
|
|
|
202
162
|
if (epoch !== null) this.lastBuiltEpoch = epoch;
|
|
203
163
|
});
|
|
204
164
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Reset analysis state for HMR geological reset.
|
|
207
|
-
*/
|
|
208
165
|
resetForHmr() {
|
|
209
166
|
this.session.resetForHmr();
|
|
210
167
|
}
|
|
211
|
-
/** Session identity (process-claimed) — with-animus derives the
|
|
212
|
-
* session-scoped alias/stub paths from it (design D2). */
|
|
213
168
|
get sessionId() {
|
|
214
169
|
return this.session.sessionId;
|
|
215
170
|
}
|
|
216
|
-
/** Set the project root at CONFIG time (with-animus) — the ONE root all
|
|
217
|
-
* session-path derivations use. The compiler hooks ADOPT
|
|
218
|
-
* compiler.context only when no root was published (bare-apply
|
|
219
|
-
* harnesses); they never overwrite this. */
|
|
220
171
|
setRootDir(rootDir) {
|
|
221
172
|
this.session.rootDir = rootDir;
|
|
222
173
|
}
|
|
223
|
-
/** One warning per plugin instance for a context/root mismatch. */
|
|
224
174
|
warnedRootDivergence = false;
|
|
225
|
-
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* silent overwrite re-keys sessionDir so the pipeline publishes
|
|
230
|
-
* artifacts where none of those consumers look. A disagreement is
|
|
231
|
-
* surfaced loudly instead (with-animus derives the root from Next's own
|
|
232
|
-
* `dir`, which equals compiler.context in real Next runs — a mismatch
|
|
233
|
-
* means a custom-webpack setup wired the plugin differently). */
|
|
175
|
+
/** Adopts `compiler.context` only when no config-time root exists: every
|
|
176
|
+
* frozen derivation came from that root, so an overwrite re-keys it.
|
|
177
|
+
* Stub path, css alias, virtual system-props target and watch-ignore are
|
|
178
|
+
* all frozen from it, so a disagreement is warned, never reconciled. */
|
|
234
179
|
adoptCompilerContext(compiler) {
|
|
235
180
|
const context = compiler.context;
|
|
236
181
|
if (!this.session.rootDir) {
|
|
@@ -242,73 +187,47 @@ var AnimusWebpackPlugin = class {
|
|
|
242
187
|
console.warn(`[animus-extract] compiler.context (${context}) differs from the configured project root (${this.session.rootDir}); keeping the configured root — run next against the app directory (or align your custom webpack context) so both agree`);
|
|
243
188
|
}
|
|
244
189
|
}
|
|
245
|
-
/** This session's artifact directory, derived from the one root. */
|
|
246
190
|
get sessionDir() {
|
|
247
191
|
return this.session.sessionDir;
|
|
248
192
|
}
|
|
249
|
-
/** Expose options for the loader */
|
|
250
193
|
getOptions() {
|
|
251
194
|
return this.options;
|
|
252
195
|
}
|
|
253
|
-
/** Expose external package directories for webpack loader allowlisting.
|
|
254
|
-
* Falls back to shared globalThis state for non-owning compiler instances. */
|
|
255
196
|
getExternalPackageDirs() {
|
|
256
197
|
return this.session.externalPackageDirs.length > 0 ? this.session.externalPackageDirs : (0, _animus_ui_extract_session.getSharedExternalDirs)();
|
|
257
198
|
}
|
|
258
|
-
/** Expose external package source entries for webpack resolve alias.
|
|
259
|
-
* Falls back to shared globalThis state for non-owning compiler instances. */
|
|
260
199
|
getExternalSourceEntries() {
|
|
261
200
|
return this.session.externalSourceEntries.size > 0 ? this.session.externalSourceEntries : (0, _animus_ui_extract_session.getSharedExternalEntries)();
|
|
262
201
|
}
|
|
263
202
|
};
|
|
264
203
|
//#endregion
|
|
265
204
|
//#region src/turbopack-config.ts
|
|
266
|
-
/** The
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* via its resolved dist entry (often `dist/index.mjs`) and must still
|
|
271
|
-
* reach the loader — manifest lookup remains the file-level gate. */
|
|
205
|
+
/** The one glob the loader registers under, derived from the shared engine
|
|
206
|
+
* extension set so the bundler families cannot drift. `.mjs` belongs in that
|
|
207
|
+
* set: an external package with no src/ is ingested through its dist entry
|
|
208
|
+
* and must still reach the loader, so do not trim it. */
|
|
272
209
|
const ANIMUS_TURBOPACK_RULE_GLOB = `*.{${_animus_ui_extract_pipeline.ENGINE_TRANSFORM_EXTENSIONS.join(",")}}`;
|
|
273
|
-
/**
|
|
274
|
-
* Resolve whether Turbopack wiring is active for this process. Default is
|
|
275
|
-
* `'auto'`: active exactly when the TURBOPACK environment variable is set
|
|
276
|
-
* (Next sets it for every Turbopack dev/build). The stable `turbopack`
|
|
277
|
-
* option wins over the deprecated `unstable_turbopack` alias.
|
|
278
|
-
*/
|
|
279
210
|
function resolveTurbopackMode(options, env = process.env) {
|
|
280
211
|
const mode = options.turbopack?.mode ?? options.unstable_turbopack?.mode ?? "auto";
|
|
281
212
|
if (mode === "on") return true;
|
|
282
213
|
if (mode === "auto") return env.TURBOPACK !== void 0;
|
|
283
214
|
return false;
|
|
284
215
|
}
|
|
285
|
-
/** rootDir-relative module request for an absolute path — always forward
|
|
286
|
-
* slashes, even when path.relative produced Windows separators. */
|
|
287
216
|
function rootRelativeRequest(rootDir, absPath) {
|
|
288
217
|
return `./${(0, path.relative)(rootDir, absPath).replace(/\\/g, "/")}`;
|
|
289
218
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Build the `turbopack` config fragment: one glob-keyed loader rule
|
|
292
|
-
* (file-level allowlisting lives in the loader via manifest lookup — Next 15
|
|
293
|
-
* rules have no condition algebra) plus resolve aliases for the virtual
|
|
294
|
-
* system-props id, the emitter's stylesheet id, and each collected external
|
|
295
|
-
* package specifier redirected to its source entry. Loader options carry
|
|
296
|
-
* the session identity (design D2: an options-borne, JSON-serializable
|
|
297
|
-
* Turbopack task input — restart-cold by construction), and the artifact
|
|
298
|
-
* aliases point into the session-scoped tree.
|
|
299
|
-
*/
|
|
300
219
|
function buildTurbopackConfig(args) {
|
|
301
220
|
const { rootDir, loaderPath, options, externalSourceEntries, sessionId, sessionDir } = args;
|
|
302
221
|
const loaderOptions = {
|
|
303
222
|
rootDir,
|
|
304
223
|
sessionId,
|
|
305
|
-
sessionDir
|
|
306
|
-
...options.strict !== void 0 ? { strict: options.strict } : {},
|
|
307
|
-
...options.cssImportTarget !== void 0 ? { cssImportTarget: options.cssImportTarget } : {}
|
|
224
|
+
sessionDir
|
|
308
225
|
};
|
|
226
|
+
if (options.strict !== void 0) loaderOptions.strict = options.strict;
|
|
227
|
+
if (options.cssImportTarget !== void 0) loaderOptions.cssImportTarget = options.cssImportTarget;
|
|
309
228
|
const resolveAlias = {
|
|
310
229
|
[_animus_ui_extract_session.TURBOPACK_SYSTEM_PROPS_ID]: rootRelativeRequest(rootDir, (0, path.join)(sessionDir, _animus_ui_extract_session.SYSTEM_PROPS_ARTIFACT)),
|
|
311
|
-
|
|
230
|
+
[_animus_ui_extract_session.ANIMUS_CSS_MODULE_ID]: rootRelativeRequest(rootDir, (0, path.join)(sessionDir, _animus_ui_extract_session.STYLES_ARTIFACT))
|
|
312
231
|
};
|
|
313
232
|
for (const [specifier, srcEntry] of externalSourceEntries) resolveAlias[specifier] = rootRelativeRequest(rootDir, srcEntry);
|
|
314
233
|
return {
|
|
@@ -319,40 +238,25 @@ function buildTurbopackConfig(args) {
|
|
|
319
238
|
resolveAlias
|
|
320
239
|
};
|
|
321
240
|
}
|
|
322
|
-
/**
|
|
323
|
-
* Locate the Turbopack loader module: built dist first, source fallback for
|
|
324
|
-
* in-repo development. CJS preferred — Turbopack's loader-runner follows
|
|
325
|
-
* the webpack loader contract (`module.exports = fn`), and the .cjs build
|
|
326
|
-
* is loadable by every runner version; ESM default-export acceptance is
|
|
327
|
-
* not guaranteed.
|
|
328
|
-
*/
|
|
329
241
|
function resolveTurbopackLoaderPath(pluginDir) {
|
|
330
242
|
return resolveLoaderPath(pluginDir, ["turbopack-loader.cjs", "turbopack-loader.mjs"], "turbopack-loader.ts");
|
|
331
243
|
}
|
|
332
244
|
//#endregion
|
|
333
245
|
//#region src/with-animus.ts
|
|
334
|
-
const
|
|
246
|
+
const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
247
|
+
const __dirname$1 = (0, path.dirname)(__filename$1);
|
|
335
248
|
let warnedGitignore = false;
|
|
336
249
|
let warnedUnstableTurbopack = false;
|
|
337
|
-
/**
|
|
338
|
-
* Wrap a Next.js config to enable Animus static CSS extraction.
|
|
339
|
-
*
|
|
340
|
-
* ```ts
|
|
341
|
-
* // next.config.ts
|
|
342
|
-
* import { withAnimus } from '@animus-ui/next-plugin';
|
|
343
|
-
* export default withAnimus({ system: './src/ds.ts' })({});
|
|
344
|
-
* ```
|
|
345
|
-
*/
|
|
346
250
|
function withAnimus(options) {
|
|
347
251
|
if (!options.system) throw new Error("[animus-extract] Missing required option `system`. Provide the path to your SystemInstance module: withAnimus({ system: \"./src/ds.ts\" })");
|
|
348
|
-
(0, _animus_ui_extract_pipeline.assertKnownOptionKeys)(options, [
|
|
252
|
+
(0, _animus_ui_extract_pipeline.assertKnownOptionKeys)({ ...options }, [
|
|
349
253
|
"cssImportTarget",
|
|
350
254
|
"turbopack",
|
|
351
255
|
"unstable_turbopack",
|
|
352
256
|
"loaderPath"
|
|
353
257
|
], [{
|
|
354
258
|
key: "root",
|
|
355
|
-
reason: "
|
|
259
|
+
reason: "this driver derives its own root — Next's `dir` under webpack, `process.cwd()` under Turbopack (Next passes no dir to a config module)"
|
|
356
260
|
}], {
|
|
357
261
|
onUnknownKey: "warn",
|
|
358
262
|
warn: (message) => console.warn(`[animus-extract] ${message}`)
|
|
@@ -367,8 +271,8 @@ function withAnimus(options) {
|
|
|
367
271
|
return {
|
|
368
272
|
...nextConfig,
|
|
369
273
|
webpack(config, context) {
|
|
370
|
-
if (
|
|
371
|
-
const rootDir =
|
|
274
|
+
if (existingWebpack) config = existingWebpack(config, context);
|
|
275
|
+
const rootDir = context.dir?.length ? context.dir : process.cwd();
|
|
372
276
|
const plugin = new AnimusWebpackPlugin(options);
|
|
373
277
|
plugin.setRootDir(rootDir);
|
|
374
278
|
const sessionDir = plugin.sessionDir;
|
|
@@ -395,8 +299,8 @@ function withAnimus(options) {
|
|
|
395
299
|
const isExternalPackageFile = (filePath) => plugin.getExternalPackageDirs().some((dir) => (0, _animus_ui_extract_pipeline.isPathWithinRoot)(dir, filePath));
|
|
396
300
|
config.plugins = config.plugins || [];
|
|
397
301
|
config.plugins.push(plugin);
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
302
|
+
const DefinePlugin = context.webpack?.DefinePlugin;
|
|
303
|
+
if (DefinePlugin) config.plugins.push(new DefinePlugin({ __ANIMUS_DEV__: JSON.stringify((0, _animus_ui_extract_pipeline.resolveMode)(options.mode, () => context.dev === true ? "development" : "production").mode === "development") }));
|
|
400
304
|
config.resolve = config.resolve || {};
|
|
401
305
|
config.resolve.alias = config.resolve.alias || {};
|
|
402
306
|
config.resolve.alias[_animus_ui_extract_session.ANIMUS_CSS_MODULE_ID] = (0, _animus_ui_extract_session.stylesPath)(sessionDir);
|
|
@@ -415,10 +319,7 @@ function withAnimus(options) {
|
|
|
415
319
|
config.module = config.module || {};
|
|
416
320
|
config.module.rules = config.module.rules || [];
|
|
417
321
|
config.module.rules.push({
|
|
418
|
-
test: (filePath) =>
|
|
419
|
-
if (/\.[jt]sx?$/.test(filePath)) return true;
|
|
420
|
-
return /\.mjs$/.test(filePath) && isExternalPackageFile(filePath);
|
|
421
|
-
},
|
|
322
|
+
test: (filePath) => (0, _animus_ui_extract_pipeline.isEngineTransformExtension)(filePath),
|
|
422
323
|
exclude: (filePath) => {
|
|
423
324
|
if (!filePath.includes("node_modules")) return false;
|
|
424
325
|
return !isExternalPackageFile(filePath);
|
|
@@ -437,20 +338,25 @@ function withAnimus(options) {
|
|
|
437
338
|
};
|
|
438
339
|
};
|
|
439
340
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
341
|
+
function bindTurbopackWatchDeathReport(outcome, rootDir) {
|
|
342
|
+
if (outcome.kind !== "started") return;
|
|
343
|
+
const handle = outcome.handle;
|
|
344
|
+
handle.onDied = () => {
|
|
345
|
+
console.error(`[animus-extract] dev watcher for ${rootDir} died — source edits are no longer extracted; restart the dev server`);
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
let liveTurbopackSession = null;
|
|
446
349
|
async function wireTurbopack(nextConfig, options) {
|
|
447
350
|
const rootDir = process.cwd();
|
|
448
351
|
const session = new _animus_ui_extract_session.ExtractionSession(options);
|
|
352
|
+
liveTurbopackSession?.close();
|
|
353
|
+
liveTurbopackSession = session;
|
|
449
354
|
session.rootDir = rootDir;
|
|
450
|
-
const
|
|
355
|
+
const aliasPairs = (0, _animus_ui_extract_pipeline.readTsconfigAliasPairs)(rootDir);
|
|
356
|
+
const builtAliases = (0, _animus_ui_extract_pipeline.buildPathAliasesJson)(aliasPairs, rootDir);
|
|
451
357
|
if (builtAliases) session.pathAliasesJson = builtAliases.json;
|
|
452
358
|
await (0, _animus_ui_extract_session.runSessionPipeline)(session);
|
|
453
|
-
if (process.env.NODE_ENV === "development") (0, _animus_ui_extract_session.startTurbopackWatcher)(session, rootDir);
|
|
359
|
+
if (process.env.NODE_ENV === "development") bindTurbopackWatchDeathReport((0, _animus_ui_extract_session.startTurbopackWatcher)(session, rootDir), rootDir);
|
|
454
360
|
const fragment = buildTurbopackConfig({
|
|
455
361
|
rootDir,
|
|
456
362
|
loaderPath: resolveTurbopackLoaderPath(__dirname$1),
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,YAAY,EACV,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,eAAe,CAAC"}
|