@kanso-labs/unplugin-style-dictionary 0.8.0 → 0.9.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/README.md +167 -5
- package/dist/index.js +123 -20
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +58 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,8 +21,9 @@ build on Rolldown/tsdown) that both need tokens compiled ahead of them.
|
|
|
21
21
|
- **Asynchronous builds**: Native support for Style Dictionary v4/v5 async
|
|
22
22
|
compilation API.
|
|
23
23
|
- **Automatic watching**: Reads the `source` and `include` patterns from your
|
|
24
|
-
Style Dictionary configurations and watches the files they match
|
|
25
|
-
|
|
24
|
+
Style Dictionary configurations and watches the files they match, including a
|
|
25
|
+
token package resolved through `node_modules` in a workspace. What a change
|
|
26
|
+
then triggers depends on the target — see
|
|
26
27
|
[Watching, per target](#watching-per-target).
|
|
27
28
|
- **Config flexibility**: Supports file paths (JSON, JSON5, JSONC, JS, MJS, TS),
|
|
28
29
|
configuration objects, or functions — including registering custom formats at
|
|
@@ -127,6 +128,33 @@ _The subpaths also need a TypeScript `moduleResolution` of `bundler`, `node16`
|
|
|
127
128
|
or `nodenext`. The deprecated `node10` cannot resolve them, and TypeScript 6
|
|
128
129
|
already warns that it stops working in 7._
|
|
129
130
|
|
|
131
|
+
### Finding a Config File
|
|
132
|
+
|
|
133
|
+
With no `config`, the root is searched for `sd.config.json`, `config.json`,
|
|
134
|
+
`sd.config.js` and `sd.config.mjs`, in that order — and the first one that
|
|
135
|
+
**looks like a Style Dictionary configuration** wins. That means declaring at
|
|
136
|
+
least one of `platforms`, `source`, `include` or `tokens`. A candidate that
|
|
137
|
+
fails the check is reported and skipped rather than adopted, so an unrelated
|
|
138
|
+
`config.json` — an extremely common name for something else — no longer gets
|
|
139
|
+
compiled over and added to the watch set. The path that was picked is printed,
|
|
140
|
+
so which configuration a build used is answerable from the console.
|
|
141
|
+
|
|
142
|
+
`config.json` stays in the list because Style Dictionary's own CLI defaults to
|
|
143
|
+
it, so a project relying on that default keeps working.
|
|
144
|
+
|
|
145
|
+
**Two of the four names are modules, and reading a module runs it.** A root
|
|
146
|
+
`sd.config.js` is imported — freshly, on every watch event — and validation
|
|
147
|
+
cannot prevent that, because the check can only look at what the import
|
|
148
|
+
returned. If you name your configuration explicitly, or have none, say so:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
StyleDictionary({ config: false })
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
That turns discovery off entirely: nothing is looked for, nothing is watched,
|
|
155
|
+
and nothing is compiled. A configuration you name yourself is never
|
|
156
|
+
second-guessed by the check above — it goes straight to Style Dictionary.
|
|
157
|
+
|
|
130
158
|
### Config File Formats
|
|
131
159
|
|
|
132
160
|
A `config` path may be `.json`, `.json5`, `.jsonc`, `.js`, `.mjs` or `.ts`. The
|
|
@@ -287,12 +315,78 @@ reaches no hook, while on a Linux runner the same edit reaches a rebuild. Treat
|
|
|
287
315
|
rolldown's watch mode as compiling once and not tracking tokens, and reach for a
|
|
288
316
|
one-shot build or another target if you need rebuild-on-change.
|
|
289
317
|
|
|
318
|
+
**A token package resolved through `node_modules` is watched too, and that took
|
|
319
|
+
a fix.** In a workspace — `app/node_modules/@acme/tokens` symlinked to
|
|
320
|
+
`packages/tokens` — Vite's dev-server watcher is built with `**/node_modules/**`
|
|
321
|
+
already in its ignore list, and the entries a consumer adds are appended after
|
|
322
|
+
it rather than subtracted from it. So the first build was correct and no edit
|
|
323
|
+
ever rebuilt, with nothing printed to say so. The plugin now un-ignores exactly
|
|
324
|
+
the files it registers, by name, on Vite 6, 7 and 8. The rest of `node_modules`
|
|
325
|
+
stays ignored, which matters: handing the whole dependency tree to the watcher
|
|
326
|
+
is thousands of files no token build reads.
|
|
327
|
+
|
|
328
|
+
Nothing is needed from you for that. If you had worked around it with a
|
|
329
|
+
`server.watch.ignored` negation of your own, it still works — the plugin appends
|
|
330
|
+
to your list rather than replacing it.
|
|
331
|
+
|
|
290
332
|
"Safe from rebuild loops" is worth stating because consuming code imports the
|
|
291
333
|
generated file, so every regenerate is itself a change the host reacts to. The
|
|
292
334
|
plugin subtracts its own output from the watch list, skips recompiling when a
|
|
293
335
|
watch rebuild re-enters `buildStart`, and skips the write entirely when a
|
|
294
336
|
rebuild renders bytes identical to what is already on disk.
|
|
295
337
|
|
|
338
|
+
## Building Only Some Platforms
|
|
339
|
+
|
|
340
|
+
Every rebuild used to compile every platform, so a dev server serving a web app
|
|
341
|
+
paid for Objective-C headers, Android XML and Dart classes on every token save.
|
|
342
|
+
`platforms` narrows it:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
StyleDictionary({
|
|
346
|
+
config: 'sd.config.json',
|
|
347
|
+
// Build everything once, then rebuild only css while serving.
|
|
348
|
+
platforms: { watch: ['css'] },
|
|
349
|
+
})
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Measured on a six-platform configuration (css, scss, js, ios, android, flutter),
|
|
353
|
+
with the timer around the build call alone:
|
|
354
|
+
|
|
355
|
+
| Tokens | All platforms | css only | Saved |
|
|
356
|
+
| ------ | ------------- | -------- | ------ |
|
|
357
|
+
| 500 | 12 ms | 1 ms | 10 ms |
|
|
358
|
+
| 3,000 | 36 ms | 2 ms | 34 ms |
|
|
359
|
+
| 10,000 | 103 ms | 4 ms | 99 ms |
|
|
360
|
+
| 30,000 | 330 ms | 12 ms | 319 ms |
|
|
361
|
+
|
|
362
|
+
An array — `platforms: ['css']` — applies to every build. The object form splits
|
|
363
|
+
the first compile from the watch rebuilds, and an omitted key means every
|
|
364
|
+
platform. A name the configuration does not define is an error, matching Style
|
|
365
|
+
Dictionary's own CLI.
|
|
366
|
+
|
|
367
|
+
**Unselected platforms keep whatever they last wrote.** Nothing removes or
|
|
368
|
+
refreshes their files, so scoping the `build` half ships stale output for the
|
|
369
|
+
rest. Scope `watch` unless that is what you want.
|
|
370
|
+
|
|
371
|
+
## Generated Output Is Disposable
|
|
372
|
+
|
|
373
|
+
Nothing removes a generated file, ever. Drop a `files` entry from a
|
|
374
|
+
configuration, remove a whole platform, or move a `buildPath`, and the old
|
|
375
|
+
output stays where it was — still resolving, still importable, still carrying
|
|
376
|
+
its old token values, and in a package build still published, with nothing in
|
|
377
|
+
the log mentioning it.
|
|
378
|
+
|
|
379
|
+
So treat the build directory as disposable: delete it when a configuration
|
|
380
|
+
changes shape, and keep it out of version control and out of any directory
|
|
381
|
+
holding hand-written files.
|
|
382
|
+
|
|
383
|
+
There is deliberately no `clean` option. Style Dictionary's
|
|
384
|
+
`cleanAllPlatforms()` does not solve this — it removes the destinations the
|
|
385
|
+
_current_ configuration declares, which are exactly the files that are not
|
|
386
|
+
orphans, and it removes the `buildPath` directory along with them. Measured:
|
|
387
|
+
after dropping `legacy.scss` from a configuration, a clean run left
|
|
388
|
+
`legacy.scss` standing and deleted `vars.css`, the file still in use.
|
|
389
|
+
|
|
296
390
|
## Skipping a Build That Would Change Nothing
|
|
297
391
|
|
|
298
392
|
A configuration whose output is already newer than everything it reads is not
|
|
@@ -443,6 +537,19 @@ StyleDictionary({
|
|
|
443
537
|
})
|
|
444
538
|
```
|
|
445
539
|
|
|
540
|
+
**A configuration that resolves no tokens is a failure, not an empty build.**
|
|
541
|
+
Style Dictionary writes the destination with nothing in it and reports success,
|
|
542
|
+
so a token file deleted mid-session used to take the generated output down with
|
|
543
|
+
it, and a `source` matching nothing shipped an empty stylesheet from a build
|
|
544
|
+
that exited 0. The check runs before the compile, so the previous good output is
|
|
545
|
+
still on disk when it fires and nothing is overwritten. The message names the
|
|
546
|
+
configuration and the patterns that matched no files.
|
|
547
|
+
|
|
548
|
+
This is about the resolved token set, not about the patterns: a configuration
|
|
549
|
+
that supplies `tokens` inline and declares no `source` at all is valid and
|
|
550
|
+
builds. And it goes through `failOnError` like any other compile failure, so
|
|
551
|
+
`failOnError: false` reports it and carries on.
|
|
552
|
+
|
|
446
553
|
A failure is always reported by the plugin, whatever `failOnError` and `silent`
|
|
447
554
|
are set to — see [Where the messages go](#where-the-messages-go) for which
|
|
448
555
|
channel it arrives on, and for the one thing that can still suppress it.
|
|
@@ -524,7 +631,7 @@ const plugin = styleDictionary.rollup({ config: 'sd.config.json' })
|
|
|
524
631
|
|
|
525
632
|
## Options Reference
|
|
526
633
|
|
|
527
|
-
|
|
634
|
+
````typescript
|
|
528
635
|
/**
|
|
529
636
|
* Options for the Style Dictionary unplugin factory, shared across all bundler
|
|
530
637
|
* targets (Vite, Rolldown, Rollup, Webpack).
|
|
@@ -651,7 +758,19 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
651
758
|
*
|
|
652
759
|
* If not provided, the root directory is searched for 'sd.config.json',
|
|
653
760
|
* 'config.json', 'sd.config.js' and 'sd.config.mjs', in that order. The
|
|
654
|
-
* first one that
|
|
761
|
+
* first one that *looks like a Style Dictionary configuration* wins — it has
|
|
762
|
+
* to declare at least one of `platforms`, `source`, `include` or `tokens` —
|
|
763
|
+
* and the path it picked is announced, so which file a build used is
|
|
764
|
+
* answerable from the console. A candidate that fails that check is reported
|
|
765
|
+
* and skipped rather than adopted, because `config.json` is an extremely
|
|
766
|
+
* common name for something else entirely.
|
|
767
|
+
*
|
|
768
|
+
* **`false` turns discovery off.** Two of the four names are modules rather
|
|
769
|
+
* than data, and reading a module means running it: a `sd.config.js` in the
|
|
770
|
+
* root is imported, freshly, on every watch event. Validation cannot prevent
|
|
771
|
+
* that, because the check can only look at what the import returned — so a
|
|
772
|
+
* project that names its configuration explicitly, or has none, should say
|
|
773
|
+
* `config: false` rather than rely on there being nothing to find.
|
|
655
774
|
*/
|
|
656
775
|
config?:
|
|
657
776
|
| ((
|
|
@@ -659,6 +778,7 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
659
778
|
) => Config | Config[] | Promise<Config | Config[]>)
|
|
660
779
|
| Config
|
|
661
780
|
| Config[]
|
|
781
|
+
| false
|
|
662
782
|
| string
|
|
663
783
|
| string[]
|
|
664
784
|
|
|
@@ -780,6 +900,48 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
780
900
|
*/
|
|
781
901
|
onBuildStart?: () => Promise<void> | void
|
|
782
902
|
|
|
903
|
+
/**
|
|
904
|
+
* Which platforms to build, by the names the configuration defines.
|
|
905
|
+
*
|
|
906
|
+
* Every rebuild used to compile every platform. Measured on a six-platform
|
|
907
|
+
* configuration (css, scss, js, ios, android, flutter), with the timer around
|
|
908
|
+
* the build call alone:
|
|
909
|
+
*
|
|
910
|
+
* ```
|
|
911
|
+
* tokens all platforms css only saved
|
|
912
|
+
* 500 12 ms 1 ms 10 ms
|
|
913
|
+
* 3000 36 ms 2 ms 34 ms
|
|
914
|
+
* 10000 103 ms 4 ms 99 ms
|
|
915
|
+
* 30000 330 ms 12 ms 319 ms
|
|
916
|
+
* ```
|
|
917
|
+
*
|
|
918
|
+
* So a dev server serving a web app paid for Objective-C headers, Android
|
|
919
|
+
* XML and Dart classes on every token save, and the cost grows with the
|
|
920
|
+
* token count.
|
|
921
|
+
*
|
|
922
|
+
* Two shapes. An array selects the same platforms for every build. An object
|
|
923
|
+
* splits the first compile from the watch rebuilds, which is the common
|
|
924
|
+
* want — build everything once, then rebuild only what the page uses:
|
|
925
|
+
*
|
|
926
|
+
* ```typescript
|
|
927
|
+
* platforms: ['css']
|
|
928
|
+
* platforms: { watch: ['css'] }
|
|
929
|
+
* ```
|
|
930
|
+
*
|
|
931
|
+
* An omitted key means every platform, so `{ watch: ['css'] }` builds all of
|
|
932
|
+
* them once and then only css. A name the configuration does not define is an
|
|
933
|
+
* error, matching Style Dictionary's own CLI — "Must be defined in the
|
|
934
|
+
* config".
|
|
935
|
+
*
|
|
936
|
+
* **Unselected platforms keep whatever they last wrote.** Their files are not
|
|
937
|
+
* removed and not refreshed, so a one-shot build that scopes platforms ships
|
|
938
|
+
* stale output for the rest. Scope the watch half rather than the build half
|
|
939
|
+
* unless that is what you want.
|
|
940
|
+
*
|
|
941
|
+
* @default undefined, which builds every platform
|
|
942
|
+
*/
|
|
943
|
+
platforms?: string[] | { build?: string[]; watch?: string[] }
|
|
944
|
+
|
|
783
945
|
/**
|
|
784
946
|
* Whether the table of generated files and their sizes is produced.
|
|
785
947
|
*
|
|
@@ -843,7 +1005,7 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
843
1005
|
*/
|
|
844
1006
|
watch?: string | string[]
|
|
845
1007
|
}
|
|
846
|
-
|
|
1008
|
+
````
|
|
847
1009
|
|
|
848
1010
|
## Migrating from `vite-plugin-style-dictionary`
|
|
849
1011
|
|
package/dist/index.js
CHANGED
|
@@ -36,9 +36,39 @@ function isMessageChannel(value) {
|
|
|
36
36
|
function isThenable(value) {
|
|
37
37
|
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
38
38
|
}
|
|
39
|
+
function looksLikeConfig(value) {
|
|
40
|
+
if (typeof value !== "object" || value === null) return false;
|
|
41
|
+
return [
|
|
42
|
+
"include",
|
|
43
|
+
"platforms",
|
|
44
|
+
"source",
|
|
45
|
+
"tokens"
|
|
46
|
+
].some((key) => key in value);
|
|
47
|
+
}
|
|
48
|
+
function nodeModulesNegations(paths) {
|
|
49
|
+
const negations = /* @__PURE__ */ new Set();
|
|
50
|
+
for (const file of paths) {
|
|
51
|
+
const normalised = file.replace(/\\/g, "/");
|
|
52
|
+
if (normalised.includes("/node_modules/")) negations.add(`!${normalised}`);
|
|
53
|
+
}
|
|
54
|
+
return Array.from(negations);
|
|
55
|
+
}
|
|
39
56
|
function paint(code, value, allowed) {
|
|
40
57
|
return allowed ? `\u001B[${code}m${value}\u001B[0m` : value;
|
|
41
58
|
}
|
|
59
|
+
async function patternsMatchingNothing(patterns) {
|
|
60
|
+
const barren = [];
|
|
61
|
+
for (const pattern of patterns) {
|
|
62
|
+
if (!GLOB_CHARACTERS.test(pattern)) {
|
|
63
|
+
if (!fs.existsSync(pattern)) barren.push(pattern);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
if ((await glob([pattern], { absolute: true })).length === 0) barren.push(pattern);
|
|
68
|
+
} catch {}
|
|
69
|
+
}
|
|
70
|
+
return barren;
|
|
71
|
+
}
|
|
42
72
|
function unwrapDefault(value) {
|
|
43
73
|
return typeof value === "object" && value !== null && "default" in value ? value.default ?? value : value;
|
|
44
74
|
}
|
|
@@ -105,6 +135,9 @@ const IMPORTED_CONFIG_EXTENSIONS = [
|
|
|
105
135
|
".mjs",
|
|
106
136
|
".ts"
|
|
107
137
|
];
|
|
138
|
+
function describeConfig(item, index) {
|
|
139
|
+
return item.file ? `The configuration ${item.file}` : `The configuration at position ${index + 1}`;
|
|
140
|
+
}
|
|
108
141
|
function isImportedConfig(file) {
|
|
109
142
|
return IMPORTED_CONFIG_EXTENSIONS.some((extension) => file.endsWith(extension));
|
|
110
143
|
}
|
|
@@ -140,10 +173,15 @@ function statOrNull(file) {
|
|
|
140
173
|
}
|
|
141
174
|
const unpluginFactory = (options = {}, meta) => {
|
|
142
175
|
const isWebpack = meta.framework === "webpack";
|
|
143
|
-
const { cache = true, errorOverlay = true, failOnError = "build", logLevel, onBuildEnd, onBuildError, onBuildStart, report = true, root: rootOption, silent = false } = options;
|
|
176
|
+
const { cache = true, errorOverlay = true, failOnError = "build", logLevel, onBuildEnd, onBuildError, onBuildStart, platforms: platformsOption, report = true, root: rootOption, silent = false } = options;
|
|
144
177
|
const level = logLevel ?? (silent ? "silent" : void 0);
|
|
145
178
|
const quiet = level === "silent" || level === "warn";
|
|
146
179
|
const verbosity = level === void 0 ? void 0 : level === "verbose" ? "verbose" : level === "silent" ? "silent" : "default";
|
|
180
|
+
const platformsFor = (context) => {
|
|
181
|
+
if (platformsOption === void 0) return void 0;
|
|
182
|
+
if (Array.isArray(platformsOption)) return platformsOption;
|
|
183
|
+
return context === void 0 ? platformsOption.build : platformsOption.watch;
|
|
184
|
+
};
|
|
147
185
|
const failsTheBuild = (context) => failOnError === true || (context === void 0 ? failOnError === "build" : failOnError === "serve");
|
|
148
186
|
let hostCommand = "build";
|
|
149
187
|
let hostMode;
|
|
@@ -164,6 +202,7 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
164
202
|
let cachedPatterns;
|
|
165
203
|
let watchRebuild = false;
|
|
166
204
|
let hasCompiled = false;
|
|
205
|
+
let hostClosed = false;
|
|
167
206
|
const expandPatterns = async (patterns) => {
|
|
168
207
|
const paths = /* @__PURE__ */ new Set();
|
|
169
208
|
const globs = [];
|
|
@@ -229,17 +268,33 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
229
268
|
};
|
|
230
269
|
const resolveConfigs = async () => {
|
|
231
270
|
let rawConfig = options.config;
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
271
|
+
if (rawConfig === false) return [];
|
|
272
|
+
if (!rawConfig) {
|
|
273
|
+
const defaults = [
|
|
274
|
+
"sd.config.json",
|
|
275
|
+
"config.json",
|
|
276
|
+
"sd.config.js",
|
|
277
|
+
"sd.config.mjs"
|
|
278
|
+
];
|
|
279
|
+
const rejected = [];
|
|
280
|
+
for (const file of defaults) {
|
|
281
|
+
const fullPath = path.resolve(root, file);
|
|
282
|
+
if (!fs.existsSync(fullPath)) continue;
|
|
283
|
+
if (!looksLikeConfig(await readConfigObject({
|
|
284
|
+
config: fullPath,
|
|
285
|
+
file: fullPath
|
|
286
|
+
}, false))) {
|
|
287
|
+
rejected.push(file);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (!announcedDiscovery) {
|
|
291
|
+
announcedDiscovery = true;
|
|
292
|
+
log(`Using the configuration it found at ${fullPath}`, "info");
|
|
293
|
+
}
|
|
240
294
|
rawConfig = file;
|
|
241
295
|
break;
|
|
242
296
|
}
|
|
297
|
+
if (rejected.length > 0) log(`Ignored ${rejected.join(", ")} in ${root}: nothing there declares platforms, source, include or tokens, so it does not look like a Style Dictionary configuration. Name it with the config option if it is one, or set config to false to stop looking.`, "error");
|
|
243
298
|
}
|
|
244
299
|
if (!rawConfig) {
|
|
245
300
|
log("No configuration specified and no default config file found. Style Dictionary will not compile.", "error");
|
|
@@ -324,9 +379,11 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
324
379
|
return loaded;
|
|
325
380
|
}
|
|
326
381
|
};
|
|
327
|
-
const declaredDestinations = (configObj) => {
|
|
382
|
+
const declaredDestinations = (configObj, only) => {
|
|
328
383
|
const destinations = [];
|
|
329
|
-
|
|
384
|
+
const entries = Object.entries(configObj.platforms ?? {});
|
|
385
|
+
const selected = only ? entries.filter(([name]) => only.includes(name)) : entries;
|
|
386
|
+
for (const [, platform] of selected) {
|
|
330
387
|
const buildPath = platform.buildPath ?? "";
|
|
331
388
|
const absoluteBuildPath = path.isAbsolute(buildPath) ? buildPath : path.resolve(root, buildPath);
|
|
332
389
|
for (const file of platform.files ?? []) if (file.destination) destinations.push(path.isAbsolute(file.destination) ? file.destination : path.resolve(absoluteBuildPath, file.destination));
|
|
@@ -340,9 +397,9 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
340
397
|
return null;
|
|
341
398
|
}
|
|
342
399
|
};
|
|
343
|
-
const isUpToDate = async (item, configObj) => {
|
|
400
|
+
const isUpToDate = async (item, configObj, only) => {
|
|
344
401
|
if (Object.values(configObj.platforms ?? {}).some((platform) => (platform.actions?.length ?? 0) > 0)) return false;
|
|
345
|
-
const destinations = declaredDestinations(configObj);
|
|
402
|
+
const destinations = declaredDestinations(configObj, only);
|
|
346
403
|
if (destinations.length === 0) return false;
|
|
347
404
|
const extraWatches = options.watch ? Array.isArray(options.watch) ? options.watch : [options.watch] : [];
|
|
348
405
|
const sources = await expandPatterns([...sourcePatternsOf(configObj), ...extraWatches.map((pattern) => (path.isAbsolute(pattern) ? pattern : path.resolve(root, pattern)).replace(/\\/g, "/"))]);
|
|
@@ -405,9 +462,10 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
405
462
|
try {
|
|
406
463
|
if (!context) log("Compiling design tokens...", "info");
|
|
407
464
|
if (onBuildStart) callHook("onBuildStart", onBuildStart);
|
|
408
|
-
for (const item of resolvedConfigs) {
|
|
465
|
+
for (const [index, item] of resolvedConfigs.entries()) {
|
|
409
466
|
const declared = cache ? await readConfigObject(item, false) : null;
|
|
410
|
-
|
|
467
|
+
const selectedPlatforms = platformsFor(context);
|
|
468
|
+
if (declared && await isUpToDate(item, declared, selectedPlatforms)) {
|
|
411
469
|
for (const destination of declaredDestinations(declared)) generatedFiles.add(destination);
|
|
412
470
|
skipped++;
|
|
413
471
|
continue;
|
|
@@ -417,8 +475,23 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
417
475
|
mutateOriginal: true,
|
|
418
476
|
verbosity
|
|
419
477
|
});
|
|
478
|
+
if (sd.allTokens.length === 0) {
|
|
479
|
+
const asObject = await readConfigObject(item, false);
|
|
480
|
+
const barren = asObject ? await patternsMatchingNothing(sourcePatternsOf(asObject)) : [];
|
|
481
|
+
throw new Error([
|
|
482
|
+
`${describeConfig(item, index)} resolved no tokens, so its output would be emptied.`,
|
|
483
|
+
barren.length > 0 ? `These patterns matched no files: ${barren.join(", ")}` : `It declares no source or include patterns that matched anything.`,
|
|
484
|
+
`Nothing was written. Set failOnError to false to build anyway.`
|
|
485
|
+
].join(" "));
|
|
486
|
+
}
|
|
420
487
|
sd.volume = atomicVolume;
|
|
421
|
-
await sd.buildAllPlatforms();
|
|
488
|
+
if (selectedPlatforms === void 0) await sd.buildAllPlatforms();
|
|
489
|
+
else {
|
|
490
|
+
const defined = Object.keys(sd.platforms);
|
|
491
|
+
const unknown = selectedPlatforms.filter((name) => !defined.includes(name));
|
|
492
|
+
if (unknown.length > 0) throw new Error(`${describeConfig(item, index)} does not define the platform(s) ${unknown.join(", ")}. It defines ${defined.join(", ")}.`);
|
|
493
|
+
for (const name of selectedPlatforms) await sd.buildPlatform(name);
|
|
494
|
+
}
|
|
422
495
|
for (const platform of Object.values(sd.platforms)) {
|
|
423
496
|
const buildPath = platform.buildPath ?? "";
|
|
424
497
|
for (const file of platform.files ?? []) if (file.destination) {
|
|
@@ -487,6 +560,8 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
487
560
|
let inFlight;
|
|
488
561
|
let waiting = [];
|
|
489
562
|
let refreshServerWatchList;
|
|
563
|
+
let announcedDiscovery = false;
|
|
564
|
+
let startupResolved;
|
|
490
565
|
let notifyBuildOutcome;
|
|
491
566
|
const drain = async () => {
|
|
492
567
|
while (pendingReason !== void 0) {
|
|
@@ -516,6 +591,7 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
516
591
|
}
|
|
517
592
|
};
|
|
518
593
|
const schedule = async (reason) => {
|
|
594
|
+
if (hostClosed) return;
|
|
519
595
|
pendingReason = reason;
|
|
520
596
|
const covered = new Promise((resolve, reject) => {
|
|
521
597
|
waiting.push((failure) => {
|
|
@@ -531,14 +607,19 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
531
607
|
debounceTimer.unref();
|
|
532
608
|
return covered;
|
|
533
609
|
};
|
|
610
|
+
const closeWatcher = () => {
|
|
611
|
+
hostClosed = true;
|
|
612
|
+
};
|
|
534
613
|
return {
|
|
535
614
|
async buildStart() {
|
|
536
615
|
adoptHost(this);
|
|
537
616
|
adoptWatchMode(this);
|
|
538
617
|
const resolved = await resolveConfigs();
|
|
539
618
|
if (resolved.length === 0) return;
|
|
540
|
-
|
|
541
|
-
|
|
619
|
+
if (!hostClosed) {
|
|
620
|
+
const { paths } = await getWatchTargets(resolved);
|
|
621
|
+
for (const file of paths) this.addWatchFile(file);
|
|
622
|
+
}
|
|
542
623
|
if (isWebpack) return;
|
|
543
624
|
if (watchRebuild && hasCompiled) {
|
|
544
625
|
watchRebuild = false;
|
|
@@ -548,8 +629,11 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
548
629
|
hasCompiled = true;
|
|
549
630
|
},
|
|
550
631
|
name: "unplugin-style-dictionary",
|
|
632
|
+
rolldown: { closeWatcher },
|
|
633
|
+
rollup: { closeWatcher },
|
|
551
634
|
vite: {
|
|
552
|
-
|
|
635
|
+
closeWatcher,
|
|
636
|
+
async configResolved(config) {
|
|
553
637
|
if (rootOption === void 0) root = config.root || process.cwd();
|
|
554
638
|
hostCommand = config.command;
|
|
555
639
|
hostMode = config.mode;
|
|
@@ -561,10 +645,28 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
561
645
|
config.logger.info(message);
|
|
562
646
|
}
|
|
563
647
|
};
|
|
648
|
+
if (config.command !== "serve") return;
|
|
649
|
+
isWatching = true;
|
|
650
|
+
try {
|
|
651
|
+
startupResolved = await resolveConfigs();
|
|
652
|
+
if (startupResolved.length === 0) return;
|
|
653
|
+
const { paths } = await getWatchTargets(startupResolved);
|
|
654
|
+
const negations = nodeModulesNegations(paths);
|
|
655
|
+
if (negations.length === 0) return;
|
|
656
|
+
const existing = config.server.watch?.ignored;
|
|
657
|
+
config.server.watch = {
|
|
658
|
+
...config.server.watch,
|
|
659
|
+
ignored: [...Array.isArray(existing) ? existing : existing === void 0 ? [] : [existing], ...negations]
|
|
660
|
+
};
|
|
661
|
+
} catch (err) {
|
|
662
|
+
log(`Could not read the configuration while preparing the watch list: ${errorMessage(err)}`, "error");
|
|
663
|
+
startupResolved = void 0;
|
|
664
|
+
}
|
|
564
665
|
},
|
|
565
666
|
async configureServer(server) {
|
|
566
667
|
isWatching = true;
|
|
567
|
-
const resolved = await resolveConfigs();
|
|
668
|
+
const resolved = startupResolved ?? await resolveConfigs();
|
|
669
|
+
startupResolved = void 0;
|
|
568
670
|
if (resolved.length === 0) return;
|
|
569
671
|
let targets = await getWatchTargets(resolved);
|
|
570
672
|
server.watcher.add(targets.paths);
|
|
@@ -604,6 +706,7 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
604
706
|
async watchChange(id) {
|
|
605
707
|
adoptHost(this);
|
|
606
708
|
adoptWatchMode(this);
|
|
709
|
+
if (hostClosed) return;
|
|
607
710
|
watchRebuild = true;
|
|
608
711
|
if (cachedPatterns && !isWatchedSource(id, cachedPatterns)) return;
|
|
609
712
|
const resolved = await resolveConfigs();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport JSON5 from 'json5'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { glob } from 'tinyglobby'\nimport { createUnplugin } from 'unplugin'\n\nimport type {\n StyleDictionaryConfigContext,\n UnpluginStyleDictionaryOptions,\n} from './types.js'\n\nimport { matchesWatchedFile } from './watch-filter.js'\n\nexport type * from './types.js'\n\n// `catch` binds `unknown`, and a thrown non-Error — a string, a rejected\n// value out of a config module — carries no `.message`. The `as Error` casts\n// this replaces claimed otherwise and printed `undefined` for exactly those\n// cases, which is the least useful thing a failure log can say.\n// A rejected promise must carry an Error, and `catch` binds `unknown`. What\n// Style Dictionary throws is already one; anything else is wrapped rather than\n// handed on raw.\n// Where the plugin's own lines go when a host offers somewhere better than the\n// console: Vite's `config.logger`, rollup's and rolldown's plugin context, or\n// webpack's `compilation`.\n//\n// **There is no `error` channel that merely reports.** Rollup's `this.error`\n// aborts the bundle — measured: a `buildStart` calling it ends the run with\n// `THREW: [plugin err-probe] fatal?` — so routing a failure report through it\n// would stop every build that reported one and silently override `failOnError`,\n// whose entire job is deciding that. A failure is therefore reported on the\n// host's warning channel, and whether the build stops stays `failOnError`'s\n// decision alone.\ninterface HostMessenger {\n error: (message: string) => void\n\n // Optional because not every host has somewhere for a progress line to go.\n // webpack's `stats` carries warnings and errors and nothing else, and\n // `Compiling design tokens...` is neither — so there it stays on the\n // console rather than being dressed up as a warning.\n info?: (message: string) => void\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error(errorMessage(error))\n}\n\n// Whether escapes may be written to this stream.\n//\n// **The three signals are ordered rather than combined into one conjunction**,\n// and that ordering is the whole of it. `FORCE_COLOR=1` on a non-TTY — a CI job\n// that wants colour in a log it will render itself — is the single job that\n// variable has, and\n// `!process.env.NO_COLOR && process.env.FORCE_COLOR !== '0' && stream.isTTY`\n// never honours it: the TTY check has the last word and answers `false`.\n//\n// `NO_COLOR` wins over `FORCE_COLOR` because the convention says so: any\n// non-empty value turns colour off, and nothing may turn it back on.\nfunction colourAllowed(stream: { isTTY?: boolean }): boolean {\n if (process.env.NO_COLOR) return false\n\n const forced = process.env.FORCE_COLOR\n if (forced === '0') return false\n if (forced !== undefined && forced !== '') return true\n\n // A terminal that has told us it cannot render escapes. Not one of the three\n // the issue named, but it is what `TERM=dumb` means and it costs a line.\n if (process.env.TERM === 'dumb') return false\n\n return stream.isTTY === true\n}\n\n// Best-effort cleanup of a temporary file whose write or rename failed. The\n// original failure is what the caller reports, so nothing here may throw.\nfunction discardTemporaryFile(temporary: string): void {\n try {\n fs.rmSync(temporary, { force: true })\n } catch {\n // Ignore: a leftover temporary file is not worth masking the real error.\n }\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n// A config file is an untyped boundary: `JSON.parse` and a dynamic `import`\n// both hand back `any`, and an `any` assigned to `configObj` spreads through\n// every read of it downstream. These two narrow that boundary once, here.\n// They are type predicates rather than assertions on purpose — a predicate is\n// a check the compiler verifies, where a cast is only a claim.\nfunction isConfig(value: unknown): value is Config {\n return typeof value === 'object' && value !== null\n}\n\n// A host's message channel, narrowed by a predicate rather than asserted: what\n// a plugin context carries under `warn` is the host's business, and a cast\n// would only claim it is callable.\nfunction isMessageChannel(value: unknown): value is (message: string) => void {\n return typeof value === 'function'\n}\n\n// A hook is the consumer's code, and what it hands back is not this plugin's to\n// assume. A predicate rather than `instanceof Promise`, which answers `false`\n// for a thenable from another realm or from a promise library — exactly the\n// case where letting a rejection escape does the damage.\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n )\n}\n\nfunction paint(code: string, value: string, allowed: boolean): string {\n return allowed ? `\\u001B[${code}m${value}\\u001B[0m` : value\n}\n\n// A config module may expose its config as a `default` export or as the\n// namespace itself. `'default' in value` is what lets the compiler reach\n// `.default` without a cast.\nfunction unwrapDefault(value: unknown): unknown {\n return typeof value === 'object' && value !== null && 'default' in value\n ? (value.default ?? value)\n : value\n}\n\n// Style Dictionary writes every generated file with a plain `writeFile` on the\n// volume it was handed, which truncates the destination and then streams the\n// new contents into it. Anything reading that file inside the window sees a\n// partial file: a consuming test run whose tokens are rebuilt mid-suite, or a\n// dev-server request landing on a rebuild, gets a truncated module and fails\n// to parse it. Writing a sibling temporary file and renaming it over the\n// destination closes the window — `rename` is atomic within a filesystem, so a\n// concurrent reader sees either the whole old file or the whole new one.\n\n// Temporary path for an atomic write of `destination`.\n//\n// It has to be a sibling of the destination, because `rename` is only atomic\n// within one filesystem and the system temp directory is often a different\n// mount. The final extension is dropped rather than kept, so the temporary\n// file cannot match a pattern written for the generated file's own extension.\n// That was load-bearing while `matchesWatchedFile` tested its globs\n// unanchored, where a leftover `vars.css.tmp` matched a `*.css` watch; it is\n// belt-and-braces now that the matcher anchors and, like the globber Style\n// Dictionary reads sources with, does not match the leading dot this name\n// already starts with. Both stay, because a temporary file only outlives its\n// rename when a write failed, and hiding one costs a string. The pid and\n// counter make the name unique, so two writes of the same destination —\n// parallel platforms in one build, or two builds overlapping — never share a\n// temporary file.\nlet temporaryFileCounter = 0\n\n// Whether the freshly rendered `temporary` holds exactly what `destination`\n// already holds. A rebuild whose inputs did not change renders byte-identical\n// output, and renaming that over the destination is a filesystem event the\n// host bundler reacts to — which is the whole of the rebuild loop, since\n// consuming code imports the generated file and every regenerate is therefore\n// a module-graph change. Comparing the two files rather than the `data`\n// argument keeps this indifferent to whether the caller passed a string, a\n// buffer or a stream, and to the encoding it passed with it.\n//\n// A destination that cannot be read is not identical, which covers the\n// ordinary case of it not existing yet.\nasync function rendersWhatIsAlreadyThere(\n temporary: string,\n destination: string,\n): Promise<boolean> {\n try {\n const [existing, rendered] = await Promise.all([\n fs.promises.readFile(destination),\n fs.promises.readFile(temporary),\n ])\n\n return existing.equals(rendered)\n } catch {\n return false\n }\n}\n\nfunction rendersWhatIsAlreadyThereSync(\n temporary: string,\n destination: string,\n): boolean {\n try {\n return fs.readFileSync(destination).equals(fs.readFileSync(temporary))\n } catch {\n return false\n }\n}\n\nfunction temporaryPathFor(destination: string): string {\n const extension = path.extname(destination)\n\n return path.join(\n path.dirname(destination),\n `.${path.basename(destination, extension)}.${process.pid}.${temporaryFileCounter++}.tmp`,\n )\n}\n\nconst writeFileAtomic: typeof fs.promises.writeFile = async (\n file,\n data,\n options,\n) => {\n // A file handle or descriptor is already-open state that a rename cannot\n // stand in for, so only a path is written atomically.\n if (typeof file !== 'string') {\n return fs.promises.writeFile(file, data, options)\n }\n\n const temporary = temporaryPathFor(file)\n\n try {\n await fs.promises.writeFile(temporary, data, options)\n\n // The check sits in front of the rename rather than in place of it: the\n // temporary file is still written, so a destination that does need\n // replacing is still replaced in one atomic step and a concurrent reader\n // still never sees a partial file.\n if (await rendersWhatIsAlreadyThere(temporary, file)) {\n discardTemporaryFile(temporary)\n return\n }\n\n await fs.promises.rename(temporary, file)\n } catch (err) {\n discardTemporaryFile(temporary)\n throw err\n }\n}\n\nconst writeFileSyncAtomic: typeof fs.writeFileSync = (file, data, options) => {\n if (typeof file !== 'string') {\n fs.writeFileSync(file, data, options)\n return\n }\n\n const temporary = temporaryPathFor(file)\n\n try {\n fs.writeFileSync(temporary, data, options)\n\n if (rendersWhatIsAlreadyThereSync(temporary, file)) {\n discardTemporaryFile(temporary)\n return\n }\n\n fs.renameSync(temporary, file)\n } catch (err) {\n discardTemporaryFile(temporary)\n throw err\n }\n}\n\n// `node:fs` with both write entry points swapped for their atomic\n// equivalents, handed to Style Dictionary as the volume it builds through.\n// Everything else — reads, `mkdir`, `access`, the `promises` namespace — is\n// inherited from `node:fs` unchanged, so only the moment a file becomes\n// visible to readers changes. Custom actions receive this volume too, so\n// whatever they emit is written the same way.\n//\n// It is assigned onto the instance rather than passed as the `volume`\n// constructor option on purpose: that option marks the volume as a custom\n// filesystem shim, which switches Style Dictionary's path resolution off for\n// every read as well.\n// `Object.create` is declared as returning `any`, so pinning the result to\n// `typeof fs` is a claim no type guard can replace. The prototype link is the\n// whole point — see the note above — so rebuilding this with a spread, which\n// copies own properties and drops the chain, is not a substitute.\n/* oxlint-disable typescript/no-unsafe-type-assertion */\nconst atomicVolume = Object.create(fs, {\n promises: {\n value: Object.create(fs.promises, {\n writeFile: { value: writeFileAtomic },\n }) as typeof fs.promises,\n },\n writeFileSync: { value: writeFileSyncAtomic },\n}) as typeof fs\n/* oxlint-enable typescript/no-unsafe-type-assertion */\n\n// A pattern is a glob when any of these appear in it. Deliberately the set\n// picomatch and tinyglobby act on, since those two are what match and expand\n// here — a path containing one of these characters literally is not\n// distinguishable from a pattern, and would not be matchable either.\nconst GLOB_CHARACTERS = /[!*?[\\]{}]/\n\n// The config extensions Style Dictionary loads with `import` rather than by\n// parsing the file — the `case` list in its own `loadFile`. They are the only\n// ones Node's permanent module cache applies to, and so the only ones this\n// plugin has to read on the build's behalf.\n//\n// Everything else Style Dictionary parses as JSON5, including `.json`, and\n// this list is what makes the plugin split the same way. Reading the two\n// halves apart is what silently unwatched a whole family of configurations:\n// a `.json5` or `.jsonc` file went down the import branch and failed there\n// while the build succeeded, and a `.json` file carrying a comment or a\n// trailing comma failed strict `JSON.parse` for the same reason.\nconst IMPORTED_CONFIG_EXTENSIONS = ['.js', '.mjs', '.ts']\n\n// A configuration as `resolveConfigs` hands it on: either the object the\n// consumer passed or the path it was read from, plus the directory relative\n// paths inside it resolve against.\ninterface ResolvedConfig {\n config: Config | string\n file?: string\n}\n\n// Whether a config path is one Style Dictionary imports rather than parses.\nfunction isImportedConfig(file: string): boolean {\n return IMPORTED_CONFIG_EXTENSIONS.some((extension) =>\n file.endsWith(extension),\n )\n}\n\n// The leading run of a pattern that contains no glob character —\n// `/p/tokens` for `/p/tokens/**/*.json`. Registering it alongside the files\n// that match today is what makes a token file created tomorrow visible:\n// watching only the current matches can never see a path that did not exist\n// when the watcher was built.\nfunction staticParentOf(pattern: string): string {\n const segments = pattern.split('/')\n const firstGlob = segments.findIndex((segment) =>\n GLOB_CHARACTERS.test(segment),\n )\n\n return firstGlob === -1\n ? path.posix.dirname(pattern)\n : segments.slice(0, firstGlob).join('/')\n}\n\n// The fingerprints of configurations this process has compiled at least once.\n// It is what lets a configuration given as an object or a function be skipped\n// at all: such a configuration has no file to stat, so an edit to it inside\n// `vite.config.ts` moves no mtime and the filesystem cannot tell the two\n// apart. Having built it here, the plugin can — the fingerprint changes with\n// the configuration.\n//\n// Module scope rather than the factory's, for the same reason `compilesInFlight`\n// below is: the instances that would otherwise repeat the work are different\n// instances, so per-instance state cannot see them. A `vitest run` stands up\n// several, and a function configuration — the form the README recommends for\n// registering custom formats — would be the one form that never skipped.\n//\n// The fingerprint carries the root, so two projects in one process never share\n// one. A configuration given as a path needs none of this: its own file is one\n// of the sources the mtime comparison reads, so an edit to it is visible across\n// processes as well as within one.\nconst compiledFingerprints = new Set<string>()\n\n// A compile that is running right now, keyed by `buildKey`, so bundler\n// instances in one process wait on each other rather than each starting their\n// own.\n//\n// Generated token files are a side effect on the filesystem, not per-bundler\n// output, and one process routinely holds several instances of this plugin. A\n// single `vitest run` on a project with two test projects and browser mode\n// stands up five Vite servers — the root one, one per project, and one more\n// per project once its HTTP server listens — and every one of them runs\n// `buildStart`. `hasCompiled` cannot see any of that: it is closure state\n// inside the factory, so each instance has its own and each compiles.\n//\n// Module scope is the only place a shared answer can live, since the\n// instances know nothing about each other. It stays a claim about identical\n// work, never about identity: the key carries the root and the resolved\n// configurations, so one script building two packages shares nothing.\nconst compilesInFlight = new Map<string, Promise<void>>()\n\n// A stable identity for a set of resolved configurations, or `null` for one\n// that cannot have a stable identity at all.\n//\n// Functions are serialised by source rather than dropped, because a `format`\n// or `transform` written inline is exactly what distinguishes two otherwise\n// identical configurations — and `JSON.stringify` omits a function outright,\n// which would make two different builds look like one.\nfunction buildKey(root: string, resolved: ResolvedConfig[]): null | string {\n try {\n return JSON.stringify(\n [root, resolved.map((item) => item.file ?? item.config)],\n (_key, value: unknown) =>\n typeof value === 'function' ? `[fn]${String(value)}` : value,\n )\n } catch {\n // A configuration that will not serialise — a circular reference, a\n // BigInt — takes no shared identity rather than a wrong one, and compiles\n // exactly as it did before.\n return null\n }\n}\n\n// The patterns one configuration reads, resolved the way the build resolves\n// them. The same `source`/`include` walk `getWatchTargets` does, for one\n// item rather than the whole set — against the working directory, because\n// that is where Style Dictionary's own `combineJSON` globs them.\nfunction sourcePatternsOf(configObj: Config): string[] {\n const patterns: string[] = []\n\n const add = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n patterns.push(\n (path.isAbsolute(pattern)\n ? pattern\n : path.resolve(process.cwd(), pattern)\n ).replace(/\\\\/g, '/'),\n )\n }\n }\n\n for (const value of [configObj.source, configObj.include]) {\n if (Array.isArray(value)) value.forEach(add)\n else add(value)\n }\n\n return patterns\n}\n\n// `fs.statSync` without the throw. A file that is missing, or that cannot be\n// read, is the same answer to every caller here: nothing to compare against.\nfunction statOrNull(file: string): fs.Stats | null {\n try {\n return fs.statSync(file)\n } catch {\n return null\n }\n}\n\n// Not exported. It cannot be called in the form a reader would guess —\n// unplugin types the factory as `(options, meta)`, and `meta` is the\n// bundler-identifying `UnpluginContextMeta` a consumer would have to build by\n// hand — so publishing it offered a name that answered nothing. What a\n// consumer imports is the default export of the entry for their bundler.\nconst unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}, meta) => {\n // webpack is the one target whose `buildStart` does not run before the\n // module graph is resolved: unplugin taps it on `make`, an\n // `AsyncParallelHook` that `EntryPlugin` taps too. The `webpack` key below\n // compiles on `beforeCompile` instead, which webpack awaits before the\n // compilation exists.\n const isWebpack = meta.framework === 'webpack'\n const {\n cache = true,\n errorOverlay = true,\n failOnError = 'build',\n logLevel,\n onBuildEnd,\n onBuildError,\n onBuildStart,\n report = true,\n root: rootOption,\n silent = false,\n } = options\n\n // `silent` predates `logLevel` and names its quietest level, so it is read\n // as one. `logLevel` wins when a consumer sets both.\n const level = logLevel ?? (silent ? 'silent' : undefined)\n\n // Whether the plugin keeps its own progress lines and size table to itself.\n // A failure is reported at every level, which is why this gate is not on the\n // error branch below.\n const quiet = level === 'silent' || level === 'warn'\n\n // What Style Dictionary is told, if anything. `undefined` is the point of\n // this: it leaves whatever the consumer's own `log.verbosity` asked for\n // standing, where the plugin used to overwrite it on every build. Style\n // Dictionary has three levels to this option's four, so `'warn'` and\n // `'info'` both map to its default — they differ in what the plugin itself\n // says, not in what Style Dictionary does.\n const verbosity =\n level === undefined\n ? undefined\n : level === 'verbose'\n ? 'verbose'\n : level === 'silent'\n ? 'silent'\n : 'default'\n\n // Whether a failure in this compile should be thrown rather than only\n // reported. The two compiles are told apart by `runBuilds`'s `context`,\n // which only the rebuild paths pass.\n const failsTheBuild = (context: string | undefined): boolean =>\n failOnError === true ||\n (context === undefined ? failOnError === 'build' : failOnError === 'serve')\n // What the host is doing, for the function form of `config`. Populated where\n // each host knows the answer and read when that function is called — the\n // same shape as `root` and the message host above, and for the same reason:\n // `resolveConfigs` is reached from five places now, and threading a context\n // parameter through all five would make every caller restate what only the\n // host can say.\n let hostCommand: 'build' | 'serve' = 'build'\n let hostMode: string | undefined\n let isWatching = false\n\n // `mode` is derived rather than invented where a host has no notion of one.\n // rollup and rolldown report nothing, and following `command` is the answer\n // Vite itself would give: its default mode is `development` serving and\n // `production` building.\n const configContext = (): StyleDictionaryConfigContext => ({\n command: hostCommand,\n mode: hostMode ?? (hostCommand === 'serve' ? 'development' : 'production'),\n watch: isWatching,\n })\n\n // Whether the host will keep rebuilding, as the plugin context reports it.\n // Read from `meta.watchMode`, which rollup, rolldown and Vite all carry and\n // webpack does not — there it comes off the compiler instead.\n const adoptWatchMode = (context: object): void => {\n const hookMeta: unknown = 'meta' in context ? context.meta : undefined\n if (typeof hookMeta !== 'object' || hookMeta === null) return\n\n const watching: unknown =\n 'watchMode' in hookMeta ? hookMeta.watchMode : undefined\n if (typeof watching === 'boolean') isWatching = watching\n }\n\n // Where a relative `config` path is looked up. The host sets it below\n // unless the consumer named one, which is why an explicit option wins: a\n // layout the host cannot describe is exactly what it is for.\n let root = rootOption\n ? path.resolve(process.cwd(), rootOption)\n : process.cwd()\n\n // Every absolute destination the last completed build wrote, spelled with\n // forward slashes so it compares against a normalised watcher path. This is\n // the half of the rebuild-loop guard that pattern matching cannot supply:\n // output written under a watched directory matches the source glob that\n // produced it, so without subtracting this set a supported layout rebuilds\n // on its own writes for as long as the dev server runs.\n const generatedDestinations = new Set<string>()\n\n // The patterns the last `getWatchTargets` derived. `watchChange` tests a\n // changed path against these before it resolves anything, so a file the\n // plugin does not care about costs one glob match instead of a full config\n // resolution — which, when `config` is a function, is the consumer's own\n // code, and the place the README tells them to register custom formats.\n //\n // It is safe to filter on a list that may be one build out of date because\n // the list always contains the config files themselves: an edit that adds a\n // source matches as a config change, which re-resolves and re-derives. The\n // one thing it cannot see is a `config` function that starts returning\n // different sources with no file changing at all, and that was never\n // observable without a rebuild to observe it in.\n let cachedPatterns: string[] | undefined\n\n // Whether `watchChange` has fired since the last `buildStart`, and whether\n // anything has been compiled yet. Rollup, rolldown and webpack all run\n // `watchChange` for every changed file and only then re-enter `buildStart`\n // — unplugin's webpack adapter awaits both in one `make` tap — so a flag\n // raised in the first is still standing in the second, and is what tells it\n // this is a watch rebuild rather than the first build of the process.\n let watchRebuild = false\n let hasCompiled = false\n\n // What a watcher is handed, and what a changed path is tested against, are\n // not the same list, and conflating them is why a glob source was watched by\n // nothing at all. Every watcher in play takes filenames rather than\n // patterns: Vite's chokidar and rollup's `FileWatcher` are both constructed\n // with `disableGlobbing: true`, Vite's `addWatchFile` drops anything that\n // fails `fs.existsSync`, and webpack never globs `fileDependencies`. So the\n // patterns stay for matching and the paths are expanded for registering.\n const expandPatterns = async (patterns: string[]): Promise<string[]> => {\n const paths = new Set<string>()\n const globs: string[] = []\n\n for (const pattern of patterns) {\n if (GLOB_CHARACTERS.test(pattern)) {\n globs.push(pattern)\n\n // Watching the directory as well as its current contents. chokidar\n // reports a creation inside a watched directory, which is the only\n // way a token file added later is ever noticed.\n const parent = staticParentOf(pattern)\n if (parent && fs.existsSync(parent)) paths.add(parent)\n } else {\n paths.add(pattern)\n }\n }\n\n if (globs.length > 0) {\n try {\n // tinyglobby matches with picomatch, which is what\n // `matchesWatchedFile` tests with, so what is registered here and what\n // is accepted there cannot disagree.\n for (const match of await glob(globs, { absolute: true })) {\n paths.add(match.replace(/\\\\/g, '/'))\n }\n } catch (err) {\n log(`Failed to expand watch patterns: ${errorMessage(err)}`, 'error')\n }\n }\n\n return Array.from(paths)\n }\n\n // Whether a changed file is a token or config source rather than something\n // this plugin just wrote. Both watch entry points ask through here, so\n // neither can react to its own output.\n const isWatchedSource = (file: string, patterns: string[]): boolean =>\n !generatedDestinations.has(file.replace(/\\\\/g, '/')) &&\n matchesWatchedFile(file, patterns)\n\n // Decided once, when the plugin is constructed, and held for its life. The\n // two streams are asked separately because they are redirected separately —\n // `build 2>err.log` leaves stdout a terminal and stderr a file.\n const stdoutColour = colourAllowed(process.stdout)\n const stderrColour = colourAllowed(process.stderr)\n\n // Where a message goes once a host has offered somewhere better than the\n // console. Set by `configResolved` under Vite, by the build hooks under\n // rollup and rolldown, and by the `webpack` block; left undefined when no\n // host has claimed it, which is every unit test binding its own context.\n let host: HostMessenger | undefined\n\n // Adopts a plugin context as the message host, if it has the channels — the\n // unit tests bind a context carrying `addWatchFile` and nothing else, and a\n // hook calling `this.warn` against that throws in a way that reads as a\n // plugin bug rather than as a missing stub.\n //\n // Only when nothing has claimed the host yet. Under Vite `configResolved`\n // has already installed the dev server's own logger, and `buildStart` runs\n // after it with a rollup-shaped context that would otherwise replace it.\n const adoptHost = (context: object): void => {\n if (host) return\n\n const warn: unknown = 'warn' in context ? context.warn : undefined\n if (!isMessageChannel(warn)) return\n\n const info: unknown = 'info' in context ? context.info : undefined\n\n host = {\n // `warn`, never `error`. Rollup's `this.error` aborts the bundle, so\n // reporting through it would stop every build that reported anything and\n // take the decision `failOnError` exists to make.\n error: (message) => {\n warn.call(context, message)\n },\n info: isMessageChannel(info)\n ? (message) => {\n info.call(context, message)\n }\n : undefined,\n }\n }\n\n // Helper to log at the configured level\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n const prefix = '[unplugin-style-dictionary]'\n\n // Ahead of the `silent` gate on purpose. `silent` is about the progress\n // lines and the size table; a compile that failed is not noise, and\n // hiding it left a broken token set shipping with nothing said at all.\n if (type === 'error') {\n // The host renders and colours its own output, so nothing painted here\n // is handed to one — an escape inside a webpack `stats` entry survives\n // into `stats.toJson()` and into whatever reads it.\n if (host) {\n host.error(`${prefix} ${message}`)\n return\n }\n\n console.error(paint('31', `${prefix} ${message}`, stderrColour))\n return\n }\n\n if (quiet) return\n\n if (host?.info) {\n host.info(`${prefix} ${message}`)\n return\n }\n\n console.log(\n paint(\n type === 'success' ? '32' : '36',\n `${prefix} ${message}`,\n stdoutColour,\n ),\n )\n }\n\n // Runs one of the consumer's `onBuild*` hooks without letting it decide the\n // fate of the build that called it.\n //\n // Two ways a hook can go wrong, and neither may propagate. A throw is caught\n // here, because a post-processing step that fails must not undo a compile the\n // plugin itself completed — the files are written and correct. A rejected\n // promise is the quieter one: the return value is deliberately not awaited,\n // so a rejection has nothing holding it and reaches the host as an unhandled\n // rejection, which under Node's default takes the process down — a dev server\n // killed from inside a hook that was only meant to reformat a file.\n //\n // Both are reported at `'error'`, so they are said at every level including\n // `silent`, and worded so neither can be read as the compile having failed.\n const callHook = <A extends unknown[]>(\n name: string,\n hook: (...args: A) => Promise<void> | void,\n ...args: A\n ): void => {\n let result: unknown\n\n try {\n // Captured rather than dropped, because the promise an `async` hook\n // returns is the thing the check below needs. Wrapping this call in a\n // block-bodied arrow — which is what the linter asks for when the return\n // type is plain `void` — discarded it, and the rejection escaped exactly\n // as it had before any of this existed.\n result = hook(...args)\n } catch (err) {\n log(`The ${name} hook threw: ${errorMessage(err)}`, 'error')\n return\n }\n\n if (!isThenable(result)) return\n\n void Promise.resolve(result).catch((err: unknown) => {\n log(`The ${name} hook rejected: ${errorMessage(err)}`, 'error')\n })\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<ResolvedConfig[]> => {\n let rawConfig = options.config\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (fs.existsSync(fullPath)) {\n rawConfig = file\n break\n }\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig(configContext())\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return { config: fullPath, file: fullPath }\n } else {\n return { config: conf }\n }\n })\n }\n\n // Imports a config module, re-evaluating it only when the file itself has\n // changed. The query string is what decides that, and it is not decoration:\n // Node's ESM cache is permanent and keyed on the specifier, so a config\n // imported without one is evaluated once and never read again — which is\n // how an edited `.mjs` config went on building the platform map the process\n // started with, for the rest of the session.\n //\n // `Date.now()` fixed that staleness and bought two problems. Every watcher\n // event registered another module record in a map nothing prunes, re-running\n // the config's own `registerFormat` side effects for a file nobody touched.\n // And its millisecond granularity meant an edit landing inside the same\n // millisecond as the previous import shared that import's key, and was\n // served the old module anyway. `mtimeMs` carries sub-millisecond\n // resolution and only moves when the file does.\n const importConfigModule = async (file: string): Promise<unknown> => {\n let version: number\n try {\n version = fs.statSync(file).mtimeMs\n } catch {\n // A config that cannot be stat'd is about to fail its import too. The\n // old key is what keeps that failure the import's to report.\n version = Date.now()\n }\n\n // The dot goes, and that is not cosmetic. `mtimeMs` is fractional, so the\n // query it produces ends in something that reads as a file extension to\n // anything deriving a loader from the specifier without stripping the\n // query first — `sd.config.ts?t=1789565080284.6606` is then a `.6606`\n // file, and a TypeScript config gets parsed as JavaScript. Replacing the\n // one dot keeps every distinct mtime a distinct key.\n const key = String(version).replace('.', '_')\n\n // Sequential on purpose: a config module runs arbitrary code at import\n // time — `registerFormat` and friends — and Style Dictionary's registries\n // are global, so importing several at once would interleave those\n // registrations.\n return unwrapDefault(await import(`${pathToFileURL(file).href}?t=${key}`))\n }\n\n // What a configuration item says, as an object. `report` is what stops the\n // two readers of this from saying the same thing twice: a bad config has\n // nowhere else to surface when the watch list is being built, while a build\n // falls back to handing Style Dictionary the path and lets its message\n // through instead.\n const readConfigObject = async (\n item: ResolvedConfig,\n reportErrors: boolean,\n ): Promise<Config | null> => {\n if (typeof item.config !== 'string') return item.config\n\n try {\n // JSON5 rather than `JSON.parse`, because that is what Style Dictionary\n // reads these files with — it is a superset, so a plain `.json` config\n // parses identically and one carrying a comment stops being a config\n // the build understands and the watch list does not.\n const loaded: unknown = isImportedConfig(item.config)\n ? await importConfigModule(item.config)\n : JSON5.parse(fs.readFileSync(item.config, 'utf-8'))\n\n if (isConfig(loaded)) return loaded\n\n if (reportErrors) {\n log(\n `Config file did not resolve to a configuration object: ${item.config}`,\n 'error',\n )\n }\n } catch (err) {\n if (reportErrors) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${errorMessage(err)}`,\n 'error',\n )\n }\n }\n\n return null\n }\n\n // Parse token files to watch\n const getWatchTargets = async (\n resolvedConfigs: ResolvedConfig[],\n ): Promise<{ paths: string[]; patterns: string[] }> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n const configObj = await readConfigObject(item, true)\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n // Against the working directory, because that is where Style\n // Dictionary resolves it: `combineJSON` globs each pattern with\n // no `cwd` of its own. Resolving against the configuration file's\n // directory instead is how the watch list came to name paths the\n // build never reads — a configuration in a subdirectory built\n // correctly and watched nothing at all.\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(process.cwd(), pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n const patterns = Array.from(filesToWatch)\n\n // Recorded here rather than at each call site, so every path that derives\n // a watch list refreshes the one `watchChange` filters against.\n cachedPatterns = patterns\n\n return { paths: await expandPatterns(patterns), patterns }\n }\n\n // What `new StyleDictionary` is handed for an item. Only a path in the JS\n // family becomes an object, because those are exactly the extensions Style\n // Dictionary's own `loadFile` reaches with `import` — the ones whose module\n // record Node then caches forever, and so the only ones a build could read\n // stale. The JSON5 family stays a path because there is nothing to gain:\n // those are read from disk on every pass either way, so a build can never\n // see one as it stood earlier in the process.\n const configForBuild = async (\n item: ResolvedConfig,\n ): Promise<Config | string> => {\n const { config } = item\n\n if (typeof config !== 'string' || !isImportedConfig(config)) return config\n\n const loaded = await readConfigObject(item, false)\n\n // A config that could not be read falls back to the path, so the failure\n // stays Style Dictionary's to report — it knows more about why an import\n // failed than this does, a `.ts` config without type stripping especially.\n if (!loaded) return item.config\n\n // `loadFile` clones what it imports before handing it on, and passing an\n // object skips that. It matters more here than it does there: the module\n // record now outlives the build, and `extend` is called with\n // `mutateOriginal`. Cloning throws on a config carrying functions — an\n // inline transform — and Style Dictionary's own fallback in that case is\n // to use the original, so this one matches it.\n try {\n return structuredClone(loaded)\n } catch {\n return loaded\n }\n }\n\n // Every absolute destination a configuration declares, read off the\n // configuration itself rather than off an extended Style Dictionary\n // instance. Reading it here is the whole point: constructing the instance\n // is what the skip exists to avoid.\n //\n // Resolved exactly as the build resolves it below, so the two name the same\n // files — a relative `buildPath` against `root`, and a `destination`\n // against that.\n const declaredDestinations = (configObj: Config): string[] => {\n const destinations: string[] = []\n\n for (const platform of Object.values(configObj.platforms ?? {})) {\n const buildPath = platform.buildPath ?? ''\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n\n for (const file of platform.files ?? []) {\n if (file.destination) {\n destinations.push(\n path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination),\n )\n }\n }\n }\n\n return destinations\n }\n\n // A stable identity for one resolved configuration, or `null` where it\n // cannot have one. Functions are serialised by source rather than dropped,\n // because an inline `format` or `transform` is exactly the edit a\n // fingerprint has to notice, and `JSON.stringify` omits a function outright.\n const configFingerprint = (item: ResolvedConfig): null | string => {\n try {\n return JSON.stringify(\n [root, item.file ?? item.config],\n (_key, value: unknown) =>\n typeof value === 'function' ? `[fn]${String(value)}` : value,\n )\n } catch {\n // Circular, or holding a BigInt. It takes no identity rather than a\n // wrong one, so it compiles every time exactly as it did before.\n return null\n }\n }\n\n // Whether every file a configuration declares is already newer than every\n // file it reads, so its compile can be skipped.\n //\n // Conservative in every direction it can be: anything it cannot establish —\n // a destination that is missing, a source it cannot stat, a configuration\n // declaring no destinations at all — is a reason to build rather than to\n // skip.\n const isUpToDate = async (\n item: ResolvedConfig,\n configObj: Config,\n ): Promise<boolean> => {\n // An action writes what no `destination` names, so there is nothing for\n // the comparison below to check and skipping would leave its work undone.\n const hasActions = Object.values(configObj.platforms ?? {}).some(\n (platform) => (platform.actions?.length ?? 0) > 0,\n )\n if (hasActions) return false\n\n const destinations = declaredDestinations(configObj)\n if (destinations.length === 0) return false\n\n // `options.watch` belongs in here as much as `source` does. A consumer\n // names an extra file because something in the build reads it — a custom\n // format's own data file, most obviously — and leaving it out let a change\n // to it be skipped over while the watcher dutifully reported it.\n const extraWatches = options.watch\n ? Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n : []\n\n const sources = await expandPatterns([\n ...sourcePatternsOf(configObj),\n ...extraWatches.map((pattern) =>\n (path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n ).replace(/\\\\/g, '/'),\n ),\n ])\n if (item.file) sources.push(item.file.replace(/\\\\/g, '/'))\n\n if (sources.length === 0) return false\n\n let newestSource = -Infinity\n let sawFile = false\n\n for (const source of sources) {\n const stats = statOrNull(source)\n if (!stats) return false\n\n // Directories are in this list on purpose — `expandPatterns` registers\n // each pattern's static parent so a token file created later is\n // noticed — but their mtime cannot be read as an input signal here. A\n // directory's mtime moves whenever an entry is added or renamed inside\n // it, and the atomic write renames every generated file into place, so\n // a `buildPath` inside a watched directory made the build itself the\n // newest thing the comparison could see. Nothing was ever up to date.\n if (stats.isDirectory()) continue\n\n sawFile = true\n newestSource = Math.max(newestSource, stats.mtimeMs)\n }\n\n // Every pattern expanded to directories alone, so nothing was actually\n // read. Style Dictionary would build an empty dictionary from that, and a\n // skip would present the empty result as current.\n if (!sawFile) return false\n\n let oldestDestination = Infinity\n for (const destination of destinations) {\n const stats = statOrNull(destination)\n if (!stats) return false\n oldestDestination = Math.min(oldestDestination, stats.mtimeMs)\n }\n\n if (oldestDestination <= newestSource) return false\n\n // A configuration given as a path has its own file among the sources\n // above, so an edit to it has already been accounted for and the skip\n // holds across processes.\n if (item.file) return true\n\n // One given as an object or a function has not. Only this process knows\n // what it looked like when those destinations were written, so the skip\n // holds only against a fingerprint recorded here.\n const fingerprint = configFingerprint(item)\n\n return fingerprint !== null && compiledFingerprints.has(fingerprint)\n }\n\n // The size-and-gzip table, in a function of its own so that the compile\n // `try` in `runBuilds` can stop before it. Everything here is presentation\n // over files Style Dictionary has already finished writing, so a throw from\n // it is a reporting bug and nothing more.\n const reportSizes = (generatedFiles: Set<string>) => {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path.relative(root, filePath).replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n // The table goes to stdout, so it follows stdout's decision — which\n // is not always stderr's, since the two are redirected separately.\n const coloredPath =\n dir === '.'\n ? paint('32', base, stdoutColour)\n : paint('90', `${dir}/`, stdoutColour) +\n paint('32', base, stdoutColour)\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // One unreadable destination costs its row rather than the table.\n // Deliberately narrower than the caller's `catch`: it covers the\n // three filesystem and gzip calls above and not the arithmetic\n // below, so a padding bug is reported rather than quietly printing\n // short.\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(2, longestPathLength - info.relativeDisplayPath.length + 2),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n info.coloredPath +\n pathPadding +\n paint(\n '90',\n `${sizePadded} │ gzip: ${info.gzipSizeStr}`,\n stdoutColour,\n ),\n )\n }\n }\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: ResolvedConfig[],\n context?: string,\n ) => {\n const startTime = Date.now()\n\n // Ahead of the `try` rather than inside it, because the reporting below\n // reads it and that reporting is deliberately outside.\n const generatedFiles = new Set<string>()\n\n // How many configurations were already up to date. Read by the reporting\n // below, which is why it sits out here with `generatedFiles`.\n let skipped = 0\n\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n // Before anything is resolved or built, and once per build — a watch\n // rebuild is a build, so this fires again for each one.\n if (onBuildStart) callHook('onBuildStart', onBuildStart)\n\n // Configurations are built one after another rather than with\n // `Promise.all`, and that is load-bearing. Two configurations may name\n // the same destination file, and each instance gets the atomic volume\n // swapped onto it below — overlapping builds would interleave those\n // writes and hand a reader a file assembled from both.\n for (const item of resolvedConfigs) {\n // Read ahead of the instance, because avoiding the instance is the\n // point: construction plus `extend` is the 15-30% of a build that\n // parses the token sources, and `buildAllPlatforms` is the rest.\n //\n // `false` so a configuration that will not parse says nothing here —\n // the build below hands Style Dictionary the path and lets its own\n // message through, which is more specific than anything this could\n // say.\n const declared = cache ? await readConfigObject(item, false) : null\n\n if (declared && (await isUpToDate(item, declared))) {\n // The destinations still have to be collected. They are what stops\n // the plugin's own output being treated as a watched source, so a\n // skipped configuration that contributed none would have its files\n // rebuild the moment a watcher noticed them.\n for (const destination of declaredDestinations(declared)) {\n generatedFiles.add(destination)\n }\n\n skipped++\n continue\n }\n\n // `{ init: false }` is the escape hatch Style Dictionary documents on\n // this constructor, and it is what makes a bad configuration\n // catchable. Left to itself the constructor ends in a call to\n // `init()` whose promise it neither stores nor returns, so a config\n // that fails to load rejects a promise nobody holds: the `catch`\n // below never runs, and the host dies with a raw stack or — where an\n // `unhandledRejection` handler suppresses it — hangs on a\n // `buildStart` that never settles. `await sd.hasInitialized` cannot\n // observe it either, since that promise is only ever resolved, at the\n // tail of a successful extend.\n //\n // It is handed the configuration as an object rather than as a path\n // for the same reason: Style Dictionary imports a path with no\n // cache-busting query of its own, so under a long-lived dev server\n // every rebuild after the first built the config the process started\n // with while the watch list followed the edit.\n const sd = new StyleDictionary(await configForBuild(item), {\n init: false,\n })\n\n // One initialisation rather than two. `init()` is `extend()` with\n // `mutateOriginal`, so the old pair loaded the configuration and\n // combined every source twice — running a custom parser or\n // preprocessor twice with it — and the first of the two ran at\n // default verbosity, which is how Style Dictionary's own warnings\n // escaped this plugin's `silent`. `config` defaults to the one the\n // constructor was handed.\n //\n // `verbosity` is `undefined` unless a consumer asked for a level, and\n // Style Dictionary falls through an unset one to the configuration's\n // own `log.verbosity`. Overwriting it here is what silenced the one\n // line explaining why a build wrote nothing. `log.warnings` is not\n // touched either way: a consumer's `warnings: 'error'` turning a\n // missing output file into a thrown build is their decision.\n await sd.extend(undefined, { mutateOriginal: true, verbosity })\n\n // Swap in the atomic volume only now that the instance has finished\n // reading its configs and token sources, so every write below lands\n // through `rename` while the read path stays exactly as it was.\n sd.volume = atomicVolume\n await sd.buildAllPlatforms()\n\n // Collected on every build rather than only on the ones whose size\n // report prints it below. The set is also what keeps a rebuild from\n // being triggered by the write it just made, and a rebuild passes a\n // `context` — so gating the collection on `!context` left it empty on\n // exactly the builds a watcher is live for.\n for (const platform of Object.values(sd.platforms)) {\n const buildPath = platform.buildPath ?? ''\n for (const file of platform.files ?? []) {\n if (file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n\n // Recorded only now, so a configuration whose build threw is never\n // treated as one this process has compiled.\n const fingerprint = configFingerprint(item)\n if (fingerprint !== null) compiledFingerprints.add(fingerprint)\n }\n\n // Replaced wholesale rather than added to, so a destination dropped from\n // a configuration stops being treated as ours and becomes watchable\n // again. A build that throws never reaches this and leaves the previous\n // set standing, which is the safe direction: the files it wrote before\n // failing are still ours.\n generatedDestinations.clear()\n for (const destination of generatedFiles) {\n generatedDestinations.add(destination.replace(/\\\\/g, '/'))\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${errorMessage(err)}`,\n 'error',\n )\n\n // Ahead of the throw decision on purpose, so the overlay sees a failure\n // whatever `failOnError` does with it. Under the dev server's default\n // the line below does not throw, and reading the outcome from a caller's\n // `catch` would see a rebuild that looked like it succeeded.\n notifyBuildOutcome?.(asError(err))\n\n // Ahead of the throw decision for the same reason as the line above: a\n // rebuild under the dev server's default does not throw, and a hook that\n // only fired when something else was about to fail would be silent on\n // exactly the builds a consumer is watching.\n if (onBuildError) callHook('onBuildError', onBuildError, err)\n\n // Reported, and then rethrown so the host stops. Swallowing it left\n // every target exiting 0 with the previous run's tokens still on disk\n // and in the bundle — a green build shipping stale values.\n if (failsTheBuild(context)) throw err\n\n // Explicit, now that the reporting below sits outside the `try`. This\n // `catch` used to end the function by falling off the end of it; a\n // failure that is not rethrown would otherwise carry on to announce a\n // compile that did not happen.\n return\n }\n\n // The compile is what the overlay reflects, so this is said here rather\n // than at the end: everything below is reporting, it returns early in\n // three places, and a size table that throws must not leave a successful\n // build looking unfinished.\n notifyBuildOutcome?.(null)\n\n // One measurement, read by the hook below and by the reporting under it.\n const duration = Date.now() - startTime\n\n // Beside the overlay notification, and for the same reason it sits here\n // rather than at the end of the function: the reporting below returns\n // early in three places, and a build that finished has finished whether or\n // not a size table gets printed for it.\n //\n // Sorted, so two runs of one configuration hand back the same order —\n // `generatedFiles` is a set in platform-then-file order, which is stable\n // in practice and guaranteed by nothing. The paths stay platform-native:\n // this is a list a consumer is going to open files with, not one the\n // watcher compares against.\n if (onBuildEnd) {\n // `toSorted` is what the linter asks for and what this cannot use:\n // `lib` is ES2022 here and `toSorted` is ES2023, so it types as an error\n // even though every Node this package supports has it. The rule guards\n // against mutating an array someone else holds, and this one was built\n // from the set on the line it appears on.\n // oxlint-disable-next-line unicorn/no-array-sort\n const files = Array.from(generatedFiles).sort((left, right) =>\n left.localeCompare(right),\n )\n callHook('onBuildEnd', onBuildEnd, files, duration)\n }\n\n // The `try` ends above, and everything from here down is reporting. Style\n // Dictionary has finished writing by now and `generatedDestinations` is\n // already replaced, so nothing below can put a file on disk in doubt —\n // which is why a throw from it must not be caught as a compile failure.\n // It used to be: a fault in the padding arithmetic printed `Compilation\n // failed after 19ms` over a build whose every token file was correct, and\n // with `failOnError` defaulting to `'build'` that stopped the bundler.\n\n // Every configuration was already current, so nothing was written. Said\n // rather than left implied: a build that prints its opening line and then\n // finishes in two milliseconds reads as one that silently did nothing.\n const everythingSkipped = skipped === resolvedConfigs.length\n\n if (context) {\n log(\n everythingSkipped\n ? `Design tokens already up to date after change in ${context} (${duration}ms)`\n : `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n return\n }\n\n // The table is skipped when nothing was written, on top of `report` and\n // `quiet`. It reads every generated file in full and gzips it, and\n // reprinting the sizes of files this build did not touch is the one case\n // where that cost buys nothing at all.\n if (report && !quiet && !everythingSkipped && generatedFiles.size > 0) {\n try {\n reportSizes(generatedFiles)\n } catch (err) {\n // At `'error'`, so it is said at every level including `silent`,\n // exactly as a compile failure is — and worded so it cannot be read\n // as one. Not rethrown: the build succeeded.\n log(\n `Failed to report generated file sizes: ${errorMessage(err)}`,\n 'error',\n )\n }\n }\n\n if (everythingSkipped) {\n log(`Design tokens are already up to date (${duration}ms)`, 'success')\n return\n }\n\n log(\n skipped > 0\n ? `Compiled successfully! (${duration}ms, ${skipped} already up to date)`\n : `Compiled successfully! (${duration}ms)`,\n 'success',\n )\n }\n\n // `runBuilds` for the first build of a process, with the compile shared\n // between every plugin instance that wants the same one.\n //\n // An instance arriving while a compile for the same key is running waits on\n // that compile instead of starting a second. It is the concurrent half that\n // needs this: an up-to-date check compares what is on disk against the\n // sources, and two instances that start together have nothing on disk to\n // compare against yet, so only a shared promise can tell them apart from\n // two genuinely separate builds.\n //\n // The entry is dropped as soon as the compile settles, so this coalesces\n // rather than caches — a later `buildStart` still compiles. Skipping one\n // whose output is already current is #212's up-to-date check, and belongs\n // with it rather than as a second mechanism here.\n //\n // A rejection reaches every waiter, which is the point: an instance that\n // waited on a failed compile must not carry on as though the tokens were\n // written. Whether that rejection is thrown at all is `failOnError`'s\n // decision, already made inside `runBuilds`.\n const compileOnceAcrossInstances = async (\n resolvedConfigs: ResolvedConfig[],\n ): Promise<void> => {\n const key = buildKey(root, resolvedConfigs)\n if (key === null) {\n await runBuilds(resolvedConfigs)\n return\n }\n\n const running = compilesInFlight.get(key)\n if (running) {\n await running\n return\n }\n\n const compile = runBuilds(resolvedConfigs)\n compilesInFlight.set(key, compile)\n\n try {\n await compile\n } finally {\n compilesInFlight.delete(key)\n }\n }\n\n // One rebuild per burst of watcher events, and never two at once.\n //\n // Two things went wrong without this. A single token edit under Vite's dev\n // server reached both the `configureServer` listener and `watchChange` —\n // Vite 6, 7 and 8 all invoke plugin `watchChange` while serving — and each\n // started its own build, so one write produced two. And nothing serialised\n // them: a four-file change started one build per file, all overlapping.\n // `runBuilds` builds its configurations one after another precisely so two\n // instances never write the same destination at once, and concurrent calls\n // to it reintroduced that one level up.\n //\n // The trailing debounce collapses the burst; the in-flight chain means a\n // trigger arriving mid-build queues exactly one follow-up rather than\n // starting a second build beside it.\n const REBUILD_DEBOUNCE_MS = 50\n\n let debounceTimer: ReturnType<typeof setTimeout> | undefined\n let pendingReason: string | undefined\n let inFlight: Promise<void> | undefined\n let waiting: Array<(failure?: { error: unknown }) => void> = []\n\n // Set by `configureServer`. A dev server's watcher is long-lived, so its\n // list has to follow a configuration that changes; every other target\n // re-registers on each build through `addWatchFile` instead.\n let refreshServerWatchList:\n | ((resolved: ResolvedConfig[]) => Promise<void>)\n | undefined\n\n // Also set by `configureServer`, and left undefined everywhere else: this is\n // how a compile outcome reaches Vite's error overlay. It is deliberately not\n // the same path as `failOnError`.\n //\n // `failOnError` decides whether the host stops; this decides whether the\n // browser is told. Under a dev server the default is not to stop, so the\n // failure is reported and swallowed — and that is exactly the case where the\n // page is left rendering the last good file with nothing to say it is stale.\n // Reading the outcome off whether `runBuilds` threw would therefore see\n // nothing at all on the only configuration that matters.\n let notifyBuildOutcome: ((error: Error | null) => void) | undefined\n\n const drain = async (): Promise<void> => {\n // A loop rather than a single pass: anything scheduled while the build\n // below is running is picked up here instead of starting a second one.\n while (pendingReason !== undefined) {\n const reason = pendingReason\n pendingReason = undefined\n\n // Captured before the await, so a trigger arriving mid-build waits for\n // the next pass rather than being told this one covered it.\n const resolvers = waiting\n waiting = []\n\n let failure: undefined | { error: unknown }\n let compiling = false\n\n try {\n const resolved = await resolveConfigs()\n if (resolved.length > 0) {\n compiling = true\n await runBuilds(resolved, reason)\n compiling = false\n hasCompiled = true\n await refreshServerWatchList?.(resolved)\n }\n } catch (err) {\n failure = { error: err }\n\n // `runBuilds` reports its own failure before rethrowing, so only the\n // other things that can throw here — a `config` function of the\n // consumer's that raises, a watch list that cannot be rebuilt — need\n // reporting. They reach the overlay for the same reason: from the\n // page's point of view the rebuild failed, whichever half of it did.\n if (!compiling) {\n log(`Rebuild failed: ${errorMessage(err)}`, 'error')\n notifyBuildOutcome?.(asError(err))\n }\n }\n\n // Handed on to whatever awaited this rebuild, which is `watchChange`\n // and so the host under a watching bundler. Vite's dev-server listener\n // has no build to fail and catches it.\n for (const settle of resolvers) settle(failure)\n }\n }\n\n // Resolves once a rebuild covering this trigger has finished.\n const schedule = async (reason: string): Promise<void> => {\n pendingReason = reason\n\n const covered = new Promise<void>((resolve, reject) => {\n waiting.push((failure) => {\n if (failure) reject(asError(failure.error))\n else resolve()\n })\n })\n\n if (debounceTimer) clearTimeout(debounceTimer)\n debounceTimer = setTimeout(() => {\n debounceTimer = undefined\n inFlight = (inFlight ?? Promise.resolve()).then(drain)\n }, REBUILD_DEBOUNCE_MS)\n\n // A pending rebuild must not be what keeps a process alive; whatever is\n // watching already is.\n debounceTimer.unref()\n\n return covered\n }\n\n return {\n async buildStart() {\n adoptHost(this)\n adoptWatchMode(this)\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`). Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch — not because\n // `watchChange` is missing there, which it is not on any Vite this\n // package supports, but because the declared peer range is wider than\n // what has been measured and the scheduler above makes a duplicate\n // trigger free.\n const { paths } = await getWatchTargets(resolved)\n for (const file of paths) {\n this.addWatchFile(file)\n }\n\n // Registering the watch list is all this hook does on webpack, and it\n // has to happen here rather than beside the compile: `addWatchFile`\n // reaches `compilation.fileDependencies`, and `beforeCompile` runs\n // before there is a compilation to add to. Compiling here as well would\n // put the race back, and run every webpack build twice.\n if (isWebpack) return\n\n // Every watch rebuild re-enters this hook, and compiling here as well as\n // in `watchChange` is what closed the loop: consuming code imports the\n // generated file, so writing it is itself a module-graph change, which\n // re-enters `buildStart`, which writes it again. `watchChange` has\n // already run for every file in this cycle and rebuilt if any of them\n // was a source, so the only thing left for a re-entry to do is the\n // re-registration above.\n //\n // `hasCompiled` is the floor under that: a host that fires\n // `watchChange` without ever re-entering here would otherwise leave the\n // flag standing, and no first compile of a process may ever be skipped —\n // the tokens have to exist before the build that consumes them.\n if (watchRebuild && hasCompiled) {\n watchRebuild = false\n return\n }\n\n await compileOnceAcrossInstances(resolved)\n hasCompiled = true\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n if (rootOption === undefined) root = config.root || process.cwd()\n\n // The only host that has both. `command` is what makes `'serve'`\n // reachable at all, since nothing else here serves.\n hostCommand = config.command\n hostMode = config.mode\n\n // Vite's own logger, so the plugin's lines obey `customLogger` and\n // `clearScreen` like every other line the dev server prints. It\n // colours and prefixes its own output, which is why nothing painted\n // reaches it.\n host = {\n error: (message) => {\n config.logger.error(message)\n },\n info: (message) => {\n config.logger.info(message)\n },\n }\n },\n\n async configureServer(server: ViteDevServer) {\n // A dev server watches, by definition. Said here rather than left to\n // `adoptWatchMode` because this hook runs *before* `buildStart` —\n // `createServer` calls it, and `buildStart` waits for the plugin\n // container — so the first `config` function of the process would\n // otherwise be told `watch: false` while a dev server started up\n // around it.\n isWatching = true\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Reassigned after every rebuild below, so a configuration that gains\n // a source is matched against its new patterns rather than the ones\n // read at start-up.\n let targets = await getWatchTargets(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(targets.paths)\n\n // Runs once per rebuild rather than once per event, which is why it\n // is handed to the scheduler rather than done in the listener.\n refreshServerWatchList = async (rebuilt) => {\n targets = await getWatchTargets(rebuilt)\n server.watcher.add(targets.paths)\n }\n\n if (errorOverlay) {\n // Whether the page is currently showing an overlay this plugin put\n // there. Only the clearing frame reads it: a success that follows a\n // success has no overlay to take down, and sending an update frame\n // for it would be traffic for nothing — and would spend the client's\n // one-time `isFirstUpdate`, which Vite uses to decide that an\n // overlay standing at the first update means a full reload.\n let overlayShowing = false\n\n notifyBuildOutcome = (error) => {\n if (error) {\n // Sent on every failure rather than only on the transition into\n // one. Vite's client replaces the overlay wholesale, so a repeat\n // is idempotent — and two different failures in a row must not\n // leave the first one's message on screen describing the second.\n overlayShowing = true\n server.hot.send({\n err: {\n message: error.message,\n plugin: 'unplugin-style-dictionary',\n stack: error.stack ?? '',\n },\n type: 'error',\n })\n return\n }\n\n if (!overlayShowing) return\n overlayShowing = false\n\n // Vite's protocol has no frame for \"take the overlay down\". The\n // client clears it when an update arrives, so an update carrying\n // nothing is the clear: it dismisses the overlay and then iterates\n // an empty list, reloading no page and touching no stylesheet.\n server.hot.send({ type: 'update', updates: [] })\n }\n }\n\n // chokidar types its listener as returning void and does not await\n // what it is handed, so an async listener left every rejection\n // floating. `schedule` owns the whole rebuild including its errors,\n // so there is nothing here left to reject.\n server.watcher.on('all', (_event, file) => {\n if (!isWatchedSource(file, targets.patterns)) return\n\n // A dev server has no build to fail, so a rebuild that throws is\n // reported by the scheduler and the server keeps serving.\n void schedule(path.basename(file)).catch(() => {})\n })\n },\n },\n\n // Rollup types `watchChange` as returning void, yet awaits it as a\n // sequential hook — and the work here is inherently asynchronous. The\n // signature is the thing that is wrong, so the rule is silenced rather\n // than the hook made to lie about finishing.\n // oxlint-disable-next-line typescript/no-misused-promises\n async watchChange(id) {\n adoptHost(this)\n adoptWatchMode(this)\n\n // Raised before any decision about `id`, because whatever this change\n // was, the host is now on its way back into `buildStart`.\n watchRebuild = true\n\n // The cheap half of the decision, taken before anything is resolved.\n // Under Vite the scope this hook sees is the whole project root rather\n // than the module graph, so most of what arrives here has nothing to do\n // with tokens, and resolving every configuration only to discard the\n // answer ran a consumer's `config` function once per unrelated file.\n // Skipped until a build has derived a list to filter against.\n if (cachedPatterns && !isWatchedSource(id, cachedPatterns)) return\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Derived again rather than trusted from the cache, because the cache\n // is what decided this path was worth resolving and not what decides a\n // rebuild. A config edit reaches here through its own filename and can\n // have dropped the very source the cached list matched.\n const { patterns } = await getWatchTargets(resolved)\n // Without this check, watchChange fires for *any* changed file in the\n // host bundler's module graph — including our own generated output,\n // since consuming code imports it. Every regenerate is itself a\n // \"change\", so skipping what is not a source here is what keeps this\n // from rebuilding forever — both the files that match no pattern and\n // the ones that match only because this plugin wrote them.\n if (!isWatchedSource(id, patterns)) return\n\n // Same division as `buildStart`: on webpack the compile belongs to\n // `beforeCompile`, which has already run for this compilation, so all\n // that is left is to re-register the watch list below.\n if (!isWebpack) await schedule(path.basename(id))\n\n // Expanded again after the build rather than reusing the list from\n // before it, so a token file the build itself produced is registered.\n for (const file of await expandPatterns(patterns)) {\n this.addWatchFile(file)\n }\n },\n\n // unplugin calls this inside `apply(compiler)`, one line before it taps\n // `make`, so the root is in place before the first compile. Without it a\n // webpack build whose `context` is not the working directory looked for\n // the configuration in the wrong place and reported ENOENT.\n webpack(compiler) {\n if (rootOption === undefined) {\n root = compiler.options.context ?? process.cwd()\n }\n\n // webpack's `buildStart` context carries no `meta`, so neither half of\n // the build context can come from there. `mode` is a webpack option, and\n // `watchMode` is only true once `watch()` has been called — which is\n // after this runs, so it is read per compile below rather than here.\n hostMode = compiler.options.mode\n\n // The compile happens in `beforeCompile`, which webpack awaits *before*\n // the compilation exists — so a message from it has nothing to attach to\n // yet and is held until one appears.\n //\n // Only failures are routed. `stats` carries warnings and errors and\n // nothing else, so the progress lines stay on the console rather than\n // being reported as warnings they are not.\n //\n // A warning rather than an error, for the same reason as on rollup: this\n // is the report, and `failOnError` decides separately whether the build\n // stops. Pushing to `compilation.errors` would fail a webpack build that\n // asked not to be failed.\n const pending: string[] = []\n host = {\n error: (message) => {\n pending.push(message)\n },\n }\n\n compiler.hooks.compilation.tap(\n 'unplugin-style-dictionary',\n (compilation) => {\n for (const message of pending.splice(0)) {\n const reported = new Error(message)\n reported.name = 'UnpluginStyleDictionaryWarning'\n compilation.warnings.push(reported)\n }\n },\n )\n\n // A `beforeCompile` that throws ends the run without ever creating a\n // compilation, and that is exactly the case that produced the message.\n // Left to the buffer it would be reported nowhere at all, so whatever is\n // still held when the run ends goes to the console after all.\n const drainToConsole = () => {\n for (const message of pending.splice(0)) {\n console.error(paint('31', message, stderrColour))\n }\n }\n compiler.hooks.failed.tap('unplugin-style-dictionary', drainToConsole)\n compiler.hooks.done.tap('unplugin-style-dictionary', drainToConsole)\n\n // `beforeCompile` is awaited before the compilation exists, so the\n // tokens are on disk before webpack resolves the module that imports\n // them. Tapped on every compilation rather than only the first: a watch\n // rebuild needs the same guarantee, and a compile that renders what is\n // already there skips its own write.\n compiler.hooks.beforeCompile.tapPromise(\n 'unplugin-style-dictionary',\n async () => {\n isWatching = compiler.watchMode\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n await compileOnceAcrossInstances(resolved)\n hasCompiled = true\n },\n )\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":";;;;;;;;;;AAkDA,SAAS,QAAQ,OAAuB;CACtC,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,aAAa,KAAK,CAAC;AACvE;AAaA,SAAS,cAAc,QAAsC;CAC3D,IAAI,QAAQ,IAAI,UAAU,OAAO;CAEjC,MAAM,SAAS,QAAQ,IAAI;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAA,KAAa,WAAW,IAAI,OAAO;CAIlD,IAAI,QAAQ,IAAI,SAAS,QAAQ,OAAO;CAExC,OAAO,OAAO,UAAU;AAC1B;AAIA,SAAS,qBAAqB,WAAyB;CACrD,IAAI;EACF,GAAG,OAAO,WAAW,EAAE,OAAO,KAAK,CAAC;CACtC,QAAQ,CAER;AACF;AAEA,SAAS,aAAa,OAAwB;CAC5C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;AAOA,SAAS,SAAS,OAAiC;CACjD,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAKA,SAAS,iBAAiB,OAAoD;CAC5E,OAAO,OAAO,UAAU;AAC1B;AAMA,SAAS,WAAW,OAA+C;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAO,MAAM,SAAS;AAE1B;AAEA,SAAS,MAAM,MAAc,OAAe,SAA0B;CACpE,OAAO,UAAU,UAAU,KAAK,GAAG,MAAM,aAAa;AACxD;AAKA,SAAS,cAAc,OAAyB;CAC9C,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,QAC9D,MAAM,WAAW,QAClB;AACN;AA0BA,IAAI,uBAAuB;AAa3B,eAAe,0BACb,WACA,aACkB;CAClB,IAAI;EACF,MAAM,CAAC,UAAU,YAAY,MAAM,QAAQ,IAAI,CAC7C,GAAG,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
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport JSON5 from 'json5'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { glob } from 'tinyglobby'\nimport { createUnplugin } from 'unplugin'\n\nimport type {\n StyleDictionaryConfigContext,\n UnpluginStyleDictionaryOptions,\n} from './types.js'\n\nimport { matchesWatchedFile } from './watch-filter.js'\n\nexport type * from './types.js'\n\n// `catch` binds `unknown`, and a thrown non-Error — a string, a rejected\n// value out of a config module — carries no `.message`. The `as Error` casts\n// this replaces claimed otherwise and printed `undefined` for exactly those\n// cases, which is the least useful thing a failure log can say.\n// A rejected promise must carry an Error, and `catch` binds `unknown`. What\n// Style Dictionary throws is already one; anything else is wrapped rather than\n// handed on raw.\n// Where the plugin's own lines go when a host offers somewhere better than the\n// console: Vite's `config.logger`, rollup's and rolldown's plugin context, or\n// webpack's `compilation`.\n//\n// **There is no `error` channel that merely reports.** Rollup's `this.error`\n// aborts the bundle — measured: a `buildStart` calling it ends the run with\n// `THREW: [plugin err-probe] fatal?` — so routing a failure report through it\n// would stop every build that reported one and silently override `failOnError`,\n// whose entire job is deciding that. A failure is therefore reported on the\n// host's warning channel, and whether the build stops stays `failOnError`'s\n// decision alone.\ninterface HostMessenger {\n error: (message: string) => void\n\n // Optional because not every host has somewhere for a progress line to go.\n // webpack's `stats` carries warnings and errors and nothing else, and\n // `Compiling design tokens...` is neither — so there it stays on the\n // console rather than being dressed up as a warning.\n info?: (message: string) => void\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error(errorMessage(error))\n}\n\n// Whether escapes may be written to this stream.\n//\n// **The three signals are ordered rather than combined into one conjunction**,\n// and that ordering is the whole of it. `FORCE_COLOR=1` on a non-TTY — a CI job\n// that wants colour in a log it will render itself — is the single job that\n// variable has, and\n// `!process.env.NO_COLOR && process.env.FORCE_COLOR !== '0' && stream.isTTY`\n// never honours it: the TTY check has the last word and answers `false`.\n//\n// `NO_COLOR` wins over `FORCE_COLOR` because the convention says so: any\n// non-empty value turns colour off, and nothing may turn it back on.\nfunction colourAllowed(stream: { isTTY?: boolean }): boolean {\n if (process.env.NO_COLOR) return false\n\n const forced = process.env.FORCE_COLOR\n if (forced === '0') return false\n if (forced !== undefined && forced !== '') return true\n\n // A terminal that has told us it cannot render escapes. Not one of the three\n // the issue named, but it is what `TERM=dumb` means and it costs a line.\n if (process.env.TERM === 'dumb') return false\n\n return stream.isTTY === true\n}\n\n// Best-effort cleanup of a temporary file whose write or rename failed. The\n// original failure is what the caller reports, so nothing here may throw.\nfunction discardTemporaryFile(temporary: string): void {\n try {\n fs.rmSync(temporary, { force: true })\n } catch {\n // Ignore: a leftover temporary file is not worth masking the real error.\n }\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n// A config file is an untyped boundary: `JSON.parse` and a dynamic `import`\n// both hand back `any`, and an `any` assigned to `configObj` spreads through\n// every read of it downstream. These two narrow that boundary once, here.\n// They are type predicates rather than assertions on purpose — a predicate is\n// a check the compiler verifies, where a cast is only a claim.\nfunction isConfig(value: unknown): value is Config {\n return typeof value === 'object' && value !== null\n}\n\n// A host's message channel, narrowed by a predicate rather than asserted: what\n// a plugin context carries under `warn` is the host's business, and a cast\n// would only claim it is callable.\nfunction isMessageChannel(value: unknown): value is (message: string) => void {\n return typeof value === 'function'\n}\n\n// A hook is the consumer's code, and what it hands back is not this plugin's to\n// assume. A predicate rather than `instanceof Promise`, which answers `false`\n// for a thenable from another realm or from a promise library — exactly the\n// case where letting a rejection escape does the damage.\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n )\n}\n\n// Whether a discovered file looks like a Style Dictionary configuration at all.\n//\n// Only applied to a file the plugin went looking for, never to one a consumer\n// named: an explicit `config` is their choice and second-guessing it would\n// reject shapes Style Dictionary accepts and this does not know about.\n//\n// `config.json` is an extremely common name for something else entirely, and\n// the plugin used to adopt whatever it found under that name, add it to the\n// watch set, and report a successful compile over it.\nfunction looksLikeConfig(value: unknown): boolean {\n if (typeof value !== 'object' || value === null) return false\n\n // The four keys any usable configuration has at least one of. `platforms`\n // alone is enough because a configuration can declare its tokens inline\n // under `tokens`, or read them through `source`/`include`.\n return ['include', 'platforms', 'source', 'tokens'].some(\n (key) => key in value,\n )\n}\n\n// Vite builds its dev-server watcher with a fixed ignore list — `**/.git/**`,\n// `**/node_modules/**`, `**/test-results/**` and the cache directory — and\n// spreads the consumer's own `server.watch.ignored` entries in *after* them.\n// Entries are appended, never subtracted, so `server.watcher.add()` cannot\n// reach a path an earlier entry already covers.\n//\n// That makes a token package resolved through `node_modules` — the shape of\n// every workspace, `app/node_modules/@acme/tokens` symlinked to\n// `packages/tokens` — build correctly once and then never rebuild, with\n// nothing said about it. Measured on Vite 6.4.3, 7.3.6 and 8.3.0: zero watcher\n// events for an edit, while a token file outside the root but outside\n// `node_modules` rebuilt in the same run.\n//\n// A negation naming the file exactly is what un-ignores it, and is deliberately\n// the narrowest form that works. `!**/node_modules/**` would restore the whole\n// dependency tree to the watcher.\nfunction nodeModulesNegations(paths: string[]): string[] {\n const negations = new Set<string>()\n\n for (const file of paths) {\n const normalised = file.replace(/\\\\/g, '/')\n if (normalised.includes('/node_modules/')) negations.add(`!${normalised}`)\n }\n\n return Array.from(negations)\n}\n\nfunction paint(code: string, value: string, allowed: boolean): string {\n return allowed ? `\\u001B[${code}m${value}\\u001B[0m` : value\n}\n\n// Which of a configuration's own `source`/`include` patterns match no file on\n// disk. Only for diagnosis: it is the emptiness of the resolved token set that\n// decides whether a build fails, because only that catches every route to an\n// empty set. This names the pattern at fault, which the token count cannot, and\n// it reports a mistyped pattern in a configuration whose others still match —\n// where nothing fails at all and one platform quietly loses its tokens.\nasync function patternsMatchingNothing(patterns: string[]): Promise<string[]> {\n const barren: string[] = []\n\n for (const pattern of patterns) {\n // A literal path is a `stat`, not a glob: `tinyglobby` treats a path with\n // no magic characters as a literal anyway, and this keeps the common case\n // off the filesystem walk.\n if (!GLOB_CHARACTERS.test(pattern)) {\n if (!fs.existsSync(pattern)) barren.push(pattern)\n continue\n }\n\n try {\n const matched = await glob([pattern], { absolute: true })\n if (matched.length === 0) barren.push(pattern)\n } catch {\n // A pattern that cannot even be globbed is the build's problem to\n // report; saying it twice, in a diagnostic, helps nobody.\n }\n }\n\n return barren\n}\n\n// A config module may expose its config as a `default` export or as the\n// namespace itself. `'default' in value` is what lets the compiler reach\n// `.default` without a cast.\nfunction unwrapDefault(value: unknown): unknown {\n return typeof value === 'object' && value !== null && 'default' in value\n ? (value.default ?? value)\n : value\n}\n\n// Style Dictionary writes every generated file with a plain `writeFile` on the\n// volume it was handed, which truncates the destination and then streams the\n// new contents into it. Anything reading that file inside the window sees a\n// partial file: a consuming test run whose tokens are rebuilt mid-suite, or a\n// dev-server request landing on a rebuild, gets a truncated module and fails\n// to parse it. Writing a sibling temporary file and renaming it over the\n// destination closes the window — `rename` is atomic within a filesystem, so a\n// concurrent reader sees either the whole old file or the whole new one.\n\n// Temporary path for an atomic write of `destination`.\n//\n// It has to be a sibling of the destination, because `rename` is only atomic\n// within one filesystem and the system temp directory is often a different\n// mount. The final extension is dropped rather than kept, so the temporary\n// file cannot match a pattern written for the generated file's own extension.\n// That was load-bearing while `matchesWatchedFile` tested its globs\n// unanchored, where a leftover `vars.css.tmp` matched a `*.css` watch; it is\n// belt-and-braces now that the matcher anchors and, like the globber Style\n// Dictionary reads sources with, does not match the leading dot this name\n// already starts with. Both stay, because a temporary file only outlives its\n// rename when a write failed, and hiding one costs a string. The pid and\n// counter make the name unique, so two writes of the same destination —\n// parallel platforms in one build, or two builds overlapping — never share a\n// temporary file.\nlet temporaryFileCounter = 0\n\n// Whether the freshly rendered `temporary` holds exactly what `destination`\n// already holds. A rebuild whose inputs did not change renders byte-identical\n// output, and renaming that over the destination is a filesystem event the\n// host bundler reacts to — which is the whole of the rebuild loop, since\n// consuming code imports the generated file and every regenerate is therefore\n// a module-graph change. Comparing the two files rather than the `data`\n// argument keeps this indifferent to whether the caller passed a string, a\n// buffer or a stream, and to the encoding it passed with it.\n//\n// A destination that cannot be read is not identical, which covers the\n// ordinary case of it not existing yet.\nasync function rendersWhatIsAlreadyThere(\n temporary: string,\n destination: string,\n): Promise<boolean> {\n try {\n const [existing, rendered] = await Promise.all([\n fs.promises.readFile(destination),\n fs.promises.readFile(temporary),\n ])\n\n return existing.equals(rendered)\n } catch {\n return false\n }\n}\n\nfunction rendersWhatIsAlreadyThereSync(\n temporary: string,\n destination: string,\n): boolean {\n try {\n return fs.readFileSync(destination).equals(fs.readFileSync(temporary))\n } catch {\n return false\n }\n}\n\nfunction temporaryPathFor(destination: string): string {\n const extension = path.extname(destination)\n\n return path.join(\n path.dirname(destination),\n `.${path.basename(destination, extension)}.${process.pid}.${temporaryFileCounter++}.tmp`,\n )\n}\n\nconst writeFileAtomic: typeof fs.promises.writeFile = async (\n file,\n data,\n options,\n) => {\n // A file handle or descriptor is already-open state that a rename cannot\n // stand in for, so only a path is written atomically.\n if (typeof file !== 'string') {\n return fs.promises.writeFile(file, data, options)\n }\n\n const temporary = temporaryPathFor(file)\n\n try {\n await fs.promises.writeFile(temporary, data, options)\n\n // The check sits in front of the rename rather than in place of it: the\n // temporary file is still written, so a destination that does need\n // replacing is still replaced in one atomic step and a concurrent reader\n // still never sees a partial file.\n if (await rendersWhatIsAlreadyThere(temporary, file)) {\n discardTemporaryFile(temporary)\n return\n }\n\n await fs.promises.rename(temporary, file)\n } catch (err) {\n discardTemporaryFile(temporary)\n throw err\n }\n}\n\nconst writeFileSyncAtomic: typeof fs.writeFileSync = (file, data, options) => {\n if (typeof file !== 'string') {\n fs.writeFileSync(file, data, options)\n return\n }\n\n const temporary = temporaryPathFor(file)\n\n try {\n fs.writeFileSync(temporary, data, options)\n\n if (rendersWhatIsAlreadyThereSync(temporary, file)) {\n discardTemporaryFile(temporary)\n return\n }\n\n fs.renameSync(temporary, file)\n } catch (err) {\n discardTemporaryFile(temporary)\n throw err\n }\n}\n\n// `node:fs` with both write entry points swapped for their atomic\n// equivalents, handed to Style Dictionary as the volume it builds through.\n// Everything else — reads, `mkdir`, `access`, the `promises` namespace — is\n// inherited from `node:fs` unchanged, so only the moment a file becomes\n// visible to readers changes. Custom actions receive this volume too, so\n// whatever they emit is written the same way.\n//\n// It is assigned onto the instance rather than passed as the `volume`\n// constructor option on purpose: that option marks the volume as a custom\n// filesystem shim, which switches Style Dictionary's path resolution off for\n// every read as well.\n// `Object.create` is declared as returning `any`, so pinning the result to\n// `typeof fs` is a claim no type guard can replace. The prototype link is the\n// whole point — see the note above — so rebuilding this with a spread, which\n// copies own properties and drops the chain, is not a substitute.\n/* oxlint-disable typescript/no-unsafe-type-assertion */\nconst atomicVolume = Object.create(fs, {\n promises: {\n value: Object.create(fs.promises, {\n writeFile: { value: writeFileAtomic },\n }) as typeof fs.promises,\n },\n writeFileSync: { value: writeFileSyncAtomic },\n}) as typeof fs\n/* oxlint-enable typescript/no-unsafe-type-assertion */\n\n// A pattern is a glob when any of these appear in it. Deliberately the set\n// picomatch and tinyglobby act on, since those two are what match and expand\n// here — a path containing one of these characters literally is not\n// distinguishable from a pattern, and would not be matchable either.\nconst GLOB_CHARACTERS = /[!*?[\\]{}]/\n\n// The config extensions Style Dictionary loads with `import` rather than by\n// parsing the file — the `case` list in its own `loadFile`. They are the only\n// ones Node's permanent module cache applies to, and so the only ones this\n// plugin has to read on the build's behalf.\n//\n// Everything else Style Dictionary parses as JSON5, including `.json`, and\n// this list is what makes the plugin split the same way. Reading the two\n// halves apart is what silently unwatched a whole family of configurations:\n// a `.json5` or `.jsonc` file went down the import branch and failed there\n// while the build succeeded, and a `.json` file carrying a comment or a\n// trailing comma failed strict `JSON.parse` for the same reason.\nconst IMPORTED_CONFIG_EXTENSIONS = ['.js', '.mjs', '.ts']\n\n// A configuration as `resolveConfigs` hands it on: either the object the\n// consumer passed or the path it was read from, plus the directory relative\n// paths inside it resolve against.\ninterface ResolvedConfig {\n config: Config | string\n file?: string\n}\n\n// How to name a configuration in a message. A path is what a consumer\n// recognises; a configuration passed as an object or returned by a function has\n// no name, so it is identified by where it sits in the list rather than by a\n// stringified dump of itself.\nfunction describeConfig(item: ResolvedConfig, index: number): string {\n return item.file\n ? `The configuration ${item.file}`\n : `The configuration at position ${index + 1}`\n}\n\n// Whether a config path is one Style Dictionary imports rather than parses.\nfunction isImportedConfig(file: string): boolean {\n return IMPORTED_CONFIG_EXTENSIONS.some((extension) =>\n file.endsWith(extension),\n )\n}\n\n// The leading run of a pattern that contains no glob character —\n// `/p/tokens` for `/p/tokens/**/*.json`. Registering it alongside the files\n// that match today is what makes a token file created tomorrow visible:\n// watching only the current matches can never see a path that did not exist\n// when the watcher was built.\nfunction staticParentOf(pattern: string): string {\n const segments = pattern.split('/')\n const firstGlob = segments.findIndex((segment) =>\n GLOB_CHARACTERS.test(segment),\n )\n\n return firstGlob === -1\n ? path.posix.dirname(pattern)\n : segments.slice(0, firstGlob).join('/')\n}\n\n// The fingerprints of configurations this process has compiled at least once.\n// It is what lets a configuration given as an object or a function be skipped\n// at all: such a configuration has no file to stat, so an edit to it inside\n// `vite.config.ts` moves no mtime and the filesystem cannot tell the two\n// apart. Having built it here, the plugin can — the fingerprint changes with\n// the configuration.\n//\n// Module scope rather than the factory's, for the same reason `compilesInFlight`\n// below is: the instances that would otherwise repeat the work are different\n// instances, so per-instance state cannot see them. A `vitest run` stands up\n// several, and a function configuration — the form the README recommends for\n// registering custom formats — would be the one form that never skipped.\n//\n// The fingerprint carries the root, so two projects in one process never share\n// one. A configuration given as a path needs none of this: its own file is one\n// of the sources the mtime comparison reads, so an edit to it is visible across\n// processes as well as within one.\nconst compiledFingerprints = new Set<string>()\n\n// A compile that is running right now, keyed by `buildKey`, so bundler\n// instances in one process wait on each other rather than each starting their\n// own.\n//\n// Generated token files are a side effect on the filesystem, not per-bundler\n// output, and one process routinely holds several instances of this plugin. A\n// single `vitest run` on a project with two test projects and browser mode\n// stands up five Vite servers — the root one, one per project, and one more\n// per project once its HTTP server listens — and every one of them runs\n// `buildStart`. `hasCompiled` cannot see any of that: it is closure state\n// inside the factory, so each instance has its own and each compiles.\n//\n// Module scope is the only place a shared answer can live, since the\n// instances know nothing about each other. It stays a claim about identical\n// work, never about identity: the key carries the root and the resolved\n// configurations, so one script building two packages shares nothing.\nconst compilesInFlight = new Map<string, Promise<void>>()\n\n// A stable identity for a set of resolved configurations, or `null` for one\n// that cannot have a stable identity at all.\n//\n// Functions are serialised by source rather than dropped, because a `format`\n// or `transform` written inline is exactly what distinguishes two otherwise\n// identical configurations — and `JSON.stringify` omits a function outright,\n// which would make two different builds look like one.\nfunction buildKey(root: string, resolved: ResolvedConfig[]): null | string {\n try {\n return JSON.stringify(\n [root, resolved.map((item) => item.file ?? item.config)],\n (_key, value: unknown) =>\n typeof value === 'function' ? `[fn]${String(value)}` : value,\n )\n } catch {\n // A configuration that will not serialise — a circular reference, a\n // BigInt — takes no shared identity rather than a wrong one, and compiles\n // exactly as it did before.\n return null\n }\n}\n\n// The patterns one configuration reads, resolved the way the build resolves\n// them. The same `source`/`include` walk `getWatchTargets` does, for one\n// item rather than the whole set — against the working directory, because\n// that is where Style Dictionary's own `combineJSON` globs them.\nfunction sourcePatternsOf(configObj: Config): string[] {\n const patterns: string[] = []\n\n const add = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n patterns.push(\n (path.isAbsolute(pattern)\n ? pattern\n : path.resolve(process.cwd(), pattern)\n ).replace(/\\\\/g, '/'),\n )\n }\n }\n\n for (const value of [configObj.source, configObj.include]) {\n if (Array.isArray(value)) value.forEach(add)\n else add(value)\n }\n\n return patterns\n}\n\n// `fs.statSync` without the throw. A file that is missing, or that cannot be\n// read, is the same answer to every caller here: nothing to compare against.\nfunction statOrNull(file: string): fs.Stats | null {\n try {\n return fs.statSync(file)\n } catch {\n return null\n }\n}\n\n// Not exported. It cannot be called in the form a reader would guess —\n// unplugin types the factory as `(options, meta)`, and `meta` is the\n// bundler-identifying `UnpluginContextMeta` a consumer would have to build by\n// hand — so publishing it offered a name that answered nothing. What a\n// consumer imports is the default export of the entry for their bundler.\nconst unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}, meta) => {\n // webpack is the one target whose `buildStart` does not run before the\n // module graph is resolved: unplugin taps it on `make`, an\n // `AsyncParallelHook` that `EntryPlugin` taps too. The `webpack` key below\n // compiles on `beforeCompile` instead, which webpack awaits before the\n // compilation exists.\n const isWebpack = meta.framework === 'webpack'\n const {\n cache = true,\n errorOverlay = true,\n failOnError = 'build',\n logLevel,\n onBuildEnd,\n onBuildError,\n onBuildStart,\n platforms: platformsOption,\n report = true,\n root: rootOption,\n silent = false,\n } = options\n\n // `silent` predates `logLevel` and names its quietest level, so it is read\n // as one. `logLevel` wins when a consumer sets both.\n const level = logLevel ?? (silent ? 'silent' : undefined)\n\n // Whether the plugin keeps its own progress lines and size table to itself.\n // A failure is reported at every level, which is why this gate is not on the\n // error branch below.\n const quiet = level === 'silent' || level === 'warn'\n\n // What Style Dictionary is told, if anything. `undefined` is the point of\n // this: it leaves whatever the consumer's own `log.verbosity` asked for\n // standing, where the plugin used to overwrite it on every build. Style\n // Dictionary has three levels to this option's four, so `'warn'` and\n // `'info'` both map to its default — they differ in what the plugin itself\n // says, not in what Style Dictionary does.\n const verbosity =\n level === undefined\n ? undefined\n : level === 'verbose'\n ? 'verbose'\n : level === 'silent'\n ? 'silent'\n : 'default'\n\n // Which platforms this compile covers, or `undefined` for all of them.\n //\n // The array form applies to every build; the object form splits the first\n // compile from the watch rebuilds, and `context` is what tells them apart —\n // only the rebuild paths pass one. An absent key means every platform, so\n // `{ watch: ['css'] }` builds everything once and then only css.\n const platformsFor = (context: string | undefined): string[] | undefined => {\n if (platformsOption === undefined) return undefined\n if (Array.isArray(platformsOption)) return platformsOption\n\n return context === undefined ? platformsOption.build : platformsOption.watch\n }\n\n // Whether a failure in this compile should be thrown rather than only\n // reported. The two compiles are told apart by `runBuilds`'s `context`,\n // which only the rebuild paths pass.\n const failsTheBuild = (context: string | undefined): boolean =>\n failOnError === true ||\n (context === undefined ? failOnError === 'build' : failOnError === 'serve')\n // What the host is doing, for the function form of `config`. Populated where\n // each host knows the answer and read when that function is called — the\n // same shape as `root` and the message host above, and for the same reason:\n // `resolveConfigs` is reached from five places now, and threading a context\n // parameter through all five would make every caller restate what only the\n // host can say.\n let hostCommand: 'build' | 'serve' = 'build'\n let hostMode: string | undefined\n let isWatching = false\n\n // `mode` is derived rather than invented where a host has no notion of one.\n // rollup and rolldown report nothing, and following `command` is the answer\n // Vite itself would give: its default mode is `development` serving and\n // `production` building.\n const configContext = (): StyleDictionaryConfigContext => ({\n command: hostCommand,\n mode: hostMode ?? (hostCommand === 'serve' ? 'development' : 'production'),\n watch: isWatching,\n })\n\n // Whether the host will keep rebuilding, as the plugin context reports it.\n // Read from `meta.watchMode`, which rollup, rolldown and Vite all carry and\n // webpack does not — there it comes off the compiler instead.\n const adoptWatchMode = (context: object): void => {\n const hookMeta: unknown = 'meta' in context ? context.meta : undefined\n if (typeof hookMeta !== 'object' || hookMeta === null) return\n\n const watching: unknown =\n 'watchMode' in hookMeta ? hookMeta.watchMode : undefined\n if (typeof watching === 'boolean') isWatching = watching\n }\n\n // Where a relative `config` path is looked up. The host sets it below\n // unless the consumer named one, which is why an explicit option wins: a\n // layout the host cannot describe is exactly what it is for.\n let root = rootOption\n ? path.resolve(process.cwd(), rootOption)\n : process.cwd()\n\n // Every absolute destination the last completed build wrote, spelled with\n // forward slashes so it compares against a normalised watcher path. This is\n // the half of the rebuild-loop guard that pattern matching cannot supply:\n // output written under a watched directory matches the source glob that\n // produced it, so without subtracting this set a supported layout rebuilds\n // on its own writes for as long as the dev server runs.\n const generatedDestinations = new Set<string>()\n\n // The patterns the last `getWatchTargets` derived. `watchChange` tests a\n // changed path against these before it resolves anything, so a file the\n // plugin does not care about costs one glob match instead of a full config\n // resolution — which, when `config` is a function, is the consumer's own\n // code, and the place the README tells them to register custom formats.\n //\n // It is safe to filter on a list that may be one build out of date because\n // the list always contains the config files themselves: an edit that adds a\n // source matches as a config change, which re-resolves and re-derives. The\n // one thing it cannot see is a `config` function that starts returning\n // different sources with no file changing at all, and that was never\n // observable without a rebuild to observe it in.\n let cachedPatterns: string[] | undefined\n\n // Whether `watchChange` has fired since the last `buildStart`, and whether\n // anything has been compiled yet. Rollup, rolldown and webpack all run\n // `watchChange` for every changed file and only then re-enter `buildStart`\n // — unplugin's webpack adapter awaits both in one `make` tap — so a flag\n // raised in the first is still standing in the second, and is what tells it\n // this is a watch rebuild rather than the first build of the process.\n let watchRebuild = false\n let hasCompiled = false\n\n // Whether the host has shut its watcher down. `await watcher.close()` is not\n // a promise that no build is in flight: rollup's `Watcher.close` clears the\n // pending build timeout, closes each task's file watcher and emits `close`,\n // and never awaits `run` — while `Task.run` checks `closed` only *after*\n // `rollupInternal` has resolved. So a build that has already entered\n // `rollupInternal` runs its `buildStart` hooks through to completion after\n // `close()` has returned to its caller, against a project that may be half\n // torn down by then. Measured on rollup 4.63.3 with no plugin of ours: a\n // `buildStart` reading a file 300ms after `close()` resolved gets ENOENT.\n //\n // `closeWatcher` is what makes that answerable. It runs synchronously inside\n // `close()`, and so before the in-flight hook resumes, which is the whole\n // reason a flag set there is worth setting. What it must not be is\n // `closeBundle`: that fires once per bundle — every `BUNDLE_END` a consumer\n // calls `result.close()` on — and would read as a shutdown on every rebuild.\n let hostClosed = false\n\n // What a watcher is handed, and what a changed path is tested against, are\n // not the same list, and conflating them is why a glob source was watched by\n // nothing at all. Every watcher in play takes filenames rather than\n // patterns: Vite's chokidar and rollup's `FileWatcher` are both constructed\n // with `disableGlobbing: true`, Vite's `addWatchFile` drops anything that\n // fails `fs.existsSync`, and webpack never globs `fileDependencies`. So the\n // patterns stay for matching and the paths are expanded for registering.\n const expandPatterns = async (patterns: string[]): Promise<string[]> => {\n const paths = new Set<string>()\n const globs: string[] = []\n\n for (const pattern of patterns) {\n if (GLOB_CHARACTERS.test(pattern)) {\n globs.push(pattern)\n\n // Watching the directory as well as its current contents. chokidar\n // reports a creation inside a watched directory, which is the only\n // way a token file added later is ever noticed.\n const parent = staticParentOf(pattern)\n if (parent && fs.existsSync(parent)) paths.add(parent)\n } else {\n paths.add(pattern)\n }\n }\n\n if (globs.length > 0) {\n try {\n // tinyglobby matches with picomatch, which is what\n // `matchesWatchedFile` tests with, so what is registered here and what\n // is accepted there cannot disagree.\n for (const match of await glob(globs, { absolute: true })) {\n paths.add(match.replace(/\\\\/g, '/'))\n }\n } catch (err) {\n log(`Failed to expand watch patterns: ${errorMessage(err)}`, 'error')\n }\n }\n\n return Array.from(paths)\n }\n\n // Whether a changed file is a token or config source rather than something\n // this plugin just wrote. Both watch entry points ask through here, so\n // neither can react to its own output.\n const isWatchedSource = (file: string, patterns: string[]): boolean =>\n !generatedDestinations.has(file.replace(/\\\\/g, '/')) &&\n matchesWatchedFile(file, patterns)\n\n // Decided once, when the plugin is constructed, and held for its life. The\n // two streams are asked separately because they are redirected separately —\n // `build 2>err.log` leaves stdout a terminal and stderr a file.\n const stdoutColour = colourAllowed(process.stdout)\n const stderrColour = colourAllowed(process.stderr)\n\n // Where a message goes once a host has offered somewhere better than the\n // console. Set by `configResolved` under Vite, by the build hooks under\n // rollup and rolldown, and by the `webpack` block; left undefined when no\n // host has claimed it, which is every unit test binding its own context.\n let host: HostMessenger | undefined\n\n // Adopts a plugin context as the message host, if it has the channels — the\n // unit tests bind a context carrying `addWatchFile` and nothing else, and a\n // hook calling `this.warn` against that throws in a way that reads as a\n // plugin bug rather than as a missing stub.\n //\n // Only when nothing has claimed the host yet. Under Vite `configResolved`\n // has already installed the dev server's own logger, and `buildStart` runs\n // after it with a rollup-shaped context that would otherwise replace it.\n const adoptHost = (context: object): void => {\n if (host) return\n\n const warn: unknown = 'warn' in context ? context.warn : undefined\n if (!isMessageChannel(warn)) return\n\n const info: unknown = 'info' in context ? context.info : undefined\n\n host = {\n // `warn`, never `error`. Rollup's `this.error` aborts the bundle, so\n // reporting through it would stop every build that reported anything and\n // take the decision `failOnError` exists to make.\n error: (message) => {\n warn.call(context, message)\n },\n info: isMessageChannel(info)\n ? (message) => {\n info.call(context, message)\n }\n : undefined,\n }\n }\n\n // Helper to log at the configured level\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n const prefix = '[unplugin-style-dictionary]'\n\n // Ahead of the `silent` gate on purpose. `silent` is about the progress\n // lines and the size table; a compile that failed is not noise, and\n // hiding it left a broken token set shipping with nothing said at all.\n if (type === 'error') {\n // The host renders and colours its own output, so nothing painted here\n // is handed to one — an escape inside a webpack `stats` entry survives\n // into `stats.toJson()` and into whatever reads it.\n if (host) {\n host.error(`${prefix} ${message}`)\n return\n }\n\n console.error(paint('31', `${prefix} ${message}`, stderrColour))\n return\n }\n\n if (quiet) return\n\n if (host?.info) {\n host.info(`${prefix} ${message}`)\n return\n }\n\n console.log(\n paint(\n type === 'success' ? '32' : '36',\n `${prefix} ${message}`,\n stdoutColour,\n ),\n )\n }\n\n // Runs one of the consumer's `onBuild*` hooks without letting it decide the\n // fate of the build that called it.\n //\n // Two ways a hook can go wrong, and neither may propagate. A throw is caught\n // here, because a post-processing step that fails must not undo a compile the\n // plugin itself completed — the files are written and correct. A rejected\n // promise is the quieter one: the return value is deliberately not awaited,\n // so a rejection has nothing holding it and reaches the host as an unhandled\n // rejection, which under Node's default takes the process down — a dev server\n // killed from inside a hook that was only meant to reformat a file.\n //\n // Both are reported at `'error'`, so they are said at every level including\n // `silent`, and worded so neither can be read as the compile having failed.\n const callHook = <A extends unknown[]>(\n name: string,\n hook: (...args: A) => Promise<void> | void,\n ...args: A\n ): void => {\n let result: unknown\n\n try {\n // Captured rather than dropped, because the promise an `async` hook\n // returns is the thing the check below needs. Wrapping this call in a\n // block-bodied arrow — which is what the linter asks for when the return\n // type is plain `void` — discarded it, and the rejection escaped exactly\n // as it had before any of this existed.\n result = hook(...args)\n } catch (err) {\n log(`The ${name} hook threw: ${errorMessage(err)}`, 'error')\n return\n }\n\n if (!isThenable(result)) return\n\n void Promise.resolve(result).catch((err: unknown) => {\n log(`The ${name} hook rejected: ${errorMessage(err)}`, 'error')\n })\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<ResolvedConfig[]> => {\n let rawConfig = options.config\n\n // Checked ahead of the discovery below, and by identity rather than\n // truthiness: `false` is falsy, so the `!rawConfig` test that triggers\n // discovery would treat \"do not discover anything\" as \"go and look\".\n if (rawConfig === false) return []\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n\n const rejected: string[] = []\n\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (!fs.existsSync(fullPath)) continue\n\n // Read before adopting. For the two `.json` names this is a parse and\n // nothing more; for the two module names it is an import, and the\n // module has already run by the time there is anything to check —\n // which is what `config: false` exists for and why validation alone\n // does not cover them.\n const candidate = await readConfigObject(\n { config: fullPath, file: fullPath },\n false,\n )\n\n if (!looksLikeConfig(candidate)) {\n rejected.push(file)\n continue\n }\n\n // Announced, because \"which configuration did it pick\" was not\n // answerable from the console at all, and discovery picks from four\n // generic names.\n if (!announcedDiscovery) {\n announcedDiscovery = true\n log(`Using the configuration it found at ${fullPath}`, 'info')\n }\n\n rawConfig = file\n break\n }\n\n // Said whether or not something usable turned up after them. A skipped\n // candidate is the interesting half of \"no configuration found\": the\n // file is right there, and the reason it was not used is not guessable.\n if (rejected.length > 0) {\n log(\n `Ignored ${rejected.join(', ')} in ${root}: nothing there declares platforms, source, include or tokens, so it does not look like a Style Dictionary configuration. Name it with the config option if it is one, or set config to false to stop looking.`,\n 'error',\n )\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig(configContext())\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return { config: fullPath, file: fullPath }\n } else {\n return { config: conf }\n }\n })\n }\n\n // Imports a config module, re-evaluating it only when the file itself has\n // changed. The query string is what decides that, and it is not decoration:\n // Node's ESM cache is permanent and keyed on the specifier, so a config\n // imported without one is evaluated once and never read again — which is\n // how an edited `.mjs` config went on building the platform map the process\n // started with, for the rest of the session.\n //\n // `Date.now()` fixed that staleness and bought two problems. Every watcher\n // event registered another module record in a map nothing prunes, re-running\n // the config's own `registerFormat` side effects for a file nobody touched.\n // And its millisecond granularity meant an edit landing inside the same\n // millisecond as the previous import shared that import's key, and was\n // served the old module anyway. `mtimeMs` carries sub-millisecond\n // resolution and only moves when the file does.\n const importConfigModule = async (file: string): Promise<unknown> => {\n let version: number\n try {\n version = fs.statSync(file).mtimeMs\n } catch {\n // A config that cannot be stat'd is about to fail its import too. The\n // old key is what keeps that failure the import's to report.\n version = Date.now()\n }\n\n // The dot goes, and that is not cosmetic. `mtimeMs` is fractional, so the\n // query it produces ends in something that reads as a file extension to\n // anything deriving a loader from the specifier without stripping the\n // query first — `sd.config.ts?t=1789565080284.6606` is then a `.6606`\n // file, and a TypeScript config gets parsed as JavaScript. Replacing the\n // one dot keeps every distinct mtime a distinct key.\n const key = String(version).replace('.', '_')\n\n // Sequential on purpose: a config module runs arbitrary code at import\n // time — `registerFormat` and friends — and Style Dictionary's registries\n // are global, so importing several at once would interleave those\n // registrations.\n return unwrapDefault(await import(`${pathToFileURL(file).href}?t=${key}`))\n }\n\n // What a configuration item says, as an object. `report` is what stops the\n // two readers of this from saying the same thing twice: a bad config has\n // nowhere else to surface when the watch list is being built, while a build\n // falls back to handing Style Dictionary the path and lets its message\n // through instead.\n const readConfigObject = async (\n item: ResolvedConfig,\n reportErrors: boolean,\n ): Promise<Config | null> => {\n if (typeof item.config !== 'string') return item.config\n\n try {\n // JSON5 rather than `JSON.parse`, because that is what Style Dictionary\n // reads these files with — it is a superset, so a plain `.json` config\n // parses identically and one carrying a comment stops being a config\n // the build understands and the watch list does not.\n const loaded: unknown = isImportedConfig(item.config)\n ? await importConfigModule(item.config)\n : JSON5.parse(fs.readFileSync(item.config, 'utf-8'))\n\n if (isConfig(loaded)) return loaded\n\n if (reportErrors) {\n log(\n `Config file did not resolve to a configuration object: ${item.config}`,\n 'error',\n )\n }\n } catch (err) {\n if (reportErrors) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${errorMessage(err)}`,\n 'error',\n )\n }\n }\n\n return null\n }\n\n // Parse token files to watch\n const getWatchTargets = async (\n resolvedConfigs: ResolvedConfig[],\n ): Promise<{ paths: string[]; patterns: string[] }> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n const configObj = await readConfigObject(item, true)\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n // Against the working directory, because that is where Style\n // Dictionary resolves it: `combineJSON` globs each pattern with\n // no `cwd` of its own. Resolving against the configuration file's\n // directory instead is how the watch list came to name paths the\n // build never reads — a configuration in a subdirectory built\n // correctly and watched nothing at all.\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(process.cwd(), pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n const patterns = Array.from(filesToWatch)\n\n // Recorded here rather than at each call site, so every path that derives\n // a watch list refreshes the one `watchChange` filters against.\n cachedPatterns = patterns\n\n return { paths: await expandPatterns(patterns), patterns }\n }\n\n // What `new StyleDictionary` is handed for an item. Only a path in the JS\n // family becomes an object, because those are exactly the extensions Style\n // Dictionary's own `loadFile` reaches with `import` — the ones whose module\n // record Node then caches forever, and so the only ones a build could read\n // stale. The JSON5 family stays a path because there is nothing to gain:\n // those are read from disk on every pass either way, so a build can never\n // see one as it stood earlier in the process.\n const configForBuild = async (\n item: ResolvedConfig,\n ): Promise<Config | string> => {\n const { config } = item\n\n if (typeof config !== 'string' || !isImportedConfig(config)) return config\n\n const loaded = await readConfigObject(item, false)\n\n // A config that could not be read falls back to the path, so the failure\n // stays Style Dictionary's to report — it knows more about why an import\n // failed than this does, a `.ts` config without type stripping especially.\n if (!loaded) return item.config\n\n // `loadFile` clones what it imports before handing it on, and passing an\n // object skips that. It matters more here than it does there: the module\n // record now outlives the build, and `extend` is called with\n // `mutateOriginal`. Cloning throws on a config carrying functions — an\n // inline transform — and Style Dictionary's own fallback in that case is\n // to use the original, so this one matches it.\n try {\n return structuredClone(loaded)\n } catch {\n return loaded\n }\n }\n\n // Every absolute destination a configuration declares, read off the\n // configuration itself rather than off an extended Style Dictionary\n // instance. Reading it here is the whole point: constructing the instance\n // is what the skip exists to avoid.\n //\n // Resolved exactly as the build resolves it below, so the two name the same\n // files — a relative `buildPath` against `root`, and a `destination`\n // against that.\n // `only` narrows this to named platforms, and exactly one caller wants that:\n // the up-to-date check, which asks whether the work *this* compile would do\n // is already done. Everywhere else the answer has to cover every declared\n // platform, because a file an unselected platform wrote earlier is still the\n // plugin's own output and has to stay out of the watch list.\n const declaredDestinations = (\n configObj: Config,\n only?: string[],\n ): string[] => {\n const destinations: string[] = []\n\n const entries = Object.entries(configObj.platforms ?? {})\n const selected = only\n ? entries.filter(([name]) => only.includes(name))\n : entries\n\n for (const [, platform] of selected) {\n const buildPath = platform.buildPath ?? ''\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n\n for (const file of platform.files ?? []) {\n if (file.destination) {\n destinations.push(\n path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination),\n )\n }\n }\n }\n\n return destinations\n }\n\n // A stable identity for one resolved configuration, or `null` where it\n // cannot have one. Functions are serialised by source rather than dropped,\n // because an inline `format` or `transform` is exactly the edit a\n // fingerprint has to notice, and `JSON.stringify` omits a function outright.\n const configFingerprint = (item: ResolvedConfig): null | string => {\n try {\n return JSON.stringify(\n [root, item.file ?? item.config],\n (_key, value: unknown) =>\n typeof value === 'function' ? `[fn]${String(value)}` : value,\n )\n } catch {\n // Circular, or holding a BigInt. It takes no identity rather than a\n // wrong one, so it compiles every time exactly as it did before.\n return null\n }\n }\n\n // Whether every file a configuration declares is already newer than every\n // file it reads, so its compile can be skipped.\n //\n // Conservative in every direction it can be: anything it cannot establish —\n // a destination that is missing, a source it cannot stat, a configuration\n // declaring no destinations at all — is a reason to build rather than to\n // skip.\n const isUpToDate = async (\n item: ResolvedConfig,\n configObj: Config,\n only?: string[],\n ): Promise<boolean> => {\n // An action writes what no `destination` names, so there is nothing for\n // the comparison below to check and skipping would leave its work undone.\n const hasActions = Object.values(configObj.platforms ?? {}).some(\n (platform) => (platform.actions?.length ?? 0) > 0,\n )\n if (hasActions) return false\n\n const destinations = declaredDestinations(configObj, only)\n if (destinations.length === 0) return false\n\n // `options.watch` belongs in here as much as `source` does. A consumer\n // names an extra file because something in the build reads it — a custom\n // format's own data file, most obviously — and leaving it out let a change\n // to it be skipped over while the watcher dutifully reported it.\n const extraWatches = options.watch\n ? Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n : []\n\n const sources = await expandPatterns([\n ...sourcePatternsOf(configObj),\n ...extraWatches.map((pattern) =>\n (path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n ).replace(/\\\\/g, '/'),\n ),\n ])\n if (item.file) sources.push(item.file.replace(/\\\\/g, '/'))\n\n if (sources.length === 0) return false\n\n let newestSource = -Infinity\n let sawFile = false\n\n for (const source of sources) {\n const stats = statOrNull(source)\n if (!stats) return false\n\n // Directories are in this list on purpose — `expandPatterns` registers\n // each pattern's static parent so a token file created later is\n // noticed — but their mtime cannot be read as an input signal here. A\n // directory's mtime moves whenever an entry is added or renamed inside\n // it, and the atomic write renames every generated file into place, so\n // a `buildPath` inside a watched directory made the build itself the\n // newest thing the comparison could see. Nothing was ever up to date.\n if (stats.isDirectory()) continue\n\n sawFile = true\n newestSource = Math.max(newestSource, stats.mtimeMs)\n }\n\n // Every pattern expanded to directories alone, so nothing was actually\n // read. Style Dictionary would build an empty dictionary from that, and a\n // skip would present the empty result as current.\n if (!sawFile) return false\n\n let oldestDestination = Infinity\n for (const destination of destinations) {\n const stats = statOrNull(destination)\n if (!stats) return false\n oldestDestination = Math.min(oldestDestination, stats.mtimeMs)\n }\n\n if (oldestDestination <= newestSource) return false\n\n // A configuration given as a path has its own file among the sources\n // above, so an edit to it has already been accounted for and the skip\n // holds across processes.\n if (item.file) return true\n\n // One given as an object or a function has not. Only this process knows\n // what it looked like when those destinations were written, so the skip\n // holds only against a fingerprint recorded here.\n const fingerprint = configFingerprint(item)\n\n return fingerprint !== null && compiledFingerprints.has(fingerprint)\n }\n\n // The size-and-gzip table, in a function of its own so that the compile\n // `try` in `runBuilds` can stop before it. Everything here is presentation\n // over files Style Dictionary has already finished writing, so a throw from\n // it is a reporting bug and nothing more.\n const reportSizes = (generatedFiles: Set<string>) => {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path.relative(root, filePath).replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n // The table goes to stdout, so it follows stdout's decision — which\n // is not always stderr's, since the two are redirected separately.\n const coloredPath =\n dir === '.'\n ? paint('32', base, stdoutColour)\n : paint('90', `${dir}/`, stdoutColour) +\n paint('32', base, stdoutColour)\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // One unreadable destination costs its row rather than the table.\n // Deliberately narrower than the caller's `catch`: it covers the\n // three filesystem and gzip calls above and not the arithmetic\n // below, so a padding bug is reported rather than quietly printing\n // short.\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(2, longestPathLength - info.relativeDisplayPath.length + 2),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n info.coloredPath +\n pathPadding +\n paint(\n '90',\n `${sizePadded} │ gzip: ${info.gzipSizeStr}`,\n stdoutColour,\n ),\n )\n }\n }\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: ResolvedConfig[],\n context?: string,\n ) => {\n const startTime = Date.now()\n\n // Ahead of the `try` rather than inside it, because the reporting below\n // reads it and that reporting is deliberately outside.\n const generatedFiles = new Set<string>()\n\n // How many configurations were already up to date. Read by the reporting\n // below, which is why it sits out here with `generatedFiles`.\n let skipped = 0\n\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n // Before anything is resolved or built, and once per build — a watch\n // rebuild is a build, so this fires again for each one.\n if (onBuildStart) callHook('onBuildStart', onBuildStart)\n\n // Configurations are built one after another rather than with\n // `Promise.all`, and that is load-bearing. Two configurations may name\n // the same destination file, and each instance gets the atomic volume\n // swapped onto it below — overlapping builds would interleave those\n // writes and hand a reader a file assembled from both.\n for (const [index, item] of resolvedConfigs.entries()) {\n // Read ahead of the instance, because avoiding the instance is the\n // point: construction plus `extend` is the 15-30% of a build that\n // parses the token sources, and `buildAllPlatforms` is the rest.\n //\n // `false` so a configuration that will not parse says nothing here —\n // the build below hands Style Dictionary the path and lets its own\n // message through, which is more specific than anything this could\n // say.\n const declared = cache ? await readConfigObject(item, false) : null\n const selectedPlatforms = platformsFor(context)\n\n if (declared && (await isUpToDate(item, declared, selectedPlatforms))) {\n // The destinations still have to be collected. They are what stops\n // the plugin's own output being treated as a watched source, so a\n // skipped configuration that contributed none would have its files\n // rebuild the moment a watcher noticed them.\n for (const destination of declaredDestinations(declared)) {\n generatedFiles.add(destination)\n }\n\n skipped++\n continue\n }\n\n // `{ init: false }` is the escape hatch Style Dictionary documents on\n // this constructor, and it is what makes a bad configuration\n // catchable. Left to itself the constructor ends in a call to\n // `init()` whose promise it neither stores nor returns, so a config\n // that fails to load rejects a promise nobody holds: the `catch`\n // below never runs, and the host dies with a raw stack or — where an\n // `unhandledRejection` handler suppresses it — hangs on a\n // `buildStart` that never settles. `await sd.hasInitialized` cannot\n // observe it either, since that promise is only ever resolved, at the\n // tail of a successful extend.\n //\n // It is handed the configuration as an object rather than as a path\n // for the same reason: Style Dictionary imports a path with no\n // cache-busting query of its own, so under a long-lived dev server\n // every rebuild after the first built the config the process started\n // with while the watch list followed the edit.\n const sd = new StyleDictionary(await configForBuild(item), {\n init: false,\n })\n\n // One initialisation rather than two. `init()` is `extend()` with\n // `mutateOriginal`, so the old pair loaded the configuration and\n // combined every source twice — running a custom parser or\n // preprocessor twice with it — and the first of the two ran at\n // default verbosity, which is how Style Dictionary's own warnings\n // escaped this plugin's `silent`. `config` defaults to the one the\n // constructor was handed.\n //\n // `verbosity` is `undefined` unless a consumer asked for a level, and\n // Style Dictionary falls through an unset one to the configuration's\n // own `log.verbosity`. Overwriting it here is what silenced the one\n // line explaining why a build wrote nothing. `log.warnings` is not\n // touched either way: a consumer's `warnings: 'error'` turning a\n // missing output file into a thrown build is their decision.\n await sd.extend(undefined, { mutateOriginal: true, verbosity })\n\n // **Before the build, and that is the whole of it.** A token set that\n // resolved to nothing is not an error anywhere in this stack: Style\n // Dictionary writes the file with no custom properties in it, prints\n // its usual `✔︎` line at any verbosity, and returns. So a token file\n // deleted mid-session took the generated output down with it and\n // reported `Rebuilt design tokens` while doing it, and a `source`\n // matching nothing shipped an empty stylesheet from a build that\n // exited 0.\n //\n // Checked here because `buildAllPlatforms` truncates and rewrites the\n // destination: one line later the previous good output is already gone\n // and an error would be accurate and useless.\n if (sd.allTokens.length === 0) {\n // The configuration as an object, so its own patterns can be named.\n // `false` because a configuration that will not parse never reaches\n // here — the `extend` above would have thrown first.\n const asObject = await readConfigObject(item, false)\n const barren = asObject\n ? await patternsMatchingNothing(sourcePatternsOf(asObject))\n : []\n\n // Thrown rather than reported, so it takes the path `failOnError`\n // already owns — the same decision, made in one place, rather than a\n // second way for a build to fail.\n throw new Error(\n [\n `${describeConfig(item, index)} resolved no tokens, so its output would be emptied.`,\n barren.length > 0\n ? `These patterns matched no files: ${barren.join(', ')}`\n : `It declares no source or include patterns that matched anything.`,\n `Nothing was written. Set failOnError to false to build anyway.`,\n ].join(' '),\n )\n }\n\n // Swap in the atomic volume only now that the instance has finished\n // reading its configs and token sources, so every write below lands\n // through `rename` while the read path stays exactly as it was.\n sd.volume = atomicVolume\n\n if (selectedPlatforms === undefined) {\n await sd.buildAllPlatforms()\n } else {\n // Named, so a typo is an error rather than a platform silently not\n // built — which is what Style Dictionary's own CLI means by \"Must be\n // defined in the config\".\n const defined = Object.keys(sd.platforms)\n const unknown = selectedPlatforms.filter(\n (name) => !defined.includes(name),\n )\n if (unknown.length > 0) {\n throw new Error(\n `${describeConfig(item, index)} does not define the platform(s) ${unknown.join(', ')}. It defines ${defined.join(', ')}.`,\n )\n }\n\n // One after another, matching the loop this sits inside: two\n // platforms may name the same destination, and `buildAllPlatforms`\n // fanning its own out with `Promise.all` is Style Dictionary's\n // choice over configurations it owns, not this plugin's over a\n // selection a consumer wrote.\n for (const name of selectedPlatforms) {\n await sd.buildPlatform(name)\n }\n }\n\n // Every declared platform, not only the ones this compile built. A\n // file an unselected platform wrote on an earlier build is still the\n // plugin's own output, and dropping it from this set would let a\n // watcher treat it as a token source and rebuild on it forever.\n //\n // Collected on every build rather than only on the ones whose size\n // report prints it below. The set is also what keeps a rebuild from\n // being triggered by the write it just made, and a rebuild passes a\n // `context` — so gating the collection on `!context` left it empty on\n // exactly the builds a watcher is live for.\n for (const platform of Object.values(sd.platforms)) {\n const buildPath = platform.buildPath ?? ''\n for (const file of platform.files ?? []) {\n if (file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n\n // Recorded only now, so a configuration whose build threw is never\n // treated as one this process has compiled.\n const fingerprint = configFingerprint(item)\n if (fingerprint !== null) compiledFingerprints.add(fingerprint)\n }\n\n // Replaced wholesale rather than added to, so a destination dropped from\n // a configuration stops being treated as ours and becomes watchable\n // again. A build that throws never reaches this and leaves the previous\n // set standing, which is the safe direction: the files it wrote before\n // failing are still ours.\n generatedDestinations.clear()\n for (const destination of generatedFiles) {\n generatedDestinations.add(destination.replace(/\\\\/g, '/'))\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${errorMessage(err)}`,\n 'error',\n )\n\n // Ahead of the throw decision on purpose, so the overlay sees a failure\n // whatever `failOnError` does with it. Under the dev server's default\n // the line below does not throw, and reading the outcome from a caller's\n // `catch` would see a rebuild that looked like it succeeded.\n notifyBuildOutcome?.(asError(err))\n\n // Ahead of the throw decision for the same reason as the line above: a\n // rebuild under the dev server's default does not throw, and a hook that\n // only fired when something else was about to fail would be silent on\n // exactly the builds a consumer is watching.\n if (onBuildError) callHook('onBuildError', onBuildError, err)\n\n // Reported, and then rethrown so the host stops. Swallowing it left\n // every target exiting 0 with the previous run's tokens still on disk\n // and in the bundle — a green build shipping stale values.\n if (failsTheBuild(context)) throw err\n\n // Explicit, now that the reporting below sits outside the `try`. This\n // `catch` used to end the function by falling off the end of it; a\n // failure that is not rethrown would otherwise carry on to announce a\n // compile that did not happen.\n return\n }\n\n // The compile is what the overlay reflects, so this is said here rather\n // than at the end: everything below is reporting, it returns early in\n // three places, and a size table that throws must not leave a successful\n // build looking unfinished.\n notifyBuildOutcome?.(null)\n\n // One measurement, read by the hook below and by the reporting under it.\n const duration = Date.now() - startTime\n\n // Beside the overlay notification, and for the same reason it sits here\n // rather than at the end of the function: the reporting below returns\n // early in three places, and a build that finished has finished whether or\n // not a size table gets printed for it.\n //\n // Sorted, so two runs of one configuration hand back the same order —\n // `generatedFiles` is a set in platform-then-file order, which is stable\n // in practice and guaranteed by nothing. The paths stay platform-native:\n // this is a list a consumer is going to open files with, not one the\n // watcher compares against.\n if (onBuildEnd) {\n // `toSorted` is what the linter asks for and what this cannot use:\n // `lib` is ES2022 here and `toSorted` is ES2023, so it types as an error\n // even though every Node this package supports has it. The rule guards\n // against mutating an array someone else holds, and this one was built\n // from the set on the line it appears on.\n // oxlint-disable-next-line unicorn/no-array-sort\n const files = Array.from(generatedFiles).sort((left, right) =>\n left.localeCompare(right),\n )\n callHook('onBuildEnd', onBuildEnd, files, duration)\n }\n\n // The `try` ends above, and everything from here down is reporting. Style\n // Dictionary has finished writing by now and `generatedDestinations` is\n // already replaced, so nothing below can put a file on disk in doubt —\n // which is why a throw from it must not be caught as a compile failure.\n // It used to be: a fault in the padding arithmetic printed `Compilation\n // failed after 19ms` over a build whose every token file was correct, and\n // with `failOnError` defaulting to `'build'` that stopped the bundler.\n\n // Every configuration was already current, so nothing was written. Said\n // rather than left implied: a build that prints its opening line and then\n // finishes in two milliseconds reads as one that silently did nothing.\n const everythingSkipped = skipped === resolvedConfigs.length\n\n if (context) {\n log(\n everythingSkipped\n ? `Design tokens already up to date after change in ${context} (${duration}ms)`\n : `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n return\n }\n\n // The table is skipped when nothing was written, on top of `report` and\n // `quiet`. It reads every generated file in full and gzips it, and\n // reprinting the sizes of files this build did not touch is the one case\n // where that cost buys nothing at all.\n if (report && !quiet && !everythingSkipped && generatedFiles.size > 0) {\n try {\n reportSizes(generatedFiles)\n } catch (err) {\n // At `'error'`, so it is said at every level including `silent`,\n // exactly as a compile failure is — and worded so it cannot be read\n // as one. Not rethrown: the build succeeded.\n log(\n `Failed to report generated file sizes: ${errorMessage(err)}`,\n 'error',\n )\n }\n }\n\n if (everythingSkipped) {\n log(`Design tokens are already up to date (${duration}ms)`, 'success')\n return\n }\n\n log(\n skipped > 0\n ? `Compiled successfully! (${duration}ms, ${skipped} already up to date)`\n : `Compiled successfully! (${duration}ms)`,\n 'success',\n )\n }\n\n // `runBuilds` for the first build of a process, with the compile shared\n // between every plugin instance that wants the same one.\n //\n // An instance arriving while a compile for the same key is running waits on\n // that compile instead of starting a second. It is the concurrent half that\n // needs this: an up-to-date check compares what is on disk against the\n // sources, and two instances that start together have nothing on disk to\n // compare against yet, so only a shared promise can tell them apart from\n // two genuinely separate builds.\n //\n // The entry is dropped as soon as the compile settles, so this coalesces\n // rather than caches — a later `buildStart` still compiles. Skipping one\n // whose output is already current is #212's up-to-date check, and belongs\n // with it rather than as a second mechanism here.\n //\n // A rejection reaches every waiter, which is the point: an instance that\n // waited on a failed compile must not carry on as though the tokens were\n // written. Whether that rejection is thrown at all is `failOnError`'s\n // decision, already made inside `runBuilds`.\n const compileOnceAcrossInstances = async (\n resolvedConfigs: ResolvedConfig[],\n ): Promise<void> => {\n const key = buildKey(root, resolvedConfigs)\n if (key === null) {\n await runBuilds(resolvedConfigs)\n return\n }\n\n const running = compilesInFlight.get(key)\n if (running) {\n await running\n return\n }\n\n const compile = runBuilds(resolvedConfigs)\n compilesInFlight.set(key, compile)\n\n try {\n await compile\n } finally {\n compilesInFlight.delete(key)\n }\n }\n\n // One rebuild per burst of watcher events, and never two at once.\n //\n // Two things went wrong without this. A single token edit under Vite's dev\n // server reached both the `configureServer` listener and `watchChange` —\n // Vite 6, 7 and 8 all invoke plugin `watchChange` while serving — and each\n // started its own build, so one write produced two. And nothing serialised\n // them: a four-file change started one build per file, all overlapping.\n // `runBuilds` builds its configurations one after another precisely so two\n // instances never write the same destination at once, and concurrent calls\n // to it reintroduced that one level up.\n //\n // The trailing debounce collapses the burst; the in-flight chain means a\n // trigger arriving mid-build queues exactly one follow-up rather than\n // starting a second build beside it.\n const REBUILD_DEBOUNCE_MS = 50\n\n let debounceTimer: ReturnType<typeof setTimeout> | undefined\n let pendingReason: string | undefined\n let inFlight: Promise<void> | undefined\n let waiting: Array<(failure?: { error: unknown }) => void> = []\n\n // Set by `configureServer`. A dev server's watcher is long-lived, so its\n // list has to follow a configuration that changes; every other target\n // re-registers on each build through `addWatchFile` instead.\n let refreshServerWatchList:\n | ((resolved: ResolvedConfig[]) => Promise<void>)\n | undefined\n\n // Whether the discovered path has been announced. Once per plugin instance:\n // `resolveConfigs` runs on every build and rebuild, and a dev server would\n // otherwise repeat the line for the rest of the session.\n let announcedDiscovery = false\n\n // Resolved by `configResolved` so it can amend the watcher's ignore list, and\n // handed to `configureServer` rather than resolved again — one start-up, one\n // call of the consumer's `config` function.\n let startupResolved: ResolvedConfig[] | undefined\n\n // Also set by `configureServer`, and left undefined everywhere else: this is\n // how a compile outcome reaches Vite's error overlay. It is deliberately not\n // the same path as `failOnError`.\n //\n // `failOnError` decides whether the host stops; this decides whether the\n // browser is told. Under a dev server the default is not to stop, so the\n // failure is reported and swallowed — and that is exactly the case where the\n // page is left rendering the last good file with nothing to say it is stale.\n // Reading the outcome off whether `runBuilds` threw would therefore see\n // nothing at all on the only configuration that matters.\n let notifyBuildOutcome: ((error: Error | null) => void) | undefined\n\n const drain = async (): Promise<void> => {\n // A loop rather than a single pass: anything scheduled while the build\n // below is running is picked up here instead of starting a second one.\n while (pendingReason !== undefined) {\n const reason = pendingReason\n pendingReason = undefined\n\n // Captured before the await, so a trigger arriving mid-build waits for\n // the next pass rather than being told this one covered it.\n const resolvers = waiting\n waiting = []\n\n let failure: undefined | { error: unknown }\n let compiling = false\n\n try {\n const resolved = await resolveConfigs()\n if (resolved.length > 0) {\n compiling = true\n await runBuilds(resolved, reason)\n compiling = false\n hasCompiled = true\n await refreshServerWatchList?.(resolved)\n }\n } catch (err) {\n failure = { error: err }\n\n // `runBuilds` reports its own failure before rethrowing, so only the\n // other things that can throw here — a `config` function of the\n // consumer's that raises, a watch list that cannot be rebuilt — need\n // reporting. They reach the overlay for the same reason: from the\n // page's point of view the rebuild failed, whichever half of it did.\n if (!compiling) {\n log(`Rebuild failed: ${errorMessage(err)}`, 'error')\n notifyBuildOutcome?.(asError(err))\n }\n }\n\n // Handed on to whatever awaited this rebuild, which is `watchChange`\n // and so the host under a watching bundler. Vite's dev-server listener\n // has no build to fail and catches it.\n for (const settle of resolvers) settle(failure)\n }\n }\n\n // Resolves once a rebuild covering this trigger has finished.\n const schedule = async (reason: string): Promise<void> => {\n // Nothing consumes a rebuild once the host has closed its watcher. This is\n // where a close actually lands: `watchChange` reaches here only after\n // resolving configurations and deriving a watch list, so a `closeWatcher`\n // arriving mid-hook finds no timer armed yet and nothing else to stop it.\n //\n // Resolving rather than rejecting, because the trigger was handled — by\n // being declined — and the caller awaiting it is a host on its way out.\n if (hostClosed) return\n\n pendingReason = reason\n\n const covered = new Promise<void>((resolve, reject) => {\n waiting.push((failure) => {\n if (failure) reject(asError(failure.error))\n else resolve()\n })\n })\n\n if (debounceTimer) clearTimeout(debounceTimer)\n debounceTimer = setTimeout(() => {\n debounceTimer = undefined\n inFlight = (inFlight ?? Promise.resolve()).then(drain)\n }, REBUILD_DEBOUNCE_MS)\n\n // A pending rebuild must not be what keeps a process alive; whatever is\n // watching already is.\n debounceTimer.unref()\n\n return covered\n }\n\n // Every host that runs a rollup-shaped watcher calls this on shutdown, and\n // all three get the same handler below. There is deliberately no webpack\n // equivalent here: it has no `closeWatcher`, its nearest thing is\n // `compiler.hooks.watchClose`, and nothing measured shows it exposed.\n //\n // It raises the flag and nothing else. A debounce timer armed before the\n // close is deliberately left to fire: the rebuild it runs is one the host\n // asked for while the project was still whole, and `drain` reports its own\n // failures. Cancelling it would be a guard no test could fail on, since a\n // trigger arriving after the close is declined by `schedule` instead.\n const closeWatcher = (): void => {\n hostClosed = true\n }\n\n return {\n async buildStart() {\n adoptHost(this)\n adoptWatchMode(this)\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`). Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch — not because\n // `watchChange` is missing there, which it is not on any Vite this\n // package supports, but because the declared peer range is wider than\n // what has been measured and the scheduler above makes a duplicate\n // trigger free.\n //\n // Skipped outright once the host has closed, because rollup discards the\n // result: with the task closed, `Task.run` returns before\n // `updateWatchedFiles`, so every path registered here goes nowhere. What\n // deriving it does still do is read each config file — with\n // `reportErrors: true` — and report an ENOENT for a project the host is\n // in the middle of tearing down. That report was the one thing this\n // block contributed after a close.\n if (!hostClosed) {\n const { paths } = await getWatchTargets(resolved)\n for (const file of paths) {\n this.addWatchFile(file)\n }\n }\n\n // Registering the watch list is all this hook does on webpack, and it\n // has to happen here rather than beside the compile: `addWatchFile`\n // reaches `compilation.fileDependencies`, and `beforeCompile` runs\n // before there is a compilation to add to. Compiling here as well would\n // put the race back, and run every webpack build twice.\n if (isWebpack) return\n\n // Every watch rebuild re-enters this hook, and compiling here as well as\n // in `watchChange` is what closed the loop: consuming code imports the\n // generated file, so writing it is itself a module-graph change, which\n // re-enters `buildStart`, which writes it again. `watchChange` has\n // already run for every file in this cycle and rebuilt if any of them\n // was a source, so the only thing left for a re-entry to do is the\n // re-registration above.\n //\n // `hasCompiled` is the floor under that: a host that fires\n // `watchChange` without ever re-entering here would otherwise leave the\n // flag standing, and no first compile of a process may ever be skipped —\n // the tokens have to exist before the build that consumes them.\n if (watchRebuild && hasCompiled) {\n watchRebuild = false\n return\n }\n\n await compileOnceAcrossInstances(resolved)\n hasCompiled = true\n },\n\n name: 'unplugin-style-dictionary',\n\n // `closeWatcher` is a rollup-shaped hook and `UnpluginOptions` declares no\n // top-level equivalent, so it is registered per target instead: rolldown\n // lists it among its input plugin hooks, and Vite's plugin type is\n // rollup's, which is what carries it to `vite build --watch`. Vite's dev\n // server runs no rollup watcher, so there it simply never fires.\n rolldown: { closeWatcher },\n\n rollup: { closeWatcher },\n\n vite: {\n closeWatcher,\n\n async configResolved(config) {\n if (rootOption === undefined) root = config.root || process.cwd()\n\n // The only host that has both. `command` is what makes `'serve'`\n // reachable at all, since nothing else here serves.\n hostCommand = config.command\n hostMode = config.mode\n\n // Vite's own logger, so the plugin's lines obey `customLogger` and\n // `clearScreen` like every other line the dev server prints. It\n // colours and prefixes its own output, which is why nothing painted\n // reaches it.\n //\n // Ahead of the early return below, because `vite build` needs the\n // logger just as much and takes that return.\n host = {\n error: (message) => {\n config.logger.error(message)\n },\n info: (message) => {\n config.logger.info(message)\n },\n }\n\n // Nothing below concerns a build: only the dev server has a watcher,\n // and only its ignore list needs amending.\n if (config.command !== 'serve') return\n\n // Ahead of the resolution below, so the `config` function a consumer\n // wrote is told `watch: true` on this call as well as on every later\n // one. Setting it in `configureServer` alone was correct until this\n // hook started resolving configurations too.\n isWatching = true\n\n // **This is the last hook that can reach the ignore list.** Vite\n // builds the watcher from the resolved config, and `configureServer`\n // runs after it exists — `server.watcher` is a parameter there — so a\n // negation added then changes nothing. Measured on Vite 6.4.3, 7.3.6\n // and 8.3.0: amending it here reaches the watcher on all three, and\n // amending it in `configureServer` does not.\n //\n // The resolution is kept for `configureServer` to reuse rather than\n // discarded, because resolving is how a `config` function gets called\n // and doing it twice in one start-up would call the consumer's code an\n // extra time for nothing.\n try {\n startupResolved = await resolveConfigs()\n if (startupResolved.length === 0) return\n\n const { paths } = await getWatchTargets(startupResolved)\n const negations = nodeModulesNegations(paths)\n if (negations.length === 0) return\n\n // Appended to whatever the consumer asked for, not replacing it.\n const existing = config.server.watch?.ignored\n config.server.watch = {\n ...config.server.watch,\n ignored: [\n ...(Array.isArray(existing)\n ? existing\n : existing === undefined\n ? []\n : [existing]),\n ...negations,\n ],\n }\n } catch (err) {\n // A configuration that cannot be resolved is the build's problem to\n // report, and it will: `buildStart` resolves again and fails there\n // with the host watching. Throwing here would fail the dev server\n // before it started, for the sake of a watch-list refinement.\n log(\n `Could not read the configuration while preparing the watch list: ${errorMessage(err)}`,\n 'error',\n )\n startupResolved = undefined\n }\n },\n\n async configureServer(server: ViteDevServer) {\n // A dev server watches, by definition. Said here rather than left to\n // `adoptWatchMode` because this hook runs *before* `buildStart` —\n // `createServer` calls it, and `buildStart` waits for the plugin\n // container — so the first `config` function of the process would\n // otherwise be told `watch: false` while a dev server started up\n // around it.\n isWatching = true\n\n // `configResolved` has already resolved these, on its way to amending\n // the watcher's ignore list. Taken rather than copied, so a later\n // rebuild re-resolves as it always did.\n const resolved = startupResolved ?? (await resolveConfigs())\n startupResolved = undefined\n if (resolved.length === 0) return\n\n // Reassigned after every rebuild below, so a configuration that gains\n // a source is matched against its new patterns rather than the ones\n // read at start-up.\n let targets = await getWatchTargets(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(targets.paths)\n\n // Runs once per rebuild rather than once per event, which is why it\n // is handed to the scheduler rather than done in the listener.\n refreshServerWatchList = async (rebuilt) => {\n targets = await getWatchTargets(rebuilt)\n server.watcher.add(targets.paths)\n }\n\n if (errorOverlay) {\n // Whether the page is currently showing an overlay this plugin put\n // there. Only the clearing frame reads it: a success that follows a\n // success has no overlay to take down, and sending an update frame\n // for it would be traffic for nothing — and would spend the client's\n // one-time `isFirstUpdate`, which Vite uses to decide that an\n // overlay standing at the first update means a full reload.\n let overlayShowing = false\n\n notifyBuildOutcome = (error) => {\n if (error) {\n // Sent on every failure rather than only on the transition into\n // one. Vite's client replaces the overlay wholesale, so a repeat\n // is idempotent — and two different failures in a row must not\n // leave the first one's message on screen describing the second.\n overlayShowing = true\n server.hot.send({\n err: {\n message: error.message,\n plugin: 'unplugin-style-dictionary',\n stack: error.stack ?? '',\n },\n type: 'error',\n })\n return\n }\n\n if (!overlayShowing) return\n overlayShowing = false\n\n // Vite's protocol has no frame for \"take the overlay down\". The\n // client clears it when an update arrives, so an update carrying\n // nothing is the clear: it dismisses the overlay and then iterates\n // an empty list, reloading no page and touching no stylesheet.\n server.hot.send({ type: 'update', updates: [] })\n }\n }\n\n // chokidar types its listener as returning void and does not await\n // what it is handed, so an async listener left every rejection\n // floating. `schedule` owns the whole rebuild including its errors,\n // so there is nothing here left to reject.\n server.watcher.on('all', (_event, file) => {\n if (!isWatchedSource(file, targets.patterns)) return\n\n // A dev server has no build to fail, so a rebuild that throws is\n // reported by the scheduler and the server keeps serving.\n void schedule(path.basename(file)).catch(() => {})\n })\n },\n },\n\n // Rollup types `watchChange` as returning void, yet awaits it as a\n // sequential hook — and the work here is inherently asynchronous. The\n // signature is the thing that is wrong, so the rule is silenced rather\n // than the hook made to lie about finishing.\n // oxlint-disable-next-line typescript/no-misused-promises\n async watchChange(id) {\n adoptHost(this)\n adoptWatchMode(this)\n\n // Ahead of everything, including the flag below: a change reported\n // after the watcher closed earns no rebuild, so there is no re-entry\n // into `buildStart` for a flag to describe.\n if (hostClosed) return\n\n // Raised before any decision about `id`, because whatever this change\n // was, the host is now on its way back into `buildStart`.\n watchRebuild = true\n\n // The cheap half of the decision, taken before anything is resolved.\n // Under Vite the scope this hook sees is the whole project root rather\n // than the module graph, so most of what arrives here has nothing to do\n // with tokens, and resolving every configuration only to discard the\n // answer ran a consumer's `config` function once per unrelated file.\n // Skipped until a build has derived a list to filter against.\n if (cachedPatterns && !isWatchedSource(id, cachedPatterns)) return\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Derived again rather than trusted from the cache, because the cache\n // is what decided this path was worth resolving and not what decides a\n // rebuild. A config edit reaches here through its own filename and can\n // have dropped the very source the cached list matched.\n const { patterns } = await getWatchTargets(resolved)\n // Without this check, watchChange fires for *any* changed file in the\n // host bundler's module graph — including our own generated output,\n // since consuming code imports it. Every regenerate is itself a\n // \"change\", so skipping what is not a source here is what keeps this\n // from rebuilding forever — both the files that match no pattern and\n // the ones that match only because this plugin wrote them.\n if (!isWatchedSource(id, patterns)) return\n\n // Same division as `buildStart`: on webpack the compile belongs to\n // `beforeCompile`, which has already run for this compilation, so all\n // that is left is to re-register the watch list below.\n if (!isWebpack) await schedule(path.basename(id))\n\n // Expanded again after the build rather than reusing the list from\n // before it, so a token file the build itself produced is registered.\n for (const file of await expandPatterns(patterns)) {\n this.addWatchFile(file)\n }\n },\n\n // unplugin calls this inside `apply(compiler)`, one line before it taps\n // `make`, so the root is in place before the first compile. Without it a\n // webpack build whose `context` is not the working directory looked for\n // the configuration in the wrong place and reported ENOENT.\n webpack(compiler) {\n if (rootOption === undefined) {\n root = compiler.options.context ?? process.cwd()\n }\n\n // webpack's `buildStart` context carries no `meta`, so neither half of\n // the build context can come from there. `mode` is a webpack option, and\n // `watchMode` is only true once `watch()` has been called — which is\n // after this runs, so it is read per compile below rather than here.\n hostMode = compiler.options.mode\n\n // The compile happens in `beforeCompile`, which webpack awaits *before*\n // the compilation exists — so a message from it has nothing to attach to\n // yet and is held until one appears.\n //\n // Only failures are routed. `stats` carries warnings and errors and\n // nothing else, so the progress lines stay on the console rather than\n // being reported as warnings they are not.\n //\n // A warning rather than an error, for the same reason as on rollup: this\n // is the report, and `failOnError` decides separately whether the build\n // stops. Pushing to `compilation.errors` would fail a webpack build that\n // asked not to be failed.\n const pending: string[] = []\n host = {\n error: (message) => {\n pending.push(message)\n },\n }\n\n compiler.hooks.compilation.tap(\n 'unplugin-style-dictionary',\n (compilation) => {\n for (const message of pending.splice(0)) {\n const reported = new Error(message)\n reported.name = 'UnpluginStyleDictionaryWarning'\n compilation.warnings.push(reported)\n }\n },\n )\n\n // A `beforeCompile` that throws ends the run without ever creating a\n // compilation, and that is exactly the case that produced the message.\n // Left to the buffer it would be reported nowhere at all, so whatever is\n // still held when the run ends goes to the console after all.\n const drainToConsole = () => {\n for (const message of pending.splice(0)) {\n console.error(paint('31', message, stderrColour))\n }\n }\n compiler.hooks.failed.tap('unplugin-style-dictionary', drainToConsole)\n compiler.hooks.done.tap('unplugin-style-dictionary', drainToConsole)\n\n // `beforeCompile` is awaited before the compilation exists, so the\n // tokens are on disk before webpack resolves the module that imports\n // them. Tapped on every compilation rather than only the first: a watch\n // rebuild needs the same guarantee, and a compile that renders what is\n // already there skips its own write.\n compiler.hooks.beforeCompile.tapPromise(\n 'unplugin-style-dictionary',\n async () => {\n isWatching = compiler.watchMode\n\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n await compileOnceAcrossInstances(resolved)\n hasCompiled = true\n },\n )\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":";;;;;;;;;;AAkDA,SAAS,QAAQ,OAAuB;CACtC,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,aAAa,KAAK,CAAC;AACvE;AAaA,SAAS,cAAc,QAAsC;CAC3D,IAAI,QAAQ,IAAI,UAAU,OAAO;CAEjC,MAAM,SAAS,QAAQ,IAAI;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAA,KAAa,WAAW,I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AM,cAAc,WAC3B,6BACA,YAAY;IACV,aAAa,SAAS;IAEtB,MAAM,WAAW,MAAM,eAAe;IACtC,IAAI,SAAS,WAAW,GAAG;IAE3B,MAAM,2BAA2B,QAAQ;IACzC,cAAc;GAChB,CACF;EACF;CACF;AACF;AAEA,MAAa,WAA2B,+BAAe,eAAe"}
|
package/dist/types.d.ts
CHANGED
|
@@ -122,9 +122,21 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
122
122
|
*
|
|
123
123
|
* If not provided, the root directory is searched for 'sd.config.json',
|
|
124
124
|
* 'config.json', 'sd.config.js' and 'sd.config.mjs', in that order. The
|
|
125
|
-
* first one that
|
|
125
|
+
* first one that *looks like a Style Dictionary configuration* wins — it has
|
|
126
|
+
* to declare at least one of `platforms`, `source`, `include` or `tokens` —
|
|
127
|
+
* and the path it picked is announced, so which file a build used is
|
|
128
|
+
* answerable from the console. A candidate that fails that check is reported
|
|
129
|
+
* and skipped rather than adopted, because `config.json` is an extremely
|
|
130
|
+
* common name for something else entirely.
|
|
131
|
+
*
|
|
132
|
+
* **`false` turns discovery off.** Two of the four names are modules rather
|
|
133
|
+
* than data, and reading a module means running it: a `sd.config.js` in the
|
|
134
|
+
* root is imported, freshly, on every watch event. Validation cannot prevent
|
|
135
|
+
* that, because the check can only look at what the import returned — so a
|
|
136
|
+
* project that names its configuration explicitly, or has none, should say
|
|
137
|
+
* `config: false` rather than rely on there being nothing to find.
|
|
126
138
|
*/
|
|
127
|
-
config?: ((context: StyleDictionaryConfigContext) => Config | Config[] | Promise<Config | Config[]>) | Config | Config[] | string | string[];
|
|
139
|
+
config?: ((context: StyleDictionaryConfigContext) => Config | Config[] | Promise<Config | Config[]>) | Config | Config[] | false | string | string[];
|
|
128
140
|
/**
|
|
129
141
|
* Whether a failed rebuild is pushed to Vite's error overlay.
|
|
130
142
|
*
|
|
@@ -237,6 +249,50 @@ export interface UnpluginStyleDictionaryOptions {
|
|
|
237
249
|
* @default undefined
|
|
238
250
|
*/
|
|
239
251
|
onBuildStart?: () => Promise<void> | void;
|
|
252
|
+
/**
|
|
253
|
+
* Which platforms to build, by the names the configuration defines.
|
|
254
|
+
*
|
|
255
|
+
* Every rebuild used to compile every platform. Measured on a six-platform
|
|
256
|
+
* configuration (css, scss, js, ios, android, flutter), with the timer around
|
|
257
|
+
* the build call alone:
|
|
258
|
+
*
|
|
259
|
+
* ```
|
|
260
|
+
* tokens all platforms css only saved
|
|
261
|
+
* 500 12 ms 1 ms 10 ms
|
|
262
|
+
* 3000 36 ms 2 ms 34 ms
|
|
263
|
+
* 10000 103 ms 4 ms 99 ms
|
|
264
|
+
* 30000 330 ms 12 ms 319 ms
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* So a dev server serving a web app paid for Objective-C headers, Android
|
|
268
|
+
* XML and Dart classes on every token save, and the cost grows with the
|
|
269
|
+
* token count.
|
|
270
|
+
*
|
|
271
|
+
* Two shapes. An array selects the same platforms for every build. An object
|
|
272
|
+
* splits the first compile from the watch rebuilds, which is the common
|
|
273
|
+
* want — build everything once, then rebuild only what the page uses:
|
|
274
|
+
*
|
|
275
|
+
* ```typescript
|
|
276
|
+
* platforms: ['css']
|
|
277
|
+
* platforms: { watch: ['css'] }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* An omitted key means every platform, so `{ watch: ['css'] }` builds all of
|
|
281
|
+
* them once and then only css. A name the configuration does not define is an
|
|
282
|
+
* error, matching Style Dictionary's own CLI — "Must be defined in the
|
|
283
|
+
* config".
|
|
284
|
+
*
|
|
285
|
+
* **Unselected platforms keep whatever they last wrote.** Their files are not
|
|
286
|
+
* removed and not refreshed, so a one-shot build that scopes platforms ships
|
|
287
|
+
* stale output for the rest. Scope the watch half rather than the build half
|
|
288
|
+
* unless that is what you want.
|
|
289
|
+
*
|
|
290
|
+
* @default undefined, which builds every platform
|
|
291
|
+
*/
|
|
292
|
+
platforms?: string[] | {
|
|
293
|
+
build?: string[];
|
|
294
|
+
watch?: string[];
|
|
295
|
+
};
|
|
240
296
|
/**
|
|
241
297
|
* Whether the table of generated files and their sizes is produced.
|
|
242
298
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanso-labs/unplugin-style-dictionary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Compile Style Dictionary design tokens ahead of your bundler (Vite, Rolldown, Rollup, or Webpack) from a single unplugin-based plugin, with automatic watching and rebuilding under Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unplugin",
|