@stillwind/integration 0.8.0 → 0.10.0
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/CHANGELOG.md +190 -0
- package/dist/astro/development.d.ts +2 -0
- package/dist/astro/development.js +2 -0
- package/dist/astro/development.js.map +1 -1
- package/dist/astro/index.d.ts +1 -1
- package/dist/astro/index.js +8 -2
- package/dist/astro/index.js.map +1 -1
- package/dist/{emission-BVi5aRbb.js → emission-BpaN4Z4m.js} +212 -69
- package/dist/emission-BpaN4Z4m.js.map +1 -0
- package/dist/fresh/index.d.ts +1 -1
- package/dist/fresh/index.js +1 -1
- package/dist/{index-DFfbZxNT.d.ts → index-B6EtrWus.d.ts} +2 -2
- package/dist/loader-cache-DfOGY8AJ.js +231 -0
- package/dist/loader-cache-DfOGY8AJ.js.map +1 -0
- package/dist/next/css-loader.d.ts +5 -2
- package/dist/next/css-loader.js +7 -2
- package/dist/next/css-loader.js.map +1 -1
- package/dist/next/index.js +2 -0
- package/dist/next/index.js.map +1 -1
- package/dist/{node-loader-D-3Ynpy1.d.ts → node-loader-Bqg7E5zq.d.ts} +6 -3
- package/dist/nuxt/index.d.ts +2 -2
- package/dist/nuxt/index.js +2 -1
- package/dist/nuxt/index.js.map +1 -1
- package/dist/{plugin-aV0zIIAe.d.ts → plugin-BAG0ZI1X.d.ts} +58 -6
- package/dist/{plugin-mPiBLdqa.js → plugin-D-45o54j.js} +5 -2
- package/dist/plugin-D-45o54j.js.map +1 -0
- package/dist/{plugin-ByYcpBcE.js → plugin-DQH8QlYh.js} +331 -36
- package/dist/plugin-DQH8QlYh.js.map +1 -0
- package/dist/{project-DUGu8g_L.d.ts → project-B_KFQist.d.ts} +2 -2
- package/dist/project-egWF2vWJ.js +428 -0
- package/dist/project-egWF2vWJ.js.map +1 -0
- package/dist/{project-BNw0nZBE.d.ts → project-mB7CODIs.d.ts} +46 -7
- package/dist/rsbuild/index.d.ts +4 -1
- package/dist/rsbuild/index.js +2 -2
- package/dist/rsbuild/index.js.map +1 -1
- package/dist/rspack/index.d.ts +1 -1
- package/dist/rspack/index.js +1 -1
- package/dist/session-Cxf4D6oQ.d.ts +163 -0
- package/dist/source-entries-J5azZ_-z.js +350 -0
- package/dist/source-entries-J5azZ_-z.js.map +1 -0
- package/dist/turbopack/css-loader.d.ts +5 -2
- package/dist/turbopack/css-loader.js +53 -17
- package/dist/turbopack/css-loader.js.map +1 -1
- package/dist/turbopack/index.d.ts +2 -2
- package/dist/turbopack/loader.d.ts +3 -2
- package/dist/turbopack/loader.js +10 -4
- package/dist/turbopack/loader.js.map +1 -1
- package/dist/turbopack/node-loader.d.ts +1 -1
- package/dist/turbopack/node-loader.js +1 -0
- package/dist/turbopack/node-loader.js.map +1 -1
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +1 -1
- package/dist/vite/runtime.d.ts +10 -3
- package/dist/vite/runtime.js +8 -1
- package/dist/vite/runtime.js.map +1 -1
- package/dist/webpack/css-loader.js +1 -1
- package/dist/webpack/document-loader.d.ts +4 -1
- package/dist/webpack/document-loader.js +5 -2
- package/dist/webpack/document-loader.js.map +1 -1
- package/dist/webpack/fragment-loader.d.ts +1 -0
- package/dist/webpack/fragment-loader.js +1 -0
- package/dist/webpack/fragment-loader.js.map +1 -1
- package/dist/webpack/index.d.ts +1 -1
- package/dist/webpack/index.js +1 -1
- package/dist/webpack/loader.js +15 -21
- package/dist/webpack/loader.js.map +1 -1
- package/dist/webpack/source-loader.d.ts +1 -0
- package/dist/webpack/source-loader.js +1 -0
- package/dist/webpack/source-loader.js.map +1 -1
- package/package.json +19 -17
- package/dist/binding-files-Ds5NpyVV.js +0 -45
- package/dist/binding-files-Ds5NpyVV.js.map +0 -1
- package/dist/emission-BVi5aRbb.js.map +0 -1
- package/dist/plugin-ByYcpBcE.js.map +0 -1
- package/dist/plugin-mPiBLdqa.js.map +0 -1
- package/dist/project-C3IH7geC.js +0 -182
- package/dist/project-C3IH7geC.js.map +0 -1
- package/dist/session-B9_rp9TH.d.ts +0 -72
- package/dist/session-DHUCQMG5.js +0 -117
- package/dist/session-DHUCQMG5.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { a as buildCompilerOptions, i as SharedTypeFacts, n as isSourceEntry, o as warnSkippedCss, r as IntegrationSession, t as buildSourceEntries } from "./source-entries-J5azZ_-z.js";
|
|
1
2
|
import { a as eachMapping, i as TraceMap, n as addSegment, r as toEncodedMap, t as GenMapping } from "./gen-mapping-D7jFzOEh.js";
|
|
2
|
-
import { n as buildCompilerOptions, r as warnSkippedCss, t as IntegrationSession } from "./session-DHUCQMG5.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
-
import { attachPlugins, cleanModuleId, compilerModuleId, composeFrameworkSourceMap, createStylesheetResolver, cssEntrypoint, cssWithSourceMap, decodeCssSourceMap, fileSourceKind, finalizeCss, finalizeModuleWithMap, isStylesheet, loadCssGraph, moduleSourceMap, nodePluginHost, warnRejectedNames } from "@stillwind/host";
|
|
6
|
-
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
5
|
+
import { attachPlugins, cleanModuleId, compilerModuleId, composeFrameworkSourceMap, createStylesheetResolver, cssEntrypoint, cssWithSourceMap, decodeCssSourceMap, fileSourceKind, finalizeCss, finalizeModuleWithMap, isStylesheet, loadCssGraph, moduleSourceMap, nodePluginHost, resolveTypeFactsEnvironment, tracePhase, warnRejectedNames } from "@stillwind/host";
|
|
6
|
+
import { dirname, extname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
7
7
|
import { readFile, readdir, realpath } from "node:fs/promises";
|
|
8
8
|
import { minifyCss } from "@stillwind/native";
|
|
9
9
|
import { isFileServingAllowed } from "vite";
|
|
@@ -21,6 +21,7 @@ const runtimeId = "\0stillwind:runtime";
|
|
|
21
21
|
const runtimeSpecifier = "virtual:stillwind/runtime";
|
|
22
22
|
/**
|
|
23
23
|
* Derives a compiler identity while retaining the source identity's query or fragment suffix.
|
|
24
|
+
*
|
|
24
25
|
* @param root - Absolute project root used by compilerModuleId.
|
|
25
26
|
* @param id - Full source resolver identity.
|
|
26
27
|
* @returns The compiler identity of the cleaned path followed by its original suffix.
|
|
@@ -74,6 +75,7 @@ function renderChunkStyles(project, name, context, code, chunk, loadSingleStyles
|
|
|
74
75
|
const { manifest, buildCss } = project.buildOutput(name);
|
|
75
76
|
/**
|
|
76
77
|
* Records a stylesheet in the chunk's Vite metadata, creating the metadata when absent.
|
|
78
|
+
*
|
|
77
79
|
* @param file - Emitted asset filename without the public base prefix.
|
|
78
80
|
*/
|
|
79
81
|
const attachCss = (file) => {
|
|
@@ -158,6 +160,7 @@ if (typeof document !== "undefined") {
|
|
|
158
160
|
// src/vite/css-minify.ts
|
|
159
161
|
/**
|
|
160
162
|
* Minifies expanded CSS and reports native parser warnings through the bundler.
|
|
163
|
+
*
|
|
161
164
|
* @param css - Generated CSS with valid resource URLs or resource placeholder tokens.
|
|
162
165
|
* @param settings - Browser targets shared with compiler generation.
|
|
163
166
|
* @param context - Bundler warning reporter.
|
|
@@ -179,6 +182,7 @@ function minifyStylesheet(css, settings, context, sourceMap) {
|
|
|
179
182
|
// src/vite/file-access.ts
|
|
180
183
|
/**
|
|
181
184
|
* Checks both the requested and canonical file before a plugin reads it.
|
|
185
|
+
*
|
|
182
186
|
* @param id - Absolute filesystem identity, optionally with a query or fragment removed for access checks.
|
|
183
187
|
* @param server - Optional development server whose file-serving policy applies to both paths.
|
|
184
188
|
* @returns The canonical absolute path after resolving symlinks.
|
|
@@ -300,6 +304,7 @@ function partitionStylesheet(parts) {
|
|
|
300
304
|
// src/vite/resources.ts
|
|
301
305
|
/**
|
|
302
306
|
* Converts local resource placeholders to escaped Vite filesystem URLs.
|
|
307
|
+
*
|
|
303
308
|
* @param resources - Placeholder records whose files have already passed access checks.
|
|
304
309
|
* @returns A new map of placeholders to JSON-escaped URL contents without surrounding quotes.
|
|
305
310
|
*/
|
|
@@ -308,6 +313,7 @@ function resourceReplacements(resources) {
|
|
|
308
313
|
}
|
|
309
314
|
/**
|
|
310
315
|
* Encodes an absolute file path as a Vite filesystem URL.
|
|
316
|
+
*
|
|
311
317
|
* @param file - Canonical absolute path, using either path separator spelling.
|
|
312
318
|
* @returns An /@fs/ URL with each path segment encoded for use in stylesheet resource requests.
|
|
313
319
|
*/
|
|
@@ -316,6 +322,7 @@ function resourceUrl(file) {
|
|
|
316
322
|
}
|
|
317
323
|
/**
|
|
318
324
|
* Extracts a readable identity from a bundler resolution without checking file existence or access.
|
|
325
|
+
*
|
|
319
326
|
* @param result - Resolution, possibly external or a file URI. Absolute external paths remain readable.
|
|
320
327
|
* @param description - Resource description included in failure messages.
|
|
321
328
|
* @returns The resolved identity, converting file URIs to filesystem paths.
|
|
@@ -329,6 +336,7 @@ function resolvedFile(result, description) {
|
|
|
329
336
|
}
|
|
330
337
|
/**
|
|
331
338
|
* Replaces recorded CSS tokens in map order without further URL escaping.
|
|
339
|
+
*
|
|
332
340
|
* @param css - Generated text containing resource placeholders.
|
|
333
341
|
* @param references - Placeholders mapped to replacement contents already escaped for CSS.
|
|
334
342
|
* @returns Replaced CSS. The supplied map is unchanged.
|
|
@@ -459,6 +467,7 @@ function buildHooks(project) {
|
|
|
459
467
|
// src/vite/http.ts
|
|
460
468
|
/**
|
|
461
469
|
* Ends a response with JSON and disables caching for development snapshots.
|
|
470
|
+
*
|
|
462
471
|
* @param response - Writable response whose status and content-type/cache-control headers are replaced.
|
|
463
472
|
* @param value - Value accepted by JSON.stringify.
|
|
464
473
|
* @param statusCode - HTTP status to send, defaulting to 200.
|
|
@@ -482,7 +491,81 @@ function sendJson(response, value, statusCode = 200) {
|
|
|
482
491
|
*/
|
|
483
492
|
function developmentHooks(project) {
|
|
484
493
|
const { settings, inputs, valueSpecifier, documentPlan, publish, compile } = project;
|
|
494
|
+
/**
|
|
495
|
+
* Compilations of changed files that {@link Plugin.watchChange} started for the next hot update,
|
|
496
|
+
* keyed by file path without a query.
|
|
497
|
+
*/
|
|
498
|
+
const pending = /* @__PURE__ */ new Map();
|
|
499
|
+
/**
|
|
500
|
+
* Compiles a changed producer and the producers that read the changed file as a dependency.
|
|
501
|
+
*
|
|
502
|
+
* @param name - Environment name.
|
|
503
|
+
* @param id - Changed file path without a query.
|
|
504
|
+
* @param type - Vite file event.
|
|
505
|
+
* @param read - Reads the current text of the changed file.
|
|
506
|
+
* @param host - Resolution, watch, and warning operations of the calling hook.
|
|
507
|
+
* @returns The recorded input before the change, the new source and its compilation when the
|
|
508
|
+
* file is a recorded producer, the consumers to check, and their new JavaScript. A consumer
|
|
509
|
+
* whose compilation fails or that is not compiled for the event has no JavaScript.
|
|
510
|
+
* @throws If the compilation of the changed producer fails.
|
|
511
|
+
*/
|
|
512
|
+
const compileChange = async (name, id, type, read, host) => {
|
|
513
|
+
const state = project.environment(name);
|
|
514
|
+
const previous = inputs(name).get(id);
|
|
515
|
+
let consumers = [...inputs(name).values()].filter((input) => !input.manual && input.id !== id && input.sourceDependencies.has(id));
|
|
516
|
+
const source = previous && type !== "delete" ? await read() : void 0;
|
|
517
|
+
const result = source === void 0 ? void 0 : await compile(name, source, id, host);
|
|
518
|
+
if (result !== void 0 && consumers.length > 0 && state.keepsInterface(id)) consumers = [];
|
|
519
|
+
const codes = /* @__PURE__ */ new Map();
|
|
520
|
+
for (const consumer of consumers) {
|
|
521
|
+
let code;
|
|
522
|
+
if (type === "update") try {
|
|
523
|
+
code = (await compile(name, consumer.code, consumer.id, host))?.code;
|
|
524
|
+
} catch {}
|
|
525
|
+
codes.set(consumer.id, code);
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
previous,
|
|
529
|
+
source,
|
|
530
|
+
result,
|
|
531
|
+
consumers,
|
|
532
|
+
codes
|
|
533
|
+
};
|
|
534
|
+
};
|
|
485
535
|
return {
|
|
536
|
+
/**
|
|
537
|
+
* Starts the compilations of a changed file for the next hot update of this environment.
|
|
538
|
+
*
|
|
539
|
+
* Vite runs this hook before it invalidates the modules of the file, and runs the hot update
|
|
540
|
+
* after the modules are invalidated. A request that arrives while a hot update compiles has to
|
|
541
|
+
* transform the invalidated module, and the module runner of an SSR environment can reload
|
|
542
|
+
* while that request still evaluates modules. The request then mixes module instances from
|
|
543
|
+
* before and after the reload. For example, SvelteKit renders a page with a second instance
|
|
544
|
+
* of the Svelte runtime and fails. A request that arrives while this hook compiles still uses
|
|
545
|
+
* the modules from before the change.
|
|
546
|
+
*
|
|
547
|
+
* @param file - Changed file path.
|
|
548
|
+
* @param change - Vite file event. Only `update` events start compilations.
|
|
549
|
+
*/
|
|
550
|
+
async watchChange(file, change) {
|
|
551
|
+
const name = this.environment?.name;
|
|
552
|
+
const server = settings.devServerRef;
|
|
553
|
+
const environment = name === void 0 ? void 0 : server?.environments[name];
|
|
554
|
+
const id = cleanModuleId(file);
|
|
555
|
+
pending.delete(id);
|
|
556
|
+
if (change.event !== "update" || !environment || project.environment(name).designSystem.observes(resolve(file), false)) return;
|
|
557
|
+
const compiled = compileChange(name, id, "update", () => readFile(file, "utf8"), {
|
|
558
|
+
resolve: (specifier, importer, options) => environment.pluginContainer.resolveId(specifier, importer, options),
|
|
559
|
+
addWatchFile: (id) => {
|
|
560
|
+
server?.watcher.add(id);
|
|
561
|
+
},
|
|
562
|
+
warn: (message) => {
|
|
563
|
+
this.warn(message);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
pending.set(id, compiled);
|
|
567
|
+
await compiled.catch(() => {});
|
|
568
|
+
},
|
|
486
569
|
/**
|
|
487
570
|
* Recompiles changed styles and selects JavaScript modules that require hot invalidation.
|
|
488
571
|
*
|
|
@@ -491,9 +574,10 @@ function developmentHooks(project) {
|
|
|
491
574
|
*
|
|
492
575
|
* @param context - Vite hot-update event with the current server, changed file, and source
|
|
493
576
|
* reader.
|
|
494
|
-
* @returns Modules affected by a design-system update,
|
|
495
|
-
*
|
|
496
|
-
*
|
|
577
|
+
* @returns Modules affected by a design-system update, the changed modules together with the
|
|
578
|
+
* producers whose JavaScript changed after an edit of a file that they read as a dependency, an
|
|
579
|
+
* empty list when a producer edit changes only CSS and no request has compiled the edited source
|
|
580
|
+
* yet, or `undefined` to retain normal Vite handling.
|
|
497
581
|
*/
|
|
498
582
|
async hotUpdate(context) {
|
|
499
583
|
const name = this.environment.name;
|
|
@@ -517,11 +601,25 @@ function developmentHooks(project) {
|
|
|
517
601
|
for (const module of modules) this.environment.moduleGraph.invalidateModule(module, /* @__PURE__ */ new Set(), context.timestamp, true);
|
|
518
602
|
return modules;
|
|
519
603
|
}
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
604
|
+
const prepared = context.type === "update" ? pending.get(id) : void 0;
|
|
605
|
+
pending.delete(id);
|
|
606
|
+
const { previous, source, result, consumers, codes } = await (prepared ?? compileChange(name, id, context.type, () => context.read(), host));
|
|
607
|
+
const stale = [];
|
|
608
|
+
for (const consumer of consumers) {
|
|
609
|
+
const module = codes.get(consumer.id) === consumer.javascript ? void 0 : this.environment.moduleGraph.getModuleById(consumer.id);
|
|
610
|
+
if (module) {
|
|
611
|
+
this.environment.moduleGraph.invalidateModule(module, /* @__PURE__ */ new Set(), context.timestamp, true);
|
|
612
|
+
stale.push(module);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (source !== void 0 || consumers.length > 0) try {
|
|
524
616
|
await publish(name, host);
|
|
617
|
+
} catch (error) {
|
|
618
|
+
if (!stale.length) throw error;
|
|
619
|
+
this.warn(`Stillwind update failed; retaining published styles: ${String(error)}`);
|
|
620
|
+
return [.../* @__PURE__ */ new Set([...context.modules, ...stale])];
|
|
621
|
+
}
|
|
622
|
+
if (previous && source !== void 0) {
|
|
525
623
|
const values = [];
|
|
526
624
|
for (const input of inputs(name).values()) {
|
|
527
625
|
if (!input.manual) continue;
|
|
@@ -532,9 +630,14 @@ function developmentHooks(project) {
|
|
|
532
630
|
values.push(value);
|
|
533
631
|
}
|
|
534
632
|
}
|
|
535
|
-
if (values.length) return [.../* @__PURE__ */ new Set([
|
|
633
|
+
if (values.length || stale.length) return [.../* @__PURE__ */ new Set([
|
|
634
|
+
...context.modules,
|
|
635
|
+
...values,
|
|
636
|
+
...stale
|
|
637
|
+
])];
|
|
536
638
|
if (!previous.manual && previous.code !== source && result?.code === previous.javascript) return [];
|
|
537
639
|
}
|
|
640
|
+
if (stale.length) return [.../* @__PURE__ */ new Set([...context.modules, ...stale])];
|
|
538
641
|
} catch (error) {
|
|
539
642
|
this.warn(`Stillwind update failed; retaining published styles: ${String(error)}`);
|
|
540
643
|
}
|
|
@@ -637,6 +740,7 @@ function publicCssSourceMap(sources, map) {
|
|
|
637
740
|
const visible = /* @__PURE__ */ new Map();
|
|
638
741
|
/**
|
|
639
742
|
* Allows a known source inside the project to use a public relative name.
|
|
743
|
+
*
|
|
640
744
|
* @param id - Resolver identity whose query and fragment are removed before checking its path.
|
|
641
745
|
*/
|
|
642
746
|
const add = (id) => {
|
|
@@ -672,6 +776,7 @@ function cssForBrowser(sources, output, replacements) {
|
|
|
672
776
|
const browserTarget = /^(android|chrome|edge|firefox|ie|ios|opera|safari|samsung)(\d+(?:\.\d+){0,2})$/;
|
|
673
777
|
/**
|
|
674
778
|
* Selects browser versions from Vite's resolved CSS target without inferring versions from JS levels.
|
|
779
|
+
*
|
|
675
780
|
* @param target - Resolved CSS target, including disabled targets and language-level strings.
|
|
676
781
|
* @returns A copy of the browser list, or an empty list if any entry cannot identify browser versions.
|
|
677
782
|
*/
|
|
@@ -681,6 +786,7 @@ function inheritCssTarget(target) {
|
|
|
681
786
|
}
|
|
682
787
|
/**
|
|
683
788
|
* Converts Stillwind browser versions to Lightning CSS's packed minimum versions.
|
|
789
|
+
*
|
|
684
790
|
* @param target - Validated compiler targets. Omission and empty lists leave minifier targets unspecified.
|
|
685
791
|
* @returns Browser versions with the oldest entry retained for each browser and ios named ios_saf.
|
|
686
792
|
* @throws If a target cannot be represented by Lightning CSS's three one-byte version components.
|
|
@@ -703,6 +809,7 @@ function minifyTargets(target) {
|
|
|
703
809
|
// src/vite/finalize.ts
|
|
704
810
|
/**
|
|
705
811
|
* Finalizes source while retaining prefix metadata for source-map generation.
|
|
812
|
+
*
|
|
706
813
|
* @param code - Compiled JavaScript before finalization.
|
|
707
814
|
* @param includeStylesheet - Whether to prepend the shared virtual stylesheet import.
|
|
708
815
|
* @returns Final code, the inserted prefix, and host finalization's removed intervals.
|
|
@@ -778,9 +885,17 @@ function isServerOnlyImportError(error) {
|
|
|
778
885
|
* @throws If dependency loading, compilation, or upstream-map reading fails.
|
|
779
886
|
*/
|
|
780
887
|
async function compileProducer(compiler, settings, config, registry, code, id, context, previous) {
|
|
888
|
+
/**
|
|
889
|
+
* Selects the automatic stylesheet import of a producer.
|
|
890
|
+
*
|
|
891
|
+
* @param id - Full Vite identity of the producer.
|
|
892
|
+
* @returns The producer stylesheet module for an SFC with automatic document CSS, or undefined.
|
|
893
|
+
*/
|
|
894
|
+
const stylesheetImports = (id) => /\.(?:astro|svelte|vue)$/.test(cleanModuleId(id)) && config.automatic !== false ? [registry.source("producer", id)] : void 0;
|
|
781
895
|
const sfc = /\.(?:astro|svelte|vue)$/.test(cleanModuleId(id));
|
|
782
896
|
/**
|
|
783
897
|
* Gives a producer a document identity suitable for compiler reports and maps.
|
|
898
|
+
*
|
|
784
899
|
* @param id - Full resolver identity. Queries and fragments are removed from the document name.
|
|
785
900
|
* @returns An encoded `stillwind-virtual:` URI for virtual modules, or a file URL for a file.
|
|
786
901
|
*/
|
|
@@ -788,6 +903,7 @@ async function compileProducer(compiler, settings, config, registry, code, id, c
|
|
|
788
903
|
const clean = cleanModuleId(id);
|
|
789
904
|
return clean.startsWith("\0") || clean.startsWith("virtual:") ? `stillwind-virtual:${encodeURIComponent(clean)}` : pathToFileURL(clean).href;
|
|
790
905
|
};
|
|
906
|
+
const sourceDependencies = /* @__PURE__ */ new Set();
|
|
791
907
|
const output = await compiler.compile(code, id, {
|
|
792
908
|
resolve: (specifier, importer) => resolveServerSource((specifier, importer, options) => context.resolve(specifier, importer, options), specifier, importer),
|
|
793
909
|
read: (id) => readFile(cleanModuleId(id), "utf8"),
|
|
@@ -795,25 +911,28 @@ async function compileProducer(compiler, settings, config, registry, code, id, c
|
|
|
795
911
|
const virtual = resolvedId.startsWith("\0") || resolvedId.startsWith("virtual:");
|
|
796
912
|
const file = virtual ? resolve(settings.projectRoot, ".stillwind-checker", `${createHash("sha256").update(resolvedId).digest("hex")}.ts`) : cleanModuleId(resolvedId);
|
|
797
913
|
const { syntax, format } = fileSourceKind(resolvedId);
|
|
914
|
+
const checkerFile = virtual || file === resolvedId ? file : `${file}.stillwind-${createHash("sha256").update(resolvedId).digest("hex").slice(0, 16)}${extname(file)}`;
|
|
798
915
|
return {
|
|
799
916
|
moduleId: virtual ? `virtual:${encodeURIComponent(resolvedId)}` : sourceModuleId(settings.projectRoot, resolvedId),
|
|
800
917
|
document: {
|
|
801
918
|
uri: documentUri(resolvedId),
|
|
802
919
|
format
|
|
803
920
|
},
|
|
804
|
-
checkerFileName:
|
|
921
|
+
checkerFileName: checkerFile,
|
|
805
922
|
projectionFileName: file.replaceAll("\\", "/"),
|
|
806
923
|
syntax
|
|
807
924
|
};
|
|
808
925
|
},
|
|
809
926
|
watch: (id) => {
|
|
810
|
-
|
|
927
|
+
sourceDependencies.add(cleanModuleId(id));
|
|
928
|
+
if (!settings.watching) context.addWatchFile(id);
|
|
811
929
|
},
|
|
812
930
|
warn: (message) => {
|
|
813
931
|
context.warn(message);
|
|
814
|
-
}
|
|
932
|
+
},
|
|
933
|
+
stylesheetImports
|
|
815
934
|
}, {
|
|
816
|
-
stylesheetImports:
|
|
935
|
+
stylesheetImports: stylesheetImports(id),
|
|
817
936
|
moduleCssImport: registry.source("value", id)
|
|
818
937
|
});
|
|
819
938
|
if (!output?.code) return;
|
|
@@ -840,7 +959,8 @@ async function compileProducer(compiler, settings, config, registry, code, id, c
|
|
|
840
959
|
manual: output.hasModuleCssImport || config.automatic === false,
|
|
841
960
|
hasModuleCssImport: output.hasModuleCssImport,
|
|
842
961
|
javascript,
|
|
843
|
-
dependencies: output.compositionModules
|
|
962
|
+
dependencies: output.compositionModules,
|
|
963
|
+
sourceDependencies
|
|
844
964
|
},
|
|
845
965
|
result: {
|
|
846
966
|
code: javascript,
|
|
@@ -861,6 +981,8 @@ async function compileProducer(compiler, settings, config, registry, code, id, c
|
|
|
861
981
|
var DesignSystem = class {
|
|
862
982
|
settings;
|
|
863
983
|
config;
|
|
984
|
+
name;
|
|
985
|
+
shared;
|
|
864
986
|
/** Compiler session retained across CSS reloads and replaced when initialization restarts. */
|
|
865
987
|
#compiler;
|
|
866
988
|
/** Plugin runtime of the applied design system, kept as the previous runtime of reloads. */
|
|
@@ -903,10 +1025,15 @@ var DesignSystem = class {
|
|
|
903
1025
|
*
|
|
904
1026
|
* @param settings - Shared project settings configured before initialization.
|
|
905
1027
|
* @param config - Compiler options that identify the CSS entrypoint.
|
|
1028
|
+
* @param name - Vite environment name, used as the resolver domain in shared type facts.
|
|
1029
|
+
* @param shared - Returns type facts shared with the other environments of the project. Each
|
|
1030
|
+
* new compiler session calls it once.
|
|
906
1031
|
*/
|
|
907
|
-
constructor(settings, config) {
|
|
1032
|
+
constructor(settings, config, name, shared) {
|
|
908
1033
|
this.settings = settings;
|
|
909
1034
|
this.config = config;
|
|
1035
|
+
this.name = name;
|
|
1036
|
+
this.shared = shared;
|
|
910
1037
|
}
|
|
911
1038
|
/**
|
|
912
1039
|
* Obtains the initialized compiler session.
|
|
@@ -952,13 +1079,15 @@ var DesignSystem = class {
|
|
|
952
1079
|
return this.cssObservedFiles.has(file) || entry && this.cssObservedDirectories.has(dirname(file));
|
|
953
1080
|
}
|
|
954
1081
|
/**
|
|
955
|
-
* Marks a design-system revision pending when an observed file changes
|
|
1082
|
+
* Marks a design-system revision pending when an observed file changes, and discards the
|
|
1083
|
+
* compiler's shared sources and facts for any changed file.
|
|
956
1084
|
*
|
|
957
1085
|
* @param file - Absolute path of the changed file. Paths that {@link DesignSystem.observes}
|
|
958
|
-
* rejects
|
|
1086
|
+
* rejects do not mark a revision pending.
|
|
959
1087
|
* @param entry - Whether the event adds or removes the file.
|
|
960
1088
|
*/
|
|
961
1089
|
changed(file, entry) {
|
|
1090
|
+
this.#compiler?.sourceChanged(file, entry);
|
|
962
1091
|
if (this.observes(file, entry)) this.cssChange++;
|
|
963
1092
|
}
|
|
964
1093
|
/**
|
|
@@ -985,7 +1114,7 @@ var DesignSystem = class {
|
|
|
985
1114
|
const version = this.settings.watching && !this.settings.cssWatching ? await designSystemVersion(loaded.dependencies, loaded.directories) : void 0;
|
|
986
1115
|
if (this.settings.cssWatching && change !== this.cssChange) continue;
|
|
987
1116
|
this.#compiler?.close();
|
|
988
|
-
this.#compiler = new IntegrationSession(this.settings.projectRoot, loaded.loader, this.config, this.settings.watching, this.settings.compilerMode, loaded.plugins);
|
|
1117
|
+
this.#compiler = new IntegrationSession(this.settings.projectRoot, loaded.loader, this.config, this.settings.watching, this.settings.compilerMode, loaded.plugins, this.settings.fixedEntries, this.settings.watching && this.settings.cssWatching ? this.settings.entries : void 0, this.shared?.(), this.name);
|
|
989
1118
|
this.#plugins = loaded.plugins;
|
|
990
1119
|
this.#initialized = true;
|
|
991
1120
|
this.resources = loaded.resources;
|
|
@@ -1125,6 +1254,7 @@ async function loadDesignSystem(settings, config, resolveImport, dependencies, s
|
|
|
1125
1254
|
const root = realpathSync(entry);
|
|
1126
1255
|
/**
|
|
1127
1256
|
* Watches relative candidates before resolution and the resolved file after success.
|
|
1257
|
+
*
|
|
1128
1258
|
* @param specifier - CSS import or resource request passed to the configured resolver.
|
|
1129
1259
|
* @param importer - Full identity of the source containing the request.
|
|
1130
1260
|
* @returns The resolver's identity with its query and fragment retained.
|
|
@@ -1225,7 +1355,9 @@ async function designSystemVersion(files, directories) {
|
|
|
1225
1355
|
return hash.digest("hex");
|
|
1226
1356
|
}
|
|
1227
1357
|
// src/vite/module-registry.ts
|
|
1228
|
-
/**
|
|
1358
|
+
/**
|
|
1359
|
+
* References issued by one project environment. Unknown IDs never supply file paths.
|
|
1360
|
+
*/
|
|
1229
1361
|
var ModuleRegistry = class {
|
|
1230
1362
|
root;
|
|
1231
1363
|
environment;
|
|
@@ -1235,6 +1367,7 @@ var ModuleRegistry = class {
|
|
|
1235
1367
|
#projections = /* @__PURE__ */ new Map();
|
|
1236
1368
|
/**
|
|
1237
1369
|
* Creates an empty registry for one project environment.
|
|
1370
|
+
*
|
|
1238
1371
|
* @param root - Project root used to derive compiler identities from source resolver identities.
|
|
1239
1372
|
* @param environment - Environment name included in every issued reference's fingerprint.
|
|
1240
1373
|
*/
|
|
@@ -1244,6 +1377,7 @@ var ModuleRegistry = class {
|
|
|
1244
1377
|
}
|
|
1245
1378
|
/**
|
|
1246
1379
|
* Issues a deterministic reference. Identical fragments reuse their fixed payloads.
|
|
1380
|
+
*
|
|
1247
1381
|
* @param kind - Reference family included in the virtual prefix and fingerprint.
|
|
1248
1382
|
* @param key - Source identity or serialized fragment content used within that family.
|
|
1249
1383
|
* @param entry - Owned payload fixed under the resulting identity.
|
|
@@ -1261,6 +1395,7 @@ var ModuleRegistry = class {
|
|
|
1261
1395
|
}
|
|
1262
1396
|
/**
|
|
1263
1397
|
* Registers a source-backed generated module.
|
|
1398
|
+
*
|
|
1264
1399
|
* @param kind - CSS value, projection, or producer registration module family.
|
|
1265
1400
|
* @param sourceId - Full resolver identity, including queries that select distinct source.
|
|
1266
1401
|
* @returns A deterministic reference for that environment, family, and compiler module identity.
|
|
@@ -1275,6 +1410,7 @@ var ModuleRegistry = class {
|
|
|
1275
1410
|
}
|
|
1276
1411
|
/**
|
|
1277
1412
|
* Registers CSS with only the resource records whose placeholders occur in it.
|
|
1413
|
+
*
|
|
1278
1414
|
* @param css - Generated fragment text before resource replacement.
|
|
1279
1415
|
* @param resources - Available placeholder records. The supplied map is unchanged.
|
|
1280
1416
|
* @returns A reference fingerprinted from CSS and selected records in map order.
|
|
@@ -1293,6 +1429,7 @@ var ModuleRegistry = class {
|
|
|
1293
1429
|
}
|
|
1294
1430
|
/**
|
|
1295
1431
|
* Looks up an issued public or resolved virtual reference.
|
|
1432
|
+
*
|
|
1296
1433
|
* @param id - virtual:stillwind identity or its NUL-prefixed resolved spelling.
|
|
1297
1434
|
* @returns The retained payload, or undefined for an unregistered identity.
|
|
1298
1435
|
*/
|
|
@@ -1301,6 +1438,7 @@ var ModuleRegistry = class {
|
|
|
1301
1438
|
}
|
|
1302
1439
|
/**
|
|
1303
1440
|
* Replaces an importer's projection edges and removes previous references with no remaining owner.
|
|
1441
|
+
*
|
|
1304
1442
|
* @param importer - Full resolver identity of the original importing document.
|
|
1305
1443
|
* @param sources - Authored projection specifiers mapped to resolved source identities. The map is copied.
|
|
1306
1444
|
*/
|
|
@@ -1311,6 +1449,7 @@ var ModuleRegistry = class {
|
|
|
1311
1449
|
}
|
|
1312
1450
|
/**
|
|
1313
1451
|
* Resolves a projection only through an importer's previously registered edge.
|
|
1452
|
+
*
|
|
1314
1453
|
* @param specifier - Authored projection request, including ?stillwind.css.
|
|
1315
1454
|
* @param importer - Full importer identity. Omission cannot select an edge.
|
|
1316
1455
|
* @returns The issued reference, or undefined when no corresponding edge exists.
|
|
@@ -1320,12 +1459,14 @@ var ModuleRegistry = class {
|
|
|
1320
1459
|
}
|
|
1321
1460
|
/**
|
|
1322
1461
|
* Removes source-backed references and projection edges after source removal.
|
|
1462
|
+
*
|
|
1323
1463
|
* @param sourceId - Full resolver identity to remove.
|
|
1324
1464
|
* @param file - Whether to match all queries and fragments of the cleaned file identity.
|
|
1325
1465
|
*/
|
|
1326
1466
|
remove(sourceId, file = false) {
|
|
1327
1467
|
/**
|
|
1328
1468
|
* Applies the selected source-removal policy to a registered identity.
|
|
1469
|
+
*
|
|
1329
1470
|
* @param id - Full resolver identity from a source entry or projection importer.
|
|
1330
1471
|
* @returns Whether the exact identity, or its cleaned file identity when requested, matches.
|
|
1331
1472
|
*/
|
|
@@ -1362,7 +1503,7 @@ var ModuleRegistry = class {
|
|
|
1362
1503
|
* resolved or read.
|
|
1363
1504
|
*/
|
|
1364
1505
|
async function resolveStylesheet(designSystem, settings, sources, revision, modules, context, complete = false) {
|
|
1365
|
-
const plan = designSystem.compiler.native.planStylesheet({
|
|
1506
|
+
const plan = tracePhase("stylesheet-plan", modules.length, () => designSystem.compiler.native.planStylesheet({
|
|
1366
1507
|
modules,
|
|
1367
1508
|
coverage: complete ? {
|
|
1368
1509
|
kind: "complete",
|
|
@@ -1370,7 +1511,7 @@ async function resolveStylesheet(designSystem, settings, sources, revision, modu
|
|
|
1370
1511
|
revision: String(revision)
|
|
1371
1512
|
} : { kind: "observed" },
|
|
1372
1513
|
placement: "document"
|
|
1373
|
-
}, settings.watching ? settings.devSourceMaps : settings.sourceMaps);
|
|
1514
|
+
}, settings.watching ? settings.devSourceMaps : settings.sourceMaps));
|
|
1374
1515
|
warnRejectedNames(plan.rejectedNames, (message) => context.warn(message));
|
|
1375
1516
|
const resources = new Map(designSystem.resources);
|
|
1376
1517
|
for (const resource of plan.resources) {
|
|
@@ -1447,13 +1588,14 @@ var ViteEnvironment = class {
|
|
|
1447
1588
|
* @param config - Compiler options shared by the project.
|
|
1448
1589
|
* @param invalidate - Invalidates Vite source identities whose JavaScript changes after a
|
|
1449
1590
|
* design-system reload.
|
|
1591
|
+
* @param shared - Returns type facts shared with the other environments of the project.
|
|
1450
1592
|
*/
|
|
1451
|
-
constructor(name, settings, config, invalidate) {
|
|
1593
|
+
constructor(name, settings, config, invalidate, shared) {
|
|
1452
1594
|
this.name = name;
|
|
1453
1595
|
this.settings = settings;
|
|
1454
1596
|
this.config = config;
|
|
1455
1597
|
this.invalidate = invalidate;
|
|
1456
|
-
this.#designSystem = new DesignSystem(settings, config);
|
|
1598
|
+
this.#designSystem = new DesignSystem(settings, config, name, shared);
|
|
1457
1599
|
}
|
|
1458
1600
|
/**
|
|
1459
1601
|
* Exposes design-system reload progress without allowing callers to replace its state.
|
|
@@ -1504,6 +1646,19 @@ var ViteEnvironment = class {
|
|
|
1504
1646
|
this.#designSystem.changed(file, entry);
|
|
1505
1647
|
}
|
|
1506
1648
|
/**
|
|
1649
|
+
* Tests whether a changed file exposes the same exports to other producers as before the change.
|
|
1650
|
+
*
|
|
1651
|
+
* @param file - Resolver identity of a file that {@link changed} received with `entry` false and
|
|
1652
|
+
* that a producer compilation prepared again since then.
|
|
1653
|
+
* @returns False when the compiler is not initialized, no producer imports the file, or the
|
|
1654
|
+
* exports cannot be compared. True means that compiling the importing producers again gives the
|
|
1655
|
+
* same JavaScript and CSS.
|
|
1656
|
+
* @throws If checker input installation fails.
|
|
1657
|
+
*/
|
|
1658
|
+
keepsInterface(file) {
|
|
1659
|
+
return this.#designSystem.initialized && this.#designSystem.compiler.keepsInterface(file);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1507
1662
|
* Closes the environment's type-facts service while retaining native compiler state and producer
|
|
1508
1663
|
* inputs.
|
|
1509
1664
|
*/
|
|
@@ -1537,6 +1692,7 @@ var ViteEnvironment = class {
|
|
|
1537
1692
|
await this.#designSystem.ensure(context, () => {
|
|
1538
1693
|
this.revision++;
|
|
1539
1694
|
});
|
|
1695
|
+
if (this.settings.watching) this.#designSystem.compiler.startChecker();
|
|
1540
1696
|
});
|
|
1541
1697
|
}
|
|
1542
1698
|
/**
|
|
@@ -1730,6 +1886,16 @@ var ViteEnvironment = class {
|
|
|
1730
1886
|
});
|
|
1731
1887
|
}
|
|
1732
1888
|
/**
|
|
1889
|
+
* Advances the publication revision without planning a stylesheet.
|
|
1890
|
+
*
|
|
1891
|
+
* A producer module embeds the revision when it loads and requests a snapshot when its document
|
|
1892
|
+
* holds an older one. Call this after a compilation whose snapshot is delivered later, so that
|
|
1893
|
+
* producers loaded in between request a snapshot that includes the compilation.
|
|
1894
|
+
*/
|
|
1895
|
+
advance() {
|
|
1896
|
+
this.revision++;
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1733
1899
|
* Advances the publication revision and delivers a current document stylesheet snapshot.
|
|
1734
1900
|
*
|
|
1735
1901
|
* The operation is serialized with compilation. A planning failure rejects before the callback is
|
|
@@ -1832,6 +1998,23 @@ var ViteEnvironment = class {
|
|
|
1832
1998
|
};
|
|
1833
1999
|
// src/vite/project.ts
|
|
1834
2000
|
/**
|
|
2001
|
+
* Milliseconds without another compilation before a delayed development publication plans the
|
|
2002
|
+
* stylesheet.
|
|
2003
|
+
*/
|
|
2004
|
+
const PUBLISH_DELAY = 20;
|
|
2005
|
+
/**
|
|
2006
|
+
* Lists the source files that the build inputs name.
|
|
2007
|
+
*
|
|
2008
|
+
* @param config - Resolved build configuration.
|
|
2009
|
+
* @returns Absolute script and component paths from the top-level and environment inputs, without
|
|
2010
|
+
* queries and duplicates. Virtual and relative inputs are left out.
|
|
2011
|
+
*/
|
|
2012
|
+
function buildEntries(config) {
|
|
2013
|
+
const input = (build) => (build?.rolldownOptions ?? build?.rollupOptions)?.input;
|
|
2014
|
+
const inputs = [input(config.build), ...Object.values(config.environments).map((environment) => input(environment.build))];
|
|
2015
|
+
return [...new Set(inputs.flatMap((input) => typeof input === "string" ? [input] : Array.isArray(input) ? input : Object.values(input ?? {})).map(cleanModuleId).filter((id) => isAbsolute(id) && isSourceEntry(id)))];
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
1835
2018
|
* Creates project state shared by compiler, development, and build plugins.
|
|
1836
2019
|
*
|
|
1837
2020
|
* Call `configure` before environment initialization, then `attachServer` when serving. Close the
|
|
@@ -1848,6 +2031,7 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1848
2031
|
watching: false,
|
|
1849
2032
|
cssWatching: false,
|
|
1850
2033
|
compilerMode: "release",
|
|
2034
|
+
entries: [],
|
|
1851
2035
|
projectRoot: "",
|
|
1852
2036
|
assetsDirectory: "assets",
|
|
1853
2037
|
publicBase: "/",
|
|
@@ -1868,9 +2052,18 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1868
2052
|
const documentStylesheets = /* @__PURE__ */ new Map();
|
|
1869
2053
|
/** CSS of the latest publication that refreshed document stylesheets, keyed by environment name. */
|
|
1870
2054
|
const publishedDocumentCss = /* @__PURE__ */ new Map();
|
|
2055
|
+
/** Delayed publications keyed by environment name, with the time of their first request. */
|
|
2056
|
+
const delayedPublications = /* @__PURE__ */ new Map();
|
|
1871
2057
|
let bindings = /* @__PURE__ */ new WeakMap();
|
|
1872
2058
|
/**
|
|
2059
|
+
* Type facts that the environments share while they resolve imports alike. Configuration
|
|
2060
|
+
* replaces it because the TypeScript settings may change.
|
|
2061
|
+
*/
|
|
2062
|
+
let sharedTypeFacts;
|
|
2063
|
+
const shareTypeFacts = () => sharedTypeFacts ??= new SharedTypeFacts(resolveTypeFactsEnvironment(settings.projectRoot, config.tsconfig));
|
|
2064
|
+
/**
|
|
1873
2065
|
* Gets or creates the compiler state owned by one Vite environment.
|
|
2066
|
+
*
|
|
1874
2067
|
* @param owner - Owning Vite instance, or a name selecting the current state. Omission selects `client`.
|
|
1875
2068
|
* @returns The retained environment state. Newly created non-client states invalidate their
|
|
1876
2069
|
* affected modules in the corresponding development module graph.
|
|
@@ -1883,7 +2076,7 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1883
2076
|
if (name === "client") return;
|
|
1884
2077
|
const graph = settings.devServerRef?.environments[name]?.moduleGraph;
|
|
1885
2078
|
for (const id of ids) for (const module of graph?.getModulesByFile(cleanModuleId(id)) ?? []) graph.invalidateModule(module);
|
|
1886
|
-
});
|
|
2079
|
+
}, shareTypeFacts);
|
|
1887
2080
|
environments.set(name, state);
|
|
1888
2081
|
if (typeof owner !== "string") bindings.set(owner, state);
|
|
1889
2082
|
}
|
|
@@ -1898,6 +2091,7 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1898
2091
|
/** Releases checker services in all currently retained compiler environments. */
|
|
1899
2092
|
const closeTypeFacts = () => {
|
|
1900
2093
|
for (const state of environments.values()) state.closeTypeFacts();
|
|
2094
|
+
sharedTypeFacts?.close();
|
|
1901
2095
|
};
|
|
1902
2096
|
/**
|
|
1903
2097
|
* Replaces compiler environments and applied settings after resolving project configuration.
|
|
@@ -1912,6 +2106,8 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1912
2106
|
const cssTarget = viteConfig.environments.client?.build.cssTarget ?? viteConfig.build.cssTarget;
|
|
1913
2107
|
const resolved = await resolveIntegrationConfig(inline, applicationRoot() ?? viteConfig.root, { target: inheritCssTarget(cssTarget) });
|
|
1914
2108
|
for (const state of environments.values()) state.close();
|
|
2109
|
+
sharedTypeFacts?.close();
|
|
2110
|
+
sharedTypeFacts = void 0;
|
|
1915
2111
|
environments.clear();
|
|
1916
2112
|
bindings = /* @__PURE__ */ new WeakMap();
|
|
1917
2113
|
for (const key of Object.keys(config)) delete config[key];
|
|
@@ -1931,11 +2127,14 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1931
2127
|
settings.cssTargets = settings.minifyCss ? minifyTargets(config.target) : void 0;
|
|
1932
2128
|
settings.watching = viteConfig.command === "serve";
|
|
1933
2129
|
settings.compilerMode = settings.watching ? "development" : "release";
|
|
2130
|
+
settings.entries = buildEntries(viteConfig);
|
|
2131
|
+
settings.fixedEntries = settings.watching || viteConfig.build.watch ? void 0 : await buildSourceEntries(settings.entries, resolved.scope);
|
|
1934
2132
|
};
|
|
1935
2133
|
/** Detaches the current server's change listeners and closes its configuration discovery watchers. */
|
|
1936
2134
|
let stopCssWatching = () => {};
|
|
1937
2135
|
/**
|
|
1938
2136
|
* Replaces server watch registrations and retains the server for module invalidation and HMR.
|
|
2137
|
+
*
|
|
1939
2138
|
* @param server - Configured development server. A null watch setting disables these watches.
|
|
1940
2139
|
* @throws If a missing configuration's parent directory cannot be watched.
|
|
1941
2140
|
*/
|
|
@@ -1946,6 +2145,7 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1946
2145
|
if (!settings.cssWatching) return;
|
|
1947
2146
|
/**
|
|
1948
2147
|
* Restarts on configuration changes or invalidates affected compiler environments.
|
|
2148
|
+
*
|
|
1949
2149
|
* @param event - Watch event. Only `add`, `change`, and `unlink` are handled.
|
|
1950
2150
|
* @param file - Changed filesystem path, normalized before dependency lookup.
|
|
1951
2151
|
*/
|
|
@@ -1976,12 +2176,19 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1976
2176
|
/** Detaches server listeners, closes discovery watchers, and closes every retained compiler environment. */
|
|
1977
2177
|
const close = () => {
|
|
1978
2178
|
stopCssWatching();
|
|
2179
|
+
for (const { timer, done } of delayedPublications.values()) {
|
|
2180
|
+
clearTimeout(timer);
|
|
2181
|
+
done.resolve();
|
|
2182
|
+
}
|
|
2183
|
+
delayedPublications.clear();
|
|
1979
2184
|
documentStylesheets.clear();
|
|
1980
2185
|
publishedDocumentCss.clear();
|
|
1981
2186
|
for (const state of environments.values()) state.close();
|
|
2187
|
+
sharedTypeFacts?.close();
|
|
1982
2188
|
};
|
|
1983
2189
|
/**
|
|
1984
2190
|
* Publishes a CSS snapshot through the matching environment's HMR channel when serving.
|
|
2191
|
+
*
|
|
1985
2192
|
* @param name - Vite environment name, or undefined for `client`.
|
|
1986
2193
|
* @param context - Resolver and watch operations used to refresh the environment's CSS.
|
|
1987
2194
|
* @returns A promise that resolves after publication, or immediately when no active server exists.
|
|
@@ -2014,6 +2221,42 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
2014
2221
|
});
|
|
2015
2222
|
});
|
|
2016
2223
|
};
|
|
2224
|
+
const publishSoon = (name) => {
|
|
2225
|
+
const server = settings.devServerRef;
|
|
2226
|
+
if (!settings.watching || !server) return;
|
|
2227
|
+
const environmentName = name ?? "client";
|
|
2228
|
+
environment(name).advance();
|
|
2229
|
+
const now = performance.now();
|
|
2230
|
+
const pending = delayedPublications.get(environmentName);
|
|
2231
|
+
if (pending) clearTimeout(pending.timer);
|
|
2232
|
+
const first = pending?.first ?? now;
|
|
2233
|
+
const done = pending?.done ?? Promise.withResolvers();
|
|
2234
|
+
const run = async () => {
|
|
2235
|
+
delayedPublications.delete(environmentName);
|
|
2236
|
+
const target = server.environments[environmentName];
|
|
2237
|
+
try {
|
|
2238
|
+
if (!target || server.ws.clients.size === 0) return;
|
|
2239
|
+
await publish(name, {
|
|
2240
|
+
resolve: (specifier, importer, options) => target.pluginContainer.resolveId(specifier, importer, options),
|
|
2241
|
+
addWatchFile: (id) => {
|
|
2242
|
+
server.watcher.add(id);
|
|
2243
|
+
},
|
|
2244
|
+
warn: (message) => {
|
|
2245
|
+
server.config.logger.warn(message);
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
} catch (error) {
|
|
2249
|
+
server.config.logger.warn(`Stillwind update failed; retaining published styles: ${String(error)}`);
|
|
2250
|
+
} finally {
|
|
2251
|
+
done.resolve();
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
delayedPublications.set(environmentName, {
|
|
2255
|
+
timer: setTimeout(run, Math.max(0, Math.min(PUBLISH_DELAY, first + 200 - now))),
|
|
2256
|
+
first,
|
|
2257
|
+
done
|
|
2258
|
+
});
|
|
2259
|
+
};
|
|
2017
2260
|
const project = {
|
|
2018
2261
|
forConfig: (viteConfig) => {
|
|
2019
2262
|
let generation = generations.get(viteConfig);
|
|
@@ -2049,6 +2292,8 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
2049
2292
|
documentPlan: (name, context, complete = false, selection) => environment(name).documentPlan(context, complete, selection),
|
|
2050
2293
|
snapshot: (name, context) => environment(name).snapshot(context),
|
|
2051
2294
|
publish,
|
|
2295
|
+
publishSoon,
|
|
2296
|
+
publications: (name) => delayedPublications.get(name ?? "client")?.done.promise ?? Promise.resolve(),
|
|
2052
2297
|
observeDocumentStylesheet: (name, url) => {
|
|
2053
2298
|
let urls = documentStylesheets.get(name);
|
|
2054
2299
|
if (!urls) {
|
|
@@ -2066,9 +2311,33 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
2066
2311
|
};
|
|
2067
2312
|
return project;
|
|
2068
2313
|
}
|
|
2314
|
+
// src/vite/react-router.ts
|
|
2315
|
+
/**
|
|
2316
|
+
* Identifies React Router's child compiler that transforms routes only to read export names.
|
|
2317
|
+
*
|
|
2318
|
+
* @param config - Resolved configuration of the compiler that owns the hook.
|
|
2319
|
+
* @returns True for the child compiler with React Router's route plugins and without its main
|
|
2320
|
+
* plugin, in both development and builds. The child does not generate application JavaScript or
|
|
2321
|
+
* CSS.
|
|
2322
|
+
*/
|
|
2323
|
+
function isReactRouterExportScan(config) {
|
|
2324
|
+
return config.command === "serve" && config.plugins.some((plugin) => plugin.name === "react-router:virtual-modules") && !config.plugins.some((plugin) => plugin.name === "react-router");
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Identifies a client route module that React Router replaces with re-exports of its route file.
|
|
2328
|
+
*
|
|
2329
|
+
* @param id - Full Vite identity of the module.
|
|
2330
|
+
* @param config - Resolved configuration of the environment that transforms the module.
|
|
2331
|
+
* @returns True when React Router's build plugin selects the module through its query. Its later
|
|
2332
|
+
* transform discards the code of the earlier transforms, and the route file supplies the styles.
|
|
2333
|
+
*/
|
|
2334
|
+
function isReactRouterClientRoute(id, config) {
|
|
2335
|
+
return id.endsWith("?__react-router-build-client-route") && config.plugins.some((plugin) => plugin.name === "react-router:build-client-route");
|
|
2336
|
+
}
|
|
2069
2337
|
// src/vite/projection-imports.ts
|
|
2070
2338
|
/**
|
|
2071
2339
|
* Finds literal projection imports in a source document without evaluating its code.
|
|
2340
|
+
*
|
|
2072
2341
|
* @param code - Original source, optionally in a supported component format.
|
|
2073
2342
|
* @param id - Full source identity whose cleaned path determines the frontend and parser language.
|
|
2074
2343
|
* @returns Distinct static and literal dynamic requests ending in ?stillwind.css, in traversal order.
|
|
@@ -2100,6 +2369,7 @@ async function projectionImports(code, id) {
|
|
|
2100
2369
|
const imports = /* @__PURE__ */ new Set();
|
|
2101
2370
|
/**
|
|
2102
2371
|
* Collects literal projection requests while traversing enumerable AST fields.
|
|
2372
|
+
*
|
|
2103
2373
|
* @param node - Parser AST node or child value. Primitive values are skipped.
|
|
2104
2374
|
*/
|
|
2105
2375
|
const visit = (node) => {
|
|
@@ -2122,8 +2392,8 @@ const warnedEntrypointImports = /* @__PURE__ */ new WeakSet();
|
|
|
2122
2392
|
/**
|
|
2123
2393
|
* Creates source transform and watch hooks for the project compiler plugin.
|
|
2124
2394
|
*
|
|
2125
|
-
* Development
|
|
2126
|
-
* Vite hook context.
|
|
2395
|
+
* Development compilations advance the CSS revision and publish one snapshot after a burst of
|
|
2396
|
+
* compilations. Invalid projection imports fail through the Vite hook context.
|
|
2127
2397
|
*
|
|
2128
2398
|
* @param project - Project configured and initialized by the compiler plugin.
|
|
2129
2399
|
* @param virtualModules - Virtual module hooks for the same project, used to reload cached
|
|
@@ -2134,11 +2404,12 @@ const warnedEntrypointImports = /* @__PURE__ */ new WeakSet();
|
|
|
2134
2404
|
* configured CSS entrypoint is imported as an ordinary stylesheet.
|
|
2135
2405
|
*/
|
|
2136
2406
|
function transformHooks(project, virtualModules, options = {}) {
|
|
2137
|
-
const { settings, publish, compile } = project;
|
|
2407
|
+
const { settings, publish, publishSoon, compile } = project;
|
|
2138
2408
|
const cachedVirtualModules = /* @__PURE__ */ new Map();
|
|
2139
2409
|
return {
|
|
2140
2410
|
/**
|
|
2141
2411
|
* Selects cached modules that need current compiler state and records virtual modules for reloading.
|
|
2412
|
+
*
|
|
2142
2413
|
* @param module - Cached module descriptor whose id includes any source query.
|
|
2143
2414
|
* @returns Whether to rerun transformation for Stillwind virtual modules or supported application sources.
|
|
2144
2415
|
*/
|
|
@@ -2157,6 +2428,7 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2157
2428
|
},
|
|
2158
2429
|
/**
|
|
2159
2430
|
* Invalidates changed configuration or removes deleted source state and publishes resulting CSS.
|
|
2431
|
+
*
|
|
2160
2432
|
* @param id - Watched filesystem identity.
|
|
2161
2433
|
* @param change - Vite event. Source removal is performed only for delete events.
|
|
2162
2434
|
* @returns Completion of removal and publication when required.
|
|
@@ -2172,6 +2444,7 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2172
2444
|
order: options.order === "normal" ? void 0 : "pre",
|
|
2173
2445
|
/**
|
|
2174
2446
|
* Reserves authored CSS names, registers source projections, and compiles supported producers.
|
|
2447
|
+
*
|
|
2175
2448
|
* @param code - Source after earlier transforms in the configured order.
|
|
2176
2449
|
* @param id - Full Vite identity, including queries that select distinct source.
|
|
2177
2450
|
* @returns Compiler output, a reloaded virtual module, or undefined when no transformed source is needed.
|
|
@@ -2191,7 +2464,7 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2191
2464
|
await project.environment(name).reserveAuthoredCss(id, code, this);
|
|
2192
2465
|
return;
|
|
2193
2466
|
}
|
|
2194
|
-
if (!/\.(?:[cm]?[jt]sx?|astro|svelte|vue)$/.test(cleanModuleId(id)) || id.includes("node_modules") || id.startsWith("\0") || /[?&](?:raw|url|type)(?:[=&]|$)/.test(id)) return;
|
|
2467
|
+
if (!/\.(?:[cm]?[jt]sx?|astro|svelte|vue)$/.test(cleanModuleId(id)) || id.includes("node_modules") || id.startsWith("\0") || /[?&](?:raw|url|type)(?:[=&]|$)/.test(id) || this.environment && isReactRouterClientRoute(id, this.environment.getTopLevelConfig())) return;
|
|
2195
2468
|
if (options.originalSource) {
|
|
2196
2469
|
id = cleanModuleId(id);
|
|
2197
2470
|
code = await readFile(await readableFile(id, settings.devServerRef), "utf8");
|
|
@@ -2206,7 +2479,7 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2206
2479
|
if (!/stillwind\/(?:alpine|astro|lit|preact|qwik|react|solid|svelte|vanilla|vue|module-css)/.test(code)) {
|
|
2207
2480
|
if (project.inputs(name).get(id)) {
|
|
2208
2481
|
await project.environment(name).removeSource(id);
|
|
2209
|
-
|
|
2482
|
+
publishSoon(name);
|
|
2210
2483
|
}
|
|
2211
2484
|
await project.environment(name).projections(id, projections);
|
|
2212
2485
|
return;
|
|
@@ -2218,7 +2491,7 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2218
2491
|
warn: this.warn.bind(this)
|
|
2219
2492
|
} : this;
|
|
2220
2493
|
const result = await compile(name, code, id, context);
|
|
2221
|
-
|
|
2494
|
+
publishSoon(name);
|
|
2222
2495
|
return result;
|
|
2223
2496
|
}
|
|
2224
2497
|
}
|
|
@@ -2268,6 +2541,7 @@ function virtualModuleHooks(project) {
|
|
|
2268
2541
|
return {
|
|
2269
2542
|
/**
|
|
2270
2543
|
* Resolves runtime aliases and issued references in the current environment's registry.
|
|
2544
|
+
*
|
|
2271
2545
|
* @param id - Authored request or resolved virtual identity.
|
|
2272
2546
|
* @param importer - Full importer identity required for registered projection edges.
|
|
2273
2547
|
* @returns A resolved virtual identity or packaged runtime path, or undefined for unrelated requests.
|
|
@@ -2291,6 +2565,7 @@ function virtualModuleHooks(project) {
|
|
|
2291
2565
|
},
|
|
2292
2566
|
/**
|
|
2293
2567
|
* Loads generated runtime, producer, projection, fragment, and explicit CSS-value modules.
|
|
2568
|
+
*
|
|
2294
2569
|
* @param id - Resolved virtual identity issued or recognized by this environment.
|
|
2295
2570
|
* @returns Generated JavaScript or snapshot CSS and its map, or undefined for unrelated modules.
|
|
2296
2571
|
* @throws If a reference is invalid, source or resource access fails, or CSS planning or compilation fails.
|
|
@@ -2448,6 +2723,7 @@ const hooks = /* @__PURE__ */ new WeakMap();
|
|
|
2448
2723
|
function attachVueHooks(plugins, project) {
|
|
2449
2724
|
/**
|
|
2450
2725
|
* Composes a Vue block's map through the recorded Stillwind transform for its source file.
|
|
2726
|
+
*
|
|
2451
2727
|
* @param result - Original load or transform result, left unchanged when a required map is absent.
|
|
2452
2728
|
* @param id - Full Vue block identity, including its `vue` query.
|
|
2453
2729
|
* @param environment - Vite environment whose top-level configuration owns the recorded input.
|
|
@@ -2477,6 +2753,7 @@ function attachVueHooks(plugins, project) {
|
|
|
2477
2753
|
const handler = typeof hook === "function" ? hook : hook.handler;
|
|
2478
2754
|
/**
|
|
2479
2755
|
* Runs the saved Vue load hook with its original receiver, then composes its map.
|
|
2756
|
+
*
|
|
2480
2757
|
* @param id - Resolver identity passed by Vite.
|
|
2481
2758
|
* @param args - Remaining load-hook arguments forwarded unchanged.
|
|
2482
2759
|
* @returns The delegated result with its map composed when the recorded input permits it.
|
|
@@ -2495,6 +2772,7 @@ function attachVueHooks(plugins, project) {
|
|
|
2495
2772
|
const handler = typeof hook === "function" ? hook : hook.handler;
|
|
2496
2773
|
/**
|
|
2497
2774
|
* Composes Vue's map and reloads components with explicit CSS values on template edits.
|
|
2775
|
+
*
|
|
2498
2776
|
* @param code - Vue block source passed by Vite.
|
|
2499
2777
|
* @param id - Resolver identity passed by Vite.
|
|
2500
2778
|
* @param args - Remaining transform-hook arguments forwarded unchanged.
|
|
@@ -2555,20 +2833,24 @@ function createVitePlugins(project, transform = {}) {
|
|
|
2555
2833
|
enforce: "pre",
|
|
2556
2834
|
/**
|
|
2557
2835
|
* Initializes the project owned by this configuration and composes Vue source maps.
|
|
2836
|
+
*
|
|
2558
2837
|
* @param config - Resolved Vite configuration whose plugin chain includes Stillwind.
|
|
2559
2838
|
* @returns Completion of project configuration.
|
|
2560
2839
|
* @throws If configuration discovery or evaluation fails.
|
|
2561
2840
|
*/
|
|
2562
2841
|
async configResolved(config) {
|
|
2842
|
+
if (isReactRouterExportScan(config)) return;
|
|
2563
2843
|
await project.forConfig(config).configure(config);
|
|
2564
2844
|
attachVueHooks(config.plugins, project);
|
|
2565
2845
|
},
|
|
2566
2846
|
/**
|
|
2567
2847
|
* Defers watch registration until the server's plugin setup succeeds.
|
|
2848
|
+
*
|
|
2568
2849
|
* @param server - Server whose configuration owns the project.
|
|
2569
2850
|
* @returns A post hook that attaches watches and records the server's environments.
|
|
2570
2851
|
*/
|
|
2571
2852
|
configureServer(server) {
|
|
2853
|
+
if (isReactRouterExportScan(server.config)) return;
|
|
2572
2854
|
const generation = project.forConfig(server.config);
|
|
2573
2855
|
return () => {
|
|
2574
2856
|
generation.attachServer(server);
|
|
@@ -2578,17 +2860,21 @@ function createVitePlugins(project, transform = {}) {
|
|
|
2578
2860
|
},
|
|
2579
2861
|
/**
|
|
2580
2862
|
* Creates compiler hooks while Vite resolves plugins for an environment.
|
|
2863
|
+
*
|
|
2581
2864
|
* @param environment - Descriptor supplied during plugin resolution. Runtime hooks receive
|
|
2582
2865
|
* their owning instance as this.environment.
|
|
2583
2866
|
* @returns Hooks that initialize and close the compiler state owned by this.environment.
|
|
2584
2867
|
*/
|
|
2585
2868
|
applyToEnvironment(environment) {
|
|
2869
|
+
if (isReactRouterExportScan(environment.getTopLevelConfig())) return false;
|
|
2586
2870
|
const generation = project.forConfig(environment.getTopLevelConfig());
|
|
2587
2871
|
return compilerPlugin(generation, transform, (owner) => {
|
|
2588
2872
|
servers.get(generation)?.delete(owner);
|
|
2589
2873
|
});
|
|
2590
2874
|
},
|
|
2591
|
-
/**
|
|
2875
|
+
/**
|
|
2876
|
+
* Releases projects after all environments owned by their server have closed.
|
|
2877
|
+
*/
|
|
2592
2878
|
closeServer() {
|
|
2593
2879
|
for (const [generation, remaining] of servers) if (remaining.size === 0) {
|
|
2594
2880
|
generation.close();
|
|
@@ -2601,13 +2887,17 @@ function createVitePlugins(project, transform = {}) {
|
|
|
2601
2887
|
enforce: "pre",
|
|
2602
2888
|
apply: "serve",
|
|
2603
2889
|
configureServer(server) {
|
|
2890
|
+
if (isReactRouterExportScan(server.config)) return;
|
|
2604
2891
|
const hook = developmentHooks(project.forConfig(server.config)).configureServer;
|
|
2605
2892
|
if (typeof hook === "function") return hook.call(this, server);
|
|
2606
2893
|
},
|
|
2607
2894
|
applyToEnvironment(environment) {
|
|
2608
|
-
|
|
2895
|
+
if (isReactRouterExportScan(environment.getTopLevelConfig())) return false;
|
|
2896
|
+
const { hotUpdate, watchChange } = developmentHooks(project.forConfig(environment.getTopLevelConfig()));
|
|
2609
2897
|
return {
|
|
2610
2898
|
name: "stillwind:development",
|
|
2899
|
+
perEnvironmentWatchChangeDuringDev: true,
|
|
2900
|
+
watchChange,
|
|
2611
2901
|
hotUpdate: transform.originalSource && typeof hotUpdate === "function" ? {
|
|
2612
2902
|
order: "pre",
|
|
2613
2903
|
handler: hotUpdate
|
|
@@ -2645,6 +2935,7 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2645
2935
|
perEnvironmentWatchChangeDuringDev: true,
|
|
2646
2936
|
/**
|
|
2647
2937
|
* Delegates generated-reference resolution using the current environment's hook context.
|
|
2938
|
+
*
|
|
2648
2939
|
* @param id - Requested module identity.
|
|
2649
2940
|
* @param importer - Importing resolver identity, when available.
|
|
2650
2941
|
* @param options - Vite resolution options forwarded unchanged.
|
|
@@ -2655,6 +2946,7 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2655
2946
|
},
|
|
2656
2947
|
/**
|
|
2657
2948
|
* Delegates generated-module loading through the current environment's registry.
|
|
2949
|
+
*
|
|
2658
2950
|
* @param id - Resolved module identity.
|
|
2659
2951
|
* @param options - Vite load options forwarded unchanged.
|
|
2660
2952
|
* @returns The virtual loader's result, or undefined when no callable hook is available.
|
|
@@ -2665,6 +2957,7 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2665
2957
|
...transformHooks(project, virtualModules, transform),
|
|
2666
2958
|
/**
|
|
2667
2959
|
* Refreshes configuration, registers its watches, and starts the current compiler environment.
|
|
2960
|
+
*
|
|
2668
2961
|
* @returns Completion of configuration refresh and environment initialization.
|
|
2669
2962
|
* @throws If refresh or environment startup fails.
|
|
2670
2963
|
*/
|
|
@@ -2673,7 +2966,9 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2673
2966
|
for (const file of project.configurationFiles) this.addWatchFile(file);
|
|
2674
2967
|
await project.environment(this.environment).start(this);
|
|
2675
2968
|
},
|
|
2676
|
-
/**
|
|
2969
|
+
/**
|
|
2970
|
+
* Releases this environment's state when its plugin container closes.
|
|
2971
|
+
*/
|
|
2677
2972
|
closeBundle() {
|
|
2678
2973
|
project.closeEnvironment(this.environment);
|
|
2679
2974
|
closed(this.environment);
|
|
@@ -2682,4 +2977,4 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2682
2977
|
}
|
|
2683
2978
|
export { renderChunkStyles as i, stillwind as n, createViteProject as r, createVitePlugins as t };
|
|
2684
2979
|
|
|
2685
|
-
//# sourceMappingURL=plugin-
|
|
2980
|
+
//# sourceMappingURL=plugin-DQH8QlYh.js.map
|