@csszyx/unplugin 0.14.5 → 0.15.1

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 (52) hide show
  1. package/README.md +4 -3
  2. package/dist/index.cjs +8 -7
  3. package/dist/index.d.cts +70 -3
  4. package/dist/index.d.mts +70 -3
  5. package/dist/index.mjs +4 -4
  6. package/dist/next-config.d.cts +1 -2
  7. package/dist/next-config.d.mts +1 -2
  8. package/dist/next-prebuild.cjs +9 -5
  9. package/dist/next-prebuild.d.cts +4 -2
  10. package/dist/next-prebuild.d.mts +4 -2
  11. package/dist/next-prebuild.mjs +8 -4
  12. package/dist/next-turbo-loader.cjs +20 -14
  13. package/dist/next-turbo-loader.d.cts +1 -1
  14. package/dist/next-turbo-loader.d.mts +1 -1
  15. package/dist/next-turbo-loader.mjs +19 -13
  16. package/dist/next-watcher.cjs +2 -2
  17. package/dist/next-watcher.d.cts +2 -2
  18. package/dist/next-watcher.d.mts +2 -2
  19. package/dist/next-watcher.mjs +2 -2
  20. package/dist/postcss.cjs +124 -0
  21. package/dist/postcss.d.cts +42 -0
  22. package/dist/postcss.d.mts +42 -0
  23. package/dist/postcss.mjs +107 -0
  24. package/dist/shared/{unplugin.RGzhYt-D.cjs → unplugin.8KYddE6x.cjs} +394 -226
  25. package/dist/shared/{unplugin.CPEWNSA0.d.cts → unplugin.BGog1Bib.d.cts} +9 -6
  26. package/dist/shared/{unplugin.CPEWNSA0.d.mts → unplugin.BGog1Bib.d.mts} +9 -6
  27. package/dist/shared/{unplugin.BU0O4IkX.mjs → unplugin.BLptVbUe.mjs} +22 -61
  28. package/dist/shared/{unplugin.BXYakiXt.d.cts → unplugin.BT7PqYuK.d.cts} +53 -55
  29. package/dist/shared/{unplugin.BXYakiXt.d.mts → unplugin.BT7PqYuK.d.mts} +53 -55
  30. package/dist/shared/{unplugin.Cji6O5jv.cjs → unplugin.BWnmKv07.cjs} +32 -69
  31. package/dist/shared/{unplugin.NlPvn5P4.mjs → unplugin.Bk9o8_RZ.mjs} +2 -6
  32. package/dist/shared/{unplugin.VtXstzEh.cjs → unplugin.BzF0V2kw.cjs} +6 -11
  33. package/dist/shared/{unplugin.CdZxp0x-.d.mts → unplugin.COlI0dJs.d.mts} +1 -1
  34. package/dist/shared/{unplugin.BnRf0Tvd.mjs → unplugin.D68hyqgb.mjs} +347 -178
  35. package/dist/shared/{unplugin.DN95k991.mjs → unplugin.DAzgbtuZ.mjs} +2 -2
  36. package/dist/shared/unplugin.DDSWQJYX.cjs +289 -0
  37. package/dist/shared/unplugin.DH_ij6cf.mjs +258 -0
  38. package/dist/shared/{unplugin.BZPdvVcj.mjs → unplugin.DK0b4fr7.mjs} +105 -127
  39. package/dist/shared/{unplugin.D8BxOOkA.cjs → unplugin.J6ue_lRJ.cjs} +121 -142
  40. package/dist/shared/{unplugin.DVbPNK3W.cjs → unplugin.gksolKh2.cjs} +6 -6
  41. package/dist/shared/{unplugin.xeED_qwh.d.cts → unplugin.rWOMecQs.d.cts} +1 -1
  42. package/dist/vite.cjs +4 -4
  43. package/dist/vite.d.cts +2 -2
  44. package/dist/vite.d.mts +1 -1
  45. package/dist/vite.mjs +4 -4
  46. package/dist/webpack.cjs +4 -4
  47. package/dist/webpack.d.cts +2 -1
  48. package/dist/webpack.d.mts +1 -1
  49. package/dist/webpack.mjs +4 -4
  50. package/package.json +19 -9
  51. package/dist/shared/unplugin.B3XoSRB8.mjs +0 -40
  52. package/dist/shared/unplugin.BkRah5Ot.cjs +0 -48
@@ -2,10 +2,10 @@
2
2
 
3
3
  const path = require('node:path');
4
4
  const fs = require('node:fs');
5
+ const safelistSource = require('./unplugin.DDSWQJYX.cjs');
5
6
  const node_crypto = require('node:crypto');
6
7
  const node_os = require('node:os');
7
8
  const lockfile = require('proper-lockfile');
8
- const htmlEscape = require('./unplugin.BkRah5Ot.cjs');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
11
 
@@ -25,13 +25,12 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
25
25
  const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
26
26
  const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
27
27
 
28
- const DEFAULT_RENAME_RETRIES = 5;
29
- const DEFAULT_RENAME_RETRY_DELAY_MS = 10;
30
28
  const DEFAULT_STALE_LOCK_MS = 3e4;
31
29
  const STALE_RECOVERY_DISABLED_MS = 2147483647;
32
- function resolveNextSafelistStatePaths(rootDir, cacheDir = ".csszyx/cache", outputFile = "csszyx-classes.html") {
30
+ function resolveNextSafelistStatePaths(rootDir, cacheDir = ".csszyx/cache", outputFile = safelistSource.SAFELIST_FILE) {
33
31
  const resolvedCacheDir = path__namespace.resolve(rootDir, cacheDir);
34
32
  return {
33
+ rootDir: path__namespace.resolve(rootDir),
35
34
  cacheDir: resolvedCacheDir,
36
35
  shardsDir: path__namespace.join(resolvedCacheDir, "safelist-shards"),
37
36
  snapshotPath: path__namespace.join(resolvedCacheDir, "safelist.snapshot.json"),
@@ -44,7 +43,7 @@ function writeNextSafelistShard(shardsDir, input, options = {}) {
44
43
  if (isExistingShardEquivalent(filePath, shard)) {
45
44
  return { filePath, changed: false };
46
45
  }
47
- atomicWriteFileSync(filePath, `${JSON.stringify(shard, null, 2)}
46
+ safelistSource.atomicWriteFileSync(filePath, `${JSON.stringify(shard, null, 2)}
48
47
  `, options);
49
48
  return { filePath, changed: true };
50
49
  }
@@ -62,14 +61,15 @@ function materializeNextSafelist(paths, options = {}) {
62
61
  recordsBySource.set(record.data.sourcePath, record);
63
62
  }
64
63
  }
65
- const sortedSources = [...recordsBySource.values()].map(({ data }) => [data.sourcePath, htmlEscape.sortStrings(new Set(data.classes))]).sort(([left], [right]) => left.localeCompare(right));
66
- const classNames = htmlEscape.sortStrings(new Set(sortedSources.flatMap(([, classSet]) => classSet)));
64
+ const sortedSources = [...recordsBySource.values()].map(({ data }) => [data.sourcePath, safelistSource.sortStrings(new Set(data.classes))]).sort(([left], [right]) => left.localeCompare(right));
65
+ const classNames = safelistSource.sortStrings(new Set(sortedSources.flatMap(([, classSet]) => classSet)));
67
66
  const snapshot = {
68
67
  version: 1,
69
68
  sources: sortedSources.map(([sourcePath, classSet]) => [sourcePath, classSet])
70
69
  };
71
- atomicWriteFileSync(paths.outputPath, renderTailwindSourceHtml(classNames), options);
72
- atomicWriteFileSync(paths.snapshotPath, `${JSON.stringify(snapshot, null, 2)}
70
+ safelistSource.atomicWriteFileSync(paths.outputPath, safelistSource.renderSafelistFile(classNames), options);
71
+ safelistSource.removeLegacySafelists(paths.rootDir, console.warn);
72
+ safelistSource.atomicWriteFileSync(paths.snapshotPath, `${JSON.stringify(snapshot, null, 2)}
73
73
  `, options);
74
74
  return {
75
75
  classCount: classNames.length,
@@ -100,17 +100,17 @@ function acquireNextSafelistStateLock(lockPath, pidOrOptions = {}) {
100
100
  } catch (error) {
101
101
  const existing2 = readLockMetadata(lockPath);
102
102
  if (existing2) {
103
- throw new Error(formatLiveLockError(existing2));
103
+ throw new NextSafelistStateLockedError(existing2);
104
104
  }
105
105
  throw error;
106
106
  }
107
107
  const existing = readLockMetadata(lockPath);
108
108
  if (existing && isLockLive(existing, options)) {
109
109
  releaseAdvisory();
110
- throw new Error(formatLiveLockError(existing));
110
+ throw new NextSafelistStateLockedError(existing);
111
111
  }
112
112
  try {
113
- atomicWriteFileSync(lockPath, `${JSON.stringify(metadata, null, 2)}
113
+ safelistSource.atomicWriteFileSync(lockPath, `${JSON.stringify(metadata, null, 2)}
114
114
  `);
115
115
  } catch (error) {
116
116
  releaseAdvisory();
@@ -118,7 +118,7 @@ function acquireNextSafelistStateLock(lockPath, pidOrOptions = {}) {
118
118
  }
119
119
  let released = false;
120
120
  const writeCurrentMetadata = (updatedAt) => {
121
- atomicWriteFileSync(lockPath, `${JSON.stringify({ ...metadata, updatedAt }, null, 2)}
121
+ safelistSource.atomicWriteFileSync(lockPath, `${JSON.stringify({ ...metadata, updatedAt }, null, 2)}
122
122
  `);
123
123
  };
124
124
  return {
@@ -148,40 +148,6 @@ function acquireNextSafelistStateLock(lockPath, pidOrOptions = {}) {
148
148
  }
149
149
  };
150
150
  }
151
- function atomicWriteFileSync(file, content, options = {}) {
152
- const dir = path__namespace.dirname(file);
153
- const tmp = path__namespace.join(
154
- dir,
155
- `.tmp-${path__namespace.basename(file)}-${process.pid}-${Date.now()}-${node_crypto.randomUUID()}`
156
- );
157
- fs__namespace.mkdirSync(dir, { recursive: true });
158
- fs__namespace.writeFileSync(tmp, content, "utf8");
159
- try {
160
- atomicRenameWithRetry(tmp, file, options);
161
- } catch (error) {
162
- try {
163
- fs__namespace.rmSync(tmp, { force: true });
164
- } catch {
165
- }
166
- throw error;
167
- }
168
- }
169
- function atomicRenameWithRetry(from, to, options = {}) {
170
- const maxRetries = options.maxRetries ?? DEFAULT_RENAME_RETRIES;
171
- const retryDelayMs = options.retryDelayMs ?? DEFAULT_RENAME_RETRY_DELAY_MS;
172
- const renameSync = options.renameSync ?? fs__namespace.renameSync;
173
- for (let attempt = 0; ; attempt++) {
174
- try {
175
- renameSync(from, to);
176
- return;
177
- } catch (error) {
178
- if (!isRetryableRenameError(error) || attempt >= maxRetries) {
179
- throw error;
180
- }
181
- sleepSync(retryDelayMs);
182
- }
183
- }
184
- }
185
151
  function isExistingShardEquivalent(filePath, shard) {
186
152
  try {
187
153
  const parsed = JSON.parse(fs__namespace.readFileSync(filePath, "utf8"));
@@ -195,7 +161,7 @@ function sameClasses(left, right) {
195
161
  }
196
162
  function normalizeShardInput(input) {
197
163
  const sourcePath = path__namespace.resolve(input.sourcePath);
198
- const classes = htmlEscape.sortStrings(
164
+ const classes = safelistSource.sortStrings(
199
165
  new Set(input.classes.map((className) => className.trim()).filter(Boolean))
200
166
  );
201
167
  const cacheKey = input.cacheKey ?? node_crypto.createHash("sha256").update(sourcePath).update("\0").update(input.sourceHash).digest("hex");
@@ -252,15 +218,6 @@ function normalizeShardRecord(filePath, data) {
252
218
  })
253
219
  };
254
220
  }
255
- function renderTailwindSourceHtml(classNames) {
256
- if (classNames.length === 0) {
257
- return "<!-- csszyx Next safelist: empty -->\n";
258
- }
259
- const structuralHtml = classNames.map((className) => `<div class="${htmlEscape.escapeHtmlAttribute(className)}"></div>`).join("\n");
260
- const scannerCandidates = htmlEscape.renderTailwindScannerCandidates(classNames);
261
- return `${structuralHtml}
262
- ${scannerCandidates}`;
263
- }
264
221
  function createLockMetadata(options) {
265
222
  const now = new Date(options.now ?? Date.now()).toISOString();
266
223
  const pid = options.pid ?? process.pid;
@@ -357,6 +314,18 @@ function isProcessAlive(pid) {
357
314
  return false;
358
315
  }
359
316
  }
317
+ class NextSafelistStateLockedError extends Error {
318
+ holder;
319
+ /**
320
+ * @param holder - metadata read from the lock file.
321
+ */
322
+ constructor(holder) {
323
+ super(formatLiveLockError(holder));
324
+ this.name = "NextSafelistStateLockedError";
325
+ this.holder = holder;
326
+ }
327
+ }
328
+ const NEXT_WATCH_LOCK_COMMAND = "csszyx next watch";
360
329
  function formatLiveLockError(metadata) {
361
330
  return [
362
331
  `csszyx Next safelist state is already locked by process ${metadata.pid}.`,
@@ -366,15 +335,6 @@ function formatLiveLockError(metadata) {
366
335
  `updatedAt=${metadata.updatedAt}`
367
336
  ].join(" ");
368
337
  }
369
- function isRetryableRenameError(error) {
370
- return typeof error === "object" && error !== null && "code" in error && (error.code === "EBUSY" || error.code === "EPERM" || error.code === "EACCES");
371
- }
372
- function sleepSync(ms) {
373
- if (ms <= 0) {
374
- return;
375
- }
376
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
377
- }
378
338
 
379
339
  function createNextCacheIdentity(input) {
380
340
  const configHash = hashString(stableStringify(input.config));
@@ -410,7 +370,7 @@ function stableStringify(value) {
410
370
  }
411
371
  function pickEnv(env, envKeys) {
412
372
  const selected = {};
413
- for (const key of htmlEscape.sortStrings(new Set(envKeys))) {
373
+ for (const key of safelistSource.sortStrings(new Set(envKeys))) {
414
374
  const value = env[key];
415
375
  if (value !== void 0) {
416
376
  selected[key] = value;
@@ -426,7 +386,7 @@ function resolveNextGenerationManifestPath(rootDir, cacheDir = ".csszyx/cache")
426
386
  return path__namespace.resolve(rootDir, cacheDir, "generation-manifest.json");
427
387
  }
428
388
  function writeNextGenerationManifest(manifestPath, manifest, options = {}) {
429
- atomicWriteFileSync(
389
+ safelistSource.atomicWriteFileSync(
430
390
  manifestPath,
431
391
  `${JSON.stringify(normalizeManifest(manifest), null, 2)}
432
392
  `,
@@ -535,6 +495,7 @@ function isNestedPackageRoot(parentRoot, candidateRoot) {
535
495
 
536
496
  function createNextStateContext(input) {
537
497
  const rootResolution = resolveNextAppRoot(input);
498
+ safelistSource.assertNoLegacySourceStylesheet(rootResolution.root);
538
499
  const cacheDir = resolveNextAppCacheDir(rootResolution.root, input.cacheDir);
539
500
  const identity = createNextCacheIdentity({
540
501
  root: rootResolution.root,
@@ -598,7 +559,7 @@ function runNextWatcherCycle(context, options = {}) {
598
559
  const lock = acquireNextSafelistStateLock(lockPath, {
599
560
  root: context.root,
600
561
  mode: context.manifestExpectation.mode,
601
- command: "csszyx next watch",
562
+ command: NEXT_WATCH_LOCK_COMMAND,
602
563
  ...options.lockOptions
603
564
  });
604
565
  try {
@@ -632,6 +593,8 @@ function runNextWatcherCycle(context, options = {}) {
632
593
  }
633
594
  }
634
595
 
596
+ exports.NEXT_WATCH_LOCK_COMMAND = NEXT_WATCH_LOCK_COMMAND;
597
+ exports.NextSafelistStateLockedError = NextSafelistStateLockedError;
635
598
  exports.createNextStateContext = createNextStateContext;
636
599
  exports.readNextGenerationManifest = readNextGenerationManifest;
637
600
  exports.runNextWatcherCycle = runNextWatcherCycle;
@@ -1,14 +1,10 @@
1
1
  import * as path from 'node:path';
2
2
  import { extractCrossModuleRegistryEntries, extractCrossModuleForwards } from '@csszyx/compiler';
3
+ import { n as normalizePathSeparators } from './unplugin.DH_ij6cf.mjs';
3
4
  import * as fs from 'node:fs';
4
5
  import { existsSync, statSync } from 'node:fs';
5
6
  import { createHash, randomUUID } from 'node:crypto';
6
7
 
7
- const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
8
- function normalizePathSeparators(value) {
9
- return value.split(WINDOWS_PATH_SEPARATOR).join("/");
10
- }
11
-
12
8
  const TSCONFIG_CANDIDATES = ["tsconfig.json", "jsconfig.json", "tsconfig.app.json"];
13
9
  const MAX_EXTENDS_DEPTH = 8;
14
10
  function collectSpecifierAliases(rootDir, resolveAlias) {
@@ -549,4 +545,4 @@ function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChar
549
545
  return total;
550
546
  }
551
547
 
552
- export { MAX_FORWARD_HOPS as M, resolveProviderPathWith as a, recordResolvedEntry as b, collectSpecifierAliases as c, isReadableProviderFile as d, createTransformCacheKey as e, forwardVisitKey as f, readTransformCache as g, recordSzvRegistryFile as h, importedSpecifiersIn as i, recordCrossModuleForwards as j, recordSzObjectRegistryFile as k, resolveCrossModuleStaticsFor as l, evictOldTransformCacheEntries as m, normalizePathSeparators as n, mayExportSzvFactories as o, evictMemoryCacheToBudget as p, resolveProviderPath as q, resolveTransformCacheDir as r, specifierBases as s, writeTransformCache as w };
548
+ export { MAX_FORWARD_HOPS as M, resolveProviderPathWith as a, recordResolvedEntry as b, collectSpecifierAliases as c, isReadableProviderFile as d, createTransformCacheKey as e, forwardVisitKey as f, readTransformCache as g, evictOldTransformCacheEntries as h, importedSpecifiersIn as i, recordSzvRegistryFile as j, recordCrossModuleForwards as k, recordSzObjectRegistryFile as l, mayExportSzvFactories as m, resolveCrossModuleStaticsFor as n, resolveProviderPath as o, evictMemoryCacheToBudget as p, resolveTransformCacheDir as r, specifierBases as s, writeTransformCache as w };
@@ -2,6 +2,7 @@
2
2
 
3
3
  const path = require('node:path');
4
4
  const compiler = require('@csszyx/compiler');
5
+ const safelistSource = require('./unplugin.DDSWQJYX.cjs');
5
6
  const fs = require('node:fs');
6
7
  const node_crypto = require('node:crypto');
7
8
 
@@ -20,11 +21,6 @@ function _interopNamespaceCompat(e) {
20
21
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
21
22
  const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
22
23
 
23
- const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
24
- function normalizePathSeparators(value) {
25
- return value.split(WINDOWS_PATH_SEPARATOR).join("/");
26
- }
27
-
28
24
  const TSCONFIG_CANDIDATES = ["tsconfig.json", "jsconfig.json", "tsconfig.app.json"];
29
25
  const MAX_EXTENDS_DEPTH = 8;
30
26
  function collectSpecifierAliases(rootDir, resolveAlias) {
@@ -115,12 +111,12 @@ function aliasedSpecifierBases(specifier, aliases) {
115
111
  continue;
116
112
  }
117
113
  if (!specifier.startsWith(alias.find)) continue;
118
- bases.push(normalizePathSeparators(alias.replacement + specifier.slice(alias.find.length)));
114
+ bases.push(safelistSource.normalizePathSeparators(alias.replacement + specifier.slice(alias.find.length)));
119
115
  }
120
116
  return bases;
121
117
  }
122
118
  function absolute(directory, target) {
123
- const resolved = normalizePathSeparators(path__namespace.resolve(directory, target));
119
+ const resolved = safelistSource.normalizePathSeparators(path__namespace.resolve(directory, target));
124
120
  const declaredTrailingSlash = target.endsWith("/") || target.endsWith("\\");
125
121
  return declaredTrailingSlash && !resolved.endsWith("/") ? `${resolved}/` : resolved;
126
122
  }
@@ -189,7 +185,7 @@ function recordSzObjectRegistryFile(registry, filePath, content) {
189
185
  );
190
186
  }
191
187
  function replaceEntriesOfKind(registry, filePath, kind, entries) {
192
- const key = normalizePathSeparators(filePath);
188
+ const key = safelistSource.normalizePathSeparators(filePath);
193
189
  const byName = emptyNameIndex();
194
190
  for (const [name, recorded] of Object.entries(registry.get(key) ?? {})) {
195
191
  if (recorded.kind !== kind) byName[name] = recorded;
@@ -211,7 +207,7 @@ const EMITTED_EXTENSION_SOURCES = [
211
207
  [".cjs", [".cts"]]
212
208
  ];
213
209
  function recordCrossModuleForwards(index, filePath, content) {
214
- const key = normalizePathSeparators(filePath);
210
+ const key = safelistSource.normalizePathSeparators(filePath);
215
211
  const forwards = compiler.extractCrossModuleForwards(content, filePath);
216
212
  if (forwards.length === 0) index.delete(key);
217
213
  else index.set(key, forwards);
@@ -321,7 +317,7 @@ function importedSpecifiersIn(source) {
321
317
  }
322
318
  function specifierBases(specifier, directory, aliases) {
323
319
  if (specifier.startsWith(".")) {
324
- return [normalizePathSeparators(path__namespace.resolve(directory, specifier))];
320
+ return [safelistSource.normalizePathSeparators(path__namespace.resolve(directory, specifier))];
325
321
  }
326
322
  return aliasedSpecifierBases(specifier, aliases);
327
323
  }
@@ -574,7 +570,6 @@ exports.forwardVisitKey = forwardVisitKey;
574
570
  exports.importedSpecifiersIn = importedSpecifiersIn;
575
571
  exports.isReadableProviderFile = isReadableProviderFile;
576
572
  exports.mayExportSzvFactories = mayExportSzvFactories;
577
- exports.normalizePathSeparators = normalizePathSeparators;
578
573
  exports.readTransformCache = readTransformCache;
579
574
  exports.recordCrossModuleForwards = recordCrossModuleForwards;
580
575
  exports.recordResolvedEntry = recordResolvedEntry;
@@ -1,4 +1,4 @@
1
- import { a as NextSafelistMaterializeResult, b as NextSafelistStateLockOptions, A as AtomicWriteOptions } from './unplugin.CPEWNSA0.mjs';
1
+ import { a as NextSafelistMaterializeResult, b as NextSafelistStateLockOptions, A as AtomicWriteOptions } from './unplugin.BGog1Bib.mjs';
2
2
 
3
3
  /** Options for one synchronous watcher materialization cycle. */
4
4
  interface NextWatcherCycleOptions {