@kanso-labs/unplugin-style-dictionary 0.2.6 → 0.3.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.
Files changed (45) hide show
  1. package/README.md +80 -24
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/cjs/index.cjs +268 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/cjs/index.d.cts +9 -0
  6. package/dist/cjs/rolldown.cjs +6 -0
  7. package/dist/cjs/rolldown.cjs.map +1 -0
  8. package/dist/cjs/rolldown.d.cts +5 -0
  9. package/dist/cjs/rollup.cjs +6 -0
  10. package/dist/cjs/rollup.cjs.map +1 -0
  11. package/dist/cjs/rollup.d.cts +5 -0
  12. package/dist/cjs/types.d.cts +43 -0
  13. package/dist/cjs/vite.cjs +6 -0
  14. package/dist/cjs/vite.cjs.map +1 -0
  15. package/dist/cjs/vite.d.cts +5 -0
  16. package/dist/cjs/webpack.cjs +6 -0
  17. package/dist/cjs/webpack.cjs.map +1 -0
  18. package/dist/cjs/webpack.d.cts +5 -0
  19. package/dist/index.d.ts +9 -7
  20. package/dist/index.js +202 -150
  21. package/dist/index.js.map +1 -1
  22. package/dist/rolldown.d.ts +6 -2
  23. package/dist/rolldown.js +3 -3
  24. package/dist/rolldown.js.map +1 -1
  25. package/dist/rollup.d.ts +6 -2
  26. package/dist/rollup.js +3 -3
  27. package/dist/rollup.js.map +1 -1
  28. package/dist/types.d.ts +31 -27
  29. package/dist/vite.d.ts +6 -2
  30. package/dist/vite.js +3 -3
  31. package/dist/vite.js.map +1 -1
  32. package/dist/webpack.d.ts +6 -2
  33. package/dist/webpack.js +3 -3
  34. package/dist/webpack.js.map +1 -1
  35. package/package.json +54 -25
  36. package/dist/index.cjs +0 -2
  37. package/dist/index.cjs.map +0 -1
  38. package/dist/rolldown.cjs +0 -2
  39. package/dist/rolldown.cjs.map +0 -1
  40. package/dist/rollup.cjs +0 -2
  41. package/dist/rollup.cjs.map +0 -1
  42. package/dist/vite.cjs +0 -2
  43. package/dist/vite.cjs.map +0 -1
  44. package/dist/webpack.cjs +0 -2
  45. package/dist/webpack.cjs.map +0 -1
@@ -0,0 +1,5 @@
1
+ import { UnpluginStyleDictionaryOptions } from "./types.cjs";
2
+ //#region src/webpack.d.ts
3
+ declare const _default: (options?: UnpluginStyleDictionaryOptions | undefined) => import("webpack").WebpackPluginInstance;
4
+ export = _default;
5
+ //# sourceMappingURL=webpack.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { UnpluginFactory } from 'unplugin';
2
- import { UnpluginStyleDictionaryOptions } from './types.js';
3
- export * from './types.js';
4
- export declare function matchesWatchedFile(file: string, patterns: string[]): boolean;
5
- export declare const unpluginFactory: UnpluginFactory<undefined | UnpluginStyleDictionaryOptions, false>;
6
- export declare const unplugin: import('unplugin').UnpluginInstance<UnpluginStyleDictionaryOptions | undefined, false>;
7
- export default unplugin;
1
+ import { UnpluginStyleDictionaryOptions } from "./types.js";
2
+ import { UnpluginFactory } from "unplugin";
3
+ //#region src/index.d.ts
4
+ declare function matchesWatchedFile(file: string, patterns: string[]): boolean;
5
+ declare const unpluginFactory: UnpluginFactory<undefined | UnpluginStyleDictionaryOptions, false>;
6
+ declare const unplugin: import("unplugin").UnpluginInstance<UnpluginStyleDictionaryOptions | undefined, false>;
7
+ //#endregion
8
+ export { type UnpluginStyleDictionaryOptions, unplugin as default, unplugin, matchesWatchedFile, unpluginFactory };
9
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,204 +1,256 @@
1
- import e from "node:fs";
2
- import t from "node:path";
3
- import { pathToFileURL as n } from "node:url";
4
- import r from "node:zlib";
5
- import i from "style-dictionary";
6
- import { createUnplugin as a } from "unplugin";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import zlib from "node:zlib";
5
+ import StyleDictionary from "style-dictionary";
6
+ import { createUnplugin } from "unplugin";
7
7
  //#region src/index.ts
8
- function o(e, t) {
9
- let n = e.replace(/\\/g, "/");
10
- return t.some((e) => e === n || n.startsWith(e.replace(/\/\*\*/g, "")) || e.includes("*") && new RegExp(e.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")).test(n));
8
+ function matchesWatchedFile(file, patterns) {
9
+ const normalizedFile = file.replace(/\\/g, "/");
10
+ return patterns.some((pattern) => {
11
+ if (pattern === normalizedFile) return true;
12
+ return normalizedFile.startsWith(pattern.replace(/\/\*\*/g, "")) || pattern.includes("*") && new RegExp(pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")).test(normalizedFile);
13
+ });
11
14
  }
12
- function s(t) {
15
+ function discardTemporaryFile(temporary) {
13
16
  try {
14
- e.rmSync(t, { force: !0 });
17
+ fs.rmSync(temporary, { force: true });
15
18
  } catch {}
16
19
  }
17
- var c = 0;
18
- function l(e) {
19
- let n = t.extname(e);
20
- return t.join(t.dirname(e), `.${t.basename(e, n)}.${process.pid}.${c++}.tmp`);
20
+ function errorMessage(error) {
21
+ return error instanceof Error ? error.message : String(error);
21
22
  }
22
- var u = Object.create(e, {
23
- promises: { value: Object.create(e.promises, { writeFile: { value: async (t, n, r) => {
24
- if (typeof t != "string") return e.promises.writeFile(t, n, r);
25
- let i = l(t);
26
- try {
27
- await e.promises.writeFile(i, n, r), await e.promises.rename(i, t);
28
- } catch (e) {
29
- throw s(i), e;
30
- }
31
- } } }) },
32
- writeFileSync: { value: (t, n, r) => {
33
- if (typeof t != "string") {
34
- e.writeFileSync(t, n, r);
35
- return;
36
- }
37
- let i = l(t);
38
- try {
39
- e.writeFileSync(i, n, r), e.renameSync(i, t);
40
- } catch (e) {
41
- throw s(i), e;
42
- }
43
- } }
44
- }), d = (a = {}) => {
45
- let { silent: s = !1 } = a, c = process.cwd(), l = (e, t = "info") => {
46
- if (s) return;
47
- let n = "[unplugin-style-dictionary]";
48
- t === "error" ? console.error(`\x1b[31m${n} ${e}\x1b[0m`) : console.log(t === "success" ? `\x1b[32m${n} ${e}\x1b[0m` : `\x1b[36m${n} ${e}\x1b[0m`);
49
- }, d = async () => {
50
- let n = a.config;
51
- if (!n) for (let r of [
23
+ function isConfig(value) {
24
+ return typeof value === "object" && value !== null;
25
+ }
26
+ function unwrapDefault(value) {
27
+ return typeof value === "object" && value !== null && "default" in value ? value.default ?? value : value;
28
+ }
29
+ let temporaryFileCounter = 0;
30
+ function temporaryPathFor(destination) {
31
+ const extension = path.extname(destination);
32
+ return path.join(path.dirname(destination), `.${path.basename(destination, extension)}.${process.pid}.${temporaryFileCounter++}.tmp`);
33
+ }
34
+ const writeFileAtomic = async (file, data, options) => {
35
+ if (typeof file !== "string") return fs.promises.writeFile(file, data, options);
36
+ const temporary = temporaryPathFor(file);
37
+ try {
38
+ await fs.promises.writeFile(temporary, data, options);
39
+ await fs.promises.rename(temporary, file);
40
+ } catch (err) {
41
+ discardTemporaryFile(temporary);
42
+ throw err;
43
+ }
44
+ };
45
+ const writeFileSyncAtomic = (file, data, options) => {
46
+ if (typeof file !== "string") {
47
+ fs.writeFileSync(file, data, options);
48
+ return;
49
+ }
50
+ const temporary = temporaryPathFor(file);
51
+ try {
52
+ fs.writeFileSync(temporary, data, options);
53
+ fs.renameSync(temporary, file);
54
+ } catch (err) {
55
+ discardTemporaryFile(temporary);
56
+ throw err;
57
+ }
58
+ };
59
+ const atomicVolume = Object.create(fs, {
60
+ promises: { value: Object.create(fs.promises, { writeFile: { value: writeFileAtomic } }) },
61
+ writeFileSync: { value: writeFileSyncAtomic }
62
+ });
63
+ const unpluginFactory = (options = {}) => {
64
+ const { silent = false } = options;
65
+ let root = process.cwd();
66
+ const log = (message, type = "info") => {
67
+ if (silent) return;
68
+ const prefix = "[unplugin-style-dictionary]";
69
+ if (type === "error") console.error(`\x1b[31m${prefix} ${message}\x1b[0m`);
70
+ else if (type === "success") console.log(`\x1b[32m${prefix} ${message}\x1b[0m`);
71
+ else console.log(`\x1b[36m${prefix} ${message}\x1b[0m`);
72
+ };
73
+ const resolveConfigs = async () => {
74
+ let rawConfig = options.config;
75
+ if (!rawConfig) for (const file of [
52
76
  "sd.config.json",
53
77
  "config.json",
54
78
  "sd.config.js",
55
79
  "sd.config.mjs"
56
80
  ]) {
57
- let i = t.resolve(c, r);
58
- if (e.existsSync(i)) {
59
- n = r;
81
+ const fullPath = path.resolve(root, file);
82
+ if (fs.existsSync(fullPath)) {
83
+ rawConfig = file;
60
84
  break;
61
85
  }
62
86
  }
63
- return n ? (typeof n == "function" && (n = await n()), (Array.isArray(n) ? n : [n]).map((e) => {
64
- if (typeof e == "string") {
65
- let n = t.resolve(c, e);
87
+ if (!rawConfig) {
88
+ log("No configuration specified and no default config file found. Style Dictionary will not compile.", "error");
89
+ return [];
90
+ }
91
+ if (typeof rawConfig === "function") rawConfig = await rawConfig();
92
+ return (Array.isArray(rawConfig) ? rawConfig : [rawConfig]).map((conf) => {
93
+ if (typeof conf === "string") {
94
+ const fullPath = path.resolve(root, conf);
66
95
  return {
67
- config: n,
68
- dir: t.dirname(n),
69
- file: n
96
+ config: fullPath,
97
+ dir: path.dirname(fullPath),
98
+ file: fullPath
70
99
  };
71
- }
72
- return {
73
- config: e,
74
- dir: c
100
+ } else return {
101
+ config: conf,
102
+ dir: root
75
103
  };
76
- })) : (l("No configuration specified and no default config file found. Style Dictionary will not compile.", "error"), []);
77
- }, f = async (r) => {
78
- let i = /* @__PURE__ */ new Set();
79
- for (let a of r) {
80
- a.file && i.add(a.file.replace(/\\/g, "/"));
81
- let r = null;
82
- if (typeof a.config == "string") try {
83
- if (a.config.endsWith(".json")) {
84
- let t = e.readFileSync(a.config, "utf-8");
85
- r = JSON.parse(t);
86
- } else {
87
- let e = await import(`${n(a.config).href}?t=${Date.now()}`);
88
- r = e.default || e;
104
+ });
105
+ };
106
+ const getWatchFiles = async (resolvedConfigs) => {
107
+ const filesToWatch = /* @__PURE__ */ new Set();
108
+ for (const item of resolvedConfigs) {
109
+ if (item.file) filesToWatch.add(item.file.replace(/\\/g, "/"));
110
+ let configObj = null;
111
+ if (typeof item.config === "string") try {
112
+ let loaded;
113
+ if (item.config.endsWith(".json")) loaded = JSON.parse(fs.readFileSync(item.config, "utf-8"));
114
+ else {
115
+ const fileUrl = pathToFileURL(item.config).href;
116
+ loaded = unwrapDefault(await import(`${fileUrl}?t=${Date.now()}`));
89
117
  }
90
- } catch (e) {
91
- l(`Failed to parse config file: ${a.config}. Error: ${e.message}`, "error");
118
+ if (isConfig(loaded)) configObj = loaded;
119
+ else log(`Config file did not resolve to a configuration object: ${item.config}`, "error");
120
+ } catch (err) {
121
+ log(`Failed to parse config file: ${item.config}. Error: ${errorMessage(err)}`, "error");
92
122
  }
93
- else r = a.config;
94
- if (r) {
95
- let e = (e) => {
96
- if (typeof e == "string") {
97
- let n = (t.isAbsolute(e) ? e : t.resolve(a.dir, e)).replace(/\\/g, "/");
98
- i.add(n);
123
+ else configObj = item.config;
124
+ if (configObj) {
125
+ const addPattern = (pattern) => {
126
+ if (typeof pattern === "string") {
127
+ const normalized = (path.isAbsolute(pattern) ? pattern : path.resolve(item.dir, pattern)).replace(/\\/g, "/");
128
+ filesToWatch.add(normalized);
99
129
  }
100
130
  };
101
- r.source && (Array.isArray(r.source) ? r.source.forEach(e) : e(r.source)), r.include && (Array.isArray(r.include) ? r.include.forEach(e) : e(r.include));
131
+ if (configObj.source) {
132
+ if (Array.isArray(configObj.source)) configObj.source.forEach(addPattern);
133
+ else addPattern(configObj.source);
134
+ }
135
+ if (configObj.include) {
136
+ if (Array.isArray(configObj.include)) configObj.include.forEach(addPattern);
137
+ else addPattern(configObj.include);
138
+ }
102
139
  }
103
140
  }
104
- if (a.watch) {
105
- let e = Array.isArray(a.watch) ? a.watch : [a.watch];
106
- for (let n of e) {
107
- let e = t.isAbsolute(n) ? n : t.resolve(c, n);
108
- i.add(e.replace(/\\/g, "/"));
141
+ if (options.watch) {
142
+ const extraWatches = Array.isArray(options.watch) ? options.watch : [options.watch];
143
+ for (const pattern of extraWatches) {
144
+ const absolutePattern = path.isAbsolute(pattern) ? pattern : path.resolve(root, pattern);
145
+ filesToWatch.add(absolutePattern.replace(/\\/g, "/"));
109
146
  }
110
147
  }
111
- return Array.from(i);
112
- }, p = async (n, a) => {
113
- let o = Date.now();
148
+ return Array.from(filesToWatch);
149
+ };
150
+ const runBuilds = async (resolvedConfigs, context) => {
151
+ const startTime = Date.now();
114
152
  try {
115
- a || l("Compiling design tokens...", "info");
116
- let d = /* @__PURE__ */ new Set();
117
- for (let e of n) {
118
- let n = new i(e.config);
119
- await n.hasInitialized;
120
- let r = await n.extend({ log: { verbosity: "silent" } });
121
- if (r.volume = u, await r.buildAllPlatforms(), !a && !s && r.platforms) for (let e of Object.keys(r.platforms)) {
122
- let n = r.platforms[e];
123
- if (n && n.files) {
124
- let e = n.buildPath || "";
125
- for (let r of n.files) if (r && r.destination) {
126
- let n = t.isAbsolute(e) ? e : t.resolve(c, e), i = t.isAbsolute(r.destination) ? r.destination : t.resolve(n, r.destination);
127
- d.add(i);
128
- }
153
+ if (!context) log("Compiling design tokens...", "info");
154
+ const generatedFiles = /* @__PURE__ */ new Set();
155
+ for (const item of resolvedConfigs) {
156
+ const sd = new StyleDictionary(item.config);
157
+ await sd.hasInitialized;
158
+ const silentSD = await sd.extend({ log: { verbosity: "silent" } });
159
+ silentSD.volume = atomicVolume;
160
+ await silentSD.buildAllPlatforms();
161
+ if (!context && !silent) for (const platform of Object.values(silentSD.platforms)) {
162
+ const buildPath = platform.buildPath ?? "";
163
+ for (const file of platform.files ?? []) if (file.destination) {
164
+ const absoluteBuildPath = path.isAbsolute(buildPath) ? buildPath : path.resolve(root, buildPath);
165
+ const absoluteDestination = path.isAbsolute(file.destination) ? file.destination : path.resolve(absoluteBuildPath, file.destination);
166
+ generatedFiles.add(absoluteDestination);
129
167
  }
130
168
  }
131
169
  }
132
- let f = Date.now() - o;
133
- if (a) l(`Rebuilt design tokens due to change in ${a} (${f}ms)`, "success");
170
+ const duration = Date.now() - startTime;
171
+ if (context) log(`Rebuilt design tokens due to change in ${context} (${duration}ms)`, "success");
134
172
  else {
135
- if (!s && d.size > 0) {
136
- let n = [];
137
- for (let i of d) if (e.existsSync(i)) {
138
- let a = t.relative(c, i).replace(/\\/g, "/"), o = t.dirname(a), s = t.basename(a), l = o === "." ? `\x1b[32m${s}\x1b[0m` : `\x1b[90m${o}/\x1b[0m\x1b[32m${s}\x1b[0m`;
173
+ if (!silent && generatedFiles.size > 0) {
174
+ const fileInfos = [];
175
+ for (const filePath of generatedFiles) if (fs.existsSync(filePath)) {
176
+ const displayPath = path.relative(root, filePath).replace(/\\/g, "/");
177
+ const dir = path.dirname(displayPath);
178
+ const base = path.basename(displayPath);
179
+ const coloredPath = dir === "." ? `\x1b[32m${base}\x1b[0m` : `\x1b[90m${dir}/\x1b[0m\x1b[32m${base}\x1b[0m`;
139
180
  try {
140
- let t = `${(e.statSync(i).size / 1024).toFixed(2)} kB`, o = e.readFileSync(i), s = `${(r.gzipSync(o).length / 1024).toFixed(2)} kB`;
141
- n.push({
142
- coloredPath: l,
143
- gzipSizeStr: s,
144
- relativeDisplayPath: a,
145
- sizeStr: t
181
+ const sizeStr = `${(fs.statSync(filePath).size / 1024).toFixed(2)} kB`;
182
+ const content = fs.readFileSync(filePath);
183
+ const gzipSizeStr = `${(zlib.gzipSync(content).length / 1024).toFixed(2)} kB`;
184
+ fileInfos.push({
185
+ coloredPath,
186
+ gzipSizeStr,
187
+ relativeDisplayPath: displayPath,
188
+ sizeStr
146
189
  });
147
190
  } catch {}
148
191
  }
149
- if (n.length > 0) {
150
- let e = Math.max(...n.map((e) => e.relativeDisplayPath.length), 0), t = Math.max(...n.map((e) => e.sizeStr.length), 0);
151
- for (let r of n) {
152
- let n = " ".repeat(Math.max(2, e - r.relativeDisplayPath.length + 2)), i = r.sizeStr.padStart(t);
153
- console.log(`${r.coloredPath}${n}\x1b[90m${i} gzip: ${r.gzipSizeStr}\x1b[0m`);
192
+ if (fileInfos.length > 0) {
193
+ const longestPathLength = Math.max(...fileInfos.map((f) => f.relativeDisplayPath.length), 0);
194
+ const longestSizeLength = Math.max(...fileInfos.map((f) => f.sizeStr.length), 0);
195
+ for (const info of fileInfos) {
196
+ const pathPadding = " ".repeat(Math.max(2, longestPathLength - info.relativeDisplayPath.length + 2));
197
+ const sizePadded = info.sizeStr.padStart(longestSizeLength);
198
+ console.log(`${info.coloredPath}${pathPadding}\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\x1b[0m`);
154
199
  }
155
200
  }
156
201
  }
157
- l(`Compiled successfully! (${f}ms)`, "success");
202
+ log(`Compiled successfully! (${duration}ms)`, "success");
158
203
  }
159
- } catch (e) {
160
- let t = Date.now() - o;
161
- l(`Compilation failed after ${t}ms: ${e.message}`, "error");
204
+ } catch (err) {
205
+ const duration = Date.now() - startTime;
206
+ log(`Compilation failed after ${duration}ms: ${errorMessage(err)}`, "error");
162
207
  }
163
208
  };
164
209
  return {
165
210
  async buildStart() {
166
- let e = await d();
167
- if (e.length === 0) return;
168
- let t = await f(e);
169
- for (let e of t) this.addWatchFile(e);
170
- await p(e);
211
+ const resolved = await resolveConfigs();
212
+ if (resolved.length === 0) return;
213
+ const watchFiles = await getWatchFiles(resolved);
214
+ for (const file of watchFiles) this.addWatchFile(file);
215
+ await runBuilds(resolved);
171
216
  },
172
217
  name: "unplugin-style-dictionary",
173
218
  vite: {
174
- configResolved(e) {
175
- c = e.root || process.cwd();
219
+ configResolved(config) {
220
+ root = config.root || process.cwd();
176
221
  },
177
- async configureServer(e) {
178
- let n = await d();
179
- if (n.length === 0) return;
180
- let r = await f(n);
181
- e.watcher.add(r), e.watcher.on("all", async (n, i) => {
182
- if (!o(i, r)) return;
183
- let a = await d();
184
- await p(a, t.basename(i));
185
- let s = await f(a);
186
- e.watcher.add(s);
222
+ async configureServer(server) {
223
+ const resolved = await resolveConfigs();
224
+ if (resolved.length === 0) return;
225
+ const filesToWatch = await getWatchFiles(resolved);
226
+ server.watcher.add(filesToWatch);
227
+ server.watcher.on("all", (_event, file) => {
228
+ if (!matchesWatchedFile(file, filesToWatch)) return;
229
+ (async () => {
230
+ try {
231
+ const currentResolved = await resolveConfigs();
232
+ await runBuilds(currentResolved, path.basename(file));
233
+ const newWatches = await getWatchFiles(currentResolved);
234
+ server.watcher.add(newWatches);
235
+ } catch (err) {
236
+ log(`Rebuild failed: ${errorMessage(err)}`, "error");
237
+ }
238
+ })();
187
239
  });
188
240
  }
189
241
  },
190
- async watchChange(e) {
191
- let n = await d();
192
- if (n.length === 0) return;
193
- let r = await f(n);
194
- if (o(e, r)) {
195
- await p(n, t.basename(e));
196
- for (let e of r) this.addWatchFile(e);
197
- }
242
+ async watchChange(id) {
243
+ const resolved = await resolveConfigs();
244
+ if (resolved.length === 0) return;
245
+ const watchFiles = await getWatchFiles(resolved);
246
+ if (!matchesWatchedFile(id, watchFiles)) return;
247
+ await runBuilds(resolved, path.basename(id));
248
+ for (const file of watchFiles) this.addWatchFile(file);
198
249
  }
199
250
  };
200
- }, f = /* #__PURE__ */ a(d);
251
+ };
252
+ const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory);
201
253
  //#endregion
202
- export { f as default, f as unplugin, o as matchesWatchedFile, d as unpluginFactory };
254
+ export { unplugin as default, unplugin, matchesWatchedFile, unpluginFactory };
203
255
 
204
256
  //# sourceMappingURL=index.js.map
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 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 { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport * from './types.js'\n\n// Whether `file` matches one of the resolved config/token watch patterns.\n// Shared by the Vite-specific `configureServer` watcher and the universal\n// `watchChange` hook — both need it, and both must skip files that don't\n// match: without this filter, `watchChange` reacts to *any* changed\n// module-graph file, including this plugin's own generated output (since\n// consuming code imports it). Every regenerate is itself a \"change\", which\n// without filtering re-triggers a rebuild forever.\nexport function matchesWatchedFile(file: string, patterns: string[]): boolean {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n return patterns.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\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// 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\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// `matchesWatchedFile` tests its globs unanchored, and a leftover\n// `vars.css.tmp` would match a `*.css` watch. The pid and counter make the\n// name unique, so two writes of the same destination — parallel platforms in\n// one build, or two builds overlapping — never share a temporary file.\nlet temporaryFileCounter = 0\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 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 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.\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\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\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()\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 {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<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 let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n if (item.config.endsWith('.json')) {\n const content = fs.readFileSync(item.config, 'utf-8')\n configObj = JSON.parse(content)\n } else {\n const fileUrl = pathToFileURL(item.config).href\n const module = await import(`${fileUrl}?t=${Date.now()}`)\n configObj = module.default || module\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${(err as Error).message}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, 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 return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\n\n for (const item of resolvedConfigs) {\n const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\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 silentSD.volume = atomicVolume\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent && silentSD.platforms) {\n for (const platformName of Object.keys(silentSD.platforms)) {\n const platform = silentSD.platforms[platformName]\n if (platform && platform.files) {\n const buildPath = platform.buildPath || ''\n for (const file of platform.files) {\n if (file && 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 }\n }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\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\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\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 // Ignore errors reading individual files\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(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${(err as Error).message}`,\n 'error',\n )\n }\n }\n\n return {\n async buildStart() {\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, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n server.watcher.on('all', async (_event, file) => {\n if (!matchesWatchedFile(file, filesToWatch)) return\n\n // Re-resolve configs to handle added/removed configs or changes to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(file))\n\n // Dynamically update the watch list in case the configurations changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n })\n },\n },\n\n async watchChange(id) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const watchFiles = await getWatchFiles(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 non-matching files here is what keeps this\n // from rebuilding forever.\n if (!matchesWatchedFile(id, watchFiles)) return\n\n await runBuilds(resolved, path.basename(id))\n\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\n}\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Q,IAAI;GACpC;GAEA,MAAM,gBAAgB,GAAuB;IAC3C,IAAM,IAAW,MAAM,EAAe;IACtC,IAAI,EAAS,WAAW,GAAG;IAE3B,IAAM,IAAe,MAAM,EAAc,CAAQ;IAKjD,AAFA,EAAO,QAAQ,IAAI,CAAY,GAE/B,EAAO,QAAQ,GAAG,OAAO,OAAO,GAAQ,MAAS;KAC/C,IAAI,CAAC,EAAmB,GAAM,CAAY,GAAG;KAG7C,IAAM,IAAkB,MAAM,EAAe;KAC7C,MAAM,EAAU,GAAiB,EAAK,SAAS,CAAI,CAAC;KAGpD,IAAM,IAAa,MAAM,EAAc,CAAe;KACtD,EAAO,QAAQ,IAAI,CAAU;IAC/B,CAAC;GACH;EACF;EAEA,MAAM,YAAY,GAAI;GACpB,IAAM,IAAW,MAAM,EAAe;GACtC,IAAI,EAAS,WAAW,GAAG;GAE3B,IAAM,IAAa,MAAM,EAAc,CAAQ;GAM1C,MAAmB,GAAI,CAAU,GAEtC;UAAM,EAAU,GAAU,EAAK,SAAS,CAAE,CAAC;IAE3C,KAAK,IAAM,KAAQ,GACjB,KAAK,aAAa,CAAI;GAHmB;EAK7C;CACF;AACF,GAEa,IAA2B,kBAAe,CAAe"}
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 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 { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport type * from './types.js'\n\n// Whether `file` matches one of the resolved config/token watch patterns.\n// Shared by the Vite-specific `configureServer` watcher and the universal\n// `watchChange` hook — both need it, and both must skip files that don't\n// match: without this filter, `watchChange` reacts to *any* changed\n// module-graph file, including this plugin's own generated output (since\n// consuming code imports it). Every regenerate is itself a \"change\", which\n// without filtering re-triggers a rebuild forever.\nexport function matchesWatchedFile(file: string, patterns: string[]): boolean {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n return patterns.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\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\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.\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 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// `matchesWatchedFile` tests its globs unanchored, and a leftover\n// `vars.css.tmp` would match a `*.css` watch. The pid and counter make the\n// name unique, so two writes of the same destination — parallel platforms in\n// one build, or two builds overlapping — never share a temporary file.\nlet temporaryFileCounter = 0\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 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 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\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\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()\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 {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<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 let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n let loaded: unknown\n\n if (item.config.endsWith('.json')) {\n loaded = JSON.parse(fs.readFileSync(item.config, 'utf-8'))\n } else {\n const fileUrl = pathToFileURL(item.config).href\n // Sequential on purpose: a config module runs arbitrary code at\n // import time — `registerFormat` and friends — and Style\n // Dictionary's registries are global, so importing several at\n // once would interleave those registrations.\n loaded = unwrapDefault(await import(`${fileUrl}?t=${Date.now()}`))\n }\n\n if (isConfig(loaded)) {\n configObj = loaded\n } else {\n log(\n `Config file did not resolve to a configuration object: ${item.config}`,\n 'error',\n )\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${errorMessage(err)}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, 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 return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\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 const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\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 silentSD.volume = atomicVolume\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent) {\n for (const platform of Object.values(silentSD.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 }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\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\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\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 // Ignore errors reading individual files\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(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\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 }\n\n return {\n async buildStart() {\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, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n // chokidar types its listener as returning void and does not await\n // what it is handed, so handing it an async function left every\n // rejection floating — `runBuilds` catches its own, but\n // `resolveConfigs` and `getWatchFiles` do not. Launching the work\n // explicitly and catching here is what keeps a bad config on disk\n // from surfacing as an unhandled rejection that kills the dev server.\n server.watcher.on('all', (_event, file) => {\n if (!matchesWatchedFile(file, filesToWatch)) return\n\n void (async () => {\n try {\n // Re-resolve configs to handle added/removed configs or changes\n // to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(file))\n\n // Dynamically update the watch list in case the configurations\n // changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n } catch (err) {\n log(`Rebuild failed: ${errorMessage(err)}`, 'error')\n }\n })()\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 const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const watchFiles = await getWatchFiles(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 non-matching files here is what keeps this\n // from rebuilding forever.\n if (!matchesWatchedFile(id, watchFiles)) return\n\n await runBuilds(resolved, path.basename(id))\n\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\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;GAM/C,IAAI,CAAC,mBAAmB,IAAI,UAAU,GAAG;GAEzC,MAAM,UAAU,UAAU,KAAK,SAAS,EAAE,CAAC;GAE3C,KAAK,MAAM,QAAQ,YACjB,KAAK,aAAa,IAAI;EAE1B;CACF;AACF;AAEA,MAAa,WAA2B,+BAAe,eAAe"}
@@ -1,2 +1,6 @@
1
- declare const _default: (options?: import('./types.js').UnpluginStyleDictionaryOptions | undefined) => import('rolldown').Plugin<any>;
2
- export default _default;
1
+ import { UnpluginStyleDictionaryOptions } from "./types.js";
2
+ //#region src/rolldown.d.ts
3
+ declare const _default: (options?: UnpluginStyleDictionaryOptions | undefined) => import("rolldown").Plugin<any>;
4
+ //#endregion
5
+ export { _default as default };
6
+ //# sourceMappingURL=rolldown.d.ts.map
package/dist/rolldown.js CHANGED
@@ -1,7 +1,7 @@
1
- import e from "./index.js";
1
+ import unplugin from "./index.js";
2
2
  //#region src/rolldown.ts
3
- var t = e.rolldown;
3
+ var rolldown_default = unplugin.rolldown;
4
4
  //#endregion
5
- export { t as default };
5
+ export { rolldown_default as default };
6
6
 
7
7
  //# sourceMappingURL=rolldown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rolldown.js","names":[],"sources":["../src/rolldown.ts"],"sourcesContent":["import { unplugin } from './index.js'\n\nexport default unplugin.rolldown\n"],"mappings":";;AAEA,IAAA,IAAe,EAAS"}
1
+ {"version":3,"file":"rolldown.js","names":[],"sources":["../src/rolldown.ts"],"sourcesContent":["import { unplugin } from './index.js'\n\nexport default unplugin.rolldown\n"],"mappings":";;AAEA,IAAA,mBAAe,SAAS"}
package/dist/rollup.d.ts CHANGED
@@ -1,2 +1,6 @@
1
- declare const _default: (options?: import('./types.js').UnpluginStyleDictionaryOptions | undefined) => import('rollup').Plugin<any>;
2
- export default _default;
1
+ import { UnpluginStyleDictionaryOptions } from "./types.js";
2
+ //#region src/rollup.d.ts
3
+ declare const _default: (options?: UnpluginStyleDictionaryOptions | undefined) => import("rollup").Plugin<any>;
4
+ //#endregion
5
+ export { _default as default };
6
+ //# sourceMappingURL=rollup.d.ts.map
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
- import e from "./index.js";
1
+ import unplugin from "./index.js";
2
2
  //#region src/rollup.ts
3
- var t = e.rollup;
3
+ var rollup_default = unplugin.rollup;
4
4
  //#endregion
5
- export { t as default };
5
+ export { rollup_default as default };
6
6
 
7
7
  //# sourceMappingURL=rollup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.js","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import { unplugin } from './index.js'\n\nexport default unplugin.rollup\n"],"mappings":";;AAEA,IAAA,IAAe,EAAS"}
1
+ {"version":3,"file":"rollup.js","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import { unplugin } from './index.js'\n\nexport default unplugin.rollup\n"],"mappings":";;AAEA,IAAA,iBAAe,SAAS"}