weapp-tailwindcss 5.0.11 → 5.0.13
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/{bundle-state-BwtEqxvU.js → bundle-state-CKWeTEhv.js} +2 -40
- package/dist/{bundle-state-CXzPknlT.mjs → bundle-state-zQ2MrDdi.mjs} +2 -34
- package/dist/bundlers/gulp/vinyl-transform.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/hmr-timing.d.ts +1 -0
- package/dist/bundlers/vite/css-memory.d.ts +27 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +9 -7
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/map-cache.d.ts +2 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates.d.ts +9 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/vite/source-scan.d.ts +1 -1
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +11 -8
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cli.js +9 -2
- package/dist/cli.mjs +8 -1
- package/dist/core.d.ts +7 -0
- package/dist/core.js +8 -5
- package/dist/core.mjs +8 -5
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
- package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/framework/index.d.ts +59 -0
- package/dist/framework.d.ts +1 -0
- package/dist/framework.js +198 -0
- package/dist/framework.mjs +180 -0
- package/dist/{generator-ChgOWNOj.js → generator-CzpArpCL.js} +1 -1
- package/dist/{generator-h2XRiJ9-.mjs → generator-ITLd7PTl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-Be88jhoY.mjs → gulp-DfOQERcV.mjs} +137 -23
- package/dist/{gulp-CHtZF-oT.js → gulp-XT8Jc7lH.js} +137 -23
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BkivBZvN.js → hmr-timing-BMftW7Us.js} +354 -225
- package/dist/{hmr-timing-Ct5w4hdM.mjs → hmr-timing-DQIP_8qP.mjs} +341 -225
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/postcss.js +9 -10
- package/dist/postcss.mjs +7 -5
- package/dist/{precheck-CY9oaH49.js → precheck-B0Z8yW7E.js} +108 -27
- package/dist/{precheck-BpHxsWRd.mjs → precheck-CRI90iL1.mjs} +109 -28
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +3 -3
- package/dist/tailwindcss/source-scan.d.ts +1 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +17 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v3-engine/types.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +19 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/{tailwindcss-Bfy2egdX.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
- package/dist/{tailwindcss-DbbAKAZP.js → tailwindcss-DZEwT3C_.js} +3 -3
- package/dist/{transform-r5evL6Hn.mjs → transform-DfcEjsZF.mjs} +29 -21
- package/dist/{transform-Cd634UZV.js → transform-YmrmxuF3.js} +29 -21
- package/dist/types/user-defined-options/general.d.ts +3 -1
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/{v3-engine-D0yA9ZkF.js → v3-engine-2rrgylhn.js} +194 -34
- package/dist/{v3-engine-CFkP6dWF.mjs → v3-engine-C6eJ0YzK.mjs} +176 -34
- package/dist/{vite-j9cB2Ff1.js → vite-CXHVsHmX.js} +2071 -1160
- package/dist/{vite-Bd8qf9dK.mjs → vite-DjI09vVN.mjs} +2071 -1160
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +476 -217
- package/dist/weapp-tw-runtime-classset-loader.js +25 -0
- package/dist/{webpack-DPdrcC2X.mjs → webpack-BcPpnT90.mjs} +251 -40
- package/dist/{webpack-CJAOcYEO.js → webpack-CfkUkMXG.js} +254 -43
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +10 -5
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-
|
|
3
|
-
import { h as traverse, m as babelParse, p as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-
|
|
4
|
-
import { r as isUniAppXEnabled } from "./tailwindcss-
|
|
1
|
+
import { $ as loadTailwindV4DesignSystem, A as normalizeTailwindSourceDirectives, B as splitGeneratorPlaceholderCssBySourceOrder, C as resolveTailwindV4SourceFromPatcher, D as hasTailwindRootDirectives, E as hasTailwindApplyDirective, F as resolveCssEntrySource, G as stripTailwindBanners, H as splitTailwindV4GeneratedCssBySourceOrder, I as VITE_MARKER_RE, K as normalizeConfigDirective, L as createCssAppend, M as normalizeTailwindV3CssEntrySource, N as parseImportRequest, O as hasTailwindSourceDirectives, P as removeTailwindSourceDirectives, Q as filterUnsupportedMiniProgramTailwindV4Candidates, R as hasTailwindGeneratedCss, U as stripGeneratorPlaceholderMarkers, V as splitTailwindGeneratedCssByBanner, W as stripTailwindBanner, _ as resolveTailwindConfigEntriesFromCssCached, at as toPosixPath$1, et as FULL_SOURCE_SCAN_EXTENSION_RE, gt as omitUndefined, it as resolveTailwindV4CssSourceBase, n as resolveTailwindV3SourceFromPatcher, nt as normalizeLegacyContentEntries, ot as createDebug, q as prependConfigDirective, r as resolveTailwindV3SourceOptionsFromPatcher, rt as resolveSourceScanPath, t as resolveTailwindV3Source, tt as isFileMatchedByTailwindSourceEntries, u as getRuntimeClassSetSignature, v as resolveTailwindV4EntriesFromCss, w as resolveTailwindV4SourceOptionsFromPatcher, x as resolveTailwindV4Source$1, z as hasTailwindGeneratedCssMarkers } from "./v3-engine-C6eJ0YzK.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-ITLd7PTl.mjs";
|
|
3
|
+
import { h as traverse, m as babelParse, p as replaceWxml, r as resolveStyleOptionsFromContext, x as md5Hash } from "./precheck-CRI90iL1.mjs";
|
|
4
|
+
import { r as isUniAppXEnabled } from "./tailwindcss-DTq3uYBK.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import { finalizeMiniProgramCss, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedMiniProgramAtRules } from "@weapp-tailwindcss/postcss";
|
|
7
|
-
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "tailwindcss-patch";
|
|
8
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
7
|
import path from "node:path";
|
|
10
8
|
import process from "node:process";
|
|
9
|
+
import { finalizeMiniProgramCss, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules } from "@weapp-tailwindcss/postcss";
|
|
10
|
+
import { LRUCache } from "lru-cache";
|
|
11
|
+
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "tailwindcss-patch";
|
|
11
12
|
import { readFile } from "node:fs/promises";
|
|
12
13
|
import { MappingChars2String, unescape } from "@weapp-core/escape";
|
|
13
14
|
//#region src/bundlers/shared/cache.ts
|
|
@@ -100,6 +101,9 @@ function removeTracedTailwindGeneratedContainerRules(root) {
|
|
|
100
101
|
rule.remove();
|
|
101
102
|
});
|
|
102
103
|
}
|
|
104
|
+
function normalizeTraceCommentBefore(value) {
|
|
105
|
+
return value?.includes("\n") ? value : "\n";
|
|
106
|
+
}
|
|
103
107
|
function annotateCssSourceTrace(css, options) {
|
|
104
108
|
if (!isCssSourceTraceEnabled(options.opts) || !options.tokenSources?.size) return css;
|
|
105
109
|
try {
|
|
@@ -114,7 +118,7 @@ function annotateCssSourceTrace(css, options) {
|
|
|
114
118
|
return `${token} <= ${sources.length > 0 ? sources.join(", ") : "<tailwind generated>"}`;
|
|
115
119
|
});
|
|
116
120
|
const comment = postcss.comment({ text: `tokens: ${lines.join(" | ")}` });
|
|
117
|
-
|
|
121
|
+
comment.raws.before = normalizeTraceCommentBefore(rule.raws.before);
|
|
118
122
|
rule.raws.before = "\n";
|
|
119
123
|
rule.parent.insertBefore(rule, comment);
|
|
120
124
|
});
|
|
@@ -131,7 +135,8 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
131
135
|
return finalizeMiniProgramCss(css, {
|
|
132
136
|
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
133
137
|
isTailwindcssV4: majorVersion === 4,
|
|
134
|
-
preservePseudoContentInit: majorVersion === 3
|
|
138
|
+
preservePseudoContentInit: majorVersion === 3,
|
|
139
|
+
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
135
140
|
});
|
|
136
141
|
}
|
|
137
142
|
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
@@ -140,12 +145,24 @@ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
|
140
145
|
return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
141
146
|
}
|
|
142
147
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
143
|
-
if (options.
|
|
144
|
-
|
|
148
|
+
if (options.majorVersion === 3 && !options.isolateCssSource) return new Set([
|
|
149
|
+
...scopedRuntime,
|
|
150
|
+
...runtime,
|
|
151
|
+
...options.currentCssCandidates ?? []
|
|
152
|
+
]);
|
|
153
|
+
if (options.isolateCssSource) {
|
|
154
|
+
if (options.matchedCssSourceFile) return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
155
|
+
return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
156
|
+
}
|
|
157
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk) return scopedRuntime;
|
|
145
158
|
return new Set([...scopedRuntime, ...runtime]);
|
|
146
159
|
}
|
|
147
|
-
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
148
|
-
|
|
160
|
+
function shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, options) {
|
|
161
|
+
if (options.target !== "weapp") return false;
|
|
162
|
+
if (source.__weappTailwindcssMeta?.isolateCssSource) return true;
|
|
163
|
+
if (source.__weappTailwindcssMeta?.matchedCssSourceFile && (sourceEntries?.length ?? 0) > 0) return true;
|
|
164
|
+
if (sourceEntries?.length === 0) return false;
|
|
165
|
+
return (majorVersion === 3 || majorVersion === 4) && sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
|
|
149
166
|
}
|
|
150
167
|
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
151
168
|
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
@@ -163,13 +180,13 @@ function isEmptyCssSourceOrderParts(parts) {
|
|
|
163
180
|
return parts.before.trim().length === 0 && parts.after.trim().length === 0;
|
|
164
181
|
}
|
|
165
182
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
183
|
+
const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
|
|
166
184
|
const preflightStyleOptions = {
|
|
167
|
-
cssPreflight:
|
|
168
|
-
cssPreflightRange:
|
|
185
|
+
cssPreflight: resolvedStyleOptions.cssPreflight,
|
|
186
|
+
cssPreflightRange: resolvedStyleOptions.cssPreflightRange
|
|
169
187
|
};
|
|
170
188
|
return {
|
|
171
|
-
...
|
|
172
|
-
atRules: opts.atRules,
|
|
189
|
+
...resolvedStyleOptions,
|
|
173
190
|
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
174
191
|
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
175
192
|
...cssHandlerOptions,
|
|
@@ -193,9 +210,9 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
193
210
|
if (exactParts) return exactParts;
|
|
194
211
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
195
212
|
}
|
|
196
|
-
function shouldUseGeneratorForCurrentCss(
|
|
213
|
+
function shouldUseGeneratorForCurrentCss(_majorVersion, cssHandlerOptions, options) {
|
|
197
214
|
const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
|
|
198
|
-
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives ||
|
|
215
|
+
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || cssHandlerOptions.isMainChunk;
|
|
199
216
|
}
|
|
200
217
|
function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
|
|
201
218
|
return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
@@ -547,98 +564,53 @@ function extractStyleDirectiveSources(source) {
|
|
|
547
564
|
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
548
565
|
while (match !== null) {
|
|
549
566
|
const styleSource = match[1] ?? "";
|
|
550
|
-
if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
|
|
567
|
+
if (hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
|
|
551
568
|
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
552
569
|
}
|
|
553
570
|
if (styleSources.length > 0) return styleSources;
|
|
554
|
-
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
571
|
+
return hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
|
|
555
572
|
}
|
|
556
573
|
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
557
|
-
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
} catch {
|
|
569
|
-
continue;
|
|
574
|
+
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) try {
|
|
575
|
+
const source = sourceOptions.sourceFile && path.resolve(sourceOptions.sourceFile) === path.resolve(sourceFile) && typeof sourceOptions.sourceCss === "string" ? sourceOptions.sourceCss : existsSync(sourceFile) ? readFileSync(sourceFile, "utf8") : void 0;
|
|
576
|
+
if (source === void 0) continue;
|
|
577
|
+
for (const styleSource of extractStyleDirectiveSources(source)) {
|
|
578
|
+
const cssEntrySource = resolveCssEntrySource(styleSource, path.dirname(sourceFile), resolveOptions);
|
|
579
|
+
if (cssEntrySource) return {
|
|
580
|
+
...cssEntrySource,
|
|
581
|
+
file: sourceFile
|
|
582
|
+
};
|
|
570
583
|
}
|
|
584
|
+
} catch {
|
|
585
|
+
continue;
|
|
571
586
|
}
|
|
572
587
|
}
|
|
573
588
|
//#endregion
|
|
574
|
-
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
575
|
-
function
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
585
|
-
return cssHandlerOptions.sourceOptions;
|
|
586
|
-
}
|
|
587
|
-
function createCssEntrySources(cssEntries) {
|
|
588
|
-
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
589
|
-
}
|
|
590
|
-
function mergeCssSources(cssSources, cssEntrySources) {
|
|
591
|
-
const merged = [];
|
|
592
|
-
const seenFiles = /* @__PURE__ */ new Set();
|
|
593
|
-
const addSource = (cssSource) => {
|
|
594
|
-
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.resolve(cssSource.file) : void 0;
|
|
595
|
-
if (file) {
|
|
596
|
-
if (seenFiles.has(file)) return;
|
|
597
|
-
seenFiles.add(file);
|
|
598
|
-
}
|
|
599
|
-
merged.push(cssSource);
|
|
600
|
-
};
|
|
601
|
-
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
602
|
-
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
603
|
-
return merged.length > 0 ? merged : void 0;
|
|
604
|
-
}
|
|
605
|
-
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
606
|
-
return omitUndefined({
|
|
607
|
-
projectRoot: sourceOptions.projectRoot,
|
|
608
|
-
baseFallbacks: sourceOptions.baseFallbacks,
|
|
609
|
-
packageName: sourceOptions.packageName,
|
|
610
|
-
base: options.base,
|
|
611
|
-
css: options.css
|
|
612
|
-
});
|
|
589
|
+
//#region src/bundlers/shared/generator-css/source-resolver/apply-reference.ts
|
|
590
|
+
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
591
|
+
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
592
|
+
const utilities = collectTailwindApplyUtilities(css);
|
|
593
|
+
return [
|
|
594
|
+
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
595
|
+
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
596
|
+
css
|
|
597
|
+
].filter(Boolean).join("\n");
|
|
613
598
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
...sourceOptions,
|
|
625
|
-
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
626
|
-
});
|
|
627
|
-
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
628
|
-
...omitUndefined(singleEntrySourceOptions),
|
|
629
|
-
base,
|
|
630
|
-
css: normalizeConfigDirective(css, config),
|
|
631
|
-
cssEntries: [cssEntry]
|
|
632
|
-
}), {
|
|
633
|
-
matchedCssSourceFile: cssEntry,
|
|
634
|
-
sourceBase: base,
|
|
635
|
-
sourceCss: css
|
|
599
|
+
function collectTailwindApplyUtilities(css) {
|
|
600
|
+
let root;
|
|
601
|
+
try {
|
|
602
|
+
root = postcss.parse(css);
|
|
603
|
+
} catch {
|
|
604
|
+
return [];
|
|
605
|
+
}
|
|
606
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
607
|
+
root.walkAtRules("apply", (rule) => {
|
|
608
|
+
for (const utility of splitCandidateTokens(rule.params)) utilities.add(utility);
|
|
636
609
|
});
|
|
610
|
+
return [...utilities].sort();
|
|
637
611
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return path.dirname(path.resolve(normalized));
|
|
641
|
-
}
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/bundlers/shared/generator-css/source-resolver/config.ts
|
|
642
614
|
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
643
615
|
if (config && existsSync(config)) return config;
|
|
644
616
|
if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
|
|
@@ -665,20 +637,8 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
665
637
|
for (const candidate of configCandidates) if (existsSync(candidate)) return candidate;
|
|
666
638
|
return sourceOptions.config;
|
|
667
639
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
671
|
-
return true;
|
|
672
|
-
}
|
|
673
|
-
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
674
|
-
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
675
|
-
}
|
|
676
|
-
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
677
|
-
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
678
|
-
}
|
|
679
|
-
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
680
|
-
return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !existsSync(cssEntrySource.config));
|
|
681
|
-
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/bundlers/shared/generator-css/source-resolver/matching.ts
|
|
682
642
|
function normalizeCssSourceForCompare(css) {
|
|
683
643
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
684
644
|
}
|
|
@@ -729,6 +689,107 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
|
729
689
|
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
730
690
|
return bestScore;
|
|
731
691
|
}
|
|
692
|
+
//#endregion
|
|
693
|
+
//#region src/bundlers/shared/generator-css/source-resolver/metadata.ts
|
|
694
|
+
function withGeneratorSourceMetadata(source, metadata) {
|
|
695
|
+
return {
|
|
696
|
+
...source,
|
|
697
|
+
__weappTailwindcssMeta: metadata
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
701
|
+
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
702
|
+
isolateCssSource: true,
|
|
703
|
+
matchedCssSourceFile: resolvedEntrySource.file,
|
|
704
|
+
sourceBase: resolvedEntrySource.base,
|
|
705
|
+
sourceCss: resolvedEntrySource.css
|
|
706
|
+
}) : source;
|
|
707
|
+
}
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
710
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
711
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
712
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
713
|
+
}
|
|
714
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
715
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
716
|
+
if (!from || !path.isAbsolute(from)) return;
|
|
717
|
+
return from.replace(/[?#].*$/, "");
|
|
718
|
+
}
|
|
719
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
720
|
+
return cssHandlerOptions.sourceOptions;
|
|
721
|
+
}
|
|
722
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
723
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
724
|
+
return path.dirname(path.resolve(normalized));
|
|
725
|
+
}
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
728
|
+
function createCssEntrySources(cssEntries) {
|
|
729
|
+
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
730
|
+
}
|
|
731
|
+
function mergeCssSources(cssSources, cssEntrySources) {
|
|
732
|
+
const merged = [];
|
|
733
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
734
|
+
const addSource = (cssSource) => {
|
|
735
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.resolve(cssSource.file) : void 0;
|
|
736
|
+
if (file) {
|
|
737
|
+
if (seenFiles.has(file)) return;
|
|
738
|
+
seenFiles.add(file);
|
|
739
|
+
}
|
|
740
|
+
merged.push(cssSource);
|
|
741
|
+
};
|
|
742
|
+
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
743
|
+
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
744
|
+
return merged.length > 0 ? merged : void 0;
|
|
745
|
+
}
|
|
746
|
+
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
747
|
+
return omitUndefined({
|
|
748
|
+
projectRoot: sourceOptions.projectRoot,
|
|
749
|
+
baseFallbacks: sourceOptions.baseFallbacks,
|
|
750
|
+
packageName: sourceOptions.packageName,
|
|
751
|
+
base: options.base,
|
|
752
|
+
css: options.css
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
756
|
+
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
757
|
+
if (!existsSync(cssEntry)) return resolveTailwindV4Source$1({
|
|
758
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
759
|
+
cssEntries: [cssEntry]
|
|
760
|
+
});
|
|
761
|
+
const css = readFileSync(cssEntry, "utf8");
|
|
762
|
+
const base = path.dirname(path.resolve(cssEntry));
|
|
763
|
+
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
764
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
|
|
765
|
+
...sourceOptions,
|
|
766
|
+
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
767
|
+
});
|
|
768
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
769
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
770
|
+
base,
|
|
771
|
+
css: normalizeConfigDirective(css, config),
|
|
772
|
+
cssEntries: [cssEntry]
|
|
773
|
+
}), {
|
|
774
|
+
matchedCssSourceFile: cssEntry,
|
|
775
|
+
sourceBase: base,
|
|
776
|
+
sourceCss: css
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
780
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
781
|
+
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
785
|
+
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
786
|
+
}
|
|
787
|
+
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
788
|
+
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
789
|
+
}
|
|
790
|
+
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
791
|
+
return Boolean(sourceSideEntrySource?.config) && (Boolean(cssEntrySource?.configRequest) || !cssEntrySource?.config) && (!cssEntrySource?.config || !existsSync(cssEntrySource.config));
|
|
792
|
+
}
|
|
732
793
|
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
733
794
|
const cssEntries = sourceOptions.cssEntries;
|
|
734
795
|
if (!cssEntries?.length) return;
|
|
@@ -906,12 +967,6 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
906
967
|
css
|
|
907
968
|
})), resolvedEntrySource);
|
|
908
969
|
}
|
|
909
|
-
function withGeneratorSourceMetadata(source, metadata) {
|
|
910
|
-
return {
|
|
911
|
-
...source,
|
|
912
|
-
__weappTailwindcssMeta: metadata
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
970
|
function resolveTailwindV3SourceEntries(source) {
|
|
916
971
|
if (!("version" in source) || source.version !== 3) return;
|
|
917
972
|
const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? path.dirname(source.config) : source.cwd });
|
|
@@ -921,35 +976,6 @@ function withTailwindV3SourceMetadata(source) {
|
|
|
921
976
|
const sourceEntries = resolveTailwindV3SourceEntries(source);
|
|
922
977
|
return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
|
|
923
978
|
}
|
|
924
|
-
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
925
|
-
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
926
|
-
matchedCssSourceFile: resolvedEntrySource.file,
|
|
927
|
-
sourceBase: resolvedEntrySource.base,
|
|
928
|
-
sourceCss: resolvedEntrySource.css
|
|
929
|
-
}) : source;
|
|
930
|
-
}
|
|
931
|
-
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
932
|
-
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
933
|
-
const utilities = collectTailwindApplyUtilities(css);
|
|
934
|
-
return [
|
|
935
|
-
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
936
|
-
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
937
|
-
css
|
|
938
|
-
].filter(Boolean).join("\n");
|
|
939
|
-
}
|
|
940
|
-
function collectTailwindApplyUtilities(css) {
|
|
941
|
-
let root;
|
|
942
|
-
try {
|
|
943
|
-
root = postcss.parse(css);
|
|
944
|
-
} catch {
|
|
945
|
-
return [];
|
|
946
|
-
}
|
|
947
|
-
const utilities = /* @__PURE__ */ new Set();
|
|
948
|
-
root.walkAtRules("apply", (rule) => {
|
|
949
|
-
for (const utility of splitCandidateTokens(rule.params)) utilities.add(utility);
|
|
950
|
-
});
|
|
951
|
-
return [...utilities].sort();
|
|
952
|
-
}
|
|
953
979
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
954
980
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
955
981
|
const cssEntrySource = resolveCssEntrySource(rawSource, base, {
|
|
@@ -982,15 +1008,19 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
982
1008
|
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
983
1009
|
...config ? { config } : {}
|
|
984
1010
|
}));
|
|
1011
|
+
const cssEntrySourceEntries = await resolveTailwindConfigEntriesFromCssCached(rawSource, resolvedEntrySource.base);
|
|
1012
|
+
const sourceMetadata = sourceWithMetadata.__weappTailwindcssMeta;
|
|
1013
|
+
const matchedSourceFile = resolvedEntrySource.file ?? sourceSideEntrySource?.file;
|
|
985
1014
|
return withGeneratorSourceMetadata(sourceWithMetadata, {
|
|
986
|
-
...
|
|
987
|
-
matchedCssSourceFile:
|
|
1015
|
+
...sourceMetadata,
|
|
1016
|
+
matchedCssSourceFile: matchedSourceFile,
|
|
1017
|
+
sourceEntries: cssEntrySourceEntries?.entries ?? sourceMetadata?.sourceEntries
|
|
988
1018
|
});
|
|
989
1019
|
}
|
|
990
1020
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
991
1021
|
const resolvedSourceOptions = sourceOptions ? omitUndefined({
|
|
992
1022
|
...sourceOptions,
|
|
993
|
-
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
1023
|
+
sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
|
|
994
1024
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
995
1025
|
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
996
1026
|
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
@@ -1004,17 +1034,18 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1004
1034
|
}));
|
|
1005
1035
|
}
|
|
1006
1036
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
1007
|
-
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
1037
|
+
const sourceSideEntrySource = normalizedSourceOptions && (shouldPreferSourceSideEntry || normalizedSourceOptions.sourceFile !== void 0) && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
1008
1038
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
1009
1039
|
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
1010
1040
|
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1011
|
-
const
|
|
1041
|
+
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
|
|
1042
|
+
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source$1(normalizedSourceOptions) : void 0;
|
|
1012
1043
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1013
1044
|
...configuredCssSource,
|
|
1014
1045
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1015
1046
|
} : configuredCssSource;
|
|
1016
1047
|
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
1017
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
1048
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1018
1049
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1019
1050
|
...preferredCssEntrySource,
|
|
1020
1051
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -1054,7 +1085,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1054
1085
|
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
1055
1086
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
1056
1087
|
cssEntries,
|
|
1057
|
-
cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
1088
|
+
cssSources: mergeCssSources(mergeCssSources(sourceOptionsFromPatcher.cssSources, selectionOptions?.cssSources), sourceOptionsFromPatcher.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
1058
1089
|
});
|
|
1059
1090
|
} catch {
|
|
1060
1091
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
@@ -1065,7 +1096,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1065
1096
|
...matchedCssEntrySource,
|
|
1066
1097
|
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
1067
1098
|
} : matchedCssEntrySource];
|
|
1068
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(
|
|
1099
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1069
1100
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1070
1101
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1071
1102
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
@@ -1100,6 +1131,10 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
|
1100
1131
|
if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
|
|
1101
1132
|
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
1102
1133
|
const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
1134
|
+
if (resolved?.entries.length === 0 && !resolved.inlineCandidates.included.size && !resolved.inlineCandidates.excluded.size && !resolved.dependencies.length) {
|
|
1135
|
+
if (sourceMetadata?.matchedCssSourceFile) return [];
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1103
1138
|
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
1104
1139
|
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
1105
1140
|
if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && path.resolve(cssSource.file) === path.resolve(sourceMetadata.matchedCssSourceFile)) return true;
|
|
@@ -1523,6 +1558,16 @@ function isCommentOnlyCss(source) {
|
|
|
1523
1558
|
return false;
|
|
1524
1559
|
}
|
|
1525
1560
|
}
|
|
1561
|
+
function unwrapMiniProgramCascadeLayers(source) {
|
|
1562
|
+
if (!source.includes("@layer")) return source;
|
|
1563
|
+
try {
|
|
1564
|
+
const root = postcss.parse(source);
|
|
1565
|
+
removeUnsupportedCascadeLayers(root);
|
|
1566
|
+
return root.toString();
|
|
1567
|
+
} catch {
|
|
1568
|
+
return source;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1526
1571
|
function stripTailwindSourceMediaFragments(source) {
|
|
1527
1572
|
let removedSourceMediaStart = false;
|
|
1528
1573
|
return source.split(/\r?\n/).filter((line) => {
|
|
@@ -1690,7 +1735,7 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
1690
1735
|
if (source.trim().length === 0) return "";
|
|
1691
1736
|
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1692
1737
|
if (cleanedSource.trim().length === 0) return "";
|
|
1693
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1738
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(unwrapMiniProgramCascadeLayers(cleanedSource)) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1694
1739
|
if (userSource.trim().length === 0) return "";
|
|
1695
1740
|
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1696
1741
|
if (options.generatorTarget !== "weapp") return userSource;
|
|
@@ -1820,10 +1865,42 @@ function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
|
|
|
1820
1865
|
};
|
|
1821
1866
|
}
|
|
1822
1867
|
//#endregion
|
|
1868
|
+
//#region src/bundlers/shared/run-tasks.ts
|
|
1869
|
+
async function runWithConcurrency(factories, limit = Math.min(4, Math.max(1, factories.length))) {
|
|
1870
|
+
if (factories.length === 0) return [];
|
|
1871
|
+
const results = Array.from({ length: factories.length });
|
|
1872
|
+
const executing = /* @__PURE__ */ new Set();
|
|
1873
|
+
let cursor = 0;
|
|
1874
|
+
const effectiveLimit = Math.max(1, limit);
|
|
1875
|
+
const scheduleNext = () => {
|
|
1876
|
+
if (cursor >= factories.length) return;
|
|
1877
|
+
const currentIndex = cursor++;
|
|
1878
|
+
const factory = factories[currentIndex];
|
|
1879
|
+
if (!factory) return;
|
|
1880
|
+
const wrapped = Promise.resolve(factory()).then((value) => {
|
|
1881
|
+
results[currentIndex] = value;
|
|
1882
|
+
}).finally(() => {
|
|
1883
|
+
executing.delete(wrapped);
|
|
1884
|
+
});
|
|
1885
|
+
executing.add(wrapped);
|
|
1886
|
+
};
|
|
1887
|
+
while (cursor < factories.length && executing.size < effectiveLimit) scheduleNext();
|
|
1888
|
+
while (cursor < factories.length) {
|
|
1889
|
+
await Promise.race(executing);
|
|
1890
|
+
scheduleNext();
|
|
1891
|
+
}
|
|
1892
|
+
await Promise.all(executing);
|
|
1893
|
+
return results;
|
|
1894
|
+
}
|
|
1895
|
+
function pushConcurrentTaskFactories(queue, factories, limit) {
|
|
1896
|
+
if (factories.length === 0) return;
|
|
1897
|
+
queue.push(runWithConcurrency(factories, limit).then(() => void 0));
|
|
1898
|
+
}
|
|
1899
|
+
//#endregion
|
|
1823
1900
|
//#region src/bundlers/shared/generator-css/validate.ts
|
|
1824
1901
|
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1825
1902
|
async function validateCandidatesByGenerator(options) {
|
|
1826
|
-
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1903
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState, skipGenerateFallback } = options;
|
|
1827
1904
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1828
1905
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1829
1906
|
const generatorOptions = {
|
|
@@ -1839,6 +1916,7 @@ async function validateCandidatesByGenerator(options) {
|
|
|
1839
1916
|
if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
|
|
1840
1917
|
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1841
1918
|
}
|
|
1919
|
+
if (skipGenerateFallback) return /* @__PURE__ */ new Set();
|
|
1842
1920
|
return (await generator.generate({
|
|
1843
1921
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1844
1922
|
candidates,
|
|
@@ -1851,6 +1929,11 @@ async function validateCandidatesByGenerator(options) {
|
|
|
1851
1929
|
}
|
|
1852
1930
|
//#endregion
|
|
1853
1931
|
//#region src/bundlers/shared/generator-css.ts
|
|
1932
|
+
function resolveGeneratorSourceConcurrency() {
|
|
1933
|
+
const configured = Number.parseInt(process.env["WEAPP_TW_GENERATOR_SOURCE_CONCURRENCY"] ?? "", 10);
|
|
1934
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
1935
|
+
return 1;
|
|
1936
|
+
}
|
|
1854
1937
|
async function generateCssByGenerator(options) {
|
|
1855
1938
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1856
1939
|
const generatorOptions = {
|
|
@@ -1891,26 +1974,32 @@ async function generateCssByGenerator(options) {
|
|
|
1891
1974
|
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
1892
1975
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1893
1976
|
cssEntries: opts.cssEntries,
|
|
1977
|
+
cssSources: options.cssSources,
|
|
1894
1978
|
getSourceCandidatesForEntries,
|
|
1895
1979
|
runtime: runtimeWithCurrentCss
|
|
1896
1980
|
});
|
|
1897
1981
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1898
1982
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1899
|
-
const
|
|
1983
|
+
const sourceConcurrency = resolveGeneratorSourceConcurrency();
|
|
1984
|
+
const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
|
|
1900
1985
|
const generator = createWeappTailwindcssGenerator(source);
|
|
1901
1986
|
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
1902
|
-
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
1903
|
-
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries
|
|
1987
|
+
const scopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
1988
|
+
const isolateCssSource = shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, {
|
|
1989
|
+
cssHandlerOptions,
|
|
1990
|
+
target: generatorOptions.target
|
|
1991
|
+
});
|
|
1904
1992
|
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
1905
1993
|
const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
|
|
1906
1994
|
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
1907
1995
|
debug("defer empty scoped css source generation: %s", file);
|
|
1908
1996
|
return;
|
|
1909
1997
|
}
|
|
1910
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1998
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) || isolateCssSource ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime ?? /* @__PURE__ */ new Set(), runtimeWithCurrentCss, {
|
|
1911
1999
|
currentCssCandidates,
|
|
1912
2000
|
cssHandlerOptions,
|
|
1913
2001
|
isolateCssSource,
|
|
2002
|
+
majorVersion,
|
|
1914
2003
|
matchedCssSourceFile
|
|
1915
2004
|
}) : runtimeWithCurrentCss;
|
|
1916
2005
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
@@ -1924,13 +2013,16 @@ async function generateCssByGenerator(options) {
|
|
|
1924
2013
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1925
2014
|
target: generatorOptions.target
|
|
1926
2015
|
});
|
|
1927
|
-
}))).filter((item) => Boolean(item)));
|
|
2016
|
+
}), sourceConcurrency)).filter((item) => Boolean(item)));
|
|
1928
2017
|
if (!generated) return;
|
|
1929
2018
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1930
2019
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1931
2020
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1932
2021
|
return {
|
|
1933
|
-
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2022
|
+
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2023
|
+
injectPreflight: false,
|
|
2024
|
+
styleOptions: generatorStyleOptions
|
|
2025
|
+
})) : options.previousCss, localImportParts?.imports),
|
|
1934
2026
|
target: generated.target,
|
|
1935
2027
|
source: "generator",
|
|
1936
2028
|
dependencies: generated.dependencies,
|
|
@@ -1962,7 +2054,8 @@ async function generateCssByGenerator(options) {
|
|
|
1962
2054
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
1963
2055
|
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
1964
2056
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
1965
|
-
|
|
2057
|
+
const fallbackLayerUserCss = generated.target === "weapp" && afterLayerParts.layer.trim().length === 0 && hasUserCssLayerBlocks(userCssRawSource) ? await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions) : "";
|
|
2058
|
+
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
|
|
1966
2059
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
1967
2060
|
hasSourceDirectives,
|
|
1968
2061
|
hasMatchedCssSourceFile
|
|
@@ -1978,11 +2071,14 @@ async function generateCssByGenerator(options) {
|
|
|
1978
2071
|
}
|
|
1979
2072
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1980
2073
|
return {
|
|
1981
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2074
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2075
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2076
|
+
cssHandlerOptions,
|
|
2077
|
+
isolateCurrentCssCandidates,
|
|
2078
|
+
localImports: localImportParts?.imports
|
|
2079
|
+
}),
|
|
2080
|
+
styleOptions: generatorStyleOptions
|
|
2081
|
+
}), localImportParts?.imports),
|
|
1986
2082
|
target: generated.target,
|
|
1987
2083
|
source: "generator",
|
|
1988
2084
|
dependencies: generated.dependencies
|
|
@@ -2021,6 +2117,18 @@ async function generateCssByGenerator(options) {
|
|
|
2021
2117
|
importFallback: generatorOptions.importFallback
|
|
2022
2118
|
});
|
|
2023
2119
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
2120
|
+
} else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource)) {
|
|
2121
|
+
const layerUserCss = await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, {
|
|
2122
|
+
generatorTarget: generated.target,
|
|
2123
|
+
generatorStyleOptions,
|
|
2124
|
+
cssUserHandlerOptions,
|
|
2125
|
+
styleHandler,
|
|
2126
|
+
importFallback: generatorOptions.importFallback
|
|
2127
|
+
});
|
|
2128
|
+
if (layerUserCss.trim().length > 0) {
|
|
2129
|
+
css = createCssSourceOrderAppend$1(css, wrapUserLayerComponentsCss(layerUserCss));
|
|
2130
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2131
|
+
}
|
|
2024
2132
|
}
|
|
2025
2133
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
2026
2134
|
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
@@ -2039,11 +2147,14 @@ async function generateCssByGenerator(options) {
|
|
|
2039
2147
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
2040
2148
|
}
|
|
2041
2149
|
return {
|
|
2042
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2150
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2151
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2152
|
+
cssHandlerOptions,
|
|
2153
|
+
isolateCurrentCssCandidates,
|
|
2154
|
+
localImports: localImportParts?.imports
|
|
2155
|
+
}),
|
|
2156
|
+
styleOptions: generatorStyleOptions
|
|
2157
|
+
}), localImportParts?.imports),
|
|
2047
2158
|
target: generated.target,
|
|
2048
2159
|
source: "generator",
|
|
2049
2160
|
dependencies: generated.dependencies
|
|
@@ -2054,11 +2165,14 @@ async function generateCssByGenerator(options) {
|
|
|
2054
2165
|
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2055
2166
|
}
|
|
2056
2167
|
return {
|
|
2057
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2168
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2169
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2170
|
+
cssHandlerOptions,
|
|
2171
|
+
isolateCurrentCssCandidates,
|
|
2172
|
+
localImports: localImportParts?.imports
|
|
2173
|
+
}),
|
|
2174
|
+
styleOptions: generatorStyleOptions
|
|
2175
|
+
}), localImportParts?.imports),
|
|
2062
2176
|
target: generated.target,
|
|
2063
2177
|
source: "generator",
|
|
2064
2178
|
dependencies: generated.dependencies
|
|
@@ -2328,7 +2442,7 @@ function createHighConfidenceLiteralRanges(source, matches) {
|
|
|
2328
2442
|
for (const match of matches) {
|
|
2329
2443
|
const candidate = match?.rawCandidate;
|
|
2330
2444
|
if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
|
|
2331
|
-
const range = resolveQuotedLiteralRange(source, match
|
|
2445
|
+
const range = resolveQuotedLiteralRange(source, match?.start ?? source.indexOf(candidate));
|
|
2332
2446
|
if (range) ranges.push(range);
|
|
2333
2447
|
}
|
|
2334
2448
|
return ranges;
|
|
@@ -2630,39 +2744,6 @@ const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
|
|
|
2630
2744
|
"mts",
|
|
2631
2745
|
"cts"
|
|
2632
2746
|
]);
|
|
2633
|
-
const CLASS_LIKE_NAME_RE = /class/i;
|
|
2634
|
-
function getPropertyName(node) {
|
|
2635
|
-
if (!node) return;
|
|
2636
|
-
if (node.type === "Identifier") return node.name;
|
|
2637
|
-
if (node.type === "StringLiteral") return node.value;
|
|
2638
|
-
}
|
|
2639
|
-
function isClassLikeStringPath(path) {
|
|
2640
|
-
const parent = path.parentPath;
|
|
2641
|
-
if (!parent) return false;
|
|
2642
|
-
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2643
|
-
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2644
|
-
if (parent.isAssignmentExpression?.()) {
|
|
2645
|
-
const left = parent.node.left;
|
|
2646
|
-
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2647
|
-
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2648
|
-
}
|
|
2649
|
-
if (parent.isJSXAttribute?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.name) ?? "");
|
|
2650
|
-
return false;
|
|
2651
|
-
}
|
|
2652
|
-
function isTemplateElementInClassLikePath(path) {
|
|
2653
|
-
const templateLiteralPath = path.parentPath;
|
|
2654
|
-
if (!templateLiteralPath?.isTemplateLiteral?.()) return false;
|
|
2655
|
-
const parent = templateLiteralPath.parentPath;
|
|
2656
|
-
if (!parent) return false;
|
|
2657
|
-
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2658
|
-
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2659
|
-
if (parent.isAssignmentExpression?.()) {
|
|
2660
|
-
const left = parent.node.left;
|
|
2661
|
-
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2662
|
-
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2663
|
-
}
|
|
2664
|
-
return false;
|
|
2665
|
-
}
|
|
2666
2747
|
async function extractScriptStringCandidates(source, extension, options) {
|
|
2667
2748
|
if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
|
|
2668
2749
|
const values = /* @__PURE__ */ new Set();
|
|
@@ -2675,10 +2756,10 @@ async function extractScriptStringCandidates(source, extension, options) {
|
|
|
2675
2756
|
}), {
|
|
2676
2757
|
noScope: true,
|
|
2677
2758
|
StringLiteral(path) {
|
|
2678
|
-
|
|
2759
|
+
values.add(path.node.value);
|
|
2679
2760
|
},
|
|
2680
2761
|
TemplateElement(path) {
|
|
2681
|
-
|
|
2762
|
+
values.add(path.node.value.raw);
|
|
2682
2763
|
}
|
|
2683
2764
|
});
|
|
2684
2765
|
} catch {
|
|
@@ -2724,7 +2805,7 @@ function createTailwindV3DefaultExtractor() {
|
|
|
2724
2805
|
//#endregion
|
|
2725
2806
|
//#region src/bundlers/vite/source-candidates.ts
|
|
2726
2807
|
const CLEAN_URL_RE = /[?#].*$/;
|
|
2727
|
-
const sourceCandidateContentCache =
|
|
2808
|
+
const sourceCandidateContentCache = new LRUCache({ max: 128 });
|
|
2728
2809
|
function cleanUrl(id) {
|
|
2729
2810
|
return resolveSourceScanPath(id.replace(CLEAN_URL_RE, ""));
|
|
2730
2811
|
}
|
|
@@ -2733,7 +2814,7 @@ function resolveSourceCandidateExtension(id) {
|
|
|
2733
2814
|
return /\.([^.\\/]+)$/.exec(normalized)?.[1] ?? "html";
|
|
2734
2815
|
}
|
|
2735
2816
|
function createSourceCandidateContentCacheKey(extension, source, bareArbitraryValues, extractor) {
|
|
2736
|
-
return `${extension}\0${JSON.stringify(bareArbitraryValues ?? false)}\0${extractor ? "custom" : "default"}\0${source}`;
|
|
2817
|
+
return `${extension}\0${JSON.stringify(bareArbitraryValues ?? false)}\0${extractor ? "custom" : "default"}\0${md5Hash(source)}`;
|
|
2737
2818
|
}
|
|
2738
2819
|
async function extractCandidates(source, extension, options) {
|
|
2739
2820
|
const candidates = options.extractor ? new Set(await options.extractor(source, extension)) : new Set(await extractSourceCandidates(source, extension, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } }));
|
|
@@ -2783,6 +2864,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2783
2864
|
}
|
|
2784
2865
|
async function syncCss(id, source) {
|
|
2785
2866
|
const normalizedId = cleanUrl(id);
|
|
2867
|
+
sourceById.set(normalizedId, source);
|
|
2786
2868
|
const contentCacheKey = createSourceCandidateContentCacheKey("css", source, options.bareArbitraryValues, options.extractor);
|
|
2787
2869
|
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
2788
2870
|
if (cachedCandidates) {
|
|
@@ -2795,6 +2877,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2795
2877
|
}
|
|
2796
2878
|
async function merge(id, source) {
|
|
2797
2879
|
const normalizedId = cleanUrl(id);
|
|
2880
|
+
sourceById.set(normalizedId, source);
|
|
2798
2881
|
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
2799
2882
|
const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
|
|
2800
2883
|
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
@@ -2804,11 +2887,20 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2804
2887
|
}
|
|
2805
2888
|
async function syncFile(id) {
|
|
2806
2889
|
const normalizedId = cleanUrl(id);
|
|
2807
|
-
|
|
2890
|
+
try {
|
|
2891
|
+
await sync(normalizedId, await readFile(normalizedId, "utf8"));
|
|
2892
|
+
} catch (error) {
|
|
2893
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") {
|
|
2894
|
+
remove(normalizedId);
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
throw error;
|
|
2898
|
+
}
|
|
2808
2899
|
}
|
|
2809
2900
|
async function syncCurrentFile(id) {
|
|
2810
2901
|
const normalizedId = cleanUrl(id);
|
|
2811
2902
|
transformCandidatesById.delete(normalizedId);
|
|
2903
|
+
cssCandidatesById.delete(normalizedId);
|
|
2812
2904
|
await syncFile(normalizedId);
|
|
2813
2905
|
}
|
|
2814
2906
|
async function scanRoot({ entries, explicit, root, outDir }) {
|
|
@@ -2876,6 +2968,9 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2876
2968
|
function source(id) {
|
|
2877
2969
|
return sourceById.get(cleanUrl(id));
|
|
2878
2970
|
}
|
|
2971
|
+
function sources() {
|
|
2972
|
+
return sourceById.entries();
|
|
2973
|
+
}
|
|
2879
2974
|
function values() {
|
|
2880
2975
|
const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
|
|
2881
2976
|
for (const candidate of inlineExcludedCandidates) values.delete(candidate);
|
|
@@ -2885,6 +2980,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2885
2980
|
if (entries === void 0) {
|
|
2886
2981
|
if (!options.excludeEntries?.length) return values();
|
|
2887
2982
|
}
|
|
2983
|
+
if (entries?.length === 0) return new Set(inlineIncludedCandidates);
|
|
2888
2984
|
const filtered = /* @__PURE__ */ new Set();
|
|
2889
2985
|
for (const [id, candidates] of candidatesById) {
|
|
2890
2986
|
if (entries !== void 0 && !isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
@@ -2905,6 +3001,11 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2905
3001
|
}
|
|
2906
3002
|
if (id) candidateSources.add(id);
|
|
2907
3003
|
};
|
|
3004
|
+
if (entries?.length === 0) {
|
|
3005
|
+
for (const candidate of inlineIncludedCandidates) addCandidateSource(candidate, void 0);
|
|
3006
|
+
for (const candidate of inlineExcludedCandidates) sources.delete(candidate);
|
|
3007
|
+
return sources;
|
|
3008
|
+
}
|
|
2908
3009
|
for (const [id, candidates] of candidatesById) {
|
|
2909
3010
|
if (entries !== void 0 && !isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
2910
3011
|
if (options.excludeEntries?.length && isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
|
|
@@ -2924,6 +3025,18 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2924
3025
|
inlineIncludedCandidates.clear();
|
|
2925
3026
|
inlineExcludedCandidates.clear();
|
|
2926
3027
|
}
|
|
3028
|
+
function clearScan() {
|
|
3029
|
+
for (const id of scanCandidatesById.keys()) {
|
|
3030
|
+
scanCandidatesById.delete(id);
|
|
3031
|
+
recompute(id);
|
|
3032
|
+
}
|
|
3033
|
+
inlineIncludedCandidates.clear();
|
|
3034
|
+
inlineExcludedCandidates.clear();
|
|
3035
|
+
}
|
|
3036
|
+
function resetScan() {
|
|
3037
|
+
inlineIncludedCandidates.clear();
|
|
3038
|
+
inlineExcludedCandidates.clear();
|
|
3039
|
+
}
|
|
2927
3040
|
function snapshot() {
|
|
2928
3041
|
return {
|
|
2929
3042
|
candidatesById: [...candidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
@@ -2955,13 +3068,13 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2955
3068
|
if (candidateSet.size === 0) continue;
|
|
2956
3069
|
cssCandidatesById.set(id, candidateSet);
|
|
2957
3070
|
}
|
|
2958
|
-
for (const [id, candidates] of snapshot.candidatesById) {
|
|
2959
|
-
const candidateSet = new Set(candidates);
|
|
2960
|
-
if (candidateSet.size === 0) continue;
|
|
2961
|
-
candidatesById.set(id, candidateSet);
|
|
2962
|
-
addCandidateSet(candidateCount, candidateSet);
|
|
2963
|
-
}
|
|
2964
3071
|
for (const [id, source] of snapshot.sourceById ?? []) sourceById.set(id, source);
|
|
3072
|
+
const ids = new Set([
|
|
3073
|
+
...scanCandidatesById.keys(),
|
|
3074
|
+
...transformCandidatesById.keys(),
|
|
3075
|
+
...cssCandidatesById.keys()
|
|
3076
|
+
]);
|
|
3077
|
+
for (const id of ids) recompute(id);
|
|
2965
3078
|
}
|
|
2966
3079
|
return {
|
|
2967
3080
|
sync,
|
|
@@ -2973,11 +3086,14 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2973
3086
|
syncInline,
|
|
2974
3087
|
remove,
|
|
2975
3088
|
source,
|
|
3089
|
+
sources,
|
|
2976
3090
|
values,
|
|
2977
3091
|
valuesForEntries,
|
|
2978
3092
|
sourcesForEntries,
|
|
2979
3093
|
snapshot,
|
|
2980
3094
|
restore,
|
|
3095
|
+
clearScan,
|
|
3096
|
+
resetScan,
|
|
2981
3097
|
clear
|
|
2982
3098
|
};
|
|
2983
3099
|
}
|
|
@@ -3060,4 +3176,4 @@ function createHmrTimingRecorder(bundler) {
|
|
|
3060
3176
|
};
|
|
3061
3177
|
}
|
|
3062
3178
|
//#endregion
|
|
3063
|
-
export {
|
|
3179
|
+
export { createCssSourceTraceCacheSignature as _, createTailwindV3DefaultExtractor as a, processCachedTask as b, validateCandidatesByGenerator as c, extractMarkedUserLayerComponentsCss as d, mergeMarkedUserLayerComponentsCss as f, annotateCssSourceTrace as g, pruneMiniProgramGeneratedCss as h, isSourceCandidateRequest as i, pushConcurrentTaskFactories as l, finalizeMiniProgramCss as m, emitHmrTiming as n, createBundleRuntimeClassSetManager as o, isPureLocalCssImportWrapper as p, createSourceCandidateCollector as r, generateCssByGenerator as s, createHmrTimingRecorder as t, runWithConcurrency as u, createCssTokenSourceMap as v, isCssSourceTraceEnabled as y };
|