@pikacss/unplugin-pikacss 0.0.60 → 0.0.61
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.mjs +53 -15
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -75,6 +75,27 @@ const unpluginFactory = (options, meta) => {
|
|
|
75
75
|
...resolvedOptions,
|
|
76
76
|
onDiagnostic
|
|
77
77
|
});
|
|
78
|
+
function currentEngine() {
|
|
79
|
+
try {
|
|
80
|
+
return ctx.engine;
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const configDependencyContents = /* @__PURE__ */ new Map();
|
|
86
|
+
function readFileOrNull(path) {
|
|
87
|
+
try {
|
|
88
|
+
return readFileSync(path, "utf-8");
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function snapshotConfigDependencies() {
|
|
94
|
+
const deps = currentEngine()?.configDependencies;
|
|
95
|
+
if (deps == null) return;
|
|
96
|
+
configDependencyContents.clear();
|
|
97
|
+
for (const dep of deps) configDependencyContents.set(dep, readFileOrNull(dep));
|
|
98
|
+
}
|
|
78
99
|
async function emitTokenReport() {
|
|
79
100
|
const reportFn = ctx.engine.designTokens?.report;
|
|
80
101
|
if (typeof reportFn !== "function") {
|
|
@@ -163,29 +184,32 @@ const unpluginFactory = (options, meta) => {
|
|
|
163
184
|
setupPromise = setupPromise.then(async () => {
|
|
164
185
|
log.debug("Setting up integration context...");
|
|
165
186
|
const moduleIds = Array.from(ctx.usages.keys());
|
|
187
|
+
const previousEngine = currentEngine();
|
|
166
188
|
pendingCssWrite = false;
|
|
167
189
|
pendingTsWrite = false;
|
|
168
190
|
hooksBound = false;
|
|
169
191
|
await ctx.setup();
|
|
170
192
|
lastSetupCwd = ctx.cwd;
|
|
171
193
|
pendingSetupCwd = null;
|
|
194
|
+
const rederived = currentEngine() !== previousEngine;
|
|
195
|
+
if (rederived) snapshotConfigDependencies();
|
|
172
196
|
await debouncedWriteCssCodegenFile();
|
|
173
197
|
await debouncedWriteTsCodegenFile();
|
|
174
198
|
bindHooks();
|
|
175
|
-
if (reload) {
|
|
199
|
+
if (reload && rederived) {
|
|
176
200
|
if (meta.framework === "vite") {
|
|
177
|
-
const promises = [];
|
|
178
201
|
moduleIds.forEach((id) => {
|
|
179
202
|
viteServers.forEach((server) => {
|
|
180
|
-
const mod
|
|
181
|
-
|
|
182
|
-
log.debug(`Invalidating and reloading module: ${id}`);
|
|
203
|
+
for (const mod of collectViteModules(server, id)) {
|
|
204
|
+
log.debug(`Invalidating module: ${mod.url}`);
|
|
183
205
|
server.moduleGraph.invalidateModule(mod);
|
|
184
|
-
promises.push(server.reloadModule(mod));
|
|
185
206
|
}
|
|
186
207
|
});
|
|
187
208
|
});
|
|
188
|
-
|
|
209
|
+
viteServers.forEach((server) => {
|
|
210
|
+
log.debug("Triggering full page reload after engine re-derivation");
|
|
211
|
+
server.hot.send({ type: "full-reload" });
|
|
212
|
+
});
|
|
189
213
|
} else if (meta.framework === "rspack") rspackCompilers.forEach((compiler) => {
|
|
190
214
|
if (compiler.watching == null) return;
|
|
191
215
|
log.debug("Invalidating rspack compiler due to setup changes");
|
|
@@ -310,19 +334,33 @@ const unpluginFactory = (options, meta) => {
|
|
|
310
334
|
}
|
|
311
335
|
return;
|
|
312
336
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (isConfigDependency) {
|
|
318
|
-
log.info(`Config dependency changed: ${id}, reloading...`);
|
|
319
|
-
pendingReload = true;
|
|
320
|
-
debouncedSetup(true);
|
|
337
|
+
if (currentEngine()?.configDependencies?.has(id) !== true) return;
|
|
338
|
+
if (readFileOrNull(id) === configDependencyContents.get(id)) {
|
|
339
|
+
log.debug(`Config dependency touched but unchanged, skipping reload: ${id}`);
|
|
340
|
+
return;
|
|
321
341
|
}
|
|
342
|
+
log.info(`Config dependency changed: ${id}, reloading...`);
|
|
343
|
+
pendingReload = true;
|
|
344
|
+
debouncedSetup(true);
|
|
322
345
|
}
|
|
323
346
|
};
|
|
324
347
|
};
|
|
325
348
|
/**
|
|
349
|
+
* Collects every module graph node that a source file owns.
|
|
350
|
+
* @internal
|
|
351
|
+
*
|
|
352
|
+
* @param server - The Vite dev server whose module graph is queried.
|
|
353
|
+
* @param id - A `ctx.usages` key: an absolute, query-stripped file path.
|
|
354
|
+
* @returns The deduplicated set of modules registered for that file, including query-suffixed variants such as a Vue SFC's `?vue&type=template` node.
|
|
355
|
+
*/
|
|
356
|
+
function collectViteModules(server, id) {
|
|
357
|
+
const modules = /* @__PURE__ */ new Set();
|
|
358
|
+
server.moduleGraph.getModulesByFile(id)?.forEach((mod) => modules.add(mod));
|
|
359
|
+
const byId = server.moduleGraph.getModuleById(id);
|
|
360
|
+
if (byId) modules.add(byId);
|
|
361
|
+
return [...modules];
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
326
364
|
* Pre-built universal bundler plugin for PikaCSS.
|
|
327
365
|
*
|
|
328
366
|
* @remarks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/unplugin-pikacss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.61",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://pikacss.github.io",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"pathe": "^2.0.3",
|
|
95
95
|
"perfect-debounce": "^2.1.0",
|
|
96
96
|
"unplugin": "^3.3.0",
|
|
97
|
-
"@pikacss/integration": "0.0.
|
|
97
|
+
"@pikacss/integration": "0.0.61"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"esbuild": "^0.28.1",
|