@csszyx/unplugin 0.15.3 → 0.17.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 +8 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -4
- package/dist/jest-transform.cjs +186 -0
- package/dist/jest-transform.d.cts +112 -0
- package/dist/jest-transform.d.mts +110 -0
- package/dist/jest-transform.mjs +175 -0
- package/dist/next-prebuild.cjs +6 -5
- package/dist/next-prebuild.mjs +5 -4
- package/dist/next-turbo-loader.cjs +10 -8
- package/dist/next-turbo-loader.mjs +7 -5
- package/dist/next-watcher.cjs +3 -2
- package/dist/next-watcher.mjs +3 -2
- package/dist/shared/{unplugin.J6ue_lRJ.cjs → unplugin.2qOISpzl.cjs} +1 -114
- package/dist/shared/{unplugin.C-oQU1jl.mjs → unplugin.2uf-U76p.mjs} +1 -1
- package/dist/shared/{unplugin.Ceq-N4jI.mjs → unplugin.995yC_cN.mjs} +2 -110
- package/dist/shared/{unplugin.ZqxgHk5F.cjs → unplugin.9zs6T4Gf.cjs} +119 -92
- package/dist/shared/{unplugin.nvme_dSL.d.cts → unplugin.BO2_hyS3.d.cts} +54 -5
- package/dist/shared/{unplugin.DH_ij6cf.mjs → unplugin.Ba3O1r8M.mjs} +2 -6
- package/dist/shared/unplugin.BqKLlo1h.cjs +8 -0
- package/dist/shared/{unplugin.Vn9x8SBP.mjs → unplugin.C3bgc29e.mjs} +3 -2
- package/dist/shared/{unplugin.CPo2xrEy.mjs → unplugin.Cs4H9z9v.mjs} +91 -66
- package/dist/shared/{unplugin.BLptVbUe.mjs → unplugin.DPSQP5XG.mjs} +1 -1
- package/dist/shared/{unplugin.DDSWQJYX.cjs → unplugin.DS6CFjim.cjs} +3 -8
- package/dist/shared/{unplugin.gksolKh2.cjs → unplugin.DXzIP7lP.cjs} +5 -4
- package/dist/shared/unplugin.DcXM9sq5.mjs +109 -0
- package/dist/shared/unplugin.Defu9wGh.cjs +115 -0
- package/dist/shared/{unplugin.CInSoHdQ.d.mts → unplugin.DptK3pl4.d.mts} +54 -5
- package/dist/shared/{unplugin.BzF0V2kw.cjs → unplugin.YcnV3Izb.cjs} +6 -6
- package/dist/shared/{unplugin.BWnmKv07.cjs → unplugin.alhYXymJ.cjs} +1 -1
- package/dist/shared/unplugin.wMeicb6E.mjs +6 -0
- package/dist/vite.cjs +6 -4
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +6 -4
- package/dist/webpack.cjs +6 -4
- package/dist/webpack.d.cts +1 -2
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.mjs +6 -4
- package/package.json +19 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
+
import { n as normalizePathSeparators } from './unplugin.wMeicb6E.mjs';
|
|
4
5
|
|
|
5
6
|
function sortStrings(values) {
|
|
6
7
|
return [...values].sort((a, b) => {
|
|
@@ -10,11 +11,6 @@ function sortStrings(values) {
|
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
|
|
14
|
-
function normalizePathSeparators(value) {
|
|
15
|
-
return value.split(WINDOWS_PATH_SEPARATOR).join("/");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
const DEFAULT_RENAME_RETRIES = 5;
|
|
19
15
|
const DEFAULT_RENAME_RETRY_DELAY_MS = 10;
|
|
20
16
|
function isRetryableRenameError(error) {
|
|
@@ -255,4 +251,4 @@ function cssImportsTailwind(code) {
|
|
|
255
251
|
return TAILWIND_IMPORT.test(stripCssBlockComments(code));
|
|
256
252
|
}
|
|
257
253
|
|
|
258
|
-
export { SAFELIST_FILE as S, appendTailwindSourceDirective as a, cssImportsTailwind as b, computeSafelistRelPath as c, atomicWriteFileSync as d, removeLegacySafelists as e, findPostcssConfigWithoutCsszyx as f, assertNoLegacySourceStylesheet as g, stripCssBlockComments as h, findLegacySourceDirective as i, legacySourceMessage as l, missingPostcssPluginMessage as m,
|
|
254
|
+
export { SAFELIST_FILE as S, appendTailwindSourceDirective as a, cssImportsTailwind as b, computeSafelistRelPath as c, atomicWriteFileSync as d, removeLegacySafelists as e, findPostcssConfigWithoutCsszyx as f, assertNoLegacySourceStylesheet as g, stripCssBlockComments as h, findLegacySourceDirective as i, legacySourceMessage as l, missingPostcssPluginMessage as m, renderSafelistFile as r, sortStrings as s };
|
|
@@ -2,9 +2,10 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { extractCrossModuleForwards, extractCrossModuleRegistryEntries, ensureRustTransformAvailable, transformRust, transformWasm, transform } from '@csszyx/compiler';
|
|
4
4
|
import { DEFAULT_IMPORTED_STATIC_SZ } from '@csszyx/types';
|
|
5
|
-
import { c as collectSpecifierAliases, i as importedSpecifiersIn, s as specifierBases, a as resolveProviderPathWith, b as recordResolvedEntry, f as forwardVisitKey, M as MAX_FORWARD_HOPS, d as isReadableProviderFile, e as createTransformCacheKey, g as readTransformCache, w as writeTransformCache } from './unplugin.
|
|
6
|
-
import { n as normalizePathSeparators
|
|
5
|
+
import { c as collectSpecifierAliases, i as importedSpecifiersIn, s as specifierBases, a as resolveProviderPathWith, b as recordResolvedEntry, f as forwardVisitKey, M as MAX_FORWARD_HOPS, d as isReadableProviderFile, e as createTransformCacheKey, g as readTransformCache, w as writeTransformCache } from './unplugin.2uf-U76p.mjs';
|
|
6
|
+
import { n as normalizePathSeparators } from './unplugin.wMeicb6E.mjs';
|
|
7
7
|
import { createHash } from 'node:crypto';
|
|
8
|
+
import { s as sortStrings } from './unplugin.Ba3O1r8M.mjs';
|
|
8
9
|
|
|
9
10
|
function resolveImportedStaticSz(value) {
|
|
10
11
|
return value ?? DEFAULT_IMPORTED_STATIC_SZ;
|
|
@@ -13,10 +13,12 @@ import { preprocess as preprocess$1 } from '@csszyx/svelte-adapter';
|
|
|
13
13
|
import { isTailwindReservedCustomProperty, CSSZYX_GLOBAL_ALIAS_PREFIX, isCsszyxGlobalAliasCustomProperty, DEFAULT_IMPORTED_STATIC_SZ, DEFAULT_BUILD_CONFIG, validateGlobalVarMangleConfig } from '@csszyx/types';
|
|
14
14
|
import { preprocess } from '@csszyx/vue-adapter';
|
|
15
15
|
import { createUnplugin } from 'unplugin';
|
|
16
|
-
import { s as sortStrings,
|
|
17
|
-
import { c as collectSpecifierAliases, r as resolveTransformCacheDir, h as evictOldTransformCacheEntries, j as recordSzvRegistryFile, k as recordCrossModuleForwards, l as recordSzObjectRegistryFile, m as mayExportSzvFactories, n as resolveProviderPath, i as importedSpecifiersIn, s as specifierBases, a as resolveProviderPathWith, o as resolveCrossModuleStaticsFor, e as createTransformCacheKey, w as writeTransformCache, g as readTransformCache, p as evictMemoryCacheToBudget, d as isReadableProviderFile } from './unplugin.
|
|
16
|
+
import { s as sortStrings, h as stripCssBlockComments, S as SAFELIST_FILE, i as findLegacySourceDirective, l as legacySourceMessage, b as cssImportsTailwind, c as computeSafelistRelPath, a as appendTailwindSourceDirective, r as renderSafelistFile, d as atomicWriteFileSync, e as removeLegacySafelists } from './unplugin.Ba3O1r8M.mjs';
|
|
17
|
+
import { c as collectSpecifierAliases, r as resolveTransformCacheDir, h as evictOldTransformCacheEntries, j as recordSzvRegistryFile, k as recordCrossModuleForwards, l as recordSzObjectRegistryFile, m as mayExportSzvFactories, n as resolveProviderPath, i as importedSpecifiersIn, s as specifierBases, a as resolveProviderPathWith, o as resolveCrossModuleStaticsFor, e as createTransformCacheKey, w as writeTransformCache, g as readTransformCache, p as evictMemoryCacheToBudget, d as isReadableProviderFile } from './unplugin.2uf-U76p.mjs';
|
|
18
18
|
import { mangleCSSSync, classAttributeSelectorKey } from '../css-mangler.mjs';
|
|
19
|
-
import {
|
|
19
|
+
import { b as importsRuntimeHelper, f as findRuntimeImportClause, r as runtimeHelperGroupsFromUsage, a as insertAfterUseDirective } from './unplugin.DcXM9sq5.mjs';
|
|
20
|
+
import { n as normalizePathSeparators } from './unplugin.wMeicb6E.mjs';
|
|
21
|
+
import { c as createMangleRuntimeModule, M as MANGLE_RUNTIME_VIRTUAL_ID, e as ensureThemeGroupsFile, R as RESOLVED_VIRTUAL_MODULE_ID, b as createMangleMapModule, d as RESOLVED_VIRTUAL_CHECKSUM_ID, f as createChecksumModule, g as RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID, i as RESOLVED_THEME_GROUPS_VIRTUAL_ID, j as createThemeGroupsModule, k as isVirtualModule, r as resolveVirtualModule, p as parseThemeBlocks, m as mergeThemes, l as discoverProjectTheme, C as CHECKSUM_PLACEHOLDER, n as CENSUS_PLACEHOLDER, T as THEME_GROUPS_VIRTUAL_ID, o as THEME_GROUPS_FILE_MARKER, t as themeGroupsSpecifier, a as parseUtilityBlocks, q as MANGLE_MAP_PLACEHOLDER, V as VAR_MANGLE_MAP_PLACEHOLDER } from './unplugin.995yC_cN.mjs';
|
|
20
22
|
import { gzipSync } from 'node:zlib';
|
|
21
23
|
import postcss from 'postcss';
|
|
22
24
|
import valueParser from 'postcss-value-parser';
|
|
@@ -1779,24 +1781,10 @@ function injectMangleMapScript(html, mangleMap, options = {}) {
|
|
|
1779
1781
|
const scriptTag = `<script id="__CSSZYX_MANGLE_MAP__" type="application/json">${safeJsonForScriptTag(checksumMap, prettyPrint)}<\/script>`;
|
|
1780
1782
|
return withScriptTag(html, scriptTag);
|
|
1781
1783
|
}
|
|
1782
|
-
function injectMangleMapAttribute(html, mangleMap, minify = false, varMangleMap = {}) {
|
|
1783
|
-
const attrName = minify ? "data-sz-m" : "data-sz-map";
|
|
1784
|
-
const jsonContent = JSON.stringify(createHydrationMangleMap(mangleMap, varMangleMap));
|
|
1785
|
-
return injectHtmlOpeningAttr(html, ` ${attrName}='${jsonContent}'`);
|
|
1786
|
-
}
|
|
1787
1784
|
function injectHydrationData(html, mangleMap, checksum, options = {}) {
|
|
1788
|
-
const {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
if (mode === "inline") {
|
|
1792
|
-
result = injectMangleMapAttribute(result, mangleMap, minify, options.varMangleMap);
|
|
1793
|
-
} else if (mode === "script") {
|
|
1794
|
-
result = injectMangleMapScript(result, mangleMap, options);
|
|
1795
|
-
} else if (mode === "both") {
|
|
1796
|
-
result = injectMangleMapAttribute(result, mangleMap, minify, options.varMangleMap);
|
|
1797
|
-
result = injectMangleMapScript(result, mangleMap, options);
|
|
1798
|
-
}
|
|
1799
|
-
return result;
|
|
1785
|
+
const { minify = false, census = true } = options;
|
|
1786
|
+
const result = injectChecksum(html, checksum, minify);
|
|
1787
|
+
return census ? injectMangleMapScript(result, mangleMap, options) : result;
|
|
1800
1788
|
}
|
|
1801
1789
|
function transformIndexHtml(html, mangleMap, checksum, options = {}) {
|
|
1802
1790
|
return injectHydrationData(html, mangleMap, checksum, options);
|
|
@@ -1910,13 +1898,25 @@ function needsRuntimeMangleRegistration(manglingEnabled, mangleMap) {
|
|
|
1910
1898
|
if (!manglingEnabled) return false;
|
|
1911
1899
|
return Object.keys(mangleMap).length > 0;
|
|
1912
1900
|
}
|
|
1901
|
+
function removedInjectChecksumMessage() {
|
|
1902
|
+
return "[csszyx] production.injectChecksum has been removed and was never read. The hydration checksum and the inert census ship on every production build, and no option turned them off \u2014 a build that set this to false still carried both. Delete the option. The census carries no class entries when production.mangle is off, and both tags are data, not script: see https://csszyx.com/docs/security/";
|
|
1903
|
+
}
|
|
1913
1904
|
function removedMangleMapDeliveryMessage() {
|
|
1914
1905
|
return "[csszyx] production.mangleMapDelivery has been removed and is ignored. The runtime mangle map is always registered from inside the JS bundle now, on every lane, so the built HTML never carries an executable inline <script> and a strict script-src 'self' policy needs no exception. Delete the option. (`window.__csszyx` is now opt-in through `production.mangleDebugGlobal`.)";
|
|
1915
1906
|
}
|
|
1916
1907
|
|
|
1908
|
+
function utilityStart(className) {
|
|
1909
|
+
let depth = 0;
|
|
1910
|
+
let start = 0;
|
|
1911
|
+
for (let index = 0; index < className.length; index += 1) {
|
|
1912
|
+
const char = className[index];
|
|
1913
|
+
if (char === "[") depth += 1;
|
|
1914
|
+
else if (char === "]") depth = Math.max(0, depth - 1);
|
|
1915
|
+
else if (char === ":" && depth === 0) start = index + 1;
|
|
1916
|
+
}
|
|
1917
|
+
return start;
|
|
1918
|
+
}
|
|
1917
1919
|
function compileManglePreserve(entries) {
|
|
1918
|
-
const exact = /* @__PURE__ */ new Set();
|
|
1919
|
-
const prefixes = [];
|
|
1920
1920
|
const list = entries ?? [];
|
|
1921
1921
|
list.forEach((entry, index) => {
|
|
1922
1922
|
if (typeof entry !== "string" || entry.length === 0) {
|
|
@@ -1929,22 +1929,34 @@ function compileManglePreserve(entries) {
|
|
|
1929
1929
|
"[csszyx] production.manglePreserve must not contain a lone `*`: it would keep every class and silently turn `production.mangle` into a no-op. Name a prefix (`bg-tag-*`) or set `production.mangle: false`."
|
|
1930
1930
|
);
|
|
1931
1931
|
}
|
|
1932
|
-
if (entry.endsWith("*")) prefixes.push(entry.slice(0, -1));
|
|
1933
|
-
else exact.add(entry);
|
|
1934
1932
|
});
|
|
1935
|
-
const
|
|
1933
|
+
const compiled = list.map((value) => ({
|
|
1934
|
+
value,
|
|
1935
|
+
prefix: value.endsWith("*") ? value.slice(0, -1) : void 0
|
|
1936
|
+
}));
|
|
1937
|
+
const keeps = (entry, className, utilityStartIndex) => entry.prefix === void 0 ? className === entry.value || className.length - utilityStartIndex === entry.value.length && className.startsWith(entry.value, utilityStartIndex) : className.startsWith(entry.prefix) || className.startsWith(entry.prefix, utilityStartIndex);
|
|
1938
|
+
const test = (className) => {
|
|
1939
|
+
if (list.length === 0) return false;
|
|
1940
|
+
const start = utilityStart(className);
|
|
1941
|
+
return compiled.some((entry) => keeps(entry, className, start));
|
|
1942
|
+
};
|
|
1936
1943
|
return {
|
|
1937
1944
|
entries: list,
|
|
1938
1945
|
test,
|
|
1939
1946
|
unmatched(census) {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1947
|
+
if (list.length === 0) return [];
|
|
1948
|
+
const matched = list.map(() => false);
|
|
1949
|
+
let remaining = list.length;
|
|
1950
|
+
for (const className of census) {
|
|
1951
|
+
const start = utilityStart(className);
|
|
1952
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1953
|
+
if (matched[index] || !keeps(compiled[index], className, start)) continue;
|
|
1954
|
+
matched[index] = true;
|
|
1955
|
+
remaining -= 1;
|
|
1945
1956
|
}
|
|
1946
|
-
|
|
1947
|
-
}
|
|
1957
|
+
if (remaining === 0) break;
|
|
1958
|
+
}
|
|
1959
|
+
return list.filter((_, index) => !matched[index]);
|
|
1948
1960
|
}
|
|
1949
1961
|
};
|
|
1950
1962
|
}
|
|
@@ -2351,8 +2363,9 @@ function quoteForConfig(entry) {
|
|
|
2351
2363
|
function preserveEntriesFor(hazard) {
|
|
2352
2364
|
const quote = quoteForConfig;
|
|
2353
2365
|
const { value } = hazard;
|
|
2354
|
-
|
|
2355
|
-
if (
|
|
2366
|
+
const utilities = hazard.renamed.map((name) => name.slice(utilityStart(name)));
|
|
2367
|
+
if (utilities.every((name) => name === value)) return [quote(value)];
|
|
2368
|
+
if (utilities.every((name) => name.startsWith(value))) return [quote(`${value}*`)];
|
|
2356
2369
|
return hazard.renamed.map(quote);
|
|
2357
2370
|
}
|
|
2358
2371
|
function mangleHybridHazardMessage(hazards) {
|
|
@@ -2360,49 +2373,40 @@ function mangleHybridHazardMessage(hazards) {
|
|
|
2360
2373
|
if (collisions.length === 0 && orphans.length === 0 && selectorMatches.length === 0) {
|
|
2361
2374
|
return null;
|
|
2362
2375
|
}
|
|
2376
|
+
const broken = selectorMatches.filter((hazard) => hazard.renamed.length > 0);
|
|
2377
|
+
const newlyMatched = selectorMatches.filter((hazard) => hazard.matchedTokens.length > 0);
|
|
2363
2378
|
const parts = ["[csszyx] production mangle found hybrid hazards:"];
|
|
2364
2379
|
if (collisions.length > 0) {
|
|
2365
2380
|
const sample = collisions.slice(0, 8).join(", ");
|
|
2366
2381
|
parts.push(
|
|
2367
|
-
|
|
2382
|
+
`${collisions.length} mangled token(s) collide with class names in non-csszyx CSS (e.g. ${sample}) \u2014 those tokens will cross-contaminate external ".${collisions[0]}" elements.`,
|
|
2383
|
+
"HOTFIX: pass `production: { mangle: false }` to the csszyx plugin to ship now. THEN fix it: if these short names are in your OWN CSS, rename them to something specific (e.g. `.x` \u2192 `.resize-handle-x`) \u2014 short/common names also clash on specificity with other libraries. Only for names in a third-party stylesheet you cannot edit, list them in `production.mangleExclude` instead. Run `npx @csszyx/cli scan-collisions` to find every offending name."
|
|
2368
2384
|
);
|
|
2369
2385
|
}
|
|
2370
2386
|
if (orphans.length > 0) {
|
|
2371
2387
|
const sample = orphans.slice(0, 8).join(", ");
|
|
2372
2388
|
parts.push(
|
|
2373
|
-
|
|
2389
|
+
`${orphans.length} mangled class(es) have no emitted CSS rule (e.g. ${sample}) \u2014 those elements lose styling.`,
|
|
2390
|
+
"Those classes are csszyx-owned but no CSS was emitted for them (e.g. a separate Tailwind plugin owns the utility CSS, or the class is not a real utility). Ensure that CSS is generated, or pass `production: { mangle: false }` to the csszyx plugin until the pipelines are reconciled."
|
|
2374
2391
|
);
|
|
2375
2392
|
}
|
|
2376
|
-
const broken = selectorMatches.filter((hazard) => hazard.renamed.length > 0);
|
|
2377
|
-
const newlyMatched = selectorMatches.filter((hazard) => hazard.matchedTokens.length > 0);
|
|
2378
2393
|
if (broken.length > 0) {
|
|
2379
2394
|
const sample = broken.slice(0, 3).map((hazard) => `${hazard.selector} \u2192 ${hazard.renamed.slice(0, 4).join(", ")}`).join("; ");
|
|
2395
|
+
const entries = [...new Set(broken.flatMap(preserveEntriesFor))].join(", ");
|
|
2380
2396
|
parts.push(
|
|
2381
|
-
|
|
2397
|
+
`${broken.length} attribute selector(s) match class names by text (e.g. ${sample}) \u2014 those rules stop matching once the classes are renamed, so the elements lose those styles.`,
|
|
2398
|
+
`Keep those classes readable with production.manglePreserve: [${entries}] (paste-ready), or key the rule off a data attribute, which mangling never touches. production.mangleExclude cannot help here: it reserves token names and does not keep a class from being renamed.`
|
|
2382
2399
|
);
|
|
2383
2400
|
}
|
|
2384
2401
|
if (newlyMatched.length > 0) {
|
|
2385
2402
|
const sample = newlyMatched.slice(0, 3).map((hazard) => `${hazard.selector} \u2192 ${hazard.matchedTokens.slice(0, 4).join(", ")}`).join("; ");
|
|
2403
|
+
const tokens = [...new Set(newlyMatched.flatMap((hazard) => hazard.matchedTokens))].map(quoteForConfig).join(", ");
|
|
2386
2404
|
parts.push(
|
|
2387
|
-
|
|
2405
|
+
`${newlyMatched.length} attribute selector(s) would start matching mangled tokens instead (e.g. ${sample}).`,
|
|
2406
|
+
`Reserve those token names with production.mangleExclude: [${tokens}] (paste-ready) so no class is renamed to one of them, or key the rule off a data attribute, which mangling never touches; a prefix or substring selector goes on matching other tokens, so the data attribute is the durable fix.`
|
|
2388
2407
|
);
|
|
2389
2408
|
}
|
|
2390
|
-
|
|
2391
|
-
parts.push(
|
|
2392
|
-
" HOTFIX: pass `production: { mangle: false }` to the csszyx plugin to ship now. THEN fix it: if these short names are in your OWN CSS, rename them to something specific (e.g. `.x` \u2192 `.resize-handle-x`) \u2014 short/common names also clash on specificity with other libraries. Only for names in a third-party stylesheet you cannot edit, list them in `production.mangleExclude` instead. Run `npx @csszyx/cli scan-collisions` to find every offending name."
|
|
2393
|
-
);
|
|
2394
|
-
} else if (orphans.length > 0) {
|
|
2395
|
-
parts.push(
|
|
2396
|
-
" Those classes are csszyx-owned but no CSS was emitted for them (e.g. a separate Tailwind plugin owns the utility CSS, or the class is not a real utility). Ensure that CSS is generated, or pass `production: { mangle: false }` to the csszyx plugin until the pipelines are reconciled."
|
|
2397
|
-
);
|
|
2398
|
-
}
|
|
2399
|
-
if (broken.length > 0) {
|
|
2400
|
-
const entries = [...new Set(broken.flatMap(preserveEntriesFor))].join(", ");
|
|
2401
|
-
parts.push(
|
|
2402
|
-
` Keep those classes readable with production.manglePreserve: [${entries}] (paste-ready), or key the rule off a data attribute, which mangling never touches. production.mangleExclude cannot help here: it reserves token names and does not keep a class from being renamed.`
|
|
2403
|
-
);
|
|
2404
|
-
}
|
|
2405
|
-
return parts.join("");
|
|
2409
|
+
return parts.join("\n");
|
|
2406
2410
|
}
|
|
2407
2411
|
const TAILWIND_IMPORT_SPECIFIER = /@import\s+["']tailwindcss(?:\/[^"']*)?["']/g;
|
|
2408
2412
|
const SOURCE_MODIFIER = /\bsource\(/;
|
|
@@ -2445,13 +2449,15 @@ function shouldWarnUnscopedMonorepo(sawTailwindEntry, tailwindEntryScoped, inMon
|
|
|
2445
2449
|
function unscopedMonorepoMessage() {
|
|
2446
2450
|
return '[csszyx] Tailwind content detection is UNSCOPED in a monorepo. Tailwind v4 scans every file under its detection base \u2014 .md/.mdx/.txt included \u2014 so a doc or fixture holding class-shaped strings becomes CSS, which can generate phantom or broken url() classes and fail the build. That base is as wide as the build makes it: a Vite build roots it at the Vite root, other setups at the workspace root. Scope it in your Tailwind CSS entry:\n @import "tailwindcss" source(none);\n @source ".";\nThat @source is your package, relative to the CSS file; csszyx auto-injects one for the classes it generates, so only your own templates need listing. Guide: https://csszyx.com/docs/monorepo-content-scope/\nSilence (if a broad scan is intentional): csszyx({ contentScopeCheck: false }).';
|
|
2447
2451
|
}
|
|
2452
|
+
const CLASS_NAME_PRECEDENCE_MARKER = 'takes precedence over the runtime "className"';
|
|
2453
|
+
const MANGLE_VARS_HOIST_SKIP_MARKER = "mangleVars skipped component CSS variable hoist";
|
|
2448
2454
|
function isAdvisoryDiagnostic(message) {
|
|
2449
|
-
return
|
|
2455
|
+
return szFallbackConsequenceOf(message) === "nudge" || message.includes(CLASS_NAME_PRECEDENCE_MARKER) || message.includes(MANGLE_VARS_HOIST_SKIP_MARKER);
|
|
2450
2456
|
}
|
|
2451
2457
|
function suppressedAdvisoryMessage(count) {
|
|
2452
2458
|
if (count <= 0) return null;
|
|
2453
|
-
const held = count === 1 ? "1 advisory
|
|
2454
|
-
return `[csszyx] ${held} not listed above.
|
|
2459
|
+
const held = count === 1 ? "1 advisory note" : `${count} advisory notes`;
|
|
2460
|
+
return `[csszyx] ${held} not listed above. An advisory reports something csszyx handled \u2014 a fallback at an sz prop, a className whose precedence over sz is unstated, or a variable hoist the planner declined \u2014 so the styles are there and a production build keeps the list short. A development build prints each one with its file and position.`;
|
|
2455
2461
|
}
|
|
2456
2462
|
function resolveQuietMode(quiet) {
|
|
2457
2463
|
if (quiet === true || quiet === "all") return "all";
|
|
@@ -2468,9 +2474,19 @@ function shouldEmitWarning(quiet, devOnly, isProduction) {
|
|
|
2468
2474
|
}
|
|
2469
2475
|
return true;
|
|
2470
2476
|
}
|
|
2477
|
+
function emitKeyValueDiagnostic(quiet, message, id, emit) {
|
|
2478
|
+
if (resolveQuietMode(quiet) === "all" || szFallbackConsequenceOf(message) !== void 0 || isAdvisoryDiagnostic(message)) {
|
|
2479
|
+
return;
|
|
2480
|
+
}
|
|
2481
|
+
emit(`[csszyx] ${id}
|
|
2482
|
+
${message}`);
|
|
2483
|
+
}
|
|
2471
2484
|
function shouldEmitMissingCssFallback(quiet, message) {
|
|
2472
2485
|
return resolveQuietMode(quiet) !== "all" && szFallbackConsequenceOf(message) === "missing-css";
|
|
2473
2486
|
}
|
|
2487
|
+
function shouldHoldAdvisories(quiet, serving, nodeEnv) {
|
|
2488
|
+
return quiet !== "off" || !serving && nodeEnv === "production";
|
|
2489
|
+
}
|
|
2474
2490
|
function emitMissingCssFallback(quiet, message, id, emit) {
|
|
2475
2491
|
if (shouldEmitMissingCssFallback(quiet, message)) emit(`[csszyx] ${id}
|
|
2476
2492
|
${message}`);
|
|
@@ -3300,6 +3316,9 @@ ${errors.join("\n")}`
|
|
|
3300
3316
|
function createCsszyxPlugins(options = {}) {
|
|
3301
3317
|
assertGlobalVarMangleConfig(options);
|
|
3302
3318
|
let manglingEnabled = options.production?.mangle === true;
|
|
3319
|
+
const censusRequested = options.production?.hydrationCensus !== false;
|
|
3320
|
+
const censusHasContent = () => manglingEnabled && Object.keys(state.mangleMap).length > 0 || Object.keys(state.varMangleMap).length > 0;
|
|
3321
|
+
let serving = false;
|
|
3303
3322
|
const importedStaticSzEnabled = options.build?.importedStaticSz ?? DEFAULT_IMPORTED_STATIC_SZ;
|
|
3304
3323
|
const szvCrossModuleRegistry = /* @__PURE__ */ new Map();
|
|
3305
3324
|
const szvCrossModuleForwards = /* @__PURE__ */ new Map();
|
|
@@ -3322,6 +3341,9 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3322
3341
|
if (options.production?.mangleMapDelivery !== void 0) {
|
|
3323
3342
|
console.warn(removedMangleMapDeliveryMessage());
|
|
3324
3343
|
}
|
|
3344
|
+
if (options.production?.injectChecksum !== void 0) {
|
|
3345
|
+
console.warn(removedInjectChecksumMessage());
|
|
3346
|
+
}
|
|
3325
3347
|
const sizeAccount = createMangleSizeAccount();
|
|
3326
3348
|
const astBudgetOverride = options.build?.astBudgetLimit;
|
|
3327
3349
|
const prescanAstBudget = astBudgetOverride ?? 5e5;
|
|
@@ -3416,6 +3438,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3416
3438
|
skipWarningEmitted: false,
|
|
3417
3439
|
classesCapped: false,
|
|
3418
3440
|
ownedClasses: /* @__PURE__ */ new Set(),
|
|
3441
|
+
mangleEligible: [],
|
|
3419
3442
|
authoredClasses: /* @__PURE__ */ new Set(),
|
|
3420
3443
|
mangleMap: {},
|
|
3421
3444
|
varMangleEntriesByFile: varMangleEntries,
|
|
@@ -4220,6 +4243,8 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4220
4243
|
const unmatched = manglePreserve.unmatched(state.ownedClasses);
|
|
4221
4244
|
if (unmatched.length > 0) emitWarning(manglePreserveNoMatchMessage(unmatched));
|
|
4222
4245
|
}
|
|
4246
|
+
state.mangleEligible = eligible;
|
|
4247
|
+
if (!manglingEnabled) return {};
|
|
4223
4248
|
return allocateMangleTokens(eligible, forbiddenTokens);
|
|
4224
4249
|
}
|
|
4225
4250
|
function freezeMangleMap() {
|
|
@@ -4437,10 +4462,11 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4437
4462
|
continue;
|
|
4438
4463
|
}
|
|
4439
4464
|
emitMissingCssFallback(quiet, message, id, console.warn);
|
|
4465
|
+
emitKeyValueDiagnostic(quiet, message, id, console.warn);
|
|
4440
4466
|
}
|
|
4441
4467
|
const advisories = result.diagnostics.filter(isAdvisoryDiagnostic);
|
|
4442
4468
|
if (advisories.length === 0) return;
|
|
4443
|
-
if (quiet
|
|
4469
|
+
if (shouldHoldAdvisories(quiet, serving, process.env.NODE_ENV)) {
|
|
4444
4470
|
state.suppressedAdvisories += advisories.length;
|
|
4445
4471
|
return;
|
|
4446
4472
|
}
|
|
@@ -4496,7 +4522,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4496
4522
|
}
|
|
4497
4523
|
let transformedCode = `${code.slice(0, htmlTag.close)} ${attrName}="${CHECKSUM_PLACEHOLDER}"${code.slice(htmlTag.close)}`;
|
|
4498
4524
|
const censusTag = `<script id="__CSSZYX_MANGLE_MAP__" type="application/json" dangerouslySetInnerHTML={{__html: \`${CENSUS_PLACEHOLDER}\`}} />`;
|
|
4499
|
-
const bodyTag = findOpeningTag(transformedCode, "body");
|
|
4525
|
+
const bodyTag = censusRequested && censusHasContent() ? findOpeningTag(transformedCode, "body") : null;
|
|
4500
4526
|
if (bodyTag) {
|
|
4501
4527
|
transformedCode = `${transformedCode.slice(0, bodyTag.close + 1)}${censusTag}${transformedCode.slice(bodyTag.close + 1)}`;
|
|
4502
4528
|
}
|
|
@@ -4859,6 +4885,7 @@ ${transformedCode}`;
|
|
|
4859
4885
|
specifierAliases = collectSpecifierAliases(root, config.resolve?.alias);
|
|
4860
4886
|
if (config.command === "serve") {
|
|
4861
4887
|
manglingEnabled = false;
|
|
4888
|
+
serving = true;
|
|
4862
4889
|
}
|
|
4863
4890
|
if (manglingEnabled && config.build?.watch) {
|
|
4864
4891
|
manglingEnabled = false;
|
|
@@ -4952,9 +4979,7 @@ ${transformedCode}`;
|
|
|
4952
4979
|
finalizeMangleMap();
|
|
4953
4980
|
const injectedMangleMap = manglingEnabled ? state.mangleMap : {};
|
|
4954
4981
|
let result = transformIndexHtml(html, injectedMangleMap, state.checksum, {
|
|
4955
|
-
|
|
4956
|
-
// checksum attribute is injected regardless.
|
|
4957
|
-
mode: "script",
|
|
4982
|
+
census: censusRequested && censusHasContent(),
|
|
4958
4983
|
minify: process.env.NODE_ENV === "production",
|
|
4959
4984
|
varMangleMap: state.varMangleMap
|
|
4960
4985
|
});
|
|
@@ -4999,7 +5024,7 @@ ${transformedCode}`;
|
|
|
4999
5024
|
const manifest = {
|
|
5000
5025
|
version: "0.4.0",
|
|
5001
5026
|
buildId: state.checksum,
|
|
5002
|
-
classes:
|
|
5027
|
+
classes: [...state.mangleEligible]
|
|
5003
5028
|
};
|
|
5004
5029
|
if (includeMangleMap && Object.keys(state.mangleMap).length > 0) {
|
|
5005
5030
|
manifest.mangleMap = state.mangleMap;
|
|
@@ -5361,4 +5386,4 @@ const esbuildPlugin = (options = {}) => {
|
|
|
5361
5386
|
};
|
|
5362
5387
|
};
|
|
5363
5388
|
|
|
5364
|
-
export {
|
|
5389
|
+
export { skippedSzFilesMessage as $, isMonorepoPackage as A, isPackagesSkippedSource as B, isRSCServerModule as C, isTailwindReservedGlobalVar as D, lateMangleCensusMessage as E, mangleCodeClassesSync as F, mangleEligibleClasses as G, mangleHybridHazardMessage as H, missingTailwindEntryMessage as I, normalizeGlobalVarAliasesForCache as J, planGlobalVarAliases as K, readGlobalVarScanCache as L, realContentHashDisabledMessage as M, recordGlobalVarSourceFile as N, resolveCompileSourceDirs as O, resolveGlobalVarScanCacheDir as P, resolveNativeCacheIdentity as Q, resolveQuietMode as R, rewriteGlobalVarCssAliases as S, rollupPlugin as T, scanGlobalVarCss as U, shouldEmitMissingCssFallback as V, shouldEmitWarning as W, shouldHoldAdvisories as X, shouldTrackGlobalVarSources as Y, shouldWarnMissingTailwindEntry as Z, shouldWarnUnscopedMonorepo as _, allocateMangleTokens as a, suppressedAdvisoryMessage as a0, unscopedMonorepoMessage as a1, validateGlobalVarAliasInputs as a2, vitePlugin as a3, watchModeMangleMessage as a4, webpackPlugin as a5, writeGlobalVarScanCache as a6, assertNoRSCBoundaryViolation as b, assertNoRSCGraphViolation as c, collectMangleHybridHazards as d, createGlobalVarAliasValidationOptions as e, createGlobalVarMapAssetSource as f, createGlobalVarScanCacheKey as g, createRSCModuleRecord as h, cssHasContentScope as i, deleteRSCModuleRecord as j, emitKeyValueDiagnostic as k, emitMissingCssFallback as l, esbuildPlugin as m, extractGlobalVarAliasesForManifest as n, fileMayContainSafelistableSz as o, findLocalImportSources as p, findRSCBoundaryViolation as q, findRSCGraphViolation as r, hasInjectableTailwindCandidate as s, hasUseClientDirective as t, unplugin as u, hasUseServerDirective as v, isAdvisoryDiagnostic as w, isCompileSourceOptedIn as x, isHardIgnoredPath as y, isMangleableCssId as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
-
import { S as SAFELIST_FILE, d as atomicWriteFileSync, s as sortStrings, r as renderSafelistFile, e as removeLegacySafelists, g as assertNoLegacySourceStylesheet } from './unplugin.
|
|
3
|
+
import { S as SAFELIST_FILE, d as atomicWriteFileSync, s as sortStrings, r as renderSafelistFile, e as removeLegacySafelists, g as assertNoLegacySourceStylesheet } from './unplugin.Ba3O1r8M.mjs';
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { hostname } from 'node:os';
|
|
6
6
|
import lockfile from 'proper-lockfile';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const node_crypto = require('node:crypto');
|
|
4
4
|
const fs = require('node:fs');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
+
const pathNormalization = require('./unplugin.BqKLlo1h.cjs');
|
|
6
7
|
|
|
7
8
|
function _interopNamespaceCompat(e) {
|
|
8
9
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -27,11 +28,6 @@ function sortStrings(values) {
|
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
|
|
31
|
-
function normalizePathSeparators(value) {
|
|
32
|
-
return value.split(WINDOWS_PATH_SEPARATOR).join("/");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
31
|
const DEFAULT_RENAME_RETRIES = 5;
|
|
36
32
|
const DEFAULT_RENAME_RETRY_DELAY_MS = 10;
|
|
37
33
|
function isRetryableRenameError(error) {
|
|
@@ -229,8 +225,8 @@ function legacySourceMessage(cssFile, target) {
|
|
|
229
225
|
const TAILWIND_SPECIFIER = String.raw`["']tailwindcss(?:\/[^"']*)?["']`;
|
|
230
226
|
const TAILWIND_IMPORT = new RegExp(String.raw`@import\s+${TAILWIND_SPECIFIER}`);
|
|
231
227
|
function computeSafelistRelPath(rootDir, safelistFilename, cssId) {
|
|
232
|
-
const safelistPath = normalizePathSeparators(path__namespace.join(rootDir, safelistFilename));
|
|
233
|
-
const cssDir = normalizePathSeparators(path__namespace.dirname(cssId));
|
|
228
|
+
const safelistPath = pathNormalization.normalizePathSeparators(path__namespace.join(rootDir, safelistFilename));
|
|
229
|
+
const cssDir = pathNormalization.normalizePathSeparators(path__namespace.dirname(cssId));
|
|
234
230
|
let relPath = path__namespace.posix.relative(cssDir, safelistPath);
|
|
235
231
|
if (!relPath.startsWith("./") && !relPath.startsWith("../")) {
|
|
236
232
|
relPath = `./${relPath}`;
|
|
@@ -282,7 +278,6 @@ exports.findLegacySourceDirective = findLegacySourceDirective;
|
|
|
282
278
|
exports.findPostcssConfigWithoutCsszyx = findPostcssConfigWithoutCsszyx;
|
|
283
279
|
exports.legacySourceMessage = legacySourceMessage;
|
|
284
280
|
exports.missingPostcssPluginMessage = missingPostcssPluginMessage;
|
|
285
|
-
exports.normalizePathSeparators = normalizePathSeparators;
|
|
286
281
|
exports.removeLegacySafelists = removeLegacySafelists;
|
|
287
282
|
exports.renderSafelistFile = renderSafelistFile;
|
|
288
283
|
exports.sortStrings = sortStrings;
|
|
@@ -4,9 +4,10 @@ const fs = require('node:fs');
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const compiler = require('@csszyx/compiler');
|
|
6
6
|
const types = require('@csszyx/types');
|
|
7
|
-
const transformCache = require('./unplugin.
|
|
8
|
-
const
|
|
7
|
+
const transformCache = require('./unplugin.YcnV3Izb.cjs');
|
|
8
|
+
const pathNormalization = require('./unplugin.BqKLlo1h.cjs');
|
|
9
9
|
const node_crypto = require('node:crypto');
|
|
10
|
+
const safelistSource = require('./unplugin.DS6CFjim.cjs');
|
|
10
11
|
|
|
11
12
|
function _interopNamespaceCompat(e) {
|
|
12
13
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -124,7 +125,7 @@ function configWithImportedStaticSz(config, importedStaticSz) {
|
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
127
|
function normalizeProviderPaths(providers) {
|
|
127
|
-
return [...new Set(providers.map(
|
|
128
|
+
return [...new Set(providers.map(pathNormalization.normalizePathSeparators))];
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
function readPackageVersion(relativePackageJson, fromUrl) {
|
|
@@ -283,7 +284,7 @@ function createNextSourceTransformCacheInput(input, filename, producer) {
|
|
|
283
284
|
};
|
|
284
285
|
}
|
|
285
286
|
function normalizeSourceFilename(filename) {
|
|
286
|
-
return
|
|
287
|
+
return pathNormalization.normalizePathSeparators(filename);
|
|
287
288
|
}
|
|
288
289
|
function normalizeGlobalVarAliasesForCache(aliases) {
|
|
289
290
|
if (!aliases) {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const LEADING_WHITESPACE_RE = /^\s+/;
|
|
2
|
+
const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
|
|
3
|
+
const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
|
|
4
|
+
const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
|
|
5
|
+
function insertAfterUseDirective(code, insertion) {
|
|
6
|
+
let offset = 0;
|
|
7
|
+
while (offset < code.length) {
|
|
8
|
+
const triviaLength = leadingTriviaLength(code.slice(offset));
|
|
9
|
+
if (triviaLength === 0) break;
|
|
10
|
+
offset += triviaLength;
|
|
11
|
+
}
|
|
12
|
+
const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
|
|
13
|
+
if (!directive) return `${insertion}${code}`;
|
|
14
|
+
const insertionOffset = offset + directive[0].length;
|
|
15
|
+
return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
|
|
16
|
+
}
|
|
17
|
+
function leadingTriviaLength(source) {
|
|
18
|
+
return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
|
|
22
|
+
function clauseNames(clauseBody) {
|
|
23
|
+
const names = [];
|
|
24
|
+
for (const part of clauseBody.split(",")) {
|
|
25
|
+
const trimmed = part.trim();
|
|
26
|
+
if (!trimmed) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const spaceAt = trimmed.search(/\s/);
|
|
30
|
+
names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
|
|
31
|
+
}
|
|
32
|
+
return names;
|
|
33
|
+
}
|
|
34
|
+
function importsRuntimeHelper(code, helper) {
|
|
35
|
+
RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
|
|
36
|
+
for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
|
|
37
|
+
if (clauseNames(match[1]).includes(helper)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
|
|
44
|
+
function findRuntimeImportClause(code) {
|
|
45
|
+
const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
|
|
46
|
+
return match ? { statement: match[0], prefixWithBody: match[1] } : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function runtimeHelperGroupsFromUsage(usage) {
|
|
50
|
+
const slim = usage.usesSzPart === true && usage.szPartArgsProvable === true && usage.usesRuntime !== true && usage.usesMerge !== true;
|
|
51
|
+
const groups = { all: [], barrel: [], merge: [] };
|
|
52
|
+
const append = (helper, toMerge = false) => {
|
|
53
|
+
groups.all.push(helper);
|
|
54
|
+
(toMerge ? groups.merge : groups.barrel).push(helper);
|
|
55
|
+
};
|
|
56
|
+
if (usage.usesRuntime) append("_sz");
|
|
57
|
+
if (usage.usesMerge) append("_szMerge");
|
|
58
|
+
if (usage.usesSzcn) append("_szcn", slim);
|
|
59
|
+
if (usage.usesSzPart) append("_szPart", slim);
|
|
60
|
+
if (usage.usesSzvPick) append("__szvPick");
|
|
61
|
+
if (usage.usesSzvPick1) append("__szvPick1");
|
|
62
|
+
if (usage.usesColorVar) append("__szColorVar");
|
|
63
|
+
if (usage.usesSpacingVar) append("__szSpacingVar");
|
|
64
|
+
if (usage.usesUnitVar) append("__szUnitVar");
|
|
65
|
+
if (usage.usesBoolClass) append("__szBoolClass");
|
|
66
|
+
return groups;
|
|
67
|
+
}
|
|
68
|
+
function injectNextRuntimeImports(code, usage) {
|
|
69
|
+
const groups = runtimeHelperGroupsFromUsage(usage);
|
|
70
|
+
const helpers = groups.all;
|
|
71
|
+
if (helpers.length === 0) {
|
|
72
|
+
return { code, injected: [] };
|
|
73
|
+
}
|
|
74
|
+
const hasRuntimeImport = code.includes("@csszyx/runtime");
|
|
75
|
+
const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
|
|
76
|
+
if (missing.length === 0) {
|
|
77
|
+
return { code, injected: [] };
|
|
78
|
+
}
|
|
79
|
+
if (groups.merge.length > 0) {
|
|
80
|
+
const mergeHelpers = missing.filter((helper) => groups.merge.includes(helper));
|
|
81
|
+
const barrelHelpers = missing.filter((helper) => groups.barrel.includes(helper));
|
|
82
|
+
let next = insertRuntimeImport(
|
|
83
|
+
code,
|
|
84
|
+
`import { ${mergeHelpers.join(", ")} } from '@csszyx/runtime/merge';
|
|
85
|
+
`
|
|
86
|
+
);
|
|
87
|
+
if (barrelHelpers.length > 0) {
|
|
88
|
+
next = insertRuntimeImport(
|
|
89
|
+
next,
|
|
90
|
+
`import { ${barrelHelpers.join(", ")} } from '@csszyx/runtime';
|
|
91
|
+
`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return { code: next, injected: missing };
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
code: insertRuntimeImport(
|
|
98
|
+
code,
|
|
99
|
+
`import { ${missing.join(", ")} } from '@csszyx/runtime';
|
|
100
|
+
`
|
|
101
|
+
),
|
|
102
|
+
injected: missing
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function insertRuntimeImport(code, importStmt) {
|
|
106
|
+
return insertAfterUseDirective(code, importStmt);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { insertAfterUseDirective as a, importsRuntimeHelper as b, findRuntimeImportClause as f, injectNextRuntimeImports as i, runtimeHelperGroupsFromUsage as r };
|