@csszyx/unplugin 0.11.11 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +6 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +4 -3
- package/dist/next-prebuild.cjs +2 -2
- package/dist/next-prebuild.mjs +2 -2
- package/dist/next-turbo-loader.cjs +4 -52
- package/dist/next-turbo-loader.mjs +3 -51
- package/dist/shared/{unplugin.B2RUVK6Z.mjs → unplugin.B9vpjOhD.mjs} +194 -34
- package/dist/shared/{unplugin.CJcFsJcf.cjs → unplugin.BK3XVHe8.cjs} +197 -35
- package/dist/shared/{unplugin.BZq6FKn2.cjs → unplugin.Bb5TeU9B.cjs} +1 -1
- package/dist/shared/unplugin.C2lHQFii.cjs +114 -0
- package/dist/shared/unplugin.CBMJufQ8.mjs +108 -0
- package/dist/shared/{unplugin.fOnGXWgS.mjs → unplugin.CDqY7kmk.mjs} +8 -1
- package/dist/shared/{unplugin.BK7BIeBn.d.cts → unplugin.CtnKJhAi.d.cts} +18 -1
- package/dist/shared/{unplugin.BK7BIeBn.d.mts → unplugin.CtnKJhAi.d.mts} +18 -1
- package/dist/shared/{unplugin.-yLpX1Ck.mjs → unplugin.DXgxFHzO.mjs} +1 -1
- package/dist/shared/{unplugin.CKIOVNOg.cjs → unplugin.DbZ7tCfN.cjs} +8 -1
- package/dist/vite.cjs +4 -3
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +4 -3
- package/dist/webpack.cjs +4 -3
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.mjs +4 -3
- package/package.json +13 -11
- package/dist/shared/unplugin.Cnxm1DcC.cjs +0 -53
- package/dist/shared/unplugin.Lhzkcj-A.mjs +0 -49
|
@@ -6,17 +6,18 @@ import * as path from 'node:path';
|
|
|
6
6
|
import { dirname } from 'node:path';
|
|
7
7
|
import { performance } from 'node:perf_hooks';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
-
import { scanGlobalVarUsages, sortStrings as sortStrings$1, ensureRustTransformAvailable, transformSourceCode, transformRust, transformOxc, ASTBudgetExceededError, transformRustBatch, transform, isRustTransformAvailable } from '@csszyx/compiler';
|
|
9
|
+
import { scanGlobalVarUsages, extractSzvRegistryEntries, sortStrings as sortStrings$1, szFallbackConsequenceOf, ensureRustTransformAvailable, transformSourceCode, transformRust, transformOxc, ASTBudgetExceededError, transformRustBatch, transform, isRustTransformAvailable } from '@csszyx/compiler';
|
|
10
10
|
import { encode, compute_mangle_checksum } from '@csszyx/core';
|
|
11
11
|
import { getNativePackageName } from '@csszyx/core/native';
|
|
12
12
|
import { preprocess as preprocess$1 } from '@csszyx/svelte-adapter';
|
|
13
13
|
import { isTailwindReservedCustomProperty, CSSZYX_GLOBAL_ALIAS_PREFIX, isCsszyxGlobalAliasCustomProperty, DEFAULT_BUILD_CONFIG, validateGlobalVarMangleConfig } from '@csszyx/types';
|
|
14
14
|
import { preprocess } from '@csszyx/vue-adapter';
|
|
15
15
|
import { createUnplugin } from 'unplugin';
|
|
16
|
-
import { n as normalizePathSeparators, r as resolveTransformCacheDir, c as createTransformCacheKey, w as writeTransformCache, e as evictOldTransformCacheEntries, a as readTransformCache, d as evictMemoryCacheToBudget, b as babelFallbackReason } from './unplugin.
|
|
16
|
+
import { n as normalizePathSeparators, r as resolveTransformCacheDir, c as createTransformCacheKey, w as writeTransformCache, e as evictOldTransformCacheEntries, a as readTransformCache, d as evictMemoryCacheToBudget, b as babelFallbackReason } from './unplugin.CDqY7kmk.mjs';
|
|
17
17
|
import { mangleCSSSync } from '../css-mangler.mjs';
|
|
18
|
-
import {
|
|
18
|
+
import { a as importsRuntimeHelper, f as findRuntimeImportClause, r as runtimeHelperGroupsFromUsage, b as insertAfterUseDirective } from './unplugin.CBMJufQ8.mjs';
|
|
19
19
|
import { s as sortStrings, a as replaceEveryLiteral, u as unicodeEscape, b as escapeDoubleQuotedString, c as escapeSingleQuotedString, e as escapeHtmlAttribute, r as renderTailwindScannerCandidates } from './unplugin.B3XoSRB8.mjs';
|
|
20
|
+
import { gzipSync } from 'node:zlib';
|
|
20
21
|
import postcss from 'postcss';
|
|
21
22
|
import valueParser from 'postcss-value-parser';
|
|
22
23
|
|
|
@@ -1863,17 +1864,19 @@ function injectMangleMapScript(html, mangleMap, options = {}) {
|
|
|
1863
1864
|
const {
|
|
1864
1865
|
prettyPrint = false,
|
|
1865
1866
|
varMangleMap = {},
|
|
1866
|
-
globalVarAliasPrefix = CSSZYX_GLOBAL_ALIAS_PREFIX
|
|
1867
|
+
globalVarAliasPrefix = CSSZYX_GLOBAL_ALIAS_PREFIX,
|
|
1868
|
+
installRuntimeObject = true
|
|
1867
1869
|
} = options;
|
|
1868
1870
|
const checksumMap = createHydrationMangleMap(mangleMap, varMangleMap);
|
|
1869
1871
|
const jsonContent = safeJsonForScriptTag(checksumMap, prettyPrint);
|
|
1870
|
-
const classMapContent = safeJsonForScriptTag(mangleMap);
|
|
1871
1872
|
const varMapContent = safeJsonForScriptTag(varMangleMap);
|
|
1873
|
+
const reuseChecksumPayload = Object.keys(varMangleMap).length === 0;
|
|
1874
|
+
const classMapExpr = reuseChecksumPayload ? '(function(){var e=document.getElementById("__CSSZYX_MANGLE_MAP__");return e?JSON.parse(e.textContent):{}})()' : safeJsonForScriptTag(mangleMap);
|
|
1872
1875
|
const scriptTag = `<script id="__CSSZYX_MANGLE_MAP__" type="application/json">${jsonContent}<\/script>`;
|
|
1873
1876
|
const prefixContent = safeJsonForScriptTag(globalVarAliasPrefix);
|
|
1874
|
-
const debugScript = `<script>(function(){var m=${
|
|
1875
|
-
const combined = `${scriptTag}
|
|
1876
|
-
${debugScript}
|
|
1877
|
+
const debugScript = `<script>(function(){var m=${classMapExpr};var vm=${varMapContent};var gp=${prefixContent};var r={};var vr={};for(var k in m)r[m[k]]=k;for(var vk in vm){var vv=vm[vk];var vs=Array.isArray(vv)?vv:[vv];for(var vi=0;vi<vs.length;vi++)(vr[vs[vi]]||(vr[vs[vi]]=[])).push(vk)}var cs=document.documentElement.getAttribute("data-sz-checksum")||"";window.__csszyx={mangleMap:m,varMangleMap:vm,checksum:cs,decode:function(c){return r[c]},encode:function(c){return m[c]},decodeVar:function(v){return vr[v]||[]},encodeVar:function(v){return vm[v]},decodeGlobalVar:function(v){var a=vr[v]||[];return v.indexOf(gp)===0?a[0]:void 0},decodeAll:function(el){return(el.className||"").split(" ").map(function(c){return r[c]||c})}}})()<\/script>`;
|
|
1878
|
+
const combined = installRuntimeObject ? `${scriptTag}
|
|
1879
|
+
${debugScript}` : scriptTag;
|
|
1877
1880
|
if (html.includes("</head>")) {
|
|
1878
1881
|
return html.replace("</head>", `${combined}
|
|
1879
1882
|
</head>`);
|
|
@@ -1978,6 +1981,42 @@ function escapeForDoubleQuotedString(value) {
|
|
|
1978
1981
|
return escapeDoubleQuotedString(value);
|
|
1979
1982
|
}
|
|
1980
1983
|
|
|
1984
|
+
function createMangleSizeAccount() {
|
|
1985
|
+
return { cssGzBefore: 0, cssGzAfter: 0, channels: /* @__PURE__ */ new Set() };
|
|
1986
|
+
}
|
|
1987
|
+
function resetMangleSizeAccount(account) {
|
|
1988
|
+
account.cssGzBefore = 0;
|
|
1989
|
+
account.cssGzAfter = 0;
|
|
1990
|
+
account.channels.clear();
|
|
1991
|
+
}
|
|
1992
|
+
function gzipBytes(text) {
|
|
1993
|
+
if (text.length === 0) return 0;
|
|
1994
|
+
return gzipSync(Buffer.from(text, "utf8")).length;
|
|
1995
|
+
}
|
|
1996
|
+
function recordCssPair(account, before, after) {
|
|
1997
|
+
if (before === after) {
|
|
1998
|
+
const bytes = gzipBytes(before);
|
|
1999
|
+
account.cssGzBefore += bytes;
|
|
2000
|
+
account.cssGzAfter += bytes;
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
account.cssGzBefore += gzipBytes(before);
|
|
2004
|
+
account.cssGzAfter += gzipBytes(after);
|
|
2005
|
+
}
|
|
2006
|
+
function computeMangleSizeVerdict(account, mapPayload) {
|
|
2007
|
+
const channels = sortStrings(account.channels);
|
|
2008
|
+
const mapCost = gzipBytes(mapPayload) * channels.length;
|
|
2009
|
+
const cssSaving = account.cssGzBefore - account.cssGzAfter;
|
|
2010
|
+
return { mapCost, cssSaving, net: mapCost - cssSaving, channels };
|
|
2011
|
+
}
|
|
2012
|
+
function mangleSizeMessage(verdict) {
|
|
2013
|
+
if (verdict.channels.length === 0) return null;
|
|
2014
|
+
if (verdict.net <= 0) return null;
|
|
2015
|
+
const cssPart = verdict.cssSaving >= 0 ? `the mangled CSS saves ${verdict.cssSaving} B` : `the mangled CSS COSTS ${-verdict.cssSaving} B (short tokens compress worse than the names they replaced)`;
|
|
2016
|
+
const channelPart = verdict.channels.length > 1 ? `${verdict.channels.join(" + ")} (${verdict.channels.length} copies)` : verdict.channels[0];
|
|
2017
|
+
return `[csszyx] production.mangle is making this build BIGGER: +${verdict.net} B gzipped. The runtime mangle map costs ${verdict.mapCost} B via ${channelPart}, while ${cssPart}. Mangling is a name-obfuscation feature; over a compressed response it does not reduce payload, because utility class names compress far better than the map they need. If you enabled it for size, set \`production.mangle: false\`. If you enabled it to hide class names, this is the expected price and you can ignore this. Narrowing \`production.mangleMapDelivery\` removes a map copy when only one channel is needed. (Measured on CSS and the map; class shortening inside JS chunks is not counted, so the real net is slightly better than this figure.)`;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
1981
2020
|
function isParserMode(value) {
|
|
1982
2021
|
return value === "rust" || value === "oxc" || value === "babel";
|
|
1983
2022
|
}
|
|
@@ -2022,6 +2061,41 @@ function isSameFileVersion(before, after) {
|
|
|
2022
2061
|
return before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs;
|
|
2023
2062
|
}
|
|
2024
2063
|
|
|
2064
|
+
function recordSzvRegistryFile(registry, filePath, content) {
|
|
2065
|
+
const key = normalizePathSeparators(filePath);
|
|
2066
|
+
const qualifies = content.includes("szv(") && content.includes("export");
|
|
2067
|
+
const entries = qualifies ? extractSzvRegistryEntries(content, filePath) : [];
|
|
2068
|
+
if (entries.length === 0) {
|
|
2069
|
+
registry.delete(key);
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
const byName = {};
|
|
2073
|
+
for (const entry of entries) {
|
|
2074
|
+
byName[entry.exportName] = entry.config;
|
|
2075
|
+
}
|
|
2076
|
+
registry.set(key, byName);
|
|
2077
|
+
}
|
|
2078
|
+
const SPECIFIER_PROBES = ["", ".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.tsx"];
|
|
2079
|
+
function resolveCrossModuleStaticsFor(registry, filename, source) {
|
|
2080
|
+
if (registry.size === 0 || !source.includes("from")) return void 0;
|
|
2081
|
+
const directory = path.dirname(filename);
|
|
2082
|
+
let resolved;
|
|
2083
|
+
for (const match of source.matchAll(/from\s*['"](\.[^'"]*)['"]/g)) {
|
|
2084
|
+
const specifier = match[1];
|
|
2085
|
+
if (resolved?.[specifier] !== void 0) continue;
|
|
2086
|
+
const base = normalizePathSeparators(path.resolve(directory, specifier));
|
|
2087
|
+
for (const probe of SPECIFIER_PROBES) {
|
|
2088
|
+
const entries = registry.get(`${base}${probe}`);
|
|
2089
|
+
if (entries !== void 0) {
|
|
2090
|
+
resolved ??= {};
|
|
2091
|
+
resolved[specifier] = entries;
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
return resolved;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2025
2099
|
function generateThemeDts(opts) {
|
|
2026
2100
|
const { theme, sourceFiles } = opts;
|
|
2027
2101
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -2411,6 +2485,13 @@ function shouldEmitWarning(quiet, devOnly, isProduction) {
|
|
|
2411
2485
|
}
|
|
2412
2486
|
return true;
|
|
2413
2487
|
}
|
|
2488
|
+
function shouldEmitMissingCssFallback(quiet, message) {
|
|
2489
|
+
return !quiet && szFallbackConsequenceOf(message) === "missing-css";
|
|
2490
|
+
}
|
|
2491
|
+
function emitMissingCssFallback(quiet, message, id, emit) {
|
|
2492
|
+
if (shouldEmitMissingCssFallback(quiet, message)) emit(`[csszyx] ${id}
|
|
2493
|
+
${message}`);
|
|
2494
|
+
}
|
|
2414
2495
|
function normalizeForMatch(p) {
|
|
2415
2496
|
const n = normalizePathSeparators(p);
|
|
2416
2497
|
return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
|
|
@@ -3172,8 +3253,19 @@ ${errors.join("\n")}`
|
|
|
3172
3253
|
}
|
|
3173
3254
|
function createCsszyxPlugins(options = {}) {
|
|
3174
3255
|
assertGlobalVarMangleConfig(options);
|
|
3175
|
-
let manglingEnabled = options.production?.mangle
|
|
3256
|
+
let manglingEnabled = options.production?.mangle === true;
|
|
3257
|
+
let crossModuleRegistryEnabled = process.env.NODE_ENV !== "development";
|
|
3258
|
+
const szvCrossModuleRegistry = /* @__PURE__ */ new Map();
|
|
3176
3259
|
const mangleReserved = new Set(options.production?.mangleExclude ?? []);
|
|
3260
|
+
const mangleMapDelivery = options.production?.mangleMapDelivery ?? "both";
|
|
3261
|
+
if (!["both", "html", "bundle"].includes(mangleMapDelivery)) {
|
|
3262
|
+
throw new Error(
|
|
3263
|
+
`[csszyx] production.mangleMapDelivery must be 'both', 'html' or 'bundle'; got ${JSON.stringify(mangleMapDelivery)}.`
|
|
3264
|
+
);
|
|
3265
|
+
}
|
|
3266
|
+
const deliverMapInHtml = mangleMapDelivery !== "bundle";
|
|
3267
|
+
const deliverMapInBundle = mangleMapDelivery !== "html";
|
|
3268
|
+
const sizeAccount = createMangleSizeAccount();
|
|
3177
3269
|
const astBudgetOverride = options.build?.astBudgetLimit;
|
|
3178
3270
|
const prescanAstBudget = astBudgetOverride ?? 5e5;
|
|
3179
3271
|
const cacheRequested = (options.build?.cache ?? DEFAULT_BUILD_CONFIG.cache) !== false;
|
|
@@ -3399,6 +3491,14 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3399
3491
|
function transformConfiguredSource(source, filename, astBudget) {
|
|
3400
3492
|
const compilerOptions = createCompilerOptions(astBudget);
|
|
3401
3493
|
const effectiveFilename = normalizeSourceFilename(filename);
|
|
3494
|
+
const crossModuleStatics = resolveCrossModuleStaticsFor(
|
|
3495
|
+
szvCrossModuleRegistry,
|
|
3496
|
+
filename,
|
|
3497
|
+
source
|
|
3498
|
+
);
|
|
3499
|
+
if (crossModuleStatics !== void 0) {
|
|
3500
|
+
compilerOptions.crossModuleStatics = crossModuleStatics;
|
|
3501
|
+
}
|
|
3402
3502
|
const cacheRoot = resolveTransformCacheDir(state.rootDir, options.build?.cacheDir);
|
|
3403
3503
|
if (cacheEnabled) {
|
|
3404
3504
|
evictTransformCacheOnce();
|
|
@@ -3510,6 +3610,10 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3510
3610
|
mangleVars: compilerOptions.mangleVars,
|
|
3511
3611
|
mangleVarHoistMaxDepth: compilerOptions.mangleVarHoistMaxDepth,
|
|
3512
3612
|
globalVarAliases: normalizeGlobalVarAliasesForCache(compilerOptions.globalVarAliases),
|
|
3613
|
+
// The registry entries fed to this file are part of its identity:
|
|
3614
|
+
// module A's config change must miss B's cached transform, or the
|
|
3615
|
+
// cache serves a stale table.
|
|
3616
|
+
crossModuleStatics: compilerOptions.crossModuleStatics === void 0 ? void 0 : JSON.stringify(compilerOptions.crossModuleStatics),
|
|
3513
3617
|
filename: effectiveFilename,
|
|
3514
3618
|
source
|
|
3515
3619
|
};
|
|
@@ -3721,6 +3825,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3721
3825
|
}
|
|
3722
3826
|
function prescanAndWriteClasses() {
|
|
3723
3827
|
refreshCompileSourceDirs();
|
|
3828
|
+
szvCrossModuleRegistry.clear();
|
|
3724
3829
|
const prescanStarted = performance.now();
|
|
3725
3830
|
const discoveredClasses = /* @__PURE__ */ new Set();
|
|
3726
3831
|
const rawDiscoveredClasses = /* @__PURE__ */ new Set();
|
|
@@ -3737,10 +3842,15 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3737
3842
|
return;
|
|
3738
3843
|
}
|
|
3739
3844
|
recordAuthoredClasses(content);
|
|
3845
|
+
recordSzvRegistryEntries(filePath, content);
|
|
3740
3846
|
if (fileMayContainSafelistableSz(content)) {
|
|
3741
3847
|
prescanSources.push({ filePath, content });
|
|
3742
3848
|
}
|
|
3743
3849
|
}
|
|
3850
|
+
function recordSzvRegistryEntries(filePath, content) {
|
|
3851
|
+
if (!crossModuleRegistryEnabled) return;
|
|
3852
|
+
recordSzvRegistryFile(szvCrossModuleRegistry, filePath, content);
|
|
3853
|
+
}
|
|
3744
3854
|
function scanDir(dir) {
|
|
3745
3855
|
let entries;
|
|
3746
3856
|
try {
|
|
@@ -3961,6 +4071,9 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3961
4071
|
usesMerge: false,
|
|
3962
4072
|
usesSzcn: false,
|
|
3963
4073
|
usesSzPart: false,
|
|
4074
|
+
usesSzvPick: false,
|
|
4075
|
+
usesSzvPick1: false,
|
|
4076
|
+
szPartArgsProvable: true,
|
|
3964
4077
|
usesColorVar: false,
|
|
3965
4078
|
usesSpacingVar: false,
|
|
3966
4079
|
usesUnitVar: false
|
|
@@ -3981,16 +4094,20 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3981
4094
|
if (message.includes("unresolvable sz spread")) {
|
|
3982
4095
|
state.spreadWarnings.add(`${id}
|
|
3983
4096
|
${message}`);
|
|
3984
|
-
|
|
4097
|
+
continue;
|
|
4098
|
+
}
|
|
4099
|
+
if (message.includes("AST budget exceeded")) {
|
|
3985
4100
|
console.warn(`[csszyx] ${id}
|
|
3986
4101
|
${message}`);
|
|
4102
|
+
continue;
|
|
3987
4103
|
}
|
|
4104
|
+
emitMissingCssFallback(quiet, message, id, console.warn);
|
|
3988
4105
|
}
|
|
3989
4106
|
if (quiet || result.diagnostics.length === 0 || process.env.NODE_ENV === "production") {
|
|
3990
4107
|
return;
|
|
3991
4108
|
}
|
|
3992
4109
|
for (const message of result.diagnostics) {
|
|
3993
|
-
if (message.includes("unresolvable sz spread") || message.includes("AST budget exceeded")) {
|
|
4110
|
+
if (message.includes("unresolvable sz spread") || message.includes("AST budget exceeded") || szFallbackConsequenceOf(message) === "missing-css") {
|
|
3994
4111
|
continue;
|
|
3995
4112
|
}
|
|
3996
4113
|
warn(`[csszyx] ${id}
|
|
@@ -4005,6 +4122,9 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4005
4122
|
usesMerge: result.usesMerge,
|
|
4006
4123
|
usesSzcn: result.usesSzcn,
|
|
4007
4124
|
usesSzPart: result.usesSzPart,
|
|
4125
|
+
usesSzvPick: result.usesSzvPick,
|
|
4126
|
+
usesSzvPick1: result.usesSzvPick1,
|
|
4127
|
+
szPartArgsProvable: result.szPartArgsProvable,
|
|
4008
4128
|
usesColorVar: result.usesColorVar,
|
|
4009
4129
|
usesSpacingVar: result.usesSpacingVar,
|
|
4010
4130
|
usesUnitVar: result.usesUnitVar,
|
|
@@ -4047,31 +4167,34 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4047
4167
|
return transformedCode;
|
|
4048
4168
|
}
|
|
4049
4169
|
function requiredRuntimeHelpers(output) {
|
|
4050
|
-
|
|
4051
|
-
if (output.usesRuntime) helpers.push("_sz");
|
|
4052
|
-
if (output.usesMerge) helpers.push("_szMerge");
|
|
4053
|
-
if (output.usesSzcn) helpers.push("_szcn");
|
|
4054
|
-
if (output.usesSzPart) helpers.push("_szPart");
|
|
4055
|
-
if (output.usesColorVar) helpers.push("__szColorVar");
|
|
4056
|
-
if (output.usesSpacingVar) helpers.push("__szSpacingVar");
|
|
4057
|
-
if (output.usesUnitVar) helpers.push("__szUnitVar");
|
|
4058
|
-
return helpers;
|
|
4170
|
+
return runtimeHelperGroupsFromUsage(output);
|
|
4059
4171
|
}
|
|
4060
4172
|
function injectRuntimeHelpers(code, output) {
|
|
4061
|
-
const
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
if (
|
|
4065
|
-
|
|
4173
|
+
const groups = requiredRuntimeHelpers(output);
|
|
4174
|
+
let result = null;
|
|
4175
|
+
let current = code;
|
|
4176
|
+
if (groups.merge.length > 0 && !current.includes("@csszyx/runtime/merge")) {
|
|
4177
|
+
current = insertRuntimeImport(
|
|
4178
|
+
current,
|
|
4179
|
+
`import { ${groups.merge.join(", ")} } from '@csszyx/runtime/merge';
|
|
4180
|
+
`
|
|
4181
|
+
);
|
|
4182
|
+
result = current;
|
|
4183
|
+
}
|
|
4184
|
+
const imports = groups.barrel;
|
|
4185
|
+
const hasRuntimeImport = imports.length > 0 && current.includes("@csszyx/runtime");
|
|
4186
|
+
const needed = hasRuntimeImport ? imports.filter((name) => !importsRuntimeHelper(current, name)) : imports;
|
|
4187
|
+
if (needed.length === 0) return result;
|
|
4188
|
+
const existingImport = findRuntimeImportClause(current);
|
|
4066
4189
|
if (existingImport) {
|
|
4067
|
-
return
|
|
4190
|
+
return current.replace(
|
|
4068
4191
|
existingImport.statement,
|
|
4069
4192
|
`${existingImport.prefixWithBody}, ${needed.join(", ")} } from '@csszyx/runtime'`
|
|
4070
4193
|
);
|
|
4071
4194
|
}
|
|
4072
4195
|
const importStatement = `import { ${needed.join(", ")} } from '@csszyx/runtime';
|
|
4073
4196
|
`;
|
|
4074
|
-
return insertRuntimeImport(
|
|
4197
|
+
return insertRuntimeImport(current, importStatement);
|
|
4075
4198
|
}
|
|
4076
4199
|
function injectThemeGroups(code, transformedCode, id, usesSzcn) {
|
|
4077
4200
|
if (!usesSzcn && !/\bszcn\s*\(/.test(code) || transformedCode.includes(THEME_GROUPS_VIRTUAL_ID) || !shouldProcessSource(id)) {
|
|
@@ -4086,7 +4209,7 @@ ${transformedCode}`;
|
|
|
4086
4209
|
if (activeFramework !== "vite" && activeFramework !== "rollup") {
|
|
4087
4210
|
return null;
|
|
4088
4211
|
}
|
|
4089
|
-
if (!manglingEnabled || !shouldProcessSource(id) || !MANGLE_RUNTIME_CONSUMER_RE.test(transformedCode) || transformedCode.includes(MANGLE_RUNTIME_VIRTUAL_ID)) {
|
|
4212
|
+
if (!manglingEnabled || !deliverMapInBundle || !shouldProcessSource(id) || !MANGLE_RUNTIME_CONSUMER_RE.test(transformedCode) || transformedCode.includes(MANGLE_RUNTIME_VIRTUAL_ID)) {
|
|
4090
4213
|
return null;
|
|
4091
4214
|
}
|
|
4092
4215
|
return insertRuntimeImport(transformedCode, `import '${MANGLE_RUNTIME_VIRTUAL_ID}';
|
|
@@ -4156,6 +4279,7 @@ ${transformedCode}`;
|
|
|
4156
4279
|
return createChecksumModule(state.checksum);
|
|
4157
4280
|
}
|
|
4158
4281
|
if (id === RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID) {
|
|
4282
|
+
sizeAccount.channels.add("bundle");
|
|
4159
4283
|
return createMangleRuntimeModule(globalVarAliasPrefix);
|
|
4160
4284
|
}
|
|
4161
4285
|
if (id === RESOLVED_THEME_GROUPS_VIRTUAL_ID) {
|
|
@@ -4203,7 +4327,12 @@ ${transformedCode}`;
|
|
|
4203
4327
|
if (matchesScriptExtension(id, [".css"])) {
|
|
4204
4328
|
return transformTailwindCssEntry(code, id);
|
|
4205
4329
|
}
|
|
4206
|
-
const hasSzProp = code.includes("sz=") || code.includes("szs=") || /\bsz\s*:\s*["'{]/.test(code) || code.includes('sz: "')
|
|
4330
|
+
const hasSzProp = code.includes("sz=") || code.includes("szs=") || /\bsz\s*:\s*["'{]/.test(code) || code.includes('sz: "') || // szr-only modules (no sz attribute) historically skipped the
|
|
4331
|
+
// compiler entirely — which also skipped the szr import
|
|
4332
|
+
// rewrite AND the szr fallback diagnostics. The substring is
|
|
4333
|
+
// deliberately loose; a false positive only costs one file
|
|
4334
|
+
// the compiler pass, which then changes nothing.
|
|
4335
|
+
code.includes("szr(");
|
|
4207
4336
|
const output = hasSzProp ? transformSzSource(code, id, (message) => this.warn(message)) : unchangedPreTransform(code);
|
|
4208
4337
|
if (!hasSzProp && shouldProcessSource(id)) {
|
|
4209
4338
|
recordFileVarMangleEntries(state, id, []);
|
|
@@ -4296,6 +4425,14 @@ ${transformedCode}`;
|
|
|
4296
4425
|
if (compiler.options?.mode === "development") {
|
|
4297
4426
|
manglingEnabled = false;
|
|
4298
4427
|
}
|
|
4428
|
+
if (compiler.watchMode === true || compiler.options?.watch === true) {
|
|
4429
|
+
crossModuleRegistryEnabled = false;
|
|
4430
|
+
}
|
|
4431
|
+
if (manglingEnabled && mangleMapDelivery !== "both") {
|
|
4432
|
+
console.warn(
|
|
4433
|
+
`[csszyx] production.mangleMapDelivery: '${mangleMapDelivery}' has no effect on the webpack lane \u2014 map delivery only narrows on vite/rollup builds.`
|
|
4434
|
+
);
|
|
4435
|
+
}
|
|
4299
4436
|
compiler.hooks.beforeCompile.tap("csszyx:prescan", () => {
|
|
4300
4437
|
announceActiveParser();
|
|
4301
4438
|
const root = compiler.context || process.cwd();
|
|
@@ -4320,6 +4457,10 @@ ${transformedCode}`;
|
|
|
4320
4457
|
/** Records the rollup lane for the mangle-runtime gate. */
|
|
4321
4458
|
buildStart() {
|
|
4322
4459
|
activeFramework = "rollup";
|
|
4460
|
+
const meta = this.meta;
|
|
4461
|
+
if (meta?.watchMode) {
|
|
4462
|
+
crossModuleRegistryEnabled = false;
|
|
4463
|
+
}
|
|
4323
4464
|
}
|
|
4324
4465
|
},
|
|
4325
4466
|
vite: {
|
|
@@ -4335,6 +4476,10 @@ ${transformedCode}`;
|
|
|
4335
4476
|
state.rootDir = root;
|
|
4336
4477
|
if (config.command === "serve") {
|
|
4337
4478
|
manglingEnabled = false;
|
|
4479
|
+
crossModuleRegistryEnabled = false;
|
|
4480
|
+
}
|
|
4481
|
+
if (config.build?.watch) {
|
|
4482
|
+
crossModuleRegistryEnabled = false;
|
|
4338
4483
|
}
|
|
4339
4484
|
evictTransformCacheOnce();
|
|
4340
4485
|
prescanAndWriteClasses();
|
|
@@ -4436,8 +4581,12 @@ ${transformedCode}`;
|
|
|
4436
4581
|
mode: "script",
|
|
4437
4582
|
minify: process.env.NODE_ENV === "production",
|
|
4438
4583
|
varMangleMap: state.varMangleMap,
|
|
4439
|
-
globalVarAliasPrefix
|
|
4584
|
+
globalVarAliasPrefix,
|
|
4585
|
+
installRuntimeObject: deliverMapInHtml
|
|
4440
4586
|
});
|
|
4587
|
+
if (manglingEnabled) {
|
|
4588
|
+
sizeAccount.channels.add("html");
|
|
4589
|
+
}
|
|
4441
4590
|
if (state.recoveryTokens.size > 0) {
|
|
4442
4591
|
const isProduction = process.env.NODE_ENV === "production";
|
|
4443
4592
|
const { manifest, strippedDevOnlyPaths } = buildRecoveryManifest(
|
|
@@ -4486,7 +4635,7 @@ ${transformedCode}`;
|
|
|
4486
4635
|
return manifest;
|
|
4487
4636
|
}
|
|
4488
4637
|
function rewriteOutputCss(source, file, shouldMangle, mangledSources, externalClasses) {
|
|
4489
|
-
|
|
4638
|
+
const css = rewriteCssWithValidatedGlobalVarPlan(
|
|
4490
4639
|
source,
|
|
4491
4640
|
file,
|
|
4492
4641
|
state.globalVarValidationResult
|
|
@@ -4499,8 +4648,9 @@ ${transformedCode}`;
|
|
|
4499
4648
|
});
|
|
4500
4649
|
for (const className of result.mangledClasses) mangledSources.add(className);
|
|
4501
4650
|
for (const className of result.unmangledClasses) externalClasses.add(className);
|
|
4502
|
-
|
|
4503
|
-
|
|
4651
|
+
const mangled = result.transformedCount > 0 ? result.css : css;
|
|
4652
|
+
recordCssPair(sizeAccount, css, mangled);
|
|
4653
|
+
return mangled;
|
|
4504
4654
|
} catch (error) {
|
|
4505
4655
|
if (isCssSyntaxError(error)) return css;
|
|
4506
4656
|
throw error;
|
|
@@ -4512,6 +4662,16 @@ ${transformedCode}`;
|
|
|
4512
4662
|
collectMangleHybridHazards(state.mangleMap, mangledSources, externalClasses)
|
|
4513
4663
|
);
|
|
4514
4664
|
if (message) console.warn(message);
|
|
4665
|
+
reportMangleSize();
|
|
4666
|
+
}
|
|
4667
|
+
function reportMangleSize() {
|
|
4668
|
+
const verdict = computeMangleSizeVerdict(
|
|
4669
|
+
sizeAccount,
|
|
4670
|
+
JSON.stringify(createHydrationMangleMap(state.mangleMap, state.varMangleMap))
|
|
4671
|
+
);
|
|
4672
|
+
const message = mangleSizeMessage(verdict);
|
|
4673
|
+
if (message) console.warn(message);
|
|
4674
|
+
resetMangleSizeAccount(sizeAccount);
|
|
4515
4675
|
}
|
|
4516
4676
|
function rewriteWebpackCodeAsset(file, source, shouldMangle, compilation, compiler) {
|
|
4517
4677
|
if (shouldMangle && file.endsWith(".html")) {
|
|
@@ -4696,4 +4856,4 @@ const esbuildPlugin = (options = {}) => {
|
|
|
4696
4856
|
};
|
|
4697
4857
|
};
|
|
4698
4858
|
|
|
4699
|
-
export {
|
|
4859
|
+
export { skippedSzFilesMessage as $, isHardIgnoredPath as A, isMonorepoPackage as B, isPackagesSkippedSource as C, isRSCServerModule as D, isTailwindReservedGlobalVar as E, mangleCodeClassesSync as F, mangleEligibleClasses as G, mangleHybridHazardMessage as H, mergeThemes as I, missingTailwindEntryMessage as J, normalizeGlobalVarAliasesForCache as K, parseThemeBlocks as L, planGlobalVarAliases as M, readGlobalVarScanCache as N, recordGlobalVarSourceFile as O, resolveCompileSourceDirs as P, resolveGlobalVarScanCacheDir as Q, resolveNativeCacheIdentity as R, rewriteGlobalVarCssAliases as S, rollupPlugin as T, scanCustomPropertyNames as U, scanGlobalVarCss as V, shouldEmitMissingCssFallback as W, shouldEmitWarning as X, shouldTrackGlobalVarSources as Y, shouldWarnMissingTailwindEntry as Z, shouldWarnUnscopedMonorepo as _, allocateMangleTokens as a, unscopedMonorepoMessage as a0, validateGlobalVarAliasInputs as a1, vitePlugin as a2, webpackPlugin as a3, writeGlobalVarScanCache as a4, appendTailwindSourceDirective as b, assertNoRSCBoundaryViolation as c, assertNoRSCGraphViolation as d, collectMangleHybridHazards as e, computeSafelistRelPath as f, createGlobalVarAliasValidationOptions as g, createGlobalVarMapAssetSource as h, createGlobalVarScanCacheKey as i, createRSCModuleRecord as j, cssHasContentScope as k, cssImportsTailwind as l, deleteRSCModuleRecord as m, emitMissingCssFallback as n, esbuildPlugin as o, extractGlobalVarAliasesForManifest as p, fileMayContainSafelistableSz as q, findLocalImportSources as r, findRSCBoundaryViolation as s, findRSCGraphViolation as t, unplugin as u, hasInjectableTailwindCandidate as v, hasTokens as w, hasUseClientDirective as x, hasUseServerDirective as y, isCompileSourceOptedIn as z };
|