@csszyx/unplugin 0.9.0 → 0.9.2

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 (43) hide show
  1. package/dist/index.cjs +19 -2
  2. package/dist/index.d.cts +91 -5
  3. package/dist/index.d.mts +90 -3
  4. package/dist/index.mjs +4 -2
  5. package/dist/next-prebuild.cjs +148 -0
  6. package/dist/next-prebuild.d.cts +66 -0
  7. package/dist/next-prebuild.d.mts +66 -0
  8. package/dist/next-prebuild.mjs +131 -0
  9. package/dist/next-turbo-loader.cjs +210 -0
  10. package/dist/next-turbo-loader.d.cts +68 -0
  11. package/dist/next-turbo-loader.d.mts +66 -0
  12. package/dist/next-turbo-loader.mjs +190 -0
  13. package/dist/next-watcher.cjs +237 -0
  14. package/dist/next-watcher.d.cts +106 -0
  15. package/dist/next-watcher.d.mts +106 -0
  16. package/dist/next-watcher.mjs +219 -0
  17. package/dist/shared/unplugin.8er8o6rn.mjs +276 -0
  18. package/dist/shared/unplugin.B_U4rZvG.cjs +281 -0
  19. package/dist/shared/{unplugin.BEOG6ePC.mjs → unplugin.BbtspS8t.mjs} +1436 -324
  20. package/dist/shared/unplugin.BceVw1eW.mjs +184 -0
  21. package/dist/shared/unplugin.BtQzlC2C.mjs +567 -0
  22. package/dist/shared/{unplugin.CL0F6RZa.cjs → unplugin.CFp386gH.cjs} +1456 -327
  23. package/dist/shared/unplugin.CPEWNSA0.d.cts +77 -0
  24. package/dist/shared/unplugin.CPEWNSA0.d.mts +77 -0
  25. package/dist/shared/unplugin.CScQRdTp.d.cts +15 -0
  26. package/dist/shared/unplugin.CScQRdTp.d.mts +15 -0
  27. package/dist/shared/unplugin.CdZxp0x-.d.mts +16 -0
  28. package/dist/shared/unplugin.DLrBgECN.d.cts +282 -0
  29. package/dist/shared/unplugin.DLrBgECN.d.mts +282 -0
  30. package/dist/shared/unplugin.DUxdYaSG.cjs +205 -0
  31. package/dist/shared/unplugin.s62yJbu1.cjs +591 -0
  32. package/dist/shared/unplugin.xeED_qwh.d.cts +16 -0
  33. package/dist/vite.cjs +3 -1
  34. package/dist/vite.d.cts +2 -1
  35. package/dist/vite.d.mts +2 -1
  36. package/dist/vite.mjs +3 -1
  37. package/dist/webpack.cjs +3 -1
  38. package/dist/webpack.d.cts +2 -1
  39. package/dist/webpack.d.mts +2 -1
  40. package/dist/webpack.mjs +3 -1
  41. package/package.json +41 -8
  42. package/dist/shared/unplugin.DUbr5w-N.d.cts +0 -49
  43. package/dist/shared/unplugin.DUbr5w-N.d.mts +0 -49
@@ -0,0 +1,591 @@
1
+ 'use strict';
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
5
+ const node_crypto = require('node:crypto');
6
+ const node_os = require('node:os');
7
+ const lockfile = require('proper-lockfile');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
+
11
+ function _interopNamespaceCompat(e) {
12
+ if (e && typeof e === 'object' && 'default' in e) return e;
13
+ const n = Object.create(null);
14
+ if (e) {
15
+ for (const k in e) {
16
+ n[k] = e[k];
17
+ }
18
+ }
19
+ n.default = e;
20
+ return n;
21
+ }
22
+
23
+ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
24
+ const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
25
+ const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
26
+
27
+ const DEFAULT_RENAME_RETRIES = 5;
28
+ const DEFAULT_RENAME_RETRY_DELAY_MS = 10;
29
+ const DEFAULT_STALE_LOCK_MS = 3e4;
30
+ function resolveNextSafelistStatePaths(rootDir, cacheDir = ".csszyx/cache", outputFile = "csszyx-classes.html") {
31
+ const resolvedCacheDir = path__namespace.resolve(rootDir, cacheDir);
32
+ return {
33
+ cacheDir: resolvedCacheDir,
34
+ shardsDir: path__namespace.join(resolvedCacheDir, "safelist-shards"),
35
+ snapshotPath: path__namespace.join(resolvedCacheDir, "safelist.snapshot.json"),
36
+ outputPath: path__namespace.resolve(rootDir, outputFile)
37
+ };
38
+ }
39
+ function writeNextSafelistShard(shardsDir, input, options = {}) {
40
+ const shard = normalizeShardInput(input);
41
+ const filePath = path__namespace.join(shardsDir, `${shard.cacheKey}.json`);
42
+ if (isExistingShardEquivalent(filePath, shard)) {
43
+ return { filePath, changed: false };
44
+ }
45
+ atomicWriteFileSync(filePath, `${JSON.stringify(shard, null, 2)}
46
+ `, options);
47
+ return { filePath, changed: true };
48
+ }
49
+ function materializeNextSafelist(paths, options = {}) {
50
+ const recordsBySource = /* @__PURE__ */ new Map();
51
+ let tombstonedSourceCount = 0;
52
+ for (const record of readShardRecords(paths.shardsDir)) {
53
+ if (!fs__namespace.existsSync(record.data.sourcePath)) {
54
+ fs__namespace.rmSync(record.filePath, { force: true });
55
+ tombstonedSourceCount++;
56
+ continue;
57
+ }
58
+ const previous = recordsBySource.get(record.data.sourcePath);
59
+ if (!previous || record.data.timestamp >= previous.data.timestamp) {
60
+ recordsBySource.set(record.data.sourcePath, record);
61
+ }
62
+ }
63
+ const sortedSources = [...recordsBySource.values()].map(({ data }) => [data.sourcePath, [...new Set(data.classes)].sort()]).sort(([left], [right]) => left.localeCompare(right));
64
+ const classNames = [...new Set(sortedSources.flatMap(([, classSet]) => classSet))].sort();
65
+ const snapshot = {
66
+ version: 1,
67
+ sources: sortedSources.map(([sourcePath, classSet]) => [sourcePath, classSet])
68
+ };
69
+ atomicWriteFileSync(paths.outputPath, renderTailwindSourceHtml(classNames), options);
70
+ atomicWriteFileSync(paths.snapshotPath, `${JSON.stringify(snapshot, null, 2)}
71
+ `, options);
72
+ return {
73
+ classCount: classNames.length,
74
+ sourceCount: sortedSources.length,
75
+ tombstonedSourceCount,
76
+ shardCount: recordsBySource.size
77
+ };
78
+ }
79
+ function acquireNextSafelistStateLock(lockPath, pidOrOptions = {}) {
80
+ const options = typeof pidOrOptions === "number" ? { pid: pidOrOptions } : pidOrOptions;
81
+ const metadata = createLockMetadata(options);
82
+ const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_LOCK_MS;
83
+ fs__namespace.mkdirSync(path__namespace.dirname(lockPath), { recursive: true });
84
+ let releaseAdvisory;
85
+ try {
86
+ releaseAdvisory = lockfile__default.lockSync(lockPath, {
87
+ realpath: false,
88
+ stale: staleAfterMs,
89
+ update: Math.max(1e3, Math.floor(staleAfterMs / 2)),
90
+ retries: 0
91
+ });
92
+ } catch (error) {
93
+ const existing2 = readLockMetadata(lockPath);
94
+ if (existing2) {
95
+ throw new Error(formatLiveLockError(existing2));
96
+ }
97
+ throw error;
98
+ }
99
+ const existing = readLockMetadata(lockPath);
100
+ if (existing && isLockLive(existing, options)) {
101
+ releaseAdvisory();
102
+ throw new Error(formatLiveLockError(existing));
103
+ }
104
+ try {
105
+ atomicWriteFileSync(lockPath, `${JSON.stringify(metadata, null, 2)}
106
+ `);
107
+ } catch (error) {
108
+ releaseAdvisory();
109
+ throw error;
110
+ }
111
+ let released = false;
112
+ const writeCurrentMetadata = (updatedAt) => {
113
+ atomicWriteFileSync(lockPath, `${JSON.stringify({ ...metadata, updatedAt }, null, 2)}
114
+ `);
115
+ };
116
+ return {
117
+ lockPath,
118
+ token: metadata.token,
119
+ heartbeat: () => {
120
+ if (!released && readLockMetadata(lockPath)?.token === metadata.token) {
121
+ writeCurrentMetadata(new Date(options.now ?? Date.now()).toISOString());
122
+ }
123
+ },
124
+ release: () => {
125
+ if (released) {
126
+ return;
127
+ }
128
+ released = true;
129
+ try {
130
+ if (readLockMetadata(lockPath)?.token === metadata.token) {
131
+ fs__namespace.rmSync(lockPath, { force: true });
132
+ }
133
+ } catch {
134
+ } finally {
135
+ try {
136
+ releaseAdvisory?.();
137
+ } catch {
138
+ }
139
+ }
140
+ }
141
+ };
142
+ }
143
+ function atomicWriteFileSync(file, content, options = {}) {
144
+ const dir = path__namespace.dirname(file);
145
+ const tmp = path__namespace.join(
146
+ dir,
147
+ `.tmp-${path__namespace.basename(file)}-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
148
+ );
149
+ fs__namespace.mkdirSync(dir, { recursive: true });
150
+ fs__namespace.writeFileSync(tmp, content, "utf8");
151
+ try {
152
+ atomicRenameWithRetry(tmp, file, options);
153
+ } catch (error) {
154
+ try {
155
+ fs__namespace.rmSync(tmp, { force: true });
156
+ } catch {
157
+ }
158
+ throw error;
159
+ }
160
+ }
161
+ function atomicRenameWithRetry(from, to, options = {}) {
162
+ const maxRetries = options.maxRetries ?? DEFAULT_RENAME_RETRIES;
163
+ const retryDelayMs = options.retryDelayMs ?? DEFAULT_RENAME_RETRY_DELAY_MS;
164
+ const renameSync = options.renameSync ?? fs__namespace.renameSync;
165
+ for (let attempt = 0; ; attempt++) {
166
+ try {
167
+ renameSync(from, to);
168
+ return;
169
+ } catch (error) {
170
+ if (!isRetryableRenameError(error) || attempt >= maxRetries) {
171
+ throw error;
172
+ }
173
+ sleepSync(retryDelayMs);
174
+ }
175
+ }
176
+ }
177
+ function isExistingShardEquivalent(filePath, shard) {
178
+ try {
179
+ const parsed = JSON.parse(fs__namespace.readFileSync(filePath, "utf8"));
180
+ return parsed.version === 1 && parsed.sourcePath === shard.sourcePath && parsed.sourceHash === shard.sourceHash;
181
+ } catch {
182
+ return false;
183
+ }
184
+ }
185
+ function normalizeShardInput(input) {
186
+ const sourcePath = path__namespace.resolve(input.sourcePath);
187
+ const classes = [
188
+ ...new Set(input.classes.map((className) => className.trim()).filter(Boolean))
189
+ ].sort();
190
+ const cacheKey = input.cacheKey ?? node_crypto.createHash("sha256").update(sourcePath).update("\0").update(input.sourceHash).digest("hex");
191
+ return {
192
+ version: 1,
193
+ cacheKey,
194
+ sourcePath,
195
+ sourceHash: input.sourceHash,
196
+ classes,
197
+ timestamp: input.timestamp !== void 0 && Number.isFinite(input.timestamp) ? input.timestamp : Date.now(),
198
+ pid: input.pid ?? process.pid
199
+ };
200
+ }
201
+ function readShardRecords(shardsDir) {
202
+ let entries;
203
+ try {
204
+ entries = fs__namespace.readdirSync(shardsDir, { withFileTypes: true });
205
+ } catch {
206
+ return [];
207
+ }
208
+ const records = [];
209
+ for (const entry of entries) {
210
+ if (!entry.isFile() || !entry.name.endsWith(".json")) {
211
+ continue;
212
+ }
213
+ const filePath = path__namespace.join(shardsDir, entry.name);
214
+ try {
215
+ const parsed = JSON.parse(fs__namespace.readFileSync(filePath, "utf8"));
216
+ const record = normalizeShardRecord(filePath, parsed);
217
+ if (record) {
218
+ records.push(record);
219
+ } else {
220
+ fs__namespace.rmSync(filePath, { force: true });
221
+ }
222
+ } catch {
223
+ fs__namespace.rmSync(filePath, { force: true });
224
+ }
225
+ }
226
+ return records;
227
+ }
228
+ function normalizeShardRecord(filePath, data) {
229
+ if (data.version !== 1 || typeof data.cacheKey !== "string" || typeof data.sourcePath !== "string" || typeof data.sourceHash !== "string" || !Array.isArray(data.classes) || typeof data.timestamp !== "number" || typeof data.pid !== "number") {
230
+ return null;
231
+ }
232
+ return {
233
+ filePath,
234
+ data: normalizeShardInput({
235
+ cacheKey: data.cacheKey,
236
+ sourcePath: data.sourcePath,
237
+ sourceHash: data.sourceHash,
238
+ classes: data.classes,
239
+ timestamp: data.timestamp,
240
+ pid: data.pid
241
+ })
242
+ };
243
+ }
244
+ function renderTailwindSourceHtml(classNames) {
245
+ if (classNames.length === 0) {
246
+ return "<!-- csszyx Next safelist: empty -->\n";
247
+ }
248
+ return `${classNames.map((className) => `<div class="${escapeHtmlAttribute(className)}"></div>`).join("\n")}
249
+ `;
250
+ }
251
+ function escapeHtmlAttribute(value) {
252
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
253
+ }
254
+ function createLockMetadata(options) {
255
+ const now = new Date(options.now ?? Date.now()).toISOString();
256
+ const pid = options.pid ?? process.pid;
257
+ return {
258
+ version: 1,
259
+ pid,
260
+ token: options.token ?? node_crypto.createHash("sha256").update(`${pid}\0${now}\0${Math.random().toString(36)}`).digest("hex"),
261
+ hostname: node_os.hostname(),
262
+ root: path__namespace.resolve(options.root ?? process.cwd()),
263
+ mode: options.mode ?? "development",
264
+ command: options.command ?? process.argv.join(" "),
265
+ startedAt: now,
266
+ updatedAt: now
267
+ };
268
+ }
269
+ function readLockMetadata(lockPath) {
270
+ try {
271
+ const parsed = JSON.parse(
272
+ fs__namespace.readFileSync(lockPath, "utf8")
273
+ );
274
+ if (parsed.version !== 1 || typeof parsed.pid !== "number" || typeof parsed.token !== "string" || typeof parsed.hostname !== "string" || typeof parsed.root !== "string" || parsed.mode !== "development" && parsed.mode !== "production" || typeof parsed.command !== "string" || typeof parsed.startedAt !== "string" || typeof parsed.updatedAt !== "string") {
275
+ return null;
276
+ }
277
+ return {
278
+ version: 1,
279
+ pid: parsed.pid,
280
+ token: parsed.token,
281
+ hostname: parsed.hostname,
282
+ root: path__namespace.resolve(parsed.root),
283
+ mode: parsed.mode,
284
+ command: parsed.command,
285
+ startedAt: parsed.startedAt,
286
+ updatedAt: parsed.updatedAt
287
+ };
288
+ } catch {
289
+ return null;
290
+ }
291
+ }
292
+ function isLockLive(metadata, options) {
293
+ const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_LOCK_MS;
294
+ const updatedAt = Date.parse(metadata.updatedAt);
295
+ const now = options.now ?? Date.now();
296
+ if (Number.isFinite(updatedAt) && now - updatedAt > staleAfterMs) {
297
+ return false;
298
+ }
299
+ if (metadata.hostname !== (options.hostname ?? node_os.hostname())) {
300
+ return true;
301
+ }
302
+ return (options.isProcessAlive ?? isProcessAlive)(metadata.pid);
303
+ }
304
+ function isProcessAlive(pid) {
305
+ try {
306
+ process.kill(pid, 0);
307
+ return true;
308
+ } catch {
309
+ return false;
310
+ }
311
+ }
312
+ function formatLiveLockError(metadata) {
313
+ return [
314
+ `csszyx Next safelist state is already locked by process ${metadata.pid}.`,
315
+ `root=${metadata.root}`,
316
+ `mode=${metadata.mode}`,
317
+ `host=${metadata.hostname}`,
318
+ `updatedAt=${metadata.updatedAt}`
319
+ ].join(" ");
320
+ }
321
+ function isRetryableRenameError(error) {
322
+ return typeof error === "object" && error !== null && "code" in error && (error.code === "EBUSY" || error.code === "EPERM" || error.code === "EACCES");
323
+ }
324
+ function sleepSync(ms) {
325
+ if (ms <= 0) {
326
+ return;
327
+ }
328
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
329
+ }
330
+
331
+ function resolveNextGenerationManifestPath(rootDir, cacheDir = ".csszyx/cache") {
332
+ return path__namespace.resolve(rootDir, cacheDir, "generation-manifest.json");
333
+ }
334
+ function writeNextGenerationManifest(manifestPath, manifest, options = {}) {
335
+ atomicWriteFileSync(
336
+ manifestPath,
337
+ `${JSON.stringify(normalizeManifest(manifest), null, 2)}
338
+ `,
339
+ options
340
+ );
341
+ }
342
+ function readNextGenerationManifest(manifestPath) {
343
+ try {
344
+ return normalizeManifest(
345
+ JSON.parse(fs__namespace.readFileSync(manifestPath, "utf8"))
346
+ );
347
+ } catch {
348
+ return null;
349
+ }
350
+ }
351
+ function validateNextGenerationManifest(manifest, expected) {
352
+ if (!manifest) {
353
+ return { ok: false, reason: "missing or unreadable generation manifest" };
354
+ }
355
+ if (manifest.schema !== 1) {
356
+ return { ok: false, reason: `unsupported generation manifest schema ${manifest.schema}` };
357
+ }
358
+ if (!manifest.completed) {
359
+ return { ok: false, reason: "generation manifest is incomplete" };
360
+ }
361
+ if (manifest.root !== path__namespace.resolve(expected.root)) {
362
+ return { ok: false, reason: "generation manifest root does not match this Next app" };
363
+ }
364
+ if (manifest.configHash !== expected.configHash) {
365
+ return { ok: false, reason: "csszyx config hash changed" };
366
+ }
367
+ if (manifest.envHash !== expected.envHash) {
368
+ return { ok: false, reason: "csszyx env hash changed" };
369
+ }
370
+ if (manifest.nextVersion !== expected.nextVersion) {
371
+ return { ok: false, reason: "Next.js version changed" };
372
+ }
373
+ if (manifest.csszyxVersion !== expected.csszyxVersion) {
374
+ return { ok: false, reason: "csszyx version changed" };
375
+ }
376
+ if (manifest.nativeVersion !== expected.nativeVersion) {
377
+ return { ok: false, reason: "csszyx native engine version changed" };
378
+ }
379
+ if (manifest.mode !== expected.mode) {
380
+ return { ok: false, reason: "generation manifest mode changed" };
381
+ }
382
+ return { ok: true };
383
+ }
384
+ function normalizeManifest(manifest) {
385
+ if (manifest.schema !== 1 || typeof manifest.generation !== "string" || typeof manifest.root !== "string" || typeof manifest.configHash !== "string" || typeof manifest.envHash !== "string" || typeof manifest.nextVersion !== "string" || typeof manifest.csszyxVersion !== "string" || typeof manifest.nativeVersion !== "string" || manifest.mode !== "development" && manifest.mode !== "production" || typeof manifest.sourceCount !== "number" || typeof manifest.completed !== "boolean" || typeof manifest.createdAt !== "string") {
386
+ throw new Error("Invalid csszyx Next generation manifest.");
387
+ }
388
+ return {
389
+ ...manifest,
390
+ root: path__namespace.resolve(manifest.root),
391
+ sourceCount: Math.max(0, Math.trunc(manifest.sourceCount))
392
+ };
393
+ }
394
+
395
+ function createNextCacheIdentity(input) {
396
+ const configHash = hashString(stableStringify(input.config));
397
+ const envHash = hashString(stableStringify(pickEnv(input.env ?? {}, input.envKeys ?? [])));
398
+ const generation = hashString(
399
+ stableStringify({
400
+ root: input.root,
401
+ configHash,
402
+ envHash,
403
+ nextVersion: input.nextVersion,
404
+ csszyxVersion: input.csszyxVersion,
405
+ nativeVersion: input.nativeVersion,
406
+ mode: input.mode
407
+ })
408
+ );
409
+ return { configHash, envHash, generation };
410
+ }
411
+ function stableStringify(value) {
412
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
413
+ return JSON.stringify(value);
414
+ }
415
+ if (typeof value === "number") {
416
+ return Number.isFinite(value) ? JSON.stringify(value) : "null";
417
+ }
418
+ if (Array.isArray(value)) {
419
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
420
+ }
421
+ if (typeof value === "object") {
422
+ const entries = Object.entries(value).filter((entry) => entry[1] !== void 0).sort(([left], [right]) => left.localeCompare(right));
423
+ return `{${entries.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`;
424
+ }
425
+ return "null";
426
+ }
427
+ function pickEnv(env, envKeys) {
428
+ const selected = {};
429
+ for (const key of [...new Set(envKeys)].sort()) {
430
+ const value = env[key];
431
+ if (value !== void 0) {
432
+ selected[key] = value;
433
+ }
434
+ }
435
+ return selected;
436
+ }
437
+ function hashString(value) {
438
+ return `sha256:${node_crypto.createHash("sha256").update(value).digest("hex")}`;
439
+ }
440
+
441
+ function resolveNextAppRoot(input) {
442
+ if (input.explicitRoot) {
443
+ return { root: path__namespace.resolve(input.explicitRoot), source: "explicit" };
444
+ }
445
+ if (input.loaderRootContext) {
446
+ const rootContextRoot = findNearestPackageRoot(input.loaderRootContext);
447
+ if (input.loaderContext) {
448
+ const loaderContextRoot = findNearestPackageRoot(input.loaderContext);
449
+ if (isNestedPackageRoot(rootContextRoot, loaderContextRoot)) {
450
+ return { root: loaderContextRoot, source: "loader-context" };
451
+ }
452
+ }
453
+ return { root: rootContextRoot, source: "loader-root-context" };
454
+ }
455
+ if (input.loaderContext) {
456
+ return { root: findNearestPackageRoot(input.loaderContext), source: "loader-context" };
457
+ }
458
+ return { root: findNearestPackageRoot(input.cwd ?? process.cwd()), source: "cwd" };
459
+ }
460
+ function resolveNextAppCacheDir(appRoot, cacheDir = ".csszyx/cache") {
461
+ return path__namespace.resolve(appRoot, cacheDir);
462
+ }
463
+ function findNearestPackageRoot(start) {
464
+ let current = path__namespace.resolve(start);
465
+ try {
466
+ const stat = fs__namespace.statSync(current);
467
+ if (stat.isFile()) {
468
+ current = path__namespace.dirname(current);
469
+ }
470
+ } catch {
471
+ }
472
+ for (; ; ) {
473
+ if (fs__namespace.existsSync(path__namespace.join(current, "package.json"))) {
474
+ return current;
475
+ }
476
+ const parent = path__namespace.dirname(current);
477
+ if (parent === current) {
478
+ return path__namespace.resolve(start);
479
+ }
480
+ current = parent;
481
+ }
482
+ }
483
+ function isNestedPackageRoot(parentRoot, candidateRoot) {
484
+ const relative = path__namespace.relative(parentRoot, candidateRoot);
485
+ return Boolean(relative) && !relative.startsWith("..") && !path__namespace.isAbsolute(relative);
486
+ }
487
+
488
+ function createNextStateContext(input) {
489
+ const rootResolution = resolveNextAppRoot(input);
490
+ const cacheDir = resolveNextAppCacheDir(rootResolution.root, input.cacheDir);
491
+ const identity = createNextCacheIdentity({
492
+ root: rootResolution.root,
493
+ config: input.config,
494
+ env: input.env,
495
+ envKeys: input.envKeys,
496
+ nextVersion: input.nextVersion,
497
+ csszyxVersion: input.csszyxVersion,
498
+ nativeVersion: input.nativeVersion,
499
+ mode: input.mode
500
+ });
501
+ const manifestExpectation = {
502
+ root: rootResolution.root,
503
+ configHash: identity.configHash,
504
+ envHash: identity.envHash,
505
+ nextVersion: input.nextVersion,
506
+ csszyxVersion: input.csszyxVersion,
507
+ nativeVersion: input.nativeVersion,
508
+ mode: input.mode
509
+ };
510
+ return {
511
+ root: rootResolution.root,
512
+ rootSource: rootResolution.source,
513
+ cacheDir,
514
+ safelist: resolveNextSafelistStatePaths(
515
+ rootResolution.root,
516
+ relativeCacheDir(rootResolution.root, cacheDir),
517
+ input.safelistOutputFile
518
+ ),
519
+ manifestPath: resolveNextGenerationManifestPath(
520
+ rootResolution.root,
521
+ relativeCacheDir(rootResolution.root, cacheDir)
522
+ ),
523
+ identity,
524
+ manifestExpectation
525
+ };
526
+ }
527
+ function createNextGenerationManifestFromContext(context, sourceCount, createdAt = (/* @__PURE__ */ new Date()).toISOString()) {
528
+ return {
529
+ schema: 1,
530
+ generation: context.identity.generation,
531
+ root: context.root,
532
+ configHash: context.identity.configHash,
533
+ envHash: context.identity.envHash,
534
+ nextVersion: context.manifestExpectation.nextVersion,
535
+ csszyxVersion: context.manifestExpectation.csszyxVersion,
536
+ nativeVersion: context.manifestExpectation.nativeVersion,
537
+ mode: context.manifestExpectation.mode,
538
+ sourceCount,
539
+ completed: true,
540
+ createdAt
541
+ };
542
+ }
543
+ function relativeCacheDir(root, cacheDir) {
544
+ const relative = path__namespace.relative(root, cacheDir);
545
+ return relative && !relative.startsWith("..") && !path__namespace.isAbsolute(relative) ? relative : cacheDir;
546
+ }
547
+
548
+ function runNextWatcherCycle(context, options = {}) {
549
+ const lockPath = path__namespace.join(context.cacheDir, "state.lock");
550
+ const lock = acquireNextSafelistStateLock(lockPath, {
551
+ root: context.root,
552
+ mode: context.manifestExpectation.mode,
553
+ command: "csszyx next watch",
554
+ ...options.lockOptions
555
+ });
556
+ try {
557
+ const materialize = materializeNextSafelist(context.safelist, options.writeOptions);
558
+ writeNextGenerationManifest(
559
+ context.manifestPath,
560
+ createNextGenerationManifestFromContext(
561
+ context,
562
+ materialize.sourceCount,
563
+ options.createdAt
564
+ ),
565
+ options.writeOptions
566
+ );
567
+ const validation = validateNextGenerationManifest(
568
+ readNextGenerationManifest(context.manifestPath),
569
+ context.manifestExpectation
570
+ );
571
+ if (!validation.ok) {
572
+ throw new Error(
573
+ `[csszyx] Next watcher wrote an invalid generation manifest: ${validation.reason}`
574
+ );
575
+ }
576
+ lock.heartbeat();
577
+ return {
578
+ materialize,
579
+ manifestPath: context.manifestPath,
580
+ lockPath
581
+ };
582
+ } finally {
583
+ lock.release();
584
+ }
585
+ }
586
+
587
+ exports.createNextStateContext = createNextStateContext;
588
+ exports.readNextGenerationManifest = readNextGenerationManifest;
589
+ exports.runNextWatcherCycle = runNextWatcherCycle;
590
+ exports.validateNextGenerationManifest = validateNextGenerationManifest;
591
+ exports.writeNextSafelistShard = writeNextSafelistShard;
@@ -0,0 +1,16 @@
1
+ import { a as NextSafelistMaterializeResult, b as NextSafelistStateLockOptions, A as AtomicWriteOptions } from './unplugin.CPEWNSA0.cjs';
2
+
3
+ /** Options for one synchronous watcher materialization cycle. */
4
+ interface NextWatcherCycleOptions {
5
+ lockOptions?: NextSafelistStateLockOptions;
6
+ writeOptions?: AtomicWriteOptions;
7
+ createdAt?: string;
8
+ }
9
+ /** Result returned by one watcher materialization cycle. */
10
+ interface NextWatcherCycleResult {
11
+ materialize: NextSafelistMaterializeResult;
12
+ manifestPath: string;
13
+ lockPath: string;
14
+ }
15
+
16
+ export type { NextWatcherCycleResult as N, NextWatcherCycleOptions as a };
package/dist/vite.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const unplugin = require('./shared/unplugin.CL0F6RZa.cjs');
5
+ const unplugin = require('./shared/unplugin.CFp386gH.cjs');
6
6
  require('node:fs');
7
7
  require('node:module');
8
8
  require('node:path');
@@ -18,6 +18,8 @@ require('./css-mangler.cjs');
18
18
  require('postcss');
19
19
  require('postcss-selector-parser');
20
20
  require('node:crypto');
21
+ require('./shared/unplugin.DUxdYaSG.cjs');
22
+ require('postcss-value-parser');
21
23
 
22
24
 
23
25
 
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { v as vitePlugin } from './shared/unplugin.DUbr5w-N.cjs';
1
+ import { v as vitePlugin } from './shared/unplugin.DLrBgECN.cjs';
2
+ import '@csszyx/compiler';
2
3
  import '@csszyx/types';
3
4
  import 'esbuild';
4
5
  import 'rollup';
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { v as vitePlugin } from './shared/unplugin.DUbr5w-N.mjs';
1
+ import { v as vitePlugin } from './shared/unplugin.DLrBgECN.mjs';
2
+ import '@csszyx/compiler';
2
3
  import '@csszyx/types';
3
4
  import 'esbuild';
4
5
  import 'rollup';
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { v as vitePlugin } from './shared/unplugin.BEOG6ePC.mjs';
1
+ import { C as vitePlugin } from './shared/unplugin.BbtspS8t.mjs';
2
2
  import 'node:fs';
3
3
  import 'node:module';
4
4
  import 'node:path';
@@ -14,6 +14,8 @@ import './css-mangler.mjs';
14
14
  import 'postcss';
15
15
  import 'postcss-selector-parser';
16
16
  import 'node:crypto';
17
+ import './shared/unplugin.BceVw1eW.mjs';
18
+ import 'postcss-value-parser';
17
19
 
18
20
 
19
21
 
package/dist/webpack.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const unplugin = require('./shared/unplugin.CL0F6RZa.cjs');
5
+ const unplugin = require('./shared/unplugin.CFp386gH.cjs');
6
6
  require('node:fs');
7
7
  require('node:module');
8
8
  require('node:path');
@@ -18,6 +18,8 @@ require('./css-mangler.cjs');
18
18
  require('postcss');
19
19
  require('postcss-selector-parser');
20
20
  require('node:crypto');
21
+ require('./shared/unplugin.DUxdYaSG.cjs');
22
+ require('postcss-value-parser');
21
23
 
22
24
 
23
25
 
@@ -1,4 +1,5 @@
1
- import { w as webpackPlugin } from './shared/unplugin.DUbr5w-N.cjs';
1
+ import { w as webpackPlugin } from './shared/unplugin.DLrBgECN.cjs';
2
+ import '@csszyx/compiler';
2
3
  import '@csszyx/types';
3
4
  import 'esbuild';
4
5
  import 'rollup';
@@ -1,4 +1,5 @@
1
- import { w as webpackPlugin } from './shared/unplugin.DUbr5w-N.mjs';
1
+ import { w as webpackPlugin } from './shared/unplugin.DLrBgECN.mjs';
2
+ import '@csszyx/compiler';
2
3
  import '@csszyx/types';
3
4
  import 'esbuild';
4
5
  import 'rollup';