@stillwind/integration 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +67 -2
- package/dist/NPM-THIRD-PARTY-LICENSES +52 -0
- package/dist/astro/development.d.ts +15 -0
- package/dist/astro/development.js +34 -0
- package/dist/astro/development.js.map +1 -0
- package/dist/astro/index.d.ts +17 -0
- package/dist/astro/index.js +194 -0
- package/dist/astro/index.js.map +1 -0
- package/dist/astro/middleware.d.ts +2 -0
- package/dist/astro/middleware.js +64 -0
- package/dist/astro/middleware.js.map +1 -0
- package/dist/binding-files-Ds5NpyVV.js +45 -0
- package/dist/binding-files-Ds5NpyVV.js.map +1 -0
- package/dist/emission-BVi5aRbb.js +520 -0
- package/dist/emission-BVi5aRbb.js.map +1 -0
- package/dist/fresh/index.d.ts +10 -0
- package/dist/fresh/index.js +55 -0
- package/dist/fresh/index.js.map +1 -0
- package/dist/gen-mapping-D7jFzOEh.js +559 -0
- package/dist/gen-mapping-D7jFzOEh.js.map +1 -0
- package/dist/index-DFfbZxNT.d.ts +12 -0
- package/dist/next/css-loader.d.ts +14 -0
- package/dist/next/css-loader.js +58 -0
- package/dist/next/css-loader.js.map +1 -0
- package/dist/next/index.d.ts +15 -0
- package/dist/next/index.js +66 -0
- package/dist/next/index.js.map +1 -0
- package/dist/node-loader-D-3Ynpy1.d.ts +19 -0
- package/dist/nuxt/index.d.ts +13 -0
- package/dist/nuxt/index.js +64 -0
- package/dist/nuxt/index.js.map +1 -0
- package/dist/plugin-C_ZFfzo2.js +2572 -0
- package/dist/plugin-C_ZFfzo2.js.map +1 -0
- package/dist/plugin-aV0zIIAe.d.ts +278 -0
- package/dist/plugin-mPiBLdqa.js +79 -0
- package/dist/plugin-mPiBLdqa.js.map +1 -0
- package/dist/project-BNw0nZBE.d.ts +58 -0
- package/dist/project-C3IH7geC.js +182 -0
- package/dist/project-C3IH7geC.js.map +1 -0
- package/dist/project-DUGu8g_L.d.ts +15 -0
- package/dist/rsbuild/index.d.ts +28 -0
- package/dist/rsbuild/index.js +77 -0
- package/dist/rsbuild/index.js.map +1 -0
- package/dist/rspack/index.d.ts +3 -0
- package/dist/rspack/index.js +1 -0
- package/dist/rules-BvKsL2at.js +91 -0
- package/dist/rules-BvKsL2at.js.map +1 -0
- package/dist/session-B9_rp9TH.d.ts +72 -0
- package/dist/session-DHUCQMG5.js +117 -0
- package/dist/session-DHUCQMG5.js.map +1 -0
- package/dist/source-map-loader-CBLiYaBI.d.ts +128 -0
- package/dist/sveltekit/handle.d.ts +13 -0
- package/dist/sveltekit/handle.js +16 -0
- package/dist/sveltekit/handle.js.map +1 -0
- package/dist/trace-mapping-DV_eP3r7.d.ts +58 -0
- package/dist/turbopack/css-loader.d.ts +15 -0
- package/dist/turbopack/css-loader.js +44 -0
- package/dist/turbopack/css-loader.js.map +1 -0
- package/dist/turbopack/index.d.ts +54 -0
- package/dist/turbopack/index.js +1 -0
- package/dist/turbopack/loader.d.ts +13 -0
- package/dist/turbopack/loader.js +70 -0
- package/dist/turbopack/loader.js.map +1 -0
- package/dist/turbopack/node-loader.d.ts +2 -0
- package/dist/turbopack/node-loader.js +20 -0
- package/dist/turbopack/node-loader.js.map +1 -0
- package/dist/turbopack/stillwind-turbopack.css +0 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/runtime-source-map.d.ts +19 -0
- package/dist/vite/runtime-source-map.js +106 -0
- package/dist/vite/runtime-source-map.js.map +1 -0
- package/dist/vite/runtime.d.ts +58 -0
- package/dist/vite/runtime.js +90 -0
- package/dist/vite/runtime.js.map +1 -0
- package/dist/webpack/css-loader.d.ts +17 -0
- package/dist/webpack/css-loader.js +36 -0
- package/dist/webpack/css-loader.js.map +1 -0
- package/dist/webpack/css-map-loader.d.ts +24 -0
- package/dist/webpack/css-map-loader.js +43 -0
- package/dist/webpack/css-map-loader.js.map +1 -0
- package/dist/webpack/document-loader.d.ts +12 -0
- package/dist/webpack/document-loader.js +19 -0
- package/dist/webpack/document-loader.js.map +1 -0
- package/dist/webpack/fragment-loader.d.ts +9 -0
- package/dist/webpack/fragment-loader.js +23 -0
- package/dist/webpack/fragment-loader.js.map +1 -0
- package/dist/webpack/index.d.ts +3 -0
- package/dist/webpack/index.js +1 -0
- package/dist/webpack/loader.d.ts +35 -0
- package/dist/webpack/loader.js +199 -0
- package/dist/webpack/loader.js.map +1 -0
- package/dist/webpack/source-loader.d.ts +11 -0
- package/dist/webpack/source-loader.js +17 -0
- package/dist/webpack/source-loader.js.map +1 -0
- package/dist/webpack/source-map-loader.d.ts +2 -0
- package/dist/webpack/source-map-loader.js +35 -0
- package/dist/webpack/source-map-loader.js.map +1 -0
- package/dist/webpack/stillwind-fragment.d.ts +1 -0
- package/dist/webpack/stillwind-fragment.js +1 -0
- package/dist/webpack/stillwind-webpack.css +1 -0
- package/package.json +133 -3
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import { n as buildCompilerOptions, r as warnSkippedCss, t as IntegrationSession } from "./session-DHUCQMG5.js";
|
|
2
|
+
import { t as nativeBindingFiles } from "./binding-files-Ds5NpyVV.js";
|
|
3
|
+
import { isBuiltin } from "node:module";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { cleanModuleId, cssEntrypoint, cssWithSourceMap, fileModuleDescriptor, loadCssGraph, nodePluginHost, warnRejectedNames } from "@stillwind/host";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
// src/webpack/rules.ts
|
|
10
|
+
/**
|
|
11
|
+
* Derives the webpack rule identifier used by inline SFC loader requests.
|
|
12
|
+
*
|
|
13
|
+
* @param config - The same configuration values registered on the loader rule. JSON serialization
|
|
14
|
+
* omits callbacks, so namingRevision must distinguish changed naming implementations.
|
|
15
|
+
* @returns A stillwind-prefixed SHA-256 hash of the serialized configuration.
|
|
16
|
+
* @throws If the configuration cannot be serialized as JSON.
|
|
17
|
+
*/
|
|
18
|
+
function loaderOptionsId(config) {
|
|
19
|
+
return "stillwind-" + createHash("sha256").update(JSON.stringify(config)).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Builds producer, document CSS, and SFC source-map loader rules without evaluating configuration.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Discovery and inline settings shared by producer rules. The object is retained.
|
|
25
|
+
* @returns Rules using absolute paths in the installed integration package. The host provides its
|
|
26
|
+
* CSS pipeline and registers StillwindPlugin when automatic document CSS is required.
|
|
27
|
+
* @throws If loader resolution or configuration serialization fails.
|
|
28
|
+
*/
|
|
29
|
+
function stillwindRules(config) {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
33
|
+
exclude: /node_modules/,
|
|
34
|
+
enforce: "pre",
|
|
35
|
+
use: [{
|
|
36
|
+
loader: fileURLToPath(new URL("./loader.js", import.meta.resolve("@stillwind/integration/webpack"))),
|
|
37
|
+
options: config,
|
|
38
|
+
ident: loaderOptionsId(config)
|
|
39
|
+
}]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
test: /\.(?:astro|svelte|vue)$/,
|
|
43
|
+
exclude: /node_modules/,
|
|
44
|
+
enforce: "pre",
|
|
45
|
+
use: [{
|
|
46
|
+
loader: fileURLToPath(new URL("./loader.js", import.meta.resolve("@stillwind/integration/webpack"))),
|
|
47
|
+
options: config,
|
|
48
|
+
ident: loaderOptionsId(config)
|
|
49
|
+
}]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
test: /stillwind-webpack\.css$/,
|
|
53
|
+
enforce: "post",
|
|
54
|
+
use: [fileURLToPath(new URL("./document-loader.js", import.meta.resolve("@stillwind/integration/webpack")))]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
test: /stillwind-webpack\.css$/,
|
|
58
|
+
enforce: "pre",
|
|
59
|
+
use: [fileURLToPath(new URL("./css-loader.js", import.meta.resolve("@stillwind/integration/webpack")))]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
test: /\.(?:astro|svelte|vue)(?:\.[cm]?[jt]sx?)?$/,
|
|
63
|
+
exclude: /node_modules/,
|
|
64
|
+
enforce: "post",
|
|
65
|
+
use: [fileURLToPath(new URL("./source-map-loader.js", import.meta.resolve("@stillwind/integration/webpack")))]
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
// src/webpack/requests.ts
|
|
70
|
+
/**
|
|
71
|
+
* Classifies a resource request and chooses the producer identity used for compilation.
|
|
72
|
+
*
|
|
73
|
+
* @param resourcePath - Absolute resource path without its query.
|
|
74
|
+
* @param resourceQuery - Query including its leading `?`, or an empty string.
|
|
75
|
+
* @returns Request flags and a producer ID. SFC blocks, CSS values, and projections share the
|
|
76
|
+
* original file identity. Export-selection queries do not change the producer identity.
|
|
77
|
+
*/
|
|
78
|
+
function classifyRequest(resourcePath, resourceQuery = "") {
|
|
79
|
+
const projection = /[?&]stillwind\.css(?:&|$)/.test(resourceQuery);
|
|
80
|
+
const cssValue = /[?&]stillwind-module-css(?:&|$)/.test(resourceQuery);
|
|
81
|
+
const sfc = /\.(?:astro|svelte|vue)$/.test(resourcePath);
|
|
82
|
+
const parameters = new URLSearchParams(resourceQuery);
|
|
83
|
+
let sourceQuery = resourceQuery;
|
|
84
|
+
if (parameters.has("export")) {
|
|
85
|
+
parameters.delete("export");
|
|
86
|
+
const query = parameters.toString();
|
|
87
|
+
sourceQuery = query ? `?${query}` : "";
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
projection,
|
|
91
|
+
cssValue,
|
|
92
|
+
sfc,
|
|
93
|
+
id: resourcePath + (projection || cssValue || sfc ? "" : sourceQuery),
|
|
94
|
+
passthrough: /[?&](?:raw|url)(?:[=&]|$)/.test(resourceQuery)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reads compiler options from a rule or an encoded SFC subrequest.
|
|
99
|
+
*
|
|
100
|
+
* @param supplied - Rule options, optionally containing `stillwindOptions` encoded as base64url
|
|
101
|
+
* JSON.
|
|
102
|
+
* @returns Decoded options when `stillwindOptions` is present, otherwise the supplied object.
|
|
103
|
+
* @throws If encoded configuration is not valid JSON.
|
|
104
|
+
*/
|
|
105
|
+
function requestOptions(supplied) {
|
|
106
|
+
return supplied.stillwindOptions ? JSON.parse(Buffer.from(supplied.stillwindOptions, "base64url").toString("utf8")) : supplied;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a module request with forward slashes, relative to the importer when possible.
|
|
110
|
+
*
|
|
111
|
+
* @param from - Absolute directory containing the importing module.
|
|
112
|
+
* @param to - Absolute path of the requested resource.
|
|
113
|
+
* @returns A relative request with `./` when needed, or an absolute path across Windows volumes.
|
|
114
|
+
*/
|
|
115
|
+
function relativeRequest(from, to) {
|
|
116
|
+
const value = path.relative(from, to).replaceAll("\\", "/");
|
|
117
|
+
return path.isAbsolute(value) || value.startsWith(".") ? value : `./${value}`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates a CSS projection or CSS value request that retains the producer configuration.
|
|
121
|
+
*
|
|
122
|
+
* SFC requests bypass other loaders. Naming callbacks use a registered rule identifier because JSON
|
|
123
|
+
* cannot encode functions.
|
|
124
|
+
*
|
|
125
|
+
* @param resourcePath - Absolute path of the original producer.
|
|
126
|
+
* @param sfc - Whether the producer is an Astro, Svelte, or Vue file.
|
|
127
|
+
* @param config - Compiler config used for the original producer.
|
|
128
|
+
* @param loaderPath - Absolute path of the producer loader.
|
|
129
|
+
* @param query - Stillwind query text without a leading `?`.
|
|
130
|
+
* @param identityConfig - Original inline settings registered on the loader rule. When evaluated
|
|
131
|
+
* config contains naming callbacks, this selects that rule instead of serializing callbacks.
|
|
132
|
+
* Defaults to config when file evaluation has not changed the registered settings.
|
|
133
|
+
* @returns A relative resource request for scripts, or an inline loader request for SFCs.
|
|
134
|
+
* @throws If SFC settings cannot be serialized for their inline request.
|
|
135
|
+
*/
|
|
136
|
+
function virtualRequest(resourcePath, sfc, config, loaderPath, query, identityConfig = config) {
|
|
137
|
+
if (!sfc) return `${relativeRequest(path.dirname(resourcePath), resourcePath)}?${query}`;
|
|
138
|
+
const configuration = config.naming ? "??" + loaderOptionsId(identityConfig) : "?stillwindOptions=" + Buffer.from(JSON.stringify(config)).toString("base64url");
|
|
139
|
+
return `!!${loaderPath.replaceAll("\\", "/")}${configuration}!${resourcePath.replaceAll("\\", "/")}?${query}`;
|
|
140
|
+
}
|
|
141
|
+
// src/webpack/sources.ts
|
|
142
|
+
/**
|
|
143
|
+
* Keeps each query-selected derivative's compiler, checker, and source-map identities distinct.
|
|
144
|
+
* @param root - Absolute project root used to derive compiler identities.
|
|
145
|
+
* @param id - Full source identity, including any query or fragment selecting transformed source.
|
|
146
|
+
* @returns Ordinary file metadata without a suffix, or distinct module/document identities and a hashed checker filename.
|
|
147
|
+
*/
|
|
148
|
+
function sourceDescriptor(root, id) {
|
|
149
|
+
const descriptor = fileModuleDescriptor(root, id);
|
|
150
|
+
const file = cleanModuleId(id);
|
|
151
|
+
const suffix = id.slice(file.length);
|
|
152
|
+
if (!suffix) return descriptor;
|
|
153
|
+
const extension = path.extname(file);
|
|
154
|
+
const key = createHash("sha256").update(id).digest("hex");
|
|
155
|
+
const checkerFileName = path.join(path.dirname(file), `.${path.basename(file, extension)}.stillwind-${key}${extension}`);
|
|
156
|
+
return {
|
|
157
|
+
...descriptor,
|
|
158
|
+
moduleId: descriptor.moduleId + suffix,
|
|
159
|
+
document: {
|
|
160
|
+
...descriptor.document,
|
|
161
|
+
uri: descriptor.document.uri + suffix
|
|
162
|
+
},
|
|
163
|
+
checkerFileName,
|
|
164
|
+
projectionFileName: checkerFileName.replaceAll("\\", "/")
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// src/webpack/compilation-styles.ts
|
|
168
|
+
/**
|
|
169
|
+
* Recompiles recorded producers and renders document CSS for a completed compilation.
|
|
170
|
+
*
|
|
171
|
+
* Manual producers are compiled for dependency composition but are excluded from the document
|
|
172
|
+
* selection. The temporary compiler closes after reconstruction.
|
|
173
|
+
*
|
|
174
|
+
* @param producers - Nonempty list of producers from the completed graph. Every producer must use
|
|
175
|
+
* the same root and config.
|
|
176
|
+
* @param io - Compilation host that reads captured dependency sources and resolves CSS, scripts,
|
|
177
|
+
* and assets.
|
|
178
|
+
* @param mode - Bundler mode. Only `development` selects development compilation.
|
|
179
|
+
* @param watch - Registers a file as a compilation dependency.
|
|
180
|
+
* @param watchDirectory - Registers a directory whose entry additions and removals invalidate the
|
|
181
|
+
* compilation.
|
|
182
|
+
* @param warn - Reports compiler warnings and the CSS statements that loading skipped through the
|
|
183
|
+
* bundler.
|
|
184
|
+
* @returns Document CSS with asset requests and an inline source map composed with recorded
|
|
185
|
+
* upstream maps.
|
|
186
|
+
* @throws If producers use different design systems, a dependency source is missing, or loading or
|
|
187
|
+
* compilation fails.
|
|
188
|
+
*/
|
|
189
|
+
async function compilationStyles(producers, io, mode, watch, watchDirectory, warn) {
|
|
190
|
+
const { config, root } = producers[0];
|
|
191
|
+
const readDependency = io.dependencyReader(producers);
|
|
192
|
+
const loaded = await loadCssGraph(path.resolve(root, cssEntrypoint(config)), buildCompilerOptions(config), {
|
|
193
|
+
read: io.read,
|
|
194
|
+
resolve: io.resolveCss,
|
|
195
|
+
documentUri: (id) => pathToFileURL(id).href,
|
|
196
|
+
sourceMapSource: (id) => pathToFileURL(id).href,
|
|
197
|
+
watch,
|
|
198
|
+
watchDirectory,
|
|
199
|
+
plugins: nodePluginHost
|
|
200
|
+
}, void 0, void 0, {
|
|
201
|
+
plugins: config.plugins,
|
|
202
|
+
tailwind: config.tailwind,
|
|
203
|
+
important: config.important,
|
|
204
|
+
root
|
|
205
|
+
});
|
|
206
|
+
warnSkippedCss(loaded.skipped, warn);
|
|
207
|
+
const compiler = new IntegrationSession(root, loaded.loader, config, false, mode === "development" ? "development" : "release", loaded.plugins);
|
|
208
|
+
const selection = [];
|
|
209
|
+
try {
|
|
210
|
+
for (const input of producers) {
|
|
211
|
+
if (input.root !== root || JSON.stringify(input.config) !== JSON.stringify(config)) throw new Error("A compilation must use one Stillwind design system");
|
|
212
|
+
const output = await compiler.compile(input.source, input.id, {
|
|
213
|
+
describe: (id) => sourceDescriptor(root, id),
|
|
214
|
+
resolve: async (specifier, importer) => ({ id: await io.resolveJs(specifier, importer) }),
|
|
215
|
+
read: readDependency,
|
|
216
|
+
watch: (id) => {
|
|
217
|
+
watch(cleanModuleId(id));
|
|
218
|
+
},
|
|
219
|
+
warn
|
|
220
|
+
}, { moduleCssImport: "stillwind/module-css" });
|
|
221
|
+
if (output && !input.manual) selection.push(output.moduleId);
|
|
222
|
+
}
|
|
223
|
+
const revision = createHash("sha256").update(producers.map((input) => `${input.source}\0`).join("")).digest("hex");
|
|
224
|
+
const plan = compiler.native.planStylesheet({
|
|
225
|
+
modules: selection,
|
|
226
|
+
coverage: {
|
|
227
|
+
kind: "complete",
|
|
228
|
+
target: "compilation",
|
|
229
|
+
revision
|
|
230
|
+
},
|
|
231
|
+
placement: "document"
|
|
232
|
+
});
|
|
233
|
+
warnRejectedNames(plan.rejectedNames, warn);
|
|
234
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
235
|
+
for (const resource of [...loaded.resources, ...plan.resources]) {
|
|
236
|
+
const owner = "moduleId" in resource ? compiler.resolverId(resource.moduleId) : resource.sourceName;
|
|
237
|
+
const file = await io.resolveAsset(resource.specifier, owner);
|
|
238
|
+
watch(file);
|
|
239
|
+
const request = relativeRequest(path.dirname(fileURLToPath(import.meta.resolve("@stillwind/integration/webpack"))), file);
|
|
240
|
+
replacements.set(resource.placeholder, JSON.stringify(request).slice(1, -1));
|
|
241
|
+
}
|
|
242
|
+
return cssWithSourceMap(plan, replacements, producers.flatMap((input) => [input.upstream, ...(input.dependencies ?? []).map((dependency) => dependency.upstream)].filter((upstream) => Boolean(upstream))));
|
|
243
|
+
} finally {
|
|
244
|
+
compiler.close();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// src/webpack/host.ts
|
|
248
|
+
/**
|
|
249
|
+
* Creates compiler operations from a producer loader context and tracks the loader itself as a
|
|
250
|
+
* dependency.
|
|
251
|
+
*
|
|
252
|
+
* Ordinary dependencies are read from the filesystem. Query-qualified dependencies pass through
|
|
253
|
+
* preceding loaders and the capture loader. Pending captures are reused by their full resolver
|
|
254
|
+
* identity.
|
|
255
|
+
*
|
|
256
|
+
* @param context - Active loader context with a complete loader chain and an `importModule`
|
|
257
|
+
* implementation for query-qualified dependencies.
|
|
258
|
+
* @param loaderPath - Absolute path of the Stillwind loader to register as a dependency.
|
|
259
|
+
* @returns A host that resolves imports, reads files, captures transformed dependencies, and
|
|
260
|
+
* forwards warnings.
|
|
261
|
+
*/
|
|
262
|
+
function createLoaderHost(context, loaderPath) {
|
|
263
|
+
const read = createReadFile(context.fs);
|
|
264
|
+
const dependencySources = /* @__PURE__ */ new Map();
|
|
265
|
+
/**
|
|
266
|
+
* Reads an ordinary dependency or captures transformed text through preceding loaders.
|
|
267
|
+
* @param dependency - Full resolver identity. A query or fragment requires a loader capture.
|
|
268
|
+
* @returns File text or captured text. Capture promises, including failures, are retained by identity.
|
|
269
|
+
* @throws If filesystem reading or the dependency's loader chain fails.
|
|
270
|
+
*/
|
|
271
|
+
const readDependency = async (dependency) => {
|
|
272
|
+
if (cleanModuleId(dependency) === dependency) return read(dependency);
|
|
273
|
+
let pending = dependencySources.get(dependency);
|
|
274
|
+
if (!pending) {
|
|
275
|
+
const capture = fileURLToPath(new URL("./source-loader.js", import.meta.resolve("@stillwind/integration/webpack")));
|
|
276
|
+
const preceding = context.loaders.slice(context.loaderIndex + 1).map((loader) => loader.request);
|
|
277
|
+
pending = context.importModule(`!!${[
|
|
278
|
+
capture,
|
|
279
|
+
...preceding,
|
|
280
|
+
dependency
|
|
281
|
+
].join("!")}`);
|
|
282
|
+
dependencySources.set(dependency, pending);
|
|
283
|
+
}
|
|
284
|
+
return (await pending).source;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Adapts loader resolution to requests relative to a source file.
|
|
288
|
+
* @param settings - Resolution policy passed to the loader's resolver factory.
|
|
289
|
+
* @returns An asynchronous resolver accepting a specifier and full importer identity. Resolver
|
|
290
|
+
* errors reject its promise, and a missing result becomes an empty string.
|
|
291
|
+
*/
|
|
292
|
+
const resolver = (settings) => {
|
|
293
|
+
const resolve = context.getResolve(settings);
|
|
294
|
+
return (specifier, importer) => new Promise((done, reject) => resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) => error ? reject(error) : done(id || "")));
|
|
295
|
+
};
|
|
296
|
+
const resolveCss = resolver(cssResolveOptions);
|
|
297
|
+
const resolveJs = resolver({
|
|
298
|
+
dependencyType: "esm",
|
|
299
|
+
extensions: [
|
|
300
|
+
".tsx",
|
|
301
|
+
".ts",
|
|
302
|
+
".jsx",
|
|
303
|
+
".js",
|
|
304
|
+
".mjs",
|
|
305
|
+
".cjs",
|
|
306
|
+
".json"
|
|
307
|
+
]
|
|
308
|
+
});
|
|
309
|
+
const resolveAsset = resolver({});
|
|
310
|
+
/**
|
|
311
|
+
* Registers a filesystem dependency for loader invalidation.
|
|
312
|
+
* @param id - Full resolver identity whose query and fragment are removed before registration.
|
|
313
|
+
*/
|
|
314
|
+
const watch = (id) => context.addDependency(cleanModuleId(id));
|
|
315
|
+
watch(loaderPath);
|
|
316
|
+
return {
|
|
317
|
+
read,
|
|
318
|
+
readDependency,
|
|
319
|
+
dependencySources,
|
|
320
|
+
resolveCss,
|
|
321
|
+
resolveAsset,
|
|
322
|
+
resolve: async (specifier, importer) => {
|
|
323
|
+
if (specifier.startsWith("node:") && isBuiltin(specifier)) return {
|
|
324
|
+
id: specifier,
|
|
325
|
+
external: true
|
|
326
|
+
};
|
|
327
|
+
try {
|
|
328
|
+
const id = await resolveJs(specifier, importer);
|
|
329
|
+
return id ? { id } : null;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
if (isBuiltin(specifier)) return {
|
|
332
|
+
id: specifier,
|
|
333
|
+
external: true
|
|
334
|
+
};
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
watch,
|
|
339
|
+
warn: (message) => context.emitWarning(new Error(message))
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Registers compiler runtime files so changes invalidate cached loader results.
|
|
344
|
+
*
|
|
345
|
+
* The function includes native binding files and JavaScript files beside the published host
|
|
346
|
+
* entrypoint.
|
|
347
|
+
*
|
|
348
|
+
* @param watch - Registers an absolute file path as a loader dependency.
|
|
349
|
+
* @throws If the host runtime directory cannot be read.
|
|
350
|
+
*/
|
|
351
|
+
function watchCompilerFiles(watch) {
|
|
352
|
+
for (const file of nativeBindingFiles()) watch(file);
|
|
353
|
+
const directory = path.dirname(fileURLToPath(import.meta.resolve("@stillwind/host")));
|
|
354
|
+
for (const file of fs.readdirSync(directory)) if (file.endsWith(".js")) watch(path.join(directory, file));
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Creates filesystem and resolution operations for reconstructing a completed compilation.
|
|
358
|
+
*
|
|
359
|
+
* Reconstruction resolves framework source files as well as scripts. Query-qualified dependency
|
|
360
|
+
* reads require captured source from producer metadata.
|
|
361
|
+
*
|
|
362
|
+
* @param context - Bundler input filesystem and resolver factory operations.
|
|
363
|
+
* @returns A host that reads files and builds dependency readers from retained producer metadata.
|
|
364
|
+
*/
|
|
365
|
+
function createCompilationHost(context) {
|
|
366
|
+
const read = createReadFile(context.fs, cleanModuleId);
|
|
367
|
+
/**
|
|
368
|
+
* Adapts compilation resolution to requests relative to a source file.
|
|
369
|
+
* @param settings - Resolution policy passed to the bundler's resolver factory.
|
|
370
|
+
* @returns An asynchronous resolver accepting a specifier and full importer identity. It forwards
|
|
371
|
+
* successful resolver results without checking for an absent identity, and rejects resolver errors.
|
|
372
|
+
*/
|
|
373
|
+
const resolver = (settings) => {
|
|
374
|
+
const resolve = context.getResolve(settings);
|
|
375
|
+
return (specifier, importer) => new Promise((done, reject) => resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) => error ? reject(error) : done(id)));
|
|
376
|
+
};
|
|
377
|
+
return {
|
|
378
|
+
read,
|
|
379
|
+
/**
|
|
380
|
+
* Creates a reader using source captured by the completed module graph.
|
|
381
|
+
* @param producers - Producer and dependency records. Later records replace earlier text for the same identity.
|
|
382
|
+
* @returns A reader that uses exact captured identities before falling back to ordinary filesystem reads.
|
|
383
|
+
*/
|
|
384
|
+
dependencyReader(producers) {
|
|
385
|
+
const sources = /* @__PURE__ */ new Map();
|
|
386
|
+
for (const input of producers) {
|
|
387
|
+
sources.set(input.id, input.source);
|
|
388
|
+
for (const dependency of input.dependencies ?? []) sources.set(dependency.id, dependency.source);
|
|
389
|
+
}
|
|
390
|
+
return (id) => {
|
|
391
|
+
if (sources.has(id)) return Promise.resolve(sources.get(id));
|
|
392
|
+
if (cleanModuleId(id) !== id) return Promise.reject(/* @__PURE__ */ new Error(`No transformed source captured for ${id}`));
|
|
393
|
+
return read(id);
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
resolveCss: resolver(cssResolveOptions),
|
|
397
|
+
resolveJs: resolver({
|
|
398
|
+
dependencyType: "esm",
|
|
399
|
+
extensions: [
|
|
400
|
+
".tsx",
|
|
401
|
+
".ts",
|
|
402
|
+
".jsx",
|
|
403
|
+
".js",
|
|
404
|
+
".mjs",
|
|
405
|
+
".cjs",
|
|
406
|
+
".vue",
|
|
407
|
+
".svelte",
|
|
408
|
+
".astro"
|
|
409
|
+
]
|
|
410
|
+
}),
|
|
411
|
+
resolveAsset: resolver({})
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* CSS resolution policy that prefers style exports and metadata fields before ordinary package
|
|
416
|
+
* entrypoints.
|
|
417
|
+
*/
|
|
418
|
+
const cssResolveOptions = {
|
|
419
|
+
conditionNames: [
|
|
420
|
+
"style",
|
|
421
|
+
"import",
|
|
422
|
+
"default"
|
|
423
|
+
],
|
|
424
|
+
extensions: [".css"],
|
|
425
|
+
mainFields: ["style", "main"]
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Adapts the bundler filesystem to asynchronous string reads.
|
|
429
|
+
*
|
|
430
|
+
* @param filesystem - Input filesystem that completes reads through a callback.
|
|
431
|
+
* @param fileId - Maps resolver identities to readable paths. Defaults to keeping the identity
|
|
432
|
+
* unchanged.
|
|
433
|
+
* @returns A reader that resolves to the filesystem value converted to a string, or rejects on read
|
|
434
|
+
* failure.
|
|
435
|
+
*/
|
|
436
|
+
function createReadFile(filesystem, fileId = (id) => id) {
|
|
437
|
+
return (id) => new Promise((resolve, reject) => filesystem.readFile(fileId(id), (error, value) => error ? reject(error) : resolve(String(value))));
|
|
438
|
+
}
|
|
439
|
+
// src/webpack/emission.ts
|
|
440
|
+
/**
|
|
441
|
+
* Stores a producer in module build metadata so cached modules can participate in CSS
|
|
442
|
+
* reconstruction.
|
|
443
|
+
*
|
|
444
|
+
* @param context - Loader context for a module in a compilation registered by `StillwindPlugin`.
|
|
445
|
+
* @param input - Producer source, compiler configuration, and captured dependency sources.
|
|
446
|
+
* @throws If the compilation has no registered emission hook or the loader context has no module.
|
|
447
|
+
*/
|
|
448
|
+
function recordProducer(context, input) {
|
|
449
|
+
requireEmission(context);
|
|
450
|
+
if (!context._module) throw new Error(incompleteGraphMessage);
|
|
451
|
+
context._module.buildInfo ??= {};
|
|
452
|
+
context._module.buildInfo.stillwind = input;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Registers CSS reconstruction after all modules in the compilation have finished.
|
|
456
|
+
*
|
|
457
|
+
* Registration is idempotent for a compilation. The hook collects cached and newly built producers,
|
|
458
|
+
* stores document CSS, and rebuilds each carrier through the host CSS pipeline.
|
|
459
|
+
*
|
|
460
|
+
* @param context - Context with a compilation, filesystem, and resolver. Register it before
|
|
461
|
+
* producer loaders run.
|
|
462
|
+
* @throws If the context has no compilation with a `finishModules` hook.
|
|
463
|
+
*/
|
|
464
|
+
function installEmission(context) {
|
|
465
|
+
const compilation = requireCompilation(context);
|
|
466
|
+
if (installed.has(compilation)) return;
|
|
467
|
+
installed.add(compilation);
|
|
468
|
+
const io = createCompilationHost(context);
|
|
469
|
+
compilation.hooks.finishModules.tapPromise("StillwindEmission", async (modules) => {
|
|
470
|
+
const completed = [...modules];
|
|
471
|
+
const producers = completed.map((module) => module.buildInfo?.stillwind).filter((input) => Boolean(input));
|
|
472
|
+
const carriers = completed.filter((module) => module.resource?.includes("stillwind-webpack.css?stillwind-document"));
|
|
473
|
+
if (!carriers.length || !producers.length) return;
|
|
474
|
+
compilation.__stillwindCss = await compilationStyles(producers, io, context.mode, (id) => {
|
|
475
|
+
compilation.fileDependencies.add(id);
|
|
476
|
+
}, (id) => {
|
|
477
|
+
compilation.contextDependencies.add(id);
|
|
478
|
+
}, (message) => {
|
|
479
|
+
compilation.warnings.push(new Error(message));
|
|
480
|
+
});
|
|
481
|
+
for (const carrier of carriers) await new Promise((resolve, reject) => compilation.rebuildModule(carrier, (error) => error ? reject(error) : resolve()));
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Compilations whose emission hooks have been registered. Membership is required before automatic
|
|
486
|
+
* loaders record producers.
|
|
487
|
+
*/
|
|
488
|
+
const installed = /* @__PURE__ */ new WeakSet();
|
|
489
|
+
const incompleteGraphMessage = "Automatic Stillwind CSS requires new StillwindPlugin(config) before compilation begins";
|
|
490
|
+
/**
|
|
491
|
+
* Obtains the compilation operations needed to reconstruct document CSS.
|
|
492
|
+
*
|
|
493
|
+
* @param context - Bundler context that must expose a `finishModules` compilation hook.
|
|
494
|
+
* @returns The compilation attached to the context.
|
|
495
|
+
* @throws If the context cannot supply a completed compilation graph.
|
|
496
|
+
*/
|
|
497
|
+
function requireCompilation(context) {
|
|
498
|
+
const compilation = context._compilation;
|
|
499
|
+
if (!compilation?.hooks?.finishModules) throw new Error(incompleteGraphMessage);
|
|
500
|
+
return compilation;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Rejects automatic CSS requests when the compilation has no registered emission hook.
|
|
504
|
+
*
|
|
505
|
+
* @param context - Loader context associated with a compilation registered by `StillwindPlugin`.
|
|
506
|
+
* @returns The nearest registered compilation holding reconstructed document CSS.
|
|
507
|
+
* @throws If the compilation is missing or its emission hook has not been registered.
|
|
508
|
+
*/
|
|
509
|
+
function requireEmission(context) {
|
|
510
|
+
let compilation = requireCompilation(context);
|
|
511
|
+
while (!installed.has(compilation)) {
|
|
512
|
+
const parent = compilation.compiler?.parentCompilation;
|
|
513
|
+
if (!parent) throw new Error(incompleteGraphMessage);
|
|
514
|
+
compilation = parent;
|
|
515
|
+
}
|
|
516
|
+
return compilation;
|
|
517
|
+
}
|
|
518
|
+
export { watchCompilerFiles as a, relativeRequest as c, stillwindRules as d, createLoaderHost as i, requestOptions as l, recordProducer as n, sourceDescriptor as o, requireEmission as r, classifyRequest as s, installEmission as t, virtualRequest as u };
|
|
519
|
+
|
|
520
|
+
//# sourceMappingURL=emission-BVi5aRbb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emission-BVi5aRbb.js","names":[],"sources":["../src/webpack/rules.ts","../src/webpack/requests.ts","../src/webpack/sources.ts","../src/webpack/compilation-styles.ts","../src/webpack/host.ts","../src/webpack/emission.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { InlineConfig } from \"@stillwind/config\";\n\n/**\n * Derives the webpack rule identifier used by inline SFC loader requests.\n *\n * @param config - The same configuration values registered on the loader rule. JSON serialization\n * omits callbacks, so namingRevision must distinguish changed naming implementations.\n * @returns A stillwind-prefixed SHA-256 hash of the serialized configuration.\n * @throws If the configuration cannot be serialized as JSON.\n */\nexport function loaderOptionsId(config: InlineConfig): string {\n return \"stillwind-\" + createHash(\"sha256\").update(JSON.stringify(config)).digest(\"hex\");\n}\n\n/** webpack-compatible producer and source-map rules, also consumed by Rspack. */\nexport interface StillwindRule {\n /** Matches resource paths, including synthetic component script suffixes where required. */\n test: RegExp;\n /** Optional exclusion applied before the loader chain, normally for node_modules. */\n exclude?: RegExp;\n /** Placement relative to ordinary loaders. Omission uses the normal loader phase. */\n enforce?: \"pre\" | \"post\";\n /** Loader entries in webpack rule order, executed according to the bundler's loader phases. */\n use: (\n | string\n | {\n /** Absolute installed loader path. */\n loader: string;\n /** Discovery and inline settings retained by the rule and evaluated by its producer loader. */\n options: InlineConfig;\n /** Registered rule identity referenced by requests that retain naming callbacks. */\n ident: string;\n }\n )[];\n}\n\n/**\n * Builds producer, document CSS, and SFC source-map loader rules without evaluating configuration.\n *\n * @param config - Discovery and inline settings shared by producer rules. The object is retained.\n * @returns Rules using absolute paths in the installed integration package. The host provides its\n * CSS pipeline and registers StillwindPlugin when automatic document CSS is required.\n * @throws If loader resolution or configuration serialization fails.\n */\nexport function stillwindRules(config: InlineConfig): StillwindRule[] {\n return [\n {\n test: /\\.[cm]?[jt]sx?$/,\n exclude: /node_modules/,\n enforce: \"pre\",\n use: [\n {\n loader: fileURLToPath(\n new URL(\"./loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n options: config,\n ident: loaderOptionsId(config),\n },\n ],\n },\n {\n test: /\\.(?:astro|svelte|vue)$/,\n exclude: /node_modules/,\n enforce: \"pre\",\n use: [\n {\n loader: fileURLToPath(\n new URL(\"./loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n options: config,\n ident: loaderOptionsId(config),\n },\n ],\n },\n {\n test: /stillwind-webpack\\.css$/,\n enforce: \"post\",\n use: [\n fileURLToPath(\n new URL(\"./document-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n {\n test: /stillwind-webpack\\.css$/,\n enforce: \"pre\",\n use: [\n fileURLToPath(\n new URL(\"./css-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n {\n // Vue inline match resources select script rules with a synthetic .vue.ts suffix.\n test: /\\.(?:astro|svelte|vue)(?:\\.[cm]?[jt]sx?)?$/,\n exclude: /node_modules/,\n enforce: \"post\",\n use: [\n fileURLToPath(\n new URL(\"./source-map-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n ];\n}\n","import path from \"node:path\";\n\nimport type { BuildConfig, InlineConfig } from \"@stillwind/config\";\n\nimport { loaderOptionsId } from \"./rules.ts\";\n\n/** Compiler options carried by a loader rule or an encoded SFC subrequest. */\nexport type LoaderOptions = InlineConfig & {\n /**\n * Base64url-encoded JSON configuration for an SFC subrequest. Omit when the rule supplies options\n * directly.\n */\n stillwindOptions?: string;\n};\n\n/** Producer identity and flags that select compilation behavior for one loader request. */\nexport interface ProducerRequest {\n /** Whether `stillwind.css` requests document CSS without importing application JavaScript. */\n projection: boolean;\n /** Whether `stillwind-module-css` requests an explicit CSS value module. */\n cssValue: boolean;\n /** Whether the resource is an Astro, Svelte, or Vue file, including its generated blocks. */\n sfc: boolean;\n /**\n * Full script identity. SFC blocks, projections, CSS values, and export selections share the\n * original producer identity.\n */\n id: string;\n /** Whether a `raw` or `url` query requires the loader to leave the input unchanged. */\n passthrough: boolean;\n}\n\n/**\n * Classifies a resource request and chooses the producer identity used for compilation.\n *\n * @param resourcePath - Absolute resource path without its query.\n * @param resourceQuery - Query including its leading `?`, or an empty string.\n * @returns Request flags and a producer ID. SFC blocks, CSS values, and projections share the\n * original file identity. Export-selection queries do not change the producer identity.\n */\nexport function classifyRequest(resourcePath: string, resourceQuery = \"\"): ProducerRequest {\n const projection = /[?&]stillwind\\.css(?:&|$)/.test(resourceQuery);\n const cssValue = /[?&]stillwind-module-css(?:&|$)/.test(resourceQuery);\n const sfc = /\\.(?:astro|svelte|vue)$/.test(resourcePath);\n const parameters = new URLSearchParams(resourceQuery);\n let sourceQuery = resourceQuery;\n if (parameters.has(\"export\")) {\n parameters.delete(\"export\");\n const query = parameters.toString();\n sourceQuery = query ? `?${query}` : \"\";\n }\n\n return {\n projection,\n cssValue,\n sfc,\n // SFC integrations re-enter the loader for blocks compiled from the original producer.\n id: resourcePath + (projection || cssValue || sfc ? \"\" : sourceQuery),\n passthrough: /[?&](?:raw|url)(?:[=&]|$)/.test(resourceQuery),\n };\n}\n\n/**\n * Reads compiler options from a rule or an encoded SFC subrequest.\n *\n * @param supplied - Rule options, optionally containing `stillwindOptions` encoded as base64url\n * JSON.\n * @returns Decoded options when `stillwindOptions` is present, otherwise the supplied object.\n * @throws If encoded configuration is not valid JSON.\n */\nexport function requestOptions(supplied: LoaderOptions): InlineConfig {\n return supplied.stillwindOptions\n ? JSON.parse(Buffer.from(supplied.stillwindOptions, \"base64url\").toString(\"utf8\"))\n : supplied;\n}\n\n/**\n * Creates a module request with forward slashes, relative to the importer when possible.\n *\n * @param from - Absolute directory containing the importing module.\n * @param to - Absolute path of the requested resource.\n * @returns A relative request with `./` when needed, or an absolute path across Windows volumes.\n */\nexport function relativeRequest(from: string, to: string): string {\n const value = path.relative(from, to).replaceAll(\"\\\\\", \"/\");\n return path.isAbsolute(value) || value.startsWith(\".\") ? value : `./${value}`;\n}\n\n/**\n * Creates a CSS projection or CSS value request that retains the producer configuration.\n *\n * SFC requests bypass other loaders. Naming callbacks use a registered rule identifier because JSON\n * cannot encode functions.\n *\n * @param resourcePath - Absolute path of the original producer.\n * @param sfc - Whether the producer is an Astro, Svelte, or Vue file.\n * @param config - Compiler config used for the original producer.\n * @param loaderPath - Absolute path of the producer loader.\n * @param query - Stillwind query text without a leading `?`.\n * @param identityConfig - Original inline settings registered on the loader rule. When evaluated\n * config contains naming callbacks, this selects that rule instead of serializing callbacks.\n * Defaults to config when file evaluation has not changed the registered settings.\n * @returns A relative resource request for scripts, or an inline loader request for SFCs.\n * @throws If SFC settings cannot be serialized for their inline request.\n */\nexport function virtualRequest(\n resourcePath: string,\n sfc: boolean,\n config: BuildConfig,\n loaderPath: string,\n query: string,\n identityConfig: InlineConfig = config,\n): string {\n if (!sfc) {\n return `${relativeRequest(path.dirname(resourcePath), resourcePath)}?${query}`;\n }\n\n const configuration = config.naming\n ? \"??\" + loaderOptionsId(identityConfig)\n : \"?stillwindOptions=\" + Buffer.from(JSON.stringify(config)).toString(\"base64url\");\n return `!!${loaderPath.replaceAll(\"\\\\\", \"/\")}${configuration}!${resourcePath.replaceAll(\"\\\\\", \"/\")}?${query}`;\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\n\nimport { cleanModuleId, fileModuleDescriptor } from \"@stillwind/host\";\n\n/**\n * Keeps each query-selected derivative's compiler, checker, and source-map identities distinct.\n * @param root - Absolute project root used to derive compiler identities.\n * @param id - Full source identity, including any query or fragment selecting transformed source.\n * @returns Ordinary file metadata without a suffix, or distinct module/document identities and a hashed checker filename.\n */\nexport function sourceDescriptor(root: string, id: string) {\n const descriptor = fileModuleDescriptor(root, id);\n const file = cleanModuleId(id);\n const suffix = id.slice(file.length);\n if (!suffix) {\n return descriptor;\n }\n const extension = path.extname(file);\n const key = createHash(\"sha256\").update(id).digest(\"hex\");\n const checkerFileName = path.join(\n path.dirname(file),\n `.${path.basename(file, extension)}.stillwind-${key}${extension}`,\n );\n return {\n ...descriptor,\n moduleId: descriptor.moduleId + suffix,\n document: {\n ...descriptor.document,\n uri: descriptor.document.uri + suffix,\n },\n checkerFileName,\n projectionFileName: checkerFileName.replaceAll(\"\\\\\", \"/\"),\n };\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport {\n cleanModuleId,\n cssEntrypoint,\n cssWithSourceMap,\n loadCssGraph,\n nodePluginHost,\n warnRejectedNames,\n type CssUpstreamMap,\n} from \"@stillwind/host\";\n\nimport { buildCompilerOptions, IntegrationSession, warnSkippedCss } from \"../session.ts\";\nimport type { ProducerInput } from \"./emission.ts\";\nimport type { CompilationHost } from \"./host.ts\";\nimport { relativeRequest } from \"./requests.ts\";\nimport { sourceDescriptor } from \"./sources.ts\";\n\n/**\n * Recompiles recorded producers and renders document CSS for a completed compilation.\n *\n * Manual producers are compiled for dependency composition but are excluded from the document\n * selection. The temporary compiler closes after reconstruction.\n *\n * @param producers - Nonempty list of producers from the completed graph. Every producer must use\n * the same root and config.\n * @param io - Compilation host that reads captured dependency sources and resolves CSS, scripts,\n * and assets.\n * @param mode - Bundler mode. Only `development` selects development compilation.\n * @param watch - Registers a file as a compilation dependency.\n * @param watchDirectory - Registers a directory whose entry additions and removals invalidate the\n * compilation.\n * @param warn - Reports compiler warnings and the CSS statements that loading skipped through the\n * bundler.\n * @returns Document CSS with asset requests and an inline source map composed with recorded\n * upstream maps.\n * @throws If producers use different design systems, a dependency source is missing, or loading or\n * compilation fails.\n */\nexport async function compilationStyles(\n producers: readonly ProducerInput[],\n io: CompilationHost,\n mode: string | undefined,\n watch: (id: string) => void,\n watchDirectory: (id: string) => void,\n warn: (message: string) => void,\n): Promise<string> {\n const { config, root } = producers[0];\n const readDependency = io.dependencyReader(producers);\n const loaded = await loadCssGraph(\n path.resolve(root, cssEntrypoint(config)),\n buildCompilerOptions(config),\n {\n read: io.read,\n resolve: io.resolveCss,\n documentUri: (id) => pathToFileURL(id).href,\n sourceMapSource: (id) => pathToFileURL(id).href,\n watch,\n watchDirectory,\n plugins: nodePluginHost,\n },\n undefined,\n undefined,\n {\n plugins: config.plugins,\n tailwind: config.tailwind,\n important: config.important,\n root,\n },\n );\n warnSkippedCss(loaded.skipped, warn);\n const compiler = new IntegrationSession(\n root,\n loaded.loader,\n config,\n false,\n mode === \"development\" ? \"development\" : \"release\",\n loaded.plugins,\n );\n const selection: string[] = [];\n try {\n for (const input of producers) {\n if (input.root !== root || JSON.stringify(input.config) !== JSON.stringify(config)) {\n throw new Error(\"A compilation must use one Stillwind design system\");\n }\n const output = await compiler.compile(\n input.source,\n input.id,\n {\n describe: (id) => sourceDescriptor(root, id),\n resolve: async (specifier, importer) => ({\n id: await io.resolveJs(specifier, importer),\n }),\n read: readDependency,\n watch: (id) => {\n watch(cleanModuleId(id));\n },\n warn,\n },\n {\n moduleCssImport: \"stillwind/module-css\",\n },\n );\n if (output && !input.manual) {\n selection.push(output.moduleId);\n }\n }\n const revision = createHash(\"sha256\")\n .update(producers.map((input) => `${input.source}\\0`).join(\"\"))\n .digest(\"hex\");\n const plan = compiler.native.planStylesheet({\n modules: selection,\n coverage: {\n kind: \"complete\",\n target: \"compilation\",\n revision,\n },\n placement: \"document\",\n });\n warnRejectedNames(plan.rejectedNames, warn);\n const replacements = new Map<string, string>();\n for (const resource of [...loaded.resources, ...plan.resources]) {\n const owner =\n \"moduleId\" in resource ? compiler.resolverId(resource.moduleId) : resource.sourceName;\n const file = await io.resolveAsset(resource.specifier, owner);\n watch(file);\n const request = relativeRequest(\n path.dirname(fileURLToPath(import.meta.resolve(\"@stillwind/integration/webpack\"))),\n file,\n );\n replacements.set(resource.placeholder, JSON.stringify(request).slice(1, -1));\n }\n return cssWithSourceMap(\n plan,\n replacements,\n producers.flatMap((input) =>\n [\n input.upstream,\n ...(input.dependencies ?? []).map((dependency) => dependency.upstream),\n ].filter((upstream): upstream is CssUpstreamMap => Boolean(upstream)),\n ),\n );\n } finally {\n compiler.close();\n }\n}\n","import fs from \"node:fs\";\nimport { isBuiltin } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { cleanModuleId, type UpstreamSourceMap } from \"@stillwind/host\";\n\nimport { nativeBindingFiles } from \"../binding-files.ts\";\nimport type { ProducerInput } from \"./emission.ts\";\n\n/** Resolver policies passed to webpack or Rspack for CSS, script, and asset imports. */\nexport interface ResolveSettings {\n /** Dependency category used to select bundler resolution behavior, such as `esm`. */\n dependencyType?: string;\n /** Package export conditions considered when resolving a request. */\n conditionNames?: string[];\n /** File extensions tested for extensionless requests, in resolution order. */\n extensions?: string[];\n /** Package metadata fields considered in resolution order. */\n mainFields?: string[];\n}\n\n/**\n * Completion handler for webpack or Rspack resolution.\n *\n * @param error - Resolution failure, or null or undefined when no error occurred.\n * @param id - Resolved resource identity. A missing or false ID declines the request.\n */\nexport type ResolveCallback = (error?: Error | null, id?: string | false) => void;\n\n/**\n * Resolver bound to the bundler's configured conditions, extensions, and package fields.\n *\n * @param directory - Absolute directory of the importing file.\n * @param specifier - Import or resource request text, including any query suffix.\n * @param callback - Receives the resolution failure or resulting resource identity.\n */\nexport type Resolver = (directory: string, specifier: string, callback: ResolveCallback) => void;\n\n/** Bundler filesystem and resolver operations shared by producer loaders and CSS reconstruction. */\nexport interface ResolverHost {\n /** Bundler input filesystem. Reads may return UTF-8 text or bytes through the callback. */\n fs: {\n /**\n * Reads through the bundler filesystem rather than bypassing its virtual files.\n * @param id - Filesystem identity without a resource query.\n * @param callback - Receives an error or file contents. Callers convert successful contents to text.\n */\n readFile(id: string, callback: (error?: Error | null, value?: string | Buffer) => void): void;\n };\n /**\n * Creates a callback resolver with the requested dependency policy.\n *\n * @param settings - Conditions, extensions, and package fields used for this resolver.\n * @returns A resolver accepting the importer directory, request text, and a completion callback.\n */\n getResolve(settings: ResolveSettings): Resolver;\n}\n\n/**\n * Loader operations required to resolve producers, capture transformed dependencies, and report\n * compilation inputs.\n */\ninterface LoaderHostContext extends ResolverHost {\n /**\n * Complete loader chain. Entries after `loaderIndex` run before Stillwind in the normal loader\n * phase.\n */\n loaders: readonly {\n /** Complete inline loader request, including its options, reused for dependency capture. */\n request: string;\n }[];\n /** Index of the currently executing Stillwind loader within `loaders`. */\n loaderIndex: number;\n /**\n * Evaluates a generated capture module through the specified loader chain.\n *\n * @param request - Inline request whose capture loader exports source and map instead of\n * executing application code.\n * @returns A promise for the generated capture module exports.\n */\n importModule(request: string): Promise<unknown>;\n /**\n * Registers a source or compiler file as a dependency of this loader result.\n *\n * @param id - Absolute filesystem path without a resource query.\n */\n addDependency(id: string): void;\n /**\n * Reports a compilation warning through the loader context.\n *\n * @param error - Warning represented as an Error instance.\n */\n emitWarning(error: Error): void;\n}\n\n/** Source and map exported by the capture loader after preceding framework transforms. */\nexport interface CapturedDependency {\n /** Transformed source text consumed by the compiler, without executing its application code. */\n source: string;\n /** Upstream map supplied by preceding loaders, or null when none was supplied. */\n map: UpstreamSourceMap;\n}\n\n/** Compiler operations and retained dependency captures for one producer loader invocation. */\nexport interface LoaderHost {\n /**\n * Reads a resource through the bundler input filesystem.\n *\n * @param id - Readable filesystem path without a query.\n * @returns A promise for the file contents converted to a string.\n */\n read: (id: string) => Promise<string>;\n /**\n * Reads ordinary files or captures query-qualified source through preceding loaders.\n *\n * @param dependency - Full resolver identity, including any query suffix.\n * @returns A promise for source text, rejecting if reading or capture fails.\n */\n readDependency: (dependency: string) => Promise<string>;\n /**\n * Pending transformed-source captures keyed by full resolver identity, retained for emission\n * metadata.\n */\n dependencySources: Map<string, Promise<CapturedDependency>>;\n /**\n * Resolves a CSS import using style export conditions and CSS extensions.\n *\n * @param specifier - CSS import text.\n * @param importer - Absolute path of the importing stylesheet.\n * @returns A promise for the resolved identity, or an empty string when the resolver declines it.\n */\n resolveCss: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves an asset using the bundler's default resolution policy.\n *\n * @param specifier - Asset request text.\n * @param importer - Absolute identity of the resource owner.\n * @returns A promise for the resolved identity, or an empty string when the resolver declines it.\n */\n resolveAsset: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a script dependency and marks Node builtins as external.\n *\n * @param specifier - Script import text, optionally naming a Node builtin.\n * @param importer - Absolute identity of the importing producer.\n * @returns A promise for the resolved identity and optional external status, or null when the\n * resolver declines the request. Other resolution errors reject the promise.\n */\n resolve: (\n specifier: string,\n importer: string,\n ) => Promise<{\n /** Full resolved source identity or Node builtin name. */\n id: string;\n /** Whether semantic traversal must skip loading the dependency as source. */\n external?: boolean;\n } | null>;\n /**\n * Registers the underlying file of a resolver identity as a loader dependency.\n *\n * @param id - File identity, optionally including a resource query that is removed before\n * registration.\n */\n watch: (id: string) => void;\n /**\n * Reports a compiler warning through the loader context.\n *\n * @param message - Warning text converted to an Error instance for the bundler.\n */\n warn: (message: string) => void;\n}\n\n/**\n * Creates compiler operations from a producer loader context and tracks the loader itself as a\n * dependency.\n *\n * Ordinary dependencies are read from the filesystem. Query-qualified dependencies pass through\n * preceding loaders and the capture loader. Pending captures are reused by their full resolver\n * identity.\n *\n * @param context - Active loader context with a complete loader chain and an `importModule`\n * implementation for query-qualified dependencies.\n * @param loaderPath - Absolute path of the Stillwind loader to register as a dependency.\n * @returns A host that resolves imports, reads files, captures transformed dependencies, and\n * forwards warnings.\n */\nexport function createLoaderHost(context: LoaderHostContext, loaderPath: string): LoaderHost {\n const read = createReadFile(context.fs);\n const dependencySources = new Map<string, Promise<CapturedDependency>>();\n /**\n * Reads an ordinary dependency or captures transformed text through preceding loaders.\n * @param dependency - Full resolver identity. A query or fragment requires a loader capture.\n * @returns File text or captured text. Capture promises, including failures, are retained by identity.\n * @throws If filesystem reading or the dependency's loader chain fails.\n */\n const readDependency = async (dependency: string) => {\n if (cleanModuleId(dependency) === dependency) {\n return read(dependency);\n }\n let pending = dependencySources.get(dependency);\n if (!pending) {\n const capture = fileURLToPath(\n new URL(\"./source-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n );\n const preceding = context.loaders\n .slice(context.loaderIndex + 1)\n .map((loader) => loader.request);\n pending = context.importModule(\n `!!${[capture, ...preceding, dependency].join(\"!\")}`,\n ) as Promise<CapturedDependency>;\n dependencySources.set(dependency, pending);\n }\n return (await pending).source;\n };\n /**\n * Adapts loader resolution to requests relative to a source file.\n * @param settings - Resolution policy passed to the loader's resolver factory.\n * @returns An asynchronous resolver accepting a specifier and full importer identity. Resolver\n * errors reject its promise, and a missing result becomes an empty string.\n */\n const resolver = (settings: ResolveSettings) => {\n const resolve = context.getResolve(settings);\n return (specifier: string, importer: string) =>\n new Promise<string>((done, reject) =>\n resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) =>\n error ? reject(error) : done(id || \"\"),\n ),\n );\n };\n const resolveCss = resolver(cssResolveOptions);\n const resolveJs = resolver({\n dependencyType: \"esm\",\n extensions: [\".tsx\", \".ts\", \".jsx\", \".js\", \".mjs\", \".cjs\", \".json\"],\n });\n const resolveAsset = resolver({});\n /**\n * Registers a filesystem dependency for loader invalidation.\n * @param id - Full resolver identity whose query and fragment are removed before registration.\n */\n const watch = (id: string) => context.addDependency(cleanModuleId(id));\n watch(loaderPath);\n return {\n read,\n readDependency,\n dependencySources,\n resolveCss,\n resolveAsset,\n resolve: async (specifier: string, importer: string) => {\n if (specifier.startsWith(\"node:\") && isBuiltin(specifier)) {\n return { id: specifier, external: true };\n }\n try {\n const id = await resolveJs(specifier, importer);\n return id ? { id } : null;\n } catch (error) {\n if (isBuiltin(specifier)) {\n return { id: specifier, external: true };\n }\n throw error;\n }\n },\n watch,\n warn: (message: string) => context.emitWarning(new Error(message)),\n };\n}\n\n/**\n * Registers compiler runtime files so changes invalidate cached loader results.\n *\n * The function includes native binding files and JavaScript files beside the published host\n * entrypoint.\n *\n * @param watch - Registers an absolute file path as a loader dependency.\n * @throws If the host runtime directory cannot be read.\n */\nexport function watchCompilerFiles(watch: (id: string) => void): void {\n for (const file of nativeBindingFiles()) {\n watch(file);\n }\n const directory = path.dirname(fileURLToPath(import.meta.resolve(\"@stillwind/host\")));\n for (const file of fs.readdirSync(directory)) {\n if (file.endsWith(\".js\")) {\n watch(path.join(directory, file));\n }\n }\n}\n\n/** File and resolver operations used after producer modules have completed compilation. */\nexport interface CompilationHost {\n /**\n * Reads the underlying file through the bundler input filesystem.\n *\n * @param id - Resolver identity whose query suffix is removed before reading.\n * @returns A promise for the file contents converted to a string.\n */\n read: (id: string) => Promise<string>;\n /**\n * Creates a reader that prefers captured producer and dependency sources over filesystem reads.\n *\n * @param producers - Producer metadata collected from the completed compilation graph.\n * @returns A reader keyed by full resolver identity. Missing query-qualified captures reject.\n * Ordinary uncaptured files are read through the filesystem.\n */\n dependencyReader: (producers: readonly ProducerInput[]) => (id: string) => Promise<string>;\n /**\n * Resolves an import from the design-system CSS graph.\n *\n * @param specifier - CSS import text.\n * @param importer - Absolute path of the importing stylesheet.\n * @returns A promise for the resolver's file identity, rejecting on resolution errors.\n */\n resolveCss: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a producer dependency, including supported framework source extensions.\n *\n * @param specifier - Script or framework import text.\n * @param importer - Absolute identity of the importing producer.\n * @returns A promise for the resolver's identity, retaining resource queries.\n */\n resolveJs: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a stylesheet asset using the bundler's default resolution policy.\n *\n * @param specifier - Asset request text.\n * @param importer - Absolute identity of the stylesheet or producer that owns the resource.\n * @returns A promise for the resolver's identity, rejecting on resolution errors.\n */\n resolveAsset: (specifier: string, importer: string) => Promise<string>;\n}\n\n/**\n * Creates filesystem and resolution operations for reconstructing a completed compilation.\n *\n * Reconstruction resolves framework source files as well as scripts. Query-qualified dependency\n * reads require captured source from producer metadata.\n *\n * @param context - Bundler input filesystem and resolver factory operations.\n * @returns A host that reads files and builds dependency readers from retained producer metadata.\n */\nexport function createCompilationHost(context: ResolverHost): CompilationHost {\n const read = createReadFile(context.fs, cleanModuleId);\n /**\n * Adapts compilation resolution to requests relative to a source file.\n * @param settings - Resolution policy passed to the bundler's resolver factory.\n * @returns An asynchronous resolver accepting a specifier and full importer identity. It forwards\n * successful resolver results without checking for an absent identity, and rejects resolver errors.\n */\n const resolver = (settings: ResolveSettings) => {\n const resolve = context.getResolve(settings);\n return (specifier: string, importer: string) =>\n new Promise<string>((done, reject) =>\n resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) =>\n error ? reject(error) : done(id as string),\n ),\n );\n };\n return {\n read,\n /**\n * Creates a reader using source captured by the completed module graph.\n * @param producers - Producer and dependency records. Later records replace earlier text for the same identity.\n * @returns A reader that uses exact captured identities before falling back to ordinary filesystem reads.\n */\n dependencyReader(producers: readonly ProducerInput[]) {\n const sources = new Map<string, string>();\n for (const input of producers) {\n sources.set(input.id, input.source);\n for (const dependency of input.dependencies ?? []) {\n sources.set(dependency.id, dependency.source);\n }\n }\n return (id: string) => {\n if (sources.has(id)) {\n return Promise.resolve(sources.get(id)!);\n }\n if (cleanModuleId(id) !== id) {\n return Promise.reject(new Error(`No transformed source captured for ${id}`));\n }\n return read(id);\n };\n },\n resolveCss: resolver(cssResolveOptions),\n resolveJs: resolver({\n dependencyType: \"esm\",\n extensions: [\".tsx\", \".ts\", \".jsx\", \".js\", \".mjs\", \".cjs\", \".vue\", \".svelte\", \".astro\"],\n }),\n resolveAsset: resolver({}),\n };\n}\n\n/**\n * CSS resolution policy that prefers style exports and metadata fields before ordinary package\n * entrypoints.\n */\nconst cssResolveOptions = {\n conditionNames: [\"style\", \"import\", \"default\"],\n extensions: [\".css\"],\n mainFields: [\"style\", \"main\"],\n};\n\n/**\n * Adapts the bundler filesystem to asynchronous string reads.\n *\n * @param filesystem - Input filesystem that completes reads through a callback.\n * @param fileId - Maps resolver identities to readable paths. Defaults to keeping the identity\n * unchanged.\n * @returns A reader that resolves to the filesystem value converted to a string, or rejects on read\n * failure.\n */\nfunction createReadFile(filesystem: ResolverHost[\"fs\"], fileId = (id: string) => id) {\n return (id: string) =>\n new Promise<string>((resolve, reject) =>\n filesystem.readFile(fileId(id), (error, value) =>\n error ? reject(error) : resolve(String(value)),\n ),\n );\n}\n","import type { BuildConfig } from \"@stillwind/config\";\nimport type { ResolvedIntegrationConfig } from \"@stillwind/config/node\";\nimport type { CssUpstreamMap } from \"@stillwind/host\";\n\nimport { compilationStyles } from \"./compilation-styles.ts\";\nimport { createCompilationHost, type ResolverHost } from \"./host.ts\";\n\n/**\n * A producer and its captured dependencies stored in bundler metadata for CSS reconstruction.\n */\nexport interface ProducerInput {\n /** Source text received by the producer loader, before Stillwind compilation. */\n source: string;\n /** Producer identity. Query-qualified script dependencies retain their query suffix. */\n id: string;\n /** Absolute project root against which compiler module identities are resolved. */\n root: string;\n /** Compiler configuration shared by every producer in this compilation. */\n config: BuildConfig;\n /**\n * Whether this producer is excluded from automatic document CSS and supplies explicit CSS values.\n */\n manual: boolean;\n /** Map from loader input back to the original source, used when composing final CSS maps. */\n upstream?: CssUpstreamMap;\n /**\n * Transformed dependencies captured through the loader chain. Cached metadata retains them for\n * reconstruction.\n */\n dependencies?: {\n /** Complete resolver identity, including the query that selected the transformed dependency. */\n id: string;\n /** Source produced by the loaders that ran before Stillwind. */\n source: string;\n /**\n * Map from the captured source back to its original source, when the preceding loaders supplied\n * one.\n */\n upstream?: CssUpstreamMap;\n }[];\n}\n\n/**\n * Stores a producer in module build metadata so cached modules can participate in CSS\n * reconstruction.\n *\n * @param context - Loader context for a module in a compilation registered by `StillwindPlugin`.\n * @param input - Producer source, compiler configuration, and captured dependency sources.\n * @throws If the compilation has no registered emission hook or the loader context has no module.\n */\nexport function recordProducer<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n input: ProducerInput,\n): void {\n requireEmission(context);\n if (!context._module) {\n throw new Error(incompleteGraphMessage);\n }\n context._module.buildInfo ??= {};\n context._module.buildInfo.stillwind = input;\n}\n\n/**\n * Bundler module metadata used to recover cached producer inputs and identify the shared document\n * CSS carrier.\n */\nexport interface EmissionModule {\n /** Resource path and query used to identify the shared document CSS carrier. */\n resource?: string;\n /** Build metadata retained by the bundler when a module is reused from cache. */\n buildInfo?: {\n /** Producer input reconstructed after the compilation graph is complete. */\n stillwind?: ProducerInput;\n /** Build fields owned by the bundler or other plugins, retained without interpretation. */\n [key: string]: unknown;\n };\n}\n\n/**\n * Compilation operations required to collect producers and rebuild document CSS carriers.\n */\nexport interface EmissionCompilation<Module extends EmissionModule = EmissionModule> {\n /** Parent compilation used by CSS extraction loaders that run a child compiler. */\n compiler?: {\n parentCompilation?: EmissionCompilation<Module>;\n };\n /** Settings evaluated by StillwindPlugin before the build run, reused by producer loaders. */\n __stillwindConfiguration?: ResolvedIntegrationConfig;\n /** Missing configuration candidates whose creation must trigger a watch rebuild. */\n missingDependencies: {\n /**\n * Registers a missing path so its creation invalidates this compilation.\n *\n * @param id - Absolute missing configuration candidate.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Compilation lifecycle operations used to wait for the completed producer graph. */\n hooks: {\n /** Runs after ordinary module builds, before document carriers are rebuilt. */\n finishModules: {\n /**\n * Registers asynchronous CSS reconstruction for the completed modules.\n *\n * @param name - Plugin registration name.\n * @param callback - Operation receiving cached and newly built modules. Rejections fail compilation.\n */\n tapPromise(name: string, callback: (modules: Iterable<Module>) => Promise<void>): void;\n };\n };\n /** Files whose changes invalidate reconstructed CSS. */\n fileDependencies: {\n /**\n * Adds a compiler or source file to watch tracking.\n *\n * @param id - Absolute dependency path.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Directories whose entry additions and removals invalidate reconstructed CSS. */\n contextDependencies: {\n /**\n * Adds a directory that a plugin lists to watch tracking.\n *\n * @param id - Absolute directory path.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Bundler warning collection receiving compiler lint and rejected-name messages. */\n warnings: {\n /**\n * Appends a warning without failing reconstruction.\n *\n * @param error - Warning represented as an Error instance.\n * @returns The collection's append result, which Stillwind ignores.\n */\n push(error: Error): unknown;\n };\n /**\n * Reruns a document carrier after reconstructed CSS has been stored on the compilation.\n *\n * @param module - Carrier from the completed module graph.\n * @param callback - Completion handler receiving an error when rebuilding fails.\n */\n rebuildModule(module: Module, callback: (error?: Error | null) => void): void;\n /**\n * Reconstructed document CSS, optionally including an inline source map. Undefined before\n * reconstruction.\n */\n __stillwindCss?: string;\n}\n\n/**\n * Bundler context used to register emission and attach producer metadata to the current\n * compilation.\n */\nexport interface EmissionContext<\n Module extends EmissionModule = EmissionModule,\n> extends ResolverHost {\n /** Current compilation, required when recording producers or installing document CSS reconstruction. */\n _compilation?: EmissionCompilation<Module>;\n /** Current bundler module whose buildInfo retains producer metadata. */\n _module?: Module;\n /**\n * Bundler mode forwarded to CSS reconstruction. Only `development` selects development\n * compilation.\n */\n mode?: string;\n}\n\n/**\n * Registers CSS reconstruction after all modules in the compilation have finished.\n *\n * Registration is idempotent for a compilation. The hook collects cached and newly built producers,\n * stores document CSS, and rebuilds each carrier through the host CSS pipeline.\n *\n * @param context - Context with a compilation, filesystem, and resolver. Register it before\n * producer loaders run.\n * @throws If the context has no compilation with a `finishModules` hook.\n */\nexport function installEmission<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): void {\n const compilation = requireCompilation(context);\n if (installed.has(compilation)) {\n return;\n }\n installed.add(compilation);\n const io = createCompilationHost(context);\n compilation.hooks.finishModules.tapPromise(\"StillwindEmission\", async (modules) => {\n const completed = [...modules];\n const producers = completed\n .map((module) => module.buildInfo?.stillwind)\n .filter((input): input is ProducerInput => Boolean(input));\n const carriers = completed.filter((module) =>\n module.resource?.includes(\"stillwind-webpack.css?stillwind-document\"),\n );\n if (!carriers.length || !producers.length) {\n return;\n }\n compilation.__stillwindCss = await compilationStyles(\n producers,\n io,\n context.mode,\n (id) => {\n compilation.fileDependencies.add(id);\n },\n (id) => {\n compilation.contextDependencies.add(id);\n },\n (message) => {\n compilation.warnings.push(new Error(message));\n },\n );\n for (const carrier of carriers) {\n await new Promise<void>((resolve, reject) =>\n compilation.rebuildModule(carrier, (error) => (error ? reject(error) : resolve())),\n );\n }\n });\n}\n\n/**\n * Compilations whose emission hooks have been registered. Membership is required before automatic\n * loaders record producers.\n */\nconst installed = new WeakSet<object>();\n\nconst incompleteGraphMessage =\n \"Automatic Stillwind CSS requires new StillwindPlugin(config) before compilation begins\";\n\n/**\n * Obtains the compilation operations needed to reconstruct document CSS.\n *\n * @param context - Bundler context that must expose a `finishModules` compilation hook.\n * @returns The compilation attached to the context.\n * @throws If the context cannot supply a completed compilation graph.\n */\nfunction requireCompilation<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): EmissionCompilation<Module> {\n const compilation = context._compilation;\n if (!compilation?.hooks?.finishModules) {\n throw new Error(incompleteGraphMessage);\n }\n return compilation;\n}\n\n/**\n * Rejects automatic CSS requests when the compilation has no registered emission hook.\n *\n * @param context - Loader context associated with a compilation registered by `StillwindPlugin`.\n * @returns The nearest registered compilation holding reconstructed document CSS.\n * @throws If the compilation is missing or its emission hook has not been registered.\n */\nexport function requireEmission<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): EmissionCompilation<Module> {\n let compilation = requireCompilation(context);\n while (!installed.has(compilation)) {\n const parent = compilation.compiler?.parentCompilation;\n if (!parent) {\n throw new Error(incompleteGraphMessage);\n }\n compilation = parent;\n }\n return compilation;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAaA,SAAgB,gBAAgB,QAA8B;CAC5D,OAAO,eAAe,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK;AACxF;;;;;;;;;AAgCA,SAAgB,eAAe,QAAuC;CACpE,OAAO;EACL;GACE,MAAM;GACN,SAAS;GACT,SAAS;GACT,KAAK,CACH;IACE,QAAQ,cACN,IAAI,IAAI,eAAe,YAAY,QAAQ,gCAAgC,CAAC,CAC9E;IACA,SAAS;IACT,OAAO,gBAAgB,MAAM;GAC/B,CACF;EACF;EACA;GACE,MAAM;GACN,SAAS;GACT,SAAS;GACT,KAAK,CACH;IACE,QAAQ,cACN,IAAI,IAAI,eAAe,YAAY,QAAQ,gCAAgC,CAAC,CAC9E;IACA,SAAS;IACT,OAAO,gBAAgB,MAAM;GAC/B,CACF;EACF;EACA;GACE,MAAM;GACN,SAAS;GACT,KAAK,CACH,cACE,IAAI,IAAI,wBAAwB,YAAY,QAAQ,gCAAgC,CAAC,CACvF,CACF;EACF;EACA;GACE,MAAM;GACN,SAAS;GACT,KAAK,CACH,cACE,IAAI,IAAI,mBAAmB,YAAY,QAAQ,gCAAgC,CAAC,CAClF,CACF;EACF;EACA;GAEE,MAAM;GACN,SAAS;G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 +1,10 @@
|
|
|
1
|
+
import { t as IntegrationConfig } from "../project-DUGu8g_L.js";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
/**
|
|
4
|
+
* Registers Stillwind after Fresh 2's Deno source loader. Place it after `fresh()`.
|
|
5
|
+
* Macro identities use the original files in both environments, so SSR and islands
|
|
6
|
+
* receive the same classes. Vite lowers the compiled JSX for Preact.
|
|
7
|
+
*/
|
|
8
|
+
export declare function stillwind(config?: IntegrationConfig): Plugin[];
|
|
9
|
+
export type { IntegrationConfig };
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|