@csszyx/unplugin 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-HOQTC45W.js → chunk-GXGGTRUA.js} +356 -37
- package/dist/index.cjs +362 -35
- package/dist/index.d.cts +96 -1
- package/dist/index.d.ts +96 -1
- package/dist/index.js +17 -1
- package/dist/vite.cjs +346 -35
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +346 -35
- package/dist/webpack.js +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -30,11 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
assertNoRSCBoundaryViolation: () => assertNoRSCBoundaryViolation,
|
|
34
|
+
assertNoRSCGraphViolation: () => assertNoRSCGraphViolation,
|
|
33
35
|
createPostCSSPlugin: () => createPostCSSPlugin,
|
|
36
|
+
createRSCModuleRecord: () => createRSCModuleRecord,
|
|
34
37
|
default: () => unplugin,
|
|
35
38
|
esbuildPlugin: () => esbuildPlugin,
|
|
36
39
|
escapeCSSClassName: () => escapeCSSClassName,
|
|
40
|
+
findRSCBoundaryViolation: () => findRSCBoundaryViolation,
|
|
41
|
+
findRSCGraphViolation: () => findRSCGraphViolation,
|
|
37
42
|
hasTokens: () => hasTokens,
|
|
43
|
+
hasUseClientDirective: () => hasUseClientDirective,
|
|
44
|
+
hasUseServerDirective: () => hasUseServerDirective,
|
|
45
|
+
isRSCServerModule: () => isRSCServerModule,
|
|
38
46
|
mangleCSS: () => mangleCSS,
|
|
39
47
|
mangleCSSSync: () => mangleCSSSync,
|
|
40
48
|
mangleCodeClassesSync: () => mangleCodeClassesSync,
|
|
@@ -243,6 +251,303 @@ function createPostCSSPlugin(mangleMap, options = {}) {
|
|
|
243
251
|
};
|
|
244
252
|
}
|
|
245
253
|
|
|
254
|
+
// src/rsc-boundary.ts
|
|
255
|
+
var fs = __toESM(require("fs"), 1);
|
|
256
|
+
var path = __toESM(require("path"), 1);
|
|
257
|
+
var SERVER_DIRECTIVE_RE = /^['"]use server['"];?$/;
|
|
258
|
+
var CLIENT_DIRECTIVE_RE = /^['"]use client['"];?$/;
|
|
259
|
+
var RUNTIME_MODULES = /* @__PURE__ */ new Set([
|
|
260
|
+
"@csszyx/runtime",
|
|
261
|
+
"@csszyx/runtime/lite",
|
|
262
|
+
"csszyx",
|
|
263
|
+
"csszyx/lite"
|
|
264
|
+
]);
|
|
265
|
+
var FORBIDDEN_SYMBOLS = /* @__PURE__ */ new Set([
|
|
266
|
+
"_sz",
|
|
267
|
+
"_sz2",
|
|
268
|
+
"_sz3",
|
|
269
|
+
"_szIf",
|
|
270
|
+
"_szMerge",
|
|
271
|
+
"_szSwitch",
|
|
272
|
+
"__csszyx_runtime__"
|
|
273
|
+
]);
|
|
274
|
+
function hasUseServerDirective(code) {
|
|
275
|
+
for (const statement of readDirectivePrologue(code)) {
|
|
276
|
+
if (SERVER_DIRECTIVE_RE.test(statement)) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
if (CLIENT_DIRECTIVE_RE.test(statement)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
function hasUseClientDirective(code) {
|
|
286
|
+
for (const statement of readDirectivePrologue(code)) {
|
|
287
|
+
if (CLIENT_DIRECTIVE_RE.test(statement)) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
if (SERVER_DIRECTIVE_RE.test(statement)) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
function isRSCServerModule(code, id) {
|
|
297
|
+
if (hasUseServerDirective(code)) {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if (hasUseClientDirective(code)) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
return isNextAppRouterEntry(id);
|
|
304
|
+
}
|
|
305
|
+
function findRSCBoundaryViolation(code, id) {
|
|
306
|
+
if (!isRSCServerModule(code, id)) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
for (const imported of findRuntimeImports(code)) {
|
|
310
|
+
for (const symbol of imported.symbols) {
|
|
311
|
+
if (FORBIDDEN_SYMBOLS.has(symbol)) {
|
|
312
|
+
return {
|
|
313
|
+
symbol,
|
|
314
|
+
path: id,
|
|
315
|
+
importChain: [id, imported.source]
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function createRSCModuleRecord(code, id) {
|
|
323
|
+
const normalized = normalizeModuleId(id);
|
|
324
|
+
return {
|
|
325
|
+
id: normalized,
|
|
326
|
+
isServer: isRSCServerModule(code, normalized),
|
|
327
|
+
isClient: hasUseClientDirective(code),
|
|
328
|
+
imports: findLocalImportSources(code).map((source) => resolveLocalModule(normalized, source)).filter((resolved) => resolved !== null),
|
|
329
|
+
runtimeImports: findRuntimeImports(code).filter((imported) => imported.symbols.some((symbol) => FORBIDDEN_SYMBOLS.has(symbol)))
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function findRSCGraphViolation(records) {
|
|
333
|
+
for (const root of records.values()) {
|
|
334
|
+
if (!root.isServer) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const violation = walkRSCGraph(root, records, [root.id], /* @__PURE__ */ new Set([root.id]));
|
|
338
|
+
if (violation) {
|
|
339
|
+
return {
|
|
340
|
+
symbol: violation.symbol,
|
|
341
|
+
path: root.id,
|
|
342
|
+
importChain: violation.importChain
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
function assertNoRSCGraphViolation(records) {
|
|
349
|
+
const violation = findRSCGraphViolation(records);
|
|
350
|
+
if (!violation) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
throw new Error(formatRSCViolation(violation));
|
|
354
|
+
}
|
|
355
|
+
function isNextAppRouterEntry(id) {
|
|
356
|
+
const clean = id.split("?")[0]?.replace(/\\/g, "/") ?? id;
|
|
357
|
+
return /(^|\/)app\/.*\/?(?:page|layout|template|loading|error|not-found|global-error|default|route)\.[cm]?[tj]sx?$/.test(clean);
|
|
358
|
+
}
|
|
359
|
+
function assertNoRSCBoundaryViolation(code, id) {
|
|
360
|
+
const violation = findRSCBoundaryViolation(code, id);
|
|
361
|
+
if (!violation) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
throw new Error(formatRSCViolation(violation));
|
|
365
|
+
}
|
|
366
|
+
function formatRSCViolation(violation) {
|
|
367
|
+
return `csszyxRSCViolation: ${violation.symbol} imported in Server Component ${violation.path}
|
|
368
|
+
Import chain: ${violation.importChain.join(" -> ")}`;
|
|
369
|
+
}
|
|
370
|
+
function walkRSCGraph(current, records, chain, seen) {
|
|
371
|
+
if (current.isClient) {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
const runtime = current.runtimeImports[0];
|
|
375
|
+
const symbol = runtime?.symbols.find((s) => FORBIDDEN_SYMBOLS.has(s));
|
|
376
|
+
if (runtime && symbol) {
|
|
377
|
+
return {
|
|
378
|
+
symbol,
|
|
379
|
+
path: chain[0] ?? current.id,
|
|
380
|
+
importChain: [...chain, runtime.source]
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
for (const importedId of current.imports) {
|
|
384
|
+
if (seen.has(importedId)) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const next = records.get(importedId);
|
|
388
|
+
if (!next) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
seen.add(importedId);
|
|
392
|
+
const violation = walkRSCGraph(next, records, [...chain, importedId], seen);
|
|
393
|
+
if (violation) {
|
|
394
|
+
return violation;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
function readDirectivePrologue(code) {
|
|
400
|
+
const out = [];
|
|
401
|
+
let i = code.charCodeAt(0) === 65279 ? 1 : 0;
|
|
402
|
+
while (i < code.length) {
|
|
403
|
+
i = skipWhitespaceAndComments(code, i);
|
|
404
|
+
const quote = code[i];
|
|
405
|
+
if (quote !== '"' && quote !== "'") {
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
let j = i + 1;
|
|
409
|
+
let escaped = false;
|
|
410
|
+
while (j < code.length) {
|
|
411
|
+
const ch = code[j];
|
|
412
|
+
if (escaped) {
|
|
413
|
+
escaped = false;
|
|
414
|
+
} else if (ch === "\\") {
|
|
415
|
+
escaped = true;
|
|
416
|
+
} else if (ch === quote) {
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
j++;
|
|
420
|
+
}
|
|
421
|
+
if (j >= code.length) {
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
let end = j + 1;
|
|
425
|
+
while (end < code.length && /[ \t\r\n]/.test(code[end])) {
|
|
426
|
+
end++;
|
|
427
|
+
}
|
|
428
|
+
if (code[end] === ";") {
|
|
429
|
+
end++;
|
|
430
|
+
}
|
|
431
|
+
out.push(code.slice(i, end).trim());
|
|
432
|
+
i = end;
|
|
433
|
+
}
|
|
434
|
+
return out;
|
|
435
|
+
}
|
|
436
|
+
function skipWhitespaceAndComments(code, start) {
|
|
437
|
+
let i = start;
|
|
438
|
+
while (i < code.length) {
|
|
439
|
+
while (i < code.length && /\s/.test(code[i])) {
|
|
440
|
+
i++;
|
|
441
|
+
}
|
|
442
|
+
if (code.startsWith("//", i)) {
|
|
443
|
+
const next = code.indexOf("\n", i + 2);
|
|
444
|
+
i = next === -1 ? code.length : next + 1;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (code.startsWith("/*", i)) {
|
|
448
|
+
const next = code.indexOf("*/", i + 2);
|
|
449
|
+
i = next === -1 ? code.length : next + 2;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
return i;
|
|
455
|
+
}
|
|
456
|
+
function findRuntimeImports(code) {
|
|
457
|
+
const imports = [];
|
|
458
|
+
const staticImportRe = /import\s+(?!type\b)([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g;
|
|
459
|
+
const sideEffectImportRe = /import\s+['"]([^'"]+)['"]/g;
|
|
460
|
+
const dynamicImportRe = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
461
|
+
let match;
|
|
462
|
+
while ((match = staticImportRe.exec(code)) !== null) {
|
|
463
|
+
const clause = match[1];
|
|
464
|
+
const source = match[2];
|
|
465
|
+
if (!RUNTIME_MODULES.has(source)) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
imports.push({ source, symbols: readImportedSymbols(clause) });
|
|
469
|
+
}
|
|
470
|
+
while ((match = sideEffectImportRe.exec(code)) !== null) {
|
|
471
|
+
const source = match[1];
|
|
472
|
+
if (RUNTIME_MODULES.has(source)) {
|
|
473
|
+
imports.push({ source, symbols: [] });
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
while ((match = dynamicImportRe.exec(code)) !== null) {
|
|
477
|
+
const source = match[1];
|
|
478
|
+
if (RUNTIME_MODULES.has(source)) {
|
|
479
|
+
imports.push({ source, symbols: Array.from(FORBIDDEN_SYMBOLS) });
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return imports;
|
|
483
|
+
}
|
|
484
|
+
function findLocalImportSources(code) {
|
|
485
|
+
const out = [];
|
|
486
|
+
const staticImportRe = /import\s+(?!type\b)(?:[\s\S]*?\s+from\s+)?['"]([^'"]+)['"]/g;
|
|
487
|
+
const exportFromRe = /export\s+(?!type\b)(?:[\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g;
|
|
488
|
+
const dynamicImportRe = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
489
|
+
let match;
|
|
490
|
+
for (const re of [staticImportRe, exportFromRe, dynamicImportRe]) {
|
|
491
|
+
while ((match = re.exec(code)) !== null) {
|
|
492
|
+
const source = match[1];
|
|
493
|
+
if (source.startsWith(".") || source.startsWith("/")) {
|
|
494
|
+
out.push(source);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return out;
|
|
499
|
+
}
|
|
500
|
+
function normalizeModuleId(id) {
|
|
501
|
+
const clean = id.split("?")[0] ?? id;
|
|
502
|
+
try {
|
|
503
|
+
return fs.realpathSync.native(clean).replace(/\\/g, "/");
|
|
504
|
+
} catch {
|
|
505
|
+
return path.resolve(clean).replace(/\\/g, "/");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function resolveLocalModule(importer, source) {
|
|
509
|
+
const base = source.startsWith("/") ? source : path.resolve(path.dirname(importer), source);
|
|
510
|
+
const candidates = [
|
|
511
|
+
base,
|
|
512
|
+
`${base}.tsx`,
|
|
513
|
+
`${base}.ts`,
|
|
514
|
+
`${base}.jsx`,
|
|
515
|
+
`${base}.js`,
|
|
516
|
+
`${base}.mjs`,
|
|
517
|
+
`${base}.cjs`,
|
|
518
|
+
path.join(base, "index.tsx"),
|
|
519
|
+
path.join(base, "index.ts"),
|
|
520
|
+
path.join(base, "index.jsx"),
|
|
521
|
+
path.join(base, "index.js")
|
|
522
|
+
];
|
|
523
|
+
for (const candidate of candidates) {
|
|
524
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
525
|
+
return normalizeModuleId(candidate);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
function readImportedSymbols(clause) {
|
|
531
|
+
const symbols = [];
|
|
532
|
+
const named = clause.match(/\{([\s\S]*?)\}/);
|
|
533
|
+
if (named) {
|
|
534
|
+
for (const part of named[1].split(",")) {
|
|
535
|
+
const trimmed = part.trim();
|
|
536
|
+
if (!trimmed || trimmed.startsWith("type ")) {
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
const sourceName = trimmed.replace(/^type\s+/, "").split(/\s+as\s+/)[0]?.trim();
|
|
540
|
+
if (sourceName) {
|
|
541
|
+
symbols.push(sourceName);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (/\*\s+as\s+\w+/.test(clause)) {
|
|
546
|
+
symbols.push(...FORBIDDEN_SYMBOLS);
|
|
547
|
+
}
|
|
548
|
+
return symbols;
|
|
549
|
+
}
|
|
550
|
+
|
|
246
551
|
// src/theme-scanner.ts
|
|
247
552
|
var EMPTY_THEME = { colors: [], spacings: [], fonts: [], radii: [], shadows: [] };
|
|
248
553
|
function stripLayerWrappers(css) {
|
|
@@ -386,8 +691,8 @@ function hasTokens(theme) {
|
|
|
386
691
|
}
|
|
387
692
|
|
|
388
693
|
// src/unplugin.ts
|
|
389
|
-
var
|
|
390
|
-
var
|
|
694
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
695
|
+
var path2 = __toESM(require("path"), 1);
|
|
391
696
|
var import_compiler = require("@csszyx/compiler");
|
|
392
697
|
var import_core = require("@csszyx/core");
|
|
393
698
|
var import_svelte_adapter = require("@csszyx/svelte-adapter");
|
|
@@ -455,7 +760,7 @@ function injectHydrationData(html, mangleMap, checksum, options = {}) {
|
|
|
455
760
|
function transformIndexHtml(html, mangleMap, checksum, options = {}) {
|
|
456
761
|
return injectHydrationData(html, mangleMap, checksum, options);
|
|
457
762
|
}
|
|
458
|
-
function buildRecoveryManifest(tokens, options
|
|
763
|
+
function buildRecoveryManifest(tokens, options) {
|
|
459
764
|
const stripped = options.production === true;
|
|
460
765
|
const strippedDevOnlyPaths = [];
|
|
461
766
|
const sorted = {};
|
|
@@ -469,14 +774,14 @@ function buildRecoveryManifest(tokens, options = {}) {
|
|
|
469
774
|
strippedDevOnlyPaths.push(data.path);
|
|
470
775
|
continue;
|
|
471
776
|
}
|
|
472
|
-
sorted[key] = data;
|
|
777
|
+
sorted[key] = stripped ? { mode: data.mode, component: data.component, path: "" } : data;
|
|
473
778
|
}
|
|
474
779
|
const serialised = JSON.stringify(sorted);
|
|
475
780
|
const fullChecksum = (0, import_node_crypto.createHash)("sha256").update(serialised).digest("hex");
|
|
476
781
|
const checksum = fullChecksum.substring(0, 16);
|
|
477
782
|
const buildId = `${Date.now().toString(36)}-${fullChecksum.substring(0, 6)}`;
|
|
478
783
|
return {
|
|
479
|
-
manifest: { buildId, checksum, tokens: sorted },
|
|
784
|
+
manifest: { buildId, checksum, mangleChecksum: options.mangleChecksum, tokens: sorted },
|
|
480
785
|
strippedDevOnlyPaths
|
|
481
786
|
};
|
|
482
787
|
}
|
|
@@ -605,8 +910,8 @@ function runThemeScan(rootDir, scanCss) {
|
|
|
605
910
|
const patterns = Array.isArray(scanCss) ? scanCss : [scanCss];
|
|
606
911
|
const sourceFiles = [];
|
|
607
912
|
for (const pattern of patterns) {
|
|
608
|
-
const resolved =
|
|
609
|
-
if (
|
|
913
|
+
const resolved = path2.isAbsolute(pattern) ? pattern : path2.join(rootDir, pattern);
|
|
914
|
+
if (fs2.existsSync(resolved)) {
|
|
610
915
|
sourceFiles.push(resolved);
|
|
611
916
|
}
|
|
612
917
|
}
|
|
@@ -615,20 +920,20 @@ function runThemeScan(rootDir, scanCss) {
|
|
|
615
920
|
}
|
|
616
921
|
const themes = sourceFiles.map((f) => {
|
|
617
922
|
try {
|
|
618
|
-
return parseThemeBlocks(
|
|
923
|
+
return parseThemeBlocks(fs2.readFileSync(f, "utf-8"));
|
|
619
924
|
} catch {
|
|
620
925
|
return null;
|
|
621
926
|
}
|
|
622
927
|
}).filter((t) => t !== null);
|
|
623
928
|
const merged = mergeThemes(themes);
|
|
624
|
-
const outputPath =
|
|
929
|
+
const outputPath = path2.join(rootDir, ".csszyx", "theme.d.ts");
|
|
625
930
|
writeThemeDts({ outputPath, theme: merged, sourceFiles });
|
|
626
931
|
if (!_hasWarnedTsConfig) {
|
|
627
932
|
_hasWarnedTsConfig = true;
|
|
628
933
|
try {
|
|
629
934
|
const checkFile = (cfgPath) => {
|
|
630
|
-
if (
|
|
631
|
-
const content =
|
|
935
|
+
if (fs2.existsSync(cfgPath)) {
|
|
936
|
+
const content = fs2.readFileSync(cfgPath, "utf-8");
|
|
632
937
|
if (!content.includes(".csszyx")) {
|
|
633
938
|
console.warn(`
|
|
634
939
|
\x1B[33m\u26A0\uFE0F CSSzyx: Theme Auto-Scan enabled, but TypeScript isn't configured. Run "npx @csszyx/cli init" to fix.\x1B[0m
|
|
@@ -638,8 +943,8 @@ function runThemeScan(rootDir, scanCss) {
|
|
|
638
943
|
}
|
|
639
944
|
return false;
|
|
640
945
|
};
|
|
641
|
-
if (!checkFile(
|
|
642
|
-
checkFile(
|
|
946
|
+
if (!checkFile(path2.join(rootDir, "tsconfig.json"))) {
|
|
947
|
+
checkFile(path2.join(rootDir, "tsconfig.app.json"));
|
|
643
948
|
}
|
|
644
949
|
} catch {
|
|
645
950
|
}
|
|
@@ -819,13 +1124,15 @@ function mangleCodeClassesSync(code, mangleMap) {
|
|
|
819
1124
|
}
|
|
820
1125
|
function createCsszyxPlugins(options = {}) {
|
|
821
1126
|
const manglingEnabled = options.production?.mangle !== false;
|
|
1127
|
+
const astBudgetOverride = options.build?.astBudgetLimit;
|
|
822
1128
|
const state = {
|
|
823
1129
|
classes: /* @__PURE__ */ new Set(),
|
|
824
1130
|
mangleMap: {},
|
|
825
1131
|
checksum: "",
|
|
826
1132
|
finalized: false,
|
|
827
1133
|
rootDir: process.cwd(),
|
|
828
|
-
recoveryTokens: /* @__PURE__ */ new Map()
|
|
1134
|
+
recoveryTokens: /* @__PURE__ */ new Map(),
|
|
1135
|
+
rscModules: /* @__PURE__ */ new Map()
|
|
829
1136
|
};
|
|
830
1137
|
const SAFELIST_FILENAME = "csszyx-classes.html";
|
|
831
1138
|
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".tsx", ".jsx", ".ts", ".js"]);
|
|
@@ -834,16 +1141,16 @@ function createCsszyxPlugins(options = {}) {
|
|
|
834
1141
|
if (classes.size === 0) {
|
|
835
1142
|
return;
|
|
836
1143
|
}
|
|
837
|
-
const safelistPath =
|
|
1144
|
+
const safelistPath = path2.join(state.rootDir, SAFELIST_FILENAME);
|
|
838
1145
|
const classList = Array.from(classes).join(" ");
|
|
839
1146
|
const content = `<!-- Auto-generated by csszyx \u2014 DO NOT EDIT -->
|
|
840
1147
|
<!-- Tailwind CSS scans this file for class name detection -->
|
|
841
1148
|
<div class="${classList}"><div class="${classList}">x</div><div class="${classList}">x</div></div>
|
|
842
1149
|
`;
|
|
843
1150
|
try {
|
|
844
|
-
const existing =
|
|
1151
|
+
const existing = fs2.existsSync(safelistPath) ? fs2.readFileSync(safelistPath, "utf-8") : "";
|
|
845
1152
|
if (existing !== content) {
|
|
846
|
-
|
|
1153
|
+
fs2.writeFileSync(safelistPath, content);
|
|
847
1154
|
}
|
|
848
1155
|
} catch {
|
|
849
1156
|
}
|
|
@@ -854,23 +1161,23 @@ function createCsszyxPlugins(options = {}) {
|
|
|
854
1161
|
function scanDir(dir) {
|
|
855
1162
|
let entries;
|
|
856
1163
|
try {
|
|
857
|
-
entries =
|
|
1164
|
+
entries = fs2.readdirSync(dir, { withFileTypes: true });
|
|
858
1165
|
} catch {
|
|
859
1166
|
return;
|
|
860
1167
|
}
|
|
861
1168
|
for (const entry of entries) {
|
|
862
1169
|
if (entry.isDirectory()) {
|
|
863
1170
|
if (!IGNORE_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
|
|
864
|
-
scanDir(
|
|
1171
|
+
scanDir(path2.join(dir, entry.name));
|
|
865
1172
|
}
|
|
866
|
-
} else if (SOURCE_EXTENSIONS.has(
|
|
867
|
-
const filePath =
|
|
1173
|
+
} else if (SOURCE_EXTENSIONS.has(path2.extname(entry.name))) {
|
|
1174
|
+
const filePath = path2.join(dir, entry.name);
|
|
868
1175
|
try {
|
|
869
|
-
const content =
|
|
1176
|
+
const content = fs2.readFileSync(filePath, "utf-8");
|
|
870
1177
|
if (!content.includes("sz=") && !content.includes("sz:")) {
|
|
871
1178
|
continue;
|
|
872
1179
|
}
|
|
873
|
-
const result = (0, import_compiler.transformSourceCode)(content, filePath);
|
|
1180
|
+
const result = (0, import_compiler.transformSourceCode)(content, filePath, { astBudget: astBudgetOverride });
|
|
874
1181
|
if (!result.transformed) {
|
|
875
1182
|
continue;
|
|
876
1183
|
}
|
|
@@ -1058,14 +1365,17 @@ function createCsszyxPlugins(options = {}) {
|
|
|
1058
1365
|
* @returns transformed code with source map, or null if no changes were made
|
|
1059
1366
|
*/
|
|
1060
1367
|
transform(code, id) {
|
|
1368
|
+
if (/\.[tj]sx?(\?.*)?$/.test(id)) {
|
|
1369
|
+
assertNoRSCBoundaryViolation(code, id);
|
|
1370
|
+
}
|
|
1061
1371
|
if (/\.css(\?.*)?$/.test(id)) {
|
|
1062
1372
|
const hasTailwindImport = code.includes('@import "tailwindcss') || code.includes("@import 'tailwindcss");
|
|
1063
1373
|
if (hasTailwindImport && state.classes.size > 0) {
|
|
1064
1374
|
const candidates = Array.from(state.classes).filter((c) => c.length >= 2 && /^[a-z]/.test(c)).join(" ");
|
|
1065
1375
|
if (candidates) {
|
|
1066
|
-
const safelistPath =
|
|
1067
|
-
const cssDir =
|
|
1068
|
-
let relPath =
|
|
1376
|
+
const safelistPath = path2.join(state.rootDir, SAFELIST_FILENAME).replace(/\\/g, "/");
|
|
1377
|
+
const cssDir = path2.dirname(id).replace(/\\/g, "/");
|
|
1378
|
+
let relPath = path2.posix.relative(cssDir, safelistPath);
|
|
1069
1379
|
if (!relPath.startsWith(".")) {
|
|
1070
1380
|
relPath = "./" + relPath;
|
|
1071
1381
|
}
|
|
@@ -1104,7 +1414,7 @@ ${sourceDirective}`
|
|
|
1104
1414
|
transformed = true;
|
|
1105
1415
|
}
|
|
1106
1416
|
} else {
|
|
1107
|
-
const result = (0, import_compiler.transformSourceCode)(code, id);
|
|
1417
|
+
const result = (0, import_compiler.transformSourceCode)(code, id, { astBudget: astBudgetOverride });
|
|
1108
1418
|
transformedCode = result.code;
|
|
1109
1419
|
usesRuntime = result.usesRuntime;
|
|
1110
1420
|
usesMerge = result.usesMerge;
|
|
@@ -1169,6 +1479,11 @@ ${sourceDirective}`
|
|
|
1169
1479
|
transformed = true;
|
|
1170
1480
|
}
|
|
1171
1481
|
}
|
|
1482
|
+
if (/\.[tj]sx?(\?.*)?$/.test(id)) {
|
|
1483
|
+
assertNoRSCBoundaryViolation(transformedCode, id);
|
|
1484
|
+
const record = createRSCModuleRecord(transformedCode, id);
|
|
1485
|
+
state.rscModules.set(record.id, record);
|
|
1486
|
+
}
|
|
1172
1487
|
if (transformed || transformedCode.includes("class=") || transformedCode.includes("className=")) {
|
|
1173
1488
|
if (szClasses !== void 0) {
|
|
1174
1489
|
for (const cls of szClasses) {
|
|
@@ -1184,6 +1499,7 @@ ${sourceDirective}`
|
|
|
1184
1499
|
/** Finalizes the mangle map after all source modules have been processed. */
|
|
1185
1500
|
buildEnd() {
|
|
1186
1501
|
finalizeMangleMap();
|
|
1502
|
+
assertNoRSCGraphViolation(state.rscModules);
|
|
1187
1503
|
if (manglingEnabled && Object.keys(state.mangleMap).length > 0) {
|
|
1188
1504
|
globalThis.__csszyx_ssr_mangle_map = state.mangleMap;
|
|
1189
1505
|
}
|
|
@@ -1206,8 +1522,8 @@ ${sourceDirective}`
|
|
|
1206
1522
|
compiler.hooks.thisCompilation.tap("csszyx:theme-deps", (compilation) => {
|
|
1207
1523
|
const root = compiler.context || process.cwd();
|
|
1208
1524
|
for (const pattern of patterns) {
|
|
1209
|
-
const resolved =
|
|
1210
|
-
if (
|
|
1525
|
+
const resolved = path2.isAbsolute(pattern) ? pattern : path2.join(root, pattern);
|
|
1526
|
+
if (fs2.existsSync(resolved)) {
|
|
1211
1527
|
compilation.fileDependencies.add(resolved);
|
|
1212
1528
|
}
|
|
1213
1529
|
}
|
|
@@ -1237,14 +1553,14 @@ ${sourceDirective}`
|
|
|
1237
1553
|
const patterns = Array.isArray(scanCss) ? scanCss : [scanCss];
|
|
1238
1554
|
const root = ctx.server.config.root || process.cwd();
|
|
1239
1555
|
const isWatched = patterns.some((p) => {
|
|
1240
|
-
const resolved =
|
|
1556
|
+
const resolved = path2.isAbsolute(p) ? p : path2.join(root, p);
|
|
1241
1557
|
return ctx.file === resolved;
|
|
1242
1558
|
});
|
|
1243
1559
|
if (isWatched) {
|
|
1244
1560
|
runThemeScan(root, scanCss);
|
|
1245
1561
|
}
|
|
1246
1562
|
}
|
|
1247
|
-
if (!SOURCE_EXTENSIONS.has(
|
|
1563
|
+
if (!SOURCE_EXTENSIONS.has(path2.extname(ctx.file))) {
|
|
1248
1564
|
return;
|
|
1249
1565
|
}
|
|
1250
1566
|
if (ctx.file.includes("node_modules")) {
|
|
@@ -1252,7 +1568,7 @@ ${sourceDirective}`
|
|
|
1252
1568
|
}
|
|
1253
1569
|
let fileContent, result;
|
|
1254
1570
|
try {
|
|
1255
|
-
fileContent =
|
|
1571
|
+
fileContent = fs2.readFileSync(ctx.file, "utf-8");
|
|
1256
1572
|
} catch {
|
|
1257
1573
|
return;
|
|
1258
1574
|
}
|
|
@@ -1260,7 +1576,7 @@ ${sourceDirective}`
|
|
|
1260
1576
|
return;
|
|
1261
1577
|
}
|
|
1262
1578
|
try {
|
|
1263
|
-
result = (0, import_compiler.transformSourceCode)(fileContent, ctx.file);
|
|
1579
|
+
result = (0, import_compiler.transformSourceCode)(fileContent, ctx.file, { astBudget: astBudgetOverride });
|
|
1264
1580
|
} catch {
|
|
1265
1581
|
return;
|
|
1266
1582
|
}
|
|
@@ -1276,7 +1592,7 @@ ${sourceDirective}`
|
|
|
1276
1592
|
}
|
|
1277
1593
|
if (state.classes.size > sizeBefore) {
|
|
1278
1594
|
writeSafelistFile(state.classes);
|
|
1279
|
-
const safelistPath =
|
|
1595
|
+
const safelistPath = path2.join(state.rootDir, SAFELIST_FILENAME);
|
|
1280
1596
|
ctx.server.watcher.emit("change", safelistPath);
|
|
1281
1597
|
}
|
|
1282
1598
|
},
|
|
@@ -1298,7 +1614,10 @@ ${sourceDirective}`
|
|
|
1298
1614
|
const isProduction = process.env.NODE_ENV === "production";
|
|
1299
1615
|
const { manifest, strippedDevOnlyPaths } = buildRecoveryManifest(
|
|
1300
1616
|
state.recoveryTokens,
|
|
1301
|
-
{
|
|
1617
|
+
{
|
|
1618
|
+
production: isProduction,
|
|
1619
|
+
mangleChecksum: state.checksum
|
|
1620
|
+
}
|
|
1302
1621
|
);
|
|
1303
1622
|
if (strippedDevOnlyPaths.length > 0) {
|
|
1304
1623
|
console.warn(
|
|
@@ -1512,10 +1831,18 @@ var esbuildPlugin = (options = {}) => {
|
|
|
1512
1831
|
};
|
|
1513
1832
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1514
1833
|
0 && (module.exports = {
|
|
1834
|
+
assertNoRSCBoundaryViolation,
|
|
1835
|
+
assertNoRSCGraphViolation,
|
|
1515
1836
|
createPostCSSPlugin,
|
|
1837
|
+
createRSCModuleRecord,
|
|
1516
1838
|
esbuildPlugin,
|
|
1517
1839
|
escapeCSSClassName,
|
|
1840
|
+
findRSCBoundaryViolation,
|
|
1841
|
+
findRSCGraphViolation,
|
|
1518
1842
|
hasTokens,
|
|
1843
|
+
hasUseClientDirective,
|
|
1844
|
+
hasUseServerDirective,
|
|
1845
|
+
isRSCServerModule,
|
|
1519
1846
|
mangleCSS,
|
|
1520
1847
|
mangleCSSSync,
|
|
1521
1848
|
mangleCodeClassesSync,
|