weapp-tailwindcss 5.0.13 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +16 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +138 -444
- package/dist/cli.mjs +134 -440
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +5 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
- package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
- package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
- package/dist/defaults.d.ts +2 -8
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-6oMJtTDO.js +170 -0
- package/dist/generator-CjzBK7h-.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +87 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +15 -7
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
- package/dist/tailwindcss-dbrbY4cd.js +1528 -0
- package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
- package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
- package/dist/v4-engine-ON_oSLfO.js +2752 -0
- package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
- package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-8PaV1gG3.mjs +2334 -0
- package/dist/webpack-CGgBOx9l.js +2346 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
2
|
const require_framework = require("./framework.js");
|
|
3
|
-
const
|
|
4
|
-
const require_generator = require("./generator-
|
|
5
|
-
const require_precheck = require("./precheck-B0Z8yW7E.js");
|
|
3
|
+
const require_v4_engine = require("./v4-engine-ON_oSLfO.js");
|
|
4
|
+
const require_generator = require("./generator-6oMJtTDO.js");
|
|
6
5
|
const require_utils = require("./utils-BCa37Wqj.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
const require_context = require("./context-B6hVF7dr.js");
|
|
7
|
+
const require_tailwindcss = require("./tailwindcss-dbrbY4cd.js");
|
|
8
|
+
const require_hmr_timing = require("./hmr-timing-CegXR9O4.js");
|
|
9
|
+
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BKYb9jxa.js");
|
|
10
10
|
require("./logger-TlKT3xmR.js");
|
|
11
11
|
let node_fs = require("node:fs");
|
|
12
12
|
node_fs = require_chunk.__toESM(node_fs);
|
|
@@ -14,14 +14,14 @@ let node_path = require("node:path");
|
|
|
14
14
|
node_path = require_chunk.__toESM(node_path);
|
|
15
15
|
let node_process = require("node:process");
|
|
16
16
|
node_process = require_chunk.__toESM(node_process);
|
|
17
|
+
let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
|
|
17
18
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
18
19
|
let lru_cache = require("lru-cache");
|
|
19
|
-
let tailwindcss_patch = require("tailwindcss-patch");
|
|
20
|
-
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
21
20
|
let node_fs_promises = require("node:fs/promises");
|
|
21
|
+
let micromatch = require("micromatch");
|
|
22
|
+
micromatch = require_chunk.__toESM(micromatch);
|
|
22
23
|
let node_buffer = require("node:buffer");
|
|
23
|
-
let
|
|
24
|
-
_weapp_tailwindcss_postcss_html_transform = require_chunk.__toESM(_weapp_tailwindcss_postcss_html_transform);
|
|
24
|
+
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
25
25
|
let comment_json = require("comment-json");
|
|
26
26
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
27
27
|
//#region src/uni-app-x/harmony.ts
|
|
@@ -130,7 +130,7 @@ function collectUsedClassNames(code, entries) {
|
|
|
130
130
|
for (const literalMatch of code.matchAll(STRING_LITERAL_RE)) {
|
|
131
131
|
const literal = literalMatch[2];
|
|
132
132
|
if (!literal) continue;
|
|
133
|
-
for (const candidate of (0,
|
|
133
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) if (entries.has(candidate)) used.add(candidate);
|
|
134
134
|
}
|
|
135
135
|
return used;
|
|
136
136
|
}
|
|
@@ -166,7 +166,7 @@ function cssToStyleExport(source) {
|
|
|
166
166
|
result[match[1]] = { "": declarations };
|
|
167
167
|
const className = unescapeCssClassSelector(match[1]);
|
|
168
168
|
result[className] = { "": declarations };
|
|
169
|
-
result[
|
|
169
|
+
result[require_context.replaceWxml(className)] = { "": declarations };
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
});
|
|
@@ -203,15 +203,15 @@ function createStyleValueFromApplySources(sources, utilityStyles) {
|
|
|
203
203
|
const className = selector.trim().match(CLASS_SELECTOR_PREFIX_RE)?.[1];
|
|
204
204
|
if (!className) continue;
|
|
205
205
|
const declarations = {};
|
|
206
|
-
for (const applyRule of applyRules) for (const utility of (0,
|
|
207
|
-
const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[
|
|
206
|
+
for (const applyRule of applyRules) for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(applyRule.params)) {
|
|
207
|
+
const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[require_context.replaceWxml(utility)]?.[""];
|
|
208
208
|
if (utilityDeclarations) Object.assign(declarations, utilityDeclarations);
|
|
209
209
|
}
|
|
210
210
|
if (Object.keys(declarations).length > 0) {
|
|
211
211
|
const unescapedClassName = unescapeCssClassSelector(className);
|
|
212
212
|
result[className] = { "": declarations };
|
|
213
213
|
result[unescapedClassName] = { "": declarations };
|
|
214
|
-
result[
|
|
214
|
+
result[require_context.replaceWxml(unescapedClassName)] = { "": declarations };
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
});
|
|
@@ -232,7 +232,7 @@ function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) {
|
|
|
232
232
|
continue;
|
|
233
233
|
}
|
|
234
234
|
root.walkAtRules("apply", (rule) => {
|
|
235
|
-
for (const utility of (0,
|
|
235
|
+
for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
return utilities;
|
|
@@ -359,18 +359,13 @@ function findFirstStyleObjectDecl(source) {
|
|
|
359
359
|
varName
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
function resolveCssFallbackFiles(
|
|
363
|
-
const files =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (file.startsWith("assets/") && file.endsWith(".js")) {
|
|
370
|
-
const withoutAssets = file.slice(7).replace(/\.js$/, "");
|
|
371
|
-
files.push(`${withoutAssets}.wxss`, `${withoutAssets}.css`);
|
|
372
|
-
}
|
|
373
|
-
return files;
|
|
362
|
+
function resolveCssFallbackFiles(styleAssetFiles = []) {
|
|
363
|
+
const files = /* @__PURE__ */ new Set();
|
|
364
|
+
for (const assetFile of styleAssetFiles) if (assetFile) files.add(assetFile);
|
|
365
|
+
return [...files];
|
|
366
|
+
}
|
|
367
|
+
function resolveStyleAssetFilesForChunk(file, styleAssetFiles) {
|
|
368
|
+
return typeof styleAssetFiles === "function" ? styleAssetFiles(file) : styleAssetFiles;
|
|
374
369
|
}
|
|
375
370
|
function resolveSourceMapFiles(file) {
|
|
376
371
|
return [
|
|
@@ -380,7 +375,7 @@ function resolveSourceMapFiles(file) {
|
|
|
380
375
|
].filter((item) => typeof item === "string");
|
|
381
376
|
}
|
|
382
377
|
function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) {
|
|
383
|
-
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(file).map((cssFile) => {
|
|
378
|
+
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(resolveStyleAssetFilesForChunk(file, options.styleAssetFiles)).map((cssFile) => {
|
|
384
379
|
const source = getBundleSource?.(cssFile);
|
|
385
380
|
return source ? cssSourceToStyleValue(source) : void 0;
|
|
386
381
|
}));
|
|
@@ -431,12 +426,15 @@ function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options =
|
|
|
431
426
|
}
|
|
432
427
|
function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
433
428
|
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
429
|
+
const styleAssetFilesByChunk = collectUniAppXBundleStyleAssetFilesByChunk(bundle);
|
|
430
|
+
const resolveStyleAssetFiles = typeof options.styleAssetFiles === "function" ? options.styleAssetFiles : (file) => [...options.styleAssetFiles ?? [], ...styleAssetFilesByChunk.get(file) ?? []];
|
|
434
431
|
let changed = false;
|
|
435
432
|
for (const [file, item] of Object.entries(bundle)) {
|
|
436
433
|
if (item.type !== "chunk" || !file.endsWith(".js")) continue;
|
|
437
434
|
const currentSource = item.code;
|
|
438
435
|
const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, {
|
|
439
436
|
...options,
|
|
437
|
+
styleAssetFiles: resolveStyleAssetFiles,
|
|
440
438
|
mapSources: collectChunkMapSourcesContent(item)
|
|
441
439
|
});
|
|
442
440
|
if (nextSource !== currentSource) {
|
|
@@ -446,6 +444,41 @@ function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
|
446
444
|
}
|
|
447
445
|
return changed;
|
|
448
446
|
}
|
|
447
|
+
function collectUniAppXBundleStyleAssetFilesByChunk(bundle) {
|
|
448
|
+
const styleAssetFilesByChunk = /* @__PURE__ */ new Map();
|
|
449
|
+
const appStyleAssetFiles = /* @__PURE__ */ new Set();
|
|
450
|
+
const assetFiles = new Set(Object.entries(bundle).filter(([, item]) => item.type === "asset").map(([file]) => file).filter(isStyleAssetFile));
|
|
451
|
+
for (const [chunkFile, item] of Object.entries(bundle)) {
|
|
452
|
+
if (item.type !== "chunk") continue;
|
|
453
|
+
const chunk = item;
|
|
454
|
+
for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
|
|
455
|
+
if (!assetFiles.has(cssFile)) continue;
|
|
456
|
+
if (APP_JS_RE.test(chunk.fileName ?? chunkFile) || APP_JS_RE.test(chunkFile)) {
|
|
457
|
+
appStyleAssetFiles.add(cssFile);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(chunkFile);
|
|
461
|
+
if (!styleAssetFiles) {
|
|
462
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
463
|
+
styleAssetFilesByChunk.set(chunkFile, styleAssetFiles);
|
|
464
|
+
}
|
|
465
|
+
styleAssetFiles.add(cssFile);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (appStyleAssetFiles.size > 0) for (const [file, item] of Object.entries(bundle)) {
|
|
469
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
470
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(file);
|
|
471
|
+
if (!styleAssetFiles) {
|
|
472
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
473
|
+
styleAssetFilesByChunk.set(file, styleAssetFiles);
|
|
474
|
+
}
|
|
475
|
+
for (const appStyleAssetFile of appStyleAssetFiles) styleAssetFiles.add(appStyleAssetFile);
|
|
476
|
+
}
|
|
477
|
+
return styleAssetFilesByChunk;
|
|
478
|
+
}
|
|
479
|
+
function isStyleAssetFile(file) {
|
|
480
|
+
return /\.(?:acss|css|jxss|qss|ttss|wxss)$/i.test(file);
|
|
481
|
+
}
|
|
449
482
|
function isUniAppXHarmonyBundle(bundle) {
|
|
450
483
|
for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true;
|
|
451
484
|
return false;
|
|
@@ -482,7 +515,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
482
515
|
//#region src/uni-app-x/vite.ts
|
|
483
516
|
let transformUVuePromise;
|
|
484
517
|
function loadTransformUVue() {
|
|
485
|
-
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-
|
|
518
|
+
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-vLwZpiTE.js")).then((mod) => mod.transformUVue));
|
|
486
519
|
return transformUVuePromise;
|
|
487
520
|
}
|
|
488
521
|
const preprocessorLangs = new Set([
|
|
@@ -554,16 +587,16 @@ function createUniAppXPlugins(options) {
|
|
|
554
587
|
}
|
|
555
588
|
async function transformStyle(code, id, query, hookContext) {
|
|
556
589
|
const parsed = query ?? parseVueRequest(id).query;
|
|
557
|
-
if (
|
|
590
|
+
if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
558
591
|
if (isCssModuleExport(code)) return;
|
|
559
|
-
const shouldGenerateCss =
|
|
592
|
+
const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
560
593
|
rememberHarmonyApplySource(code);
|
|
561
594
|
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
562
595
|
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
563
596
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
564
597
|
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
565
598
|
if (!styleHandlerOptions) {
|
|
566
|
-
styleHandlerOptions =
|
|
599
|
+
styleHandlerOptions = require_v4_engine.omitUndefined({
|
|
567
600
|
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
568
601
|
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
569
602
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
@@ -581,7 +614,7 @@ function createUniAppXPlugins(options) {
|
|
|
581
614
|
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
582
615
|
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
583
616
|
for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
|
|
584
|
-
const postcssMap = await
|
|
617
|
+
const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
|
|
585
618
|
return {
|
|
586
619
|
code: postcssResult.css,
|
|
587
620
|
map: postcssMap
|
|
@@ -622,7 +655,7 @@ function createUniAppXPlugins(options) {
|
|
|
622
655
|
const transformUVue = await loadTransformUVue();
|
|
623
656
|
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
624
657
|
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
625
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet,
|
|
658
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
|
|
626
659
|
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
627
660
|
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
628
661
|
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
@@ -685,7 +718,7 @@ function createUniAppXPlugins(options) {
|
|
|
685
718
|
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
686
719
|
return async () => {
|
|
687
720
|
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
688
|
-
const absoluteFile =
|
|
721
|
+
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
|
|
689
722
|
const rawSource = originalSource.source.toString();
|
|
690
723
|
await require_hmr_timing.processCachedTask({
|
|
691
724
|
cache,
|
|
@@ -717,89 +750,24 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
717
750
|
};
|
|
718
751
|
}
|
|
719
752
|
//#endregion
|
|
720
|
-
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
721
|
-
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
722
|
-
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
723
|
-
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
724
|
-
const MUSTACHE_OPEN = "{{";
|
|
725
|
-
const MUSTACHE_CLOSE = "}}";
|
|
726
|
-
function isUrlLikeCandidate(candidate) {
|
|
727
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
728
|
-
}
|
|
729
|
-
function isArbitraryValueCandidate(candidate) {
|
|
730
|
-
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
731
|
-
}
|
|
732
|
-
function collectClassAttributeValues(source) {
|
|
733
|
-
const values = [];
|
|
734
|
-
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
735
|
-
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
736
|
-
while (matched !== null) {
|
|
737
|
-
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
738
|
-
const quote = source[quoteIndex];
|
|
739
|
-
if (quote !== "\"" && quote !== "'") {
|
|
740
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
741
|
-
continue;
|
|
742
|
-
}
|
|
743
|
-
let expressionDepth = 0;
|
|
744
|
-
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
745
|
-
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
746
|
-
expressionDepth++;
|
|
747
|
-
index += 1;
|
|
748
|
-
continue;
|
|
749
|
-
}
|
|
750
|
-
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
751
|
-
expressionDepth--;
|
|
752
|
-
index += 1;
|
|
753
|
-
continue;
|
|
754
|
-
}
|
|
755
|
-
if (expressionDepth === 0 && source[index] === quote) {
|
|
756
|
-
values.push(source.slice(quoteIndex + 1, index));
|
|
757
|
-
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
758
|
-
break;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
762
|
-
}
|
|
763
|
-
return values;
|
|
764
|
-
}
|
|
765
|
-
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
766
|
-
const matches = /* @__PURE__ */ new Set();
|
|
767
|
-
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
768
|
-
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
769
|
-
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
770
|
-
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
771
|
-
while (quoted !== null) {
|
|
772
|
-
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
773
|
-
for (const candidate of (0, tailwindcss_patch.splitCandidateTokens)(literal)) {
|
|
774
|
-
const normalized = candidate.trim();
|
|
775
|
-
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
776
|
-
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
777
|
-
matches.add(normalized);
|
|
778
|
-
}
|
|
779
|
-
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
return [...matches];
|
|
783
|
-
}
|
|
784
|
-
function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
785
|
-
if (candidates.has("container")) return candidates;
|
|
786
|
-
if (!sourceCandidates.has("container")) return candidates;
|
|
787
|
-
return new Set([...candidates, "container"]);
|
|
788
|
-
}
|
|
789
|
-
//#endregion
|
|
790
753
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
791
754
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
792
|
-
const
|
|
793
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...
|
|
755
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
756
|
+
return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
794
757
|
}
|
|
795
758
|
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
796
759
|
const entries = [];
|
|
760
|
+
const seen = /* @__PURE__ */ new Set();
|
|
797
761
|
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
798
762
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
799
|
-
const base =
|
|
763
|
+
const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
800
764
|
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
|
|
765
|
+
const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
|
|
766
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
767
|
+
if (seen.has(key)) continue;
|
|
768
|
+
seen.add(key);
|
|
801
769
|
entries.push({
|
|
802
|
-
file:
|
|
770
|
+
file: resolvedFile,
|
|
803
771
|
source: cssSource.css
|
|
804
772
|
});
|
|
805
773
|
}
|
|
@@ -839,16 +807,15 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
839
807
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
840
808
|
function createCssAssetEmitter(context) {
|
|
841
809
|
return (fileName, source) => {
|
|
842
|
-
const replayAsset = createReplayCssAsset(fileName, source);
|
|
843
810
|
if (context.emitFile) {
|
|
844
811
|
context.emitFile({
|
|
845
812
|
type: "asset",
|
|
846
813
|
fileName,
|
|
847
814
|
source
|
|
848
815
|
});
|
|
849
|
-
return
|
|
816
|
+
return;
|
|
850
817
|
}
|
|
851
|
-
return
|
|
818
|
+
return createReplayCssAsset(fileName, source);
|
|
852
819
|
};
|
|
853
820
|
}
|
|
854
821
|
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
@@ -868,6 +835,23 @@ const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
|
868
835
|
".jxss",
|
|
869
836
|
".tyss"
|
|
870
837
|
];
|
|
838
|
+
function resolveCssOutputRealPath(value) {
|
|
839
|
+
const resolved = node_path.default.resolve(value);
|
|
840
|
+
let current = resolved;
|
|
841
|
+
const pendingSegments = [];
|
|
842
|
+
while (!(0, node_fs.existsSync)(current)) {
|
|
843
|
+
const parent = node_path.default.dirname(current);
|
|
844
|
+
if (parent === current) return resolved;
|
|
845
|
+
pendingSegments.unshift(node_path.default.basename(current));
|
|
846
|
+
current = parent;
|
|
847
|
+
}
|
|
848
|
+
try {
|
|
849
|
+
const realPath = node_fs.realpathSync.native(current);
|
|
850
|
+
return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
|
|
851
|
+
} catch {
|
|
852
|
+
return resolved;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
871
855
|
function normalizeStyleOutputExtension(value) {
|
|
872
856
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
873
857
|
const normalized = value.trim().toLowerCase();
|
|
@@ -896,17 +880,32 @@ function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
|
896
880
|
if (!cssMatcher || !stem) return;
|
|
897
881
|
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
898
882
|
}
|
|
883
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
884
|
+
const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
|
|
885
|
+
const stemSuffix = `/${cleanStem}`;
|
|
886
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
887
|
+
for (const file of files ?? []) {
|
|
888
|
+
const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
889
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
890
|
+
const extension = node_path.default.extname(cleanFile);
|
|
891
|
+
if (!extension || extension === ".css") continue;
|
|
892
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
893
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
894
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
895
|
+
}
|
|
896
|
+
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
897
|
+
}
|
|
899
898
|
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
900
|
-
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ??
|
|
899
|
+
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
901
900
|
}
|
|
902
901
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
903
|
-
const normalizedFile =
|
|
904
|
-
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return
|
|
902
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.isAbsolute(file) ? node_path.default.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(file)) : file);
|
|
903
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.basename(file));
|
|
905
904
|
return normalizedFile;
|
|
906
905
|
}
|
|
907
906
|
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
908
907
|
if (typeof sourceRoot !== "string" || sourceRoot.trim().length === 0) return;
|
|
909
|
-
return
|
|
908
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.isAbsolute(sourceRoot) ? node_path.default.relative(rootDir, sourceRoot) : sourceRoot).replace(/\/+$/, "");
|
|
910
909
|
}
|
|
911
910
|
function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
912
911
|
const outputFile = resolveReplayCssOutputFile(rootDir, file);
|
|
@@ -917,7 +916,7 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
917
916
|
return outputFile;
|
|
918
917
|
}
|
|
919
918
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
920
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !
|
|
919
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !require_source_candidate_scan_signature.isCSSRequest(file)) return file;
|
|
921
920
|
const stem = file.replace(/[?#].*$/, "").replace(SOURCE_STYLE_OUTPUT_EXT_RE, "");
|
|
922
921
|
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
923
922
|
cssMatcher: opts.cssMatcher,
|
|
@@ -931,12 +930,27 @@ function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTar
|
|
|
931
930
|
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
932
931
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
933
932
|
const matchedStyleExtension = !isWebGeneratorTarget && !preserveCssExtension ? resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) : void 0;
|
|
934
|
-
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) &&
|
|
935
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !
|
|
933
|
+
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) && require_source_candidate_scan_signature.isCSSRequest(normalizedFile)) return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, matchedStyleExtension);
|
|
934
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !require_source_candidate_scan_signature.isCSSRequest(normalizedFile)) return normalizedFile;
|
|
936
935
|
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
937
936
|
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(normalizedFile)) return normalizedFile;
|
|
938
937
|
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
939
938
|
}
|
|
939
|
+
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
940
|
+
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot);
|
|
941
|
+
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
942
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !require_source_candidate_scan_signature.isCSSRequest(normalizedFile)) return normalizedFile;
|
|
943
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
944
|
+
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
945
|
+
if (matchedStyleFile) return matchedStyleFile;
|
|
946
|
+
const styleExtension = resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? resolveMiniProgramStyleOutputExtension({
|
|
947
|
+
cssMatcher: opts.cssMatcher,
|
|
948
|
+
fallback: styleOutputExtension,
|
|
949
|
+
files: styleOutputFiles,
|
|
950
|
+
stem
|
|
951
|
+
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
952
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
953
|
+
}
|
|
940
954
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
941
955
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
942
956
|
try {
|
|
@@ -956,6 +970,23 @@ function stripStyleFileExtension(file) {
|
|
|
956
970
|
}
|
|
957
971
|
//#endregion
|
|
958
972
|
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
973
|
+
function resolveStyleMatchingRealPath(value) {
|
|
974
|
+
const resolved = node_path.default.resolve(value);
|
|
975
|
+
let current = resolved;
|
|
976
|
+
const pendingSegments = [];
|
|
977
|
+
while (!(0, node_fs.existsSync)(current)) {
|
|
978
|
+
const parent = node_path.default.dirname(current);
|
|
979
|
+
if (parent === current) return resolved;
|
|
980
|
+
pendingSegments.unshift(node_path.default.basename(current));
|
|
981
|
+
current = parent;
|
|
982
|
+
}
|
|
983
|
+
try {
|
|
984
|
+
const realPath = node_fs.realpathSync.native(current);
|
|
985
|
+
return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
|
|
986
|
+
} catch {
|
|
987
|
+
return resolved;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
959
990
|
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
960
991
|
return stripStyleFileExtension(node_path.default.resolve(outputRoot, outputFile)) === stripStyleFileExtension(node_path.default.resolve(cssSourceFile));
|
|
961
992
|
}
|
|
@@ -963,13 +994,13 @@ function collectStyleFileMatchBases(file, roots) {
|
|
|
963
994
|
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
964
995
|
const bases = /* @__PURE__ */ new Set();
|
|
965
996
|
const addBase = (candidate) => {
|
|
966
|
-
const base =
|
|
997
|
+
const base = require_source_candidate_scan_signature.slash(stripStyleFileExtension(candidate));
|
|
967
998
|
if (base.length > 0) bases.add(base);
|
|
968
999
|
};
|
|
969
1000
|
addBase(normalizedFile);
|
|
970
1001
|
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => node_path.default.resolve(root));
|
|
971
1002
|
if (node_path.default.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
972
|
-
const relative = node_path.default.relative(root, normalizedFile);
|
|
1003
|
+
const relative = node_path.default.relative(resolveStyleMatchingRealPath(root), resolveStyleMatchingRealPath(normalizedFile));
|
|
973
1004
|
if (relative && !relative.startsWith("..") && !node_path.default.isAbsolute(relative)) addBase(relative);
|
|
974
1005
|
}
|
|
975
1006
|
else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
@@ -993,7 +1024,7 @@ function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRo
|
|
|
993
1024
|
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
994
1025
|
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
995
1026
|
let bestScore = 0;
|
|
996
|
-
const hasDirectorySegment = (value) =>
|
|
1027
|
+
const hasDirectorySegment = (value) => require_source_candidate_scan_signature.slash(value).includes("/");
|
|
997
1028
|
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
998
1029
|
else if (hasDirectorySegment(sourceBase) && outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
999
1030
|
else if (hasDirectorySegment(outputBase) && sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
@@ -1009,11 +1040,11 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1009
1040
|
return node_path.default.resolve(file.replace(/[?#].*$/, ""));
|
|
1010
1041
|
}
|
|
1011
1042
|
function collectConfiguredCssEntries(opts) {
|
|
1012
|
-
const
|
|
1043
|
+
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1013
1044
|
return [
|
|
1014
1045
|
...opts.cssEntries ?? [],
|
|
1015
1046
|
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
1016
|
-
...
|
|
1047
|
+
...runtimeCssEntries ?? []
|
|
1017
1048
|
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1018
1049
|
}
|
|
1019
1050
|
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
@@ -1028,9 +1059,9 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1028
1059
|
};
|
|
1029
1060
|
addCandidate(node_path.default.dirname(node_path.default.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
1030
1061
|
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
1031
|
-
const
|
|
1032
|
-
const sourceBaseFallback = opts.tailwindcss?.v4?.base ??
|
|
1033
|
-
const sourceRoot = opts.tailwindcssBasedir ??
|
|
1062
|
+
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1063
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1064
|
+
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1034
1065
|
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1035
1066
|
for (const cssEntry of configuredCssEntries) {
|
|
1036
1067
|
const resolvedCssEntry = node_path.default.resolve(cssEntry);
|
|
@@ -1041,7 +1072,7 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1041
1072
|
const cssSourceCss = typeof cssSource.css === "string" ? normalizeCssSourceForCompare(cssSource.css) : void 0;
|
|
1042
1073
|
if (cssSourceFile && !isMatchingCssSourceFile(file, cssSourceFile, outputRoot) && cssSourceCss !== normalizedSource) continue;
|
|
1043
1074
|
addCandidate(cssSourceFile ? node_path.default.dirname(cssSourceFile) : void 0);
|
|
1044
|
-
addCandidate(
|
|
1075
|
+
addCandidate(require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback));
|
|
1045
1076
|
}
|
|
1046
1077
|
return candidates;
|
|
1047
1078
|
}
|
|
@@ -1052,7 +1083,7 @@ function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
|
1052
1083
|
if (node_path.default.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
1053
1084
|
for (const base of baseCandidates) {
|
|
1054
1085
|
const configFile = node_path.default.resolve(base, request);
|
|
1055
|
-
if ((0, node_fs.existsSync)(configFile)) return `@config ${quote}${
|
|
1086
|
+
if ((0, node_fs.existsSync)(configFile)) return `@config ${quote}${require_source_candidate_scan_signature.slash(configFile)}${quote};`;
|
|
1056
1087
|
}
|
|
1057
1088
|
return full;
|
|
1058
1089
|
});
|
|
@@ -1060,7 +1091,7 @@ function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
|
1060
1091
|
//#endregion
|
|
1061
1092
|
//#region src/bundlers/vite/generate-bundle/css-handler-options.ts
|
|
1062
1093
|
function resolveViteCssHandlerExtraOptions(file) {
|
|
1063
|
-
return
|
|
1094
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, "")).includes("/") ? { isMainChunk: false } : {};
|
|
1064
1095
|
}
|
|
1065
1096
|
function createCssHandlerOptionsCache(options) {
|
|
1066
1097
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -1070,7 +1101,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1070
1101
|
const appType = options.getAppType();
|
|
1071
1102
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
1072
1103
|
const outputRoot = options.getOutputRoot?.();
|
|
1073
|
-
const from = outputRoot ? node_path.default.resolve(outputRoot, file) : file;
|
|
1104
|
+
const from = node_path.default.isAbsolute(file) ? file : outputRoot ? node_path.default.resolve(outputRoot, file) : file;
|
|
1074
1105
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
1075
1106
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
|
|
1076
1107
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
@@ -1079,7 +1110,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1079
1110
|
isMainChunk,
|
|
1080
1111
|
...extraOptions,
|
|
1081
1112
|
postcssOptions: { options: { from } },
|
|
1082
|
-
majorVersion,
|
|
1113
|
+
majorVersion: require_context.normalizeStyleHandlerMajorVersion(majorVersion),
|
|
1083
1114
|
sourceOptions: { outputRoot }
|
|
1084
1115
|
};
|
|
1085
1116
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
@@ -1104,6 +1135,91 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1104
1135
|
};
|
|
1105
1136
|
}
|
|
1106
1137
|
//#endregion
|
|
1138
|
+
//#region src/bundlers/vite/generate-bundle/root-style-output.ts
|
|
1139
|
+
function isRootMiniProgramStyleOutputFile$1(file) {
|
|
1140
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1141
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
1142
|
+
}
|
|
1143
|
+
function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
1144
|
+
const normalizedTargetFile = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
1145
|
+
const normalizedImportedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
1146
|
+
const targetDir = node_path.default.posix.dirname(normalizedTargetFile);
|
|
1147
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
1148
|
+
const relative = node_path.default.posix.relative(baseDir, normalizedImportedFile);
|
|
1149
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
1150
|
+
}
|
|
1151
|
+
function createCssImportShell$1(targetFile, importedFile) {
|
|
1152
|
+
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
1153
|
+
}
|
|
1154
|
+
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
1155
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1156
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
1157
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
1158
|
+
}
|
|
1159
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
1160
|
+
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
1161
|
+
}
|
|
1162
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
1163
|
+
return appType === "taro";
|
|
1164
|
+
}
|
|
1165
|
+
//#endregion
|
|
1166
|
+
//#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
|
|
1167
|
+
function resolveCssBundleOutputFile(options) {
|
|
1168
|
+
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
|
|
1169
|
+
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
1170
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
1171
|
+
return outputFile;
|
|
1172
|
+
}
|
|
1173
|
+
function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource) {
|
|
1174
|
+
return rawSource.trim().length > 0 && outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file);
|
|
1175
|
+
}
|
|
1176
|
+
function resolveOutputFileFromMatchedCssSource(options) {
|
|
1177
|
+
const { bundleFiles, defaultStyleOutputExtension, isWebGeneratorTarget, opts, rootDir, shouldPreserveAppCssExtension, sourceFile, sourceRoot } = options;
|
|
1178
|
+
if (!sourceFile) return;
|
|
1179
|
+
if (isWebGeneratorTarget) return;
|
|
1180
|
+
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
1181
|
+
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
1182
|
+
}
|
|
1183
|
+
function createMatchedCssSourceOutputResolver(options) {
|
|
1184
|
+
const { assetSourceFile, file, originalFileNames, resolveOutputFileFromMatchedCssSource } = options;
|
|
1185
|
+
return (sourceFile) => {
|
|
1186
|
+
if (!sourceFile) return;
|
|
1187
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalFileNames?.some((originalFile) => require_source_candidate_scan_signature.normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
|
|
1188
|
+
return resolveOutputFileFromMatchedCssSource(sourceFile);
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAssetResults) {
|
|
1192
|
+
const sourceKey = require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile);
|
|
1193
|
+
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (require_source_candidate_scan_signature.normalizeOutputPathKey(file) === sourceKey) return true;
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
function applyCssResultToBundle(options) {
|
|
1197
|
+
const { appType, assetSourceFile, bundle, emitOrReplayCssAsset, file, originalSource, outputFile, source, viteProcessedCssAsset } = options;
|
|
1198
|
+
if (outputFile === file) {
|
|
1199
|
+
originalSource.source = source;
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(appType) ? createCssImportShell$1(file, outputFile) : void 0;
|
|
1203
|
+
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
1204
|
+
const existingOutput = bundle[outputFile];
|
|
1205
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1206
|
+
else {
|
|
1207
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1208
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1209
|
+
}
|
|
1210
|
+
originalSource.source = importShellSource ?? source;
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
const existingOutput = bundle[outputFile];
|
|
1214
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1215
|
+
else {
|
|
1216
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1217
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1218
|
+
}
|
|
1219
|
+
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
1220
|
+
else originalSource.source = importShellSource ?? "";
|
|
1221
|
+
}
|
|
1222
|
+
//#endregion
|
|
1107
1223
|
//#region src/bundlers/vite/generate-bundle/css-share-scope.ts
|
|
1108
1224
|
const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
|
|
1109
1225
|
const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
|
|
@@ -1122,13 +1238,13 @@ function hasPathDependentCssUrl(rawSource) {
|
|
|
1122
1238
|
return false;
|
|
1123
1239
|
}
|
|
1124
1240
|
function createCssTransformShareScope(file, rawSource) {
|
|
1125
|
-
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${
|
|
1241
|
+
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.dirname(file))}`;
|
|
1126
1242
|
return "global";
|
|
1127
1243
|
}
|
|
1128
1244
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
1129
|
-
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${
|
|
1245
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_source_candidate_scan_signature.normalizeOutputPathKey(file)}`;
|
|
1130
1246
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1131
|
-
if (
|
|
1247
|
+
if (require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${require_source_candidate_scan_signature.normalizeOutputPathKey(file)}`;
|
|
1132
1248
|
return createCssTransformShareScope(file, rawSource);
|
|
1133
1249
|
}
|
|
1134
1250
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -1144,12 +1260,13 @@ function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
|
1144
1260
|
//#endregion
|
|
1145
1261
|
//#region src/bundlers/vite/generate-bundle/env-flags.ts
|
|
1146
1262
|
function resolveGenerateBundleEnvFlags() {
|
|
1263
|
+
const slowJsAstWarnMs = Number(node_process.default.env["WEAPP_TW_VITE_SLOW_JS_AST_WARN_MS"] ?? 1e3);
|
|
1147
1264
|
return {
|
|
1148
1265
|
forceRuntimeRefreshByEnv: node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1149
1266
|
disableDirtyOptimization: node_process.default.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1150
1267
|
disableJsPrecheck: node_process.default.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1",
|
|
1151
1268
|
debugCssDiff: node_process.default.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1",
|
|
1152
|
-
|
|
1269
|
+
slowJsAstWarnMs: Number.isFinite(slowJsAstWarnMs) && slowJsAstWarnMs >= 0 ? slowJsAstWarnMs : 1e3
|
|
1153
1270
|
};
|
|
1154
1271
|
}
|
|
1155
1272
|
//#endregion
|
|
@@ -1621,8 +1738,13 @@ function extractSfcStyleSources(source) {
|
|
|
1621
1738
|
function hasSfcStyleSources(source) {
|
|
1622
1739
|
return extractSfcStyleSources(source).length > 0;
|
|
1623
1740
|
}
|
|
1624
|
-
function hasTailwindGenerationSource(source) {
|
|
1625
|
-
|
|
1741
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
1742
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1743
|
+
return require_v4_engine.hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source);
|
|
1744
|
+
}
|
|
1745
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1746
|
+
if (require_v4_engine.isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1747
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1626
1748
|
}
|
|
1627
1749
|
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1628
1750
|
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
@@ -1636,7 +1758,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1636
1758
|
return;
|
|
1637
1759
|
}
|
|
1638
1760
|
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1639
|
-
if (!rawSource || !
|
|
1761
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1640
1762
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1641
1763
|
return;
|
|
1642
1764
|
}
|
|
@@ -1648,9 +1770,9 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1648
1770
|
};
|
|
1649
1771
|
}
|
|
1650
1772
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1651
|
-
return
|
|
1773
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1652
1774
|
}
|
|
1653
|
-
function collectChunkModuleIds$
|
|
1775
|
+
function collectChunkModuleIds$2(output) {
|
|
1654
1776
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1655
1777
|
return [
|
|
1656
1778
|
output.facadeModuleId,
|
|
@@ -1684,13 +1806,13 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1684
1806
|
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1685
1807
|
return;
|
|
1686
1808
|
}
|
|
1687
|
-
const normalizedSiblingJsFile =
|
|
1688
|
-
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" &&
|
|
1809
|
+
const normalizedSiblingJsFile = require_source_candidate_scan_signature.normalizeOutputPathKey(siblingJsFile);
|
|
1810
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1689
1811
|
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1690
1812
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1691
1813
|
return;
|
|
1692
1814
|
}
|
|
1693
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1815
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1694
1816
|
if (sourceFiles.length === 0) {
|
|
1695
1817
|
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1696
1818
|
return;
|
|
@@ -1710,18 +1832,18 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1710
1832
|
return bestSources[0]?.sourceFile;
|
|
1711
1833
|
}
|
|
1712
1834
|
function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1713
|
-
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1835
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, void 0);
|
|
1714
1836
|
if (!siblingJsFile) {
|
|
1715
1837
|
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1716
1838
|
return;
|
|
1717
1839
|
}
|
|
1718
|
-
const normalizedSiblingJsFile =
|
|
1719
|
-
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" &&
|
|
1840
|
+
const normalizedSiblingJsFile = require_source_candidate_scan_signature.normalizeOutputPathKey(siblingJsFile);
|
|
1841
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1720
1842
|
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1721
1843
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1722
1844
|
return;
|
|
1723
1845
|
}
|
|
1724
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1846
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1725
1847
|
if (sourceFiles.length === 0) {
|
|
1726
1848
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1727
1849
|
return;
|
|
@@ -1743,8 +1865,8 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1743
1865
|
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1744
1866
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1745
1867
|
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1746
|
-
if (!rawSource || !
|
|
1747
|
-
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) &&
|
|
1868
|
+
if (!sourceFile || !rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1869
|
+
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1748
1870
|
file,
|
|
1749
1871
|
source,
|
|
1750
1872
|
score: scoreMatchingStyleFileBase(outputFile, file, outputRoot, sourceRoot)
|
|
@@ -1758,7 +1880,7 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1758
1880
|
}
|
|
1759
1881
|
}
|
|
1760
1882
|
if (!sourceFile || !rawSource) return;
|
|
1761
|
-
if (!
|
|
1883
|
+
if (!hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1762
1884
|
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1763
1885
|
return;
|
|
1764
1886
|
}
|
|
@@ -1775,7 +1897,7 @@ function readBundleAssetSource(output) {
|
|
|
1775
1897
|
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
1776
1898
|
}
|
|
1777
1899
|
function normalizePackageRoot(root) {
|
|
1778
|
-
return
|
|
1900
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
1779
1901
|
}
|
|
1780
1902
|
function collectMiniProgramSubpackageRoots(bundle) {
|
|
1781
1903
|
let hasAppJson = false;
|
|
@@ -1798,12 +1920,12 @@ function collectMiniProgramSubpackageRoots(bundle) {
|
|
|
1798
1920
|
return hasAppJson ? roots : void 0;
|
|
1799
1921
|
}
|
|
1800
1922
|
function isSubpackageOutputFile(file, subpackageRoots) {
|
|
1801
|
-
const normalizedFile =
|
|
1923
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1802
1924
|
for (const root of subpackageRoots) if (root.length > 0 && (normalizedFile === root || normalizedFile.startsWith(`${root}/`) || normalizedFile.endsWith(`/${root}`) || normalizedFile.includes(`/${root}/`))) return true;
|
|
1803
1925
|
return false;
|
|
1804
1926
|
}
|
|
1805
1927
|
function resolveSubpackageSourceRootFromModuleId(moduleId, subpackageRoot) {
|
|
1806
|
-
const file =
|
|
1928
|
+
const file = require_source_candidate_scan_signature.slash(node_path.default.resolve(moduleId.replace(/[?#].*$/, "")));
|
|
1807
1929
|
const normalizedRoot = normalizePackageRoot(subpackageRoot);
|
|
1808
1930
|
const rootSegment = `/${normalizedRoot}/`;
|
|
1809
1931
|
const rootIndex = file.lastIndexOf(rootSegment);
|
|
@@ -1818,7 +1940,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1818
1940
|
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1819
1941
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1820
1942
|
if (!matchedSubpackageRoot) continue;
|
|
1821
|
-
for (const moduleId of collectChunkModuleIds$
|
|
1943
|
+
for (const moduleId of collectChunkModuleIds$2(entry.output)) {
|
|
1822
1944
|
if (!node_path.default.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1823
1945
|
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1824
1946
|
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
@@ -1843,16 +1965,16 @@ const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
|
1843
1965
|
function isCssOutputFile(file) {
|
|
1844
1966
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1845
1967
|
}
|
|
1846
|
-
function getAssetFile(bundleFile, asset) {
|
|
1968
|
+
function getAssetFile$1(bundleFile, asset) {
|
|
1847
1969
|
return asset.fileName || bundleFile;
|
|
1848
1970
|
}
|
|
1849
|
-
function readAssetSource(asset) {
|
|
1971
|
+
function readAssetSource$2(asset) {
|
|
1850
1972
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1851
1973
|
}
|
|
1852
1974
|
function clearAssetSource(asset) {
|
|
1853
1975
|
asset.source = "";
|
|
1854
1976
|
}
|
|
1855
|
-
function appendCss(baseCss, css) {
|
|
1977
|
+
function appendCss$1(baseCss, css) {
|
|
1856
1978
|
if (baseCss.length === 0) return css;
|
|
1857
1979
|
if (css.length === 0) return baseCss;
|
|
1858
1980
|
return `${baseCss}\n${css}`;
|
|
@@ -1880,7 +2002,7 @@ function removeTailwindSourceMediaWrappers(css) {
|
|
|
1880
2002
|
}
|
|
1881
2003
|
}
|
|
1882
2004
|
function removeTailwindEntryDirectivesFromCss(css) {
|
|
1883
|
-
return
|
|
2005
|
+
return require_v4_engine.removeTailwindSourceDirectives(removeTailwindSourceMediaWrappers(css));
|
|
1884
2006
|
}
|
|
1885
2007
|
function stripStyleExtension(file) {
|
|
1886
2008
|
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
@@ -1891,15 +2013,15 @@ function isStyleImportRequest(request) {
|
|
|
1891
2013
|
function resolveImportedStyleFile(targetFile, request) {
|
|
1892
2014
|
if (!isStyleImportRequest(request)) return;
|
|
1893
2015
|
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
1894
|
-
if (cleanRequest.startsWith("/")) return
|
|
1895
|
-
const targetDir = posix.posix.dirname(
|
|
1896
|
-
return
|
|
2016
|
+
if (cleanRequest.startsWith("/")) return require_source_candidate_scan_signature.normalizeOutputPathKey(cleanRequest.slice(1));
|
|
2017
|
+
const targetDir = posix.posix.dirname(require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile));
|
|
2018
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1897
2019
|
}
|
|
1898
2020
|
function collectImportedStyleFiles(css, targetFile) {
|
|
1899
2021
|
const imports = /* @__PURE__ */ new Set();
|
|
1900
2022
|
try {
|
|
1901
2023
|
_weapp_tailwindcss_postcss.postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
1902
|
-
const importedFile = resolveImportedStyleFile(targetFile,
|
|
2024
|
+
const importedFile = resolveImportedStyleFile(targetFile, require_v4_engine.parseImportRequest(atRule.params));
|
|
1903
2025
|
if (importedFile) imports.add(importedFile);
|
|
1904
2026
|
});
|
|
1905
2027
|
} catch {}
|
|
@@ -1910,31 +2032,31 @@ function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile
|
|
|
1910
2032
|
}
|
|
1911
2033
|
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
1912
2034
|
if (!markerFile) return false;
|
|
1913
|
-
return
|
|
2035
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(targetFile)) === require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
1914
2036
|
}
|
|
1915
2037
|
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1916
|
-
const blocks =
|
|
1917
|
-
if (blocks.length <= 1) return
|
|
2038
|
+
const blocks = require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2039
|
+
if (blocks.length <= 1) return require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1918
2040
|
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1919
|
-
return matchedCss.length > 0 ? matchedCss.join("\n") :
|
|
2041
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1920
2042
|
}
|
|
1921
2043
|
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1922
|
-
return
|
|
2044
|
+
return require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
1923
2045
|
}
|
|
1924
2046
|
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1925
2047
|
const sources = [];
|
|
1926
|
-
const excludedFileKey =
|
|
2048
|
+
const excludedFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(excludedFile);
|
|
1927
2049
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1928
2050
|
if (output.type !== "asset") continue;
|
|
1929
|
-
const file =
|
|
2051
|
+
const file = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1930
2052
|
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1931
|
-
const source =
|
|
2053
|
+
const source = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1932
2054
|
if (source.length > 0) sources.push(source);
|
|
1933
2055
|
}
|
|
1934
2056
|
return sources;
|
|
1935
2057
|
}
|
|
1936
2058
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
1937
|
-
const blocks =
|
|
2059
|
+
const blocks = require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1938
2060
|
if (blocks.length !== 1) return;
|
|
1939
2061
|
const file = blocks[0]?.file;
|
|
1940
2062
|
return typeof file === "string" && file.length > 0 ? file : void 0;
|
|
@@ -1968,9 +2090,9 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1968
2090
|
let updated = 0;
|
|
1969
2091
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1970
2092
|
if (output.type !== "asset") continue;
|
|
1971
|
-
const file = getAssetFile(bundleFile, output);
|
|
2093
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1972
2094
|
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
1973
|
-
const rawSource = readAssetSource(output);
|
|
2095
|
+
const rawSource = readAssetSource$2(output);
|
|
1974
2096
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
1975
2097
|
if (nextCss === rawSource) continue;
|
|
1976
2098
|
output.source = nextCss;
|
|
@@ -1982,32 +2104,61 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1982
2104
|
return updated;
|
|
1983
2105
|
}
|
|
1984
2106
|
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
1985
|
-
if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" &&
|
|
2107
|
+
if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(options.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile);
|
|
1986
2108
|
if (options.injectIntoMain === false) return false;
|
|
1987
|
-
const targetFileKey =
|
|
1988
|
-
return
|
|
2109
|
+
const targetFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile);
|
|
2110
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile) !== targetFileKey && (opts.mainCssChunkMatcher(sourceFile, opts.appType) || typeof options.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(options.outputFile) !== targetFileKey && opts.mainCssChunkMatcher(options.outputFile, opts.appType));
|
|
1989
2111
|
}
|
|
1990
2112
|
function isRootStyleOutputFile(file) {
|
|
1991
|
-
const normalized =
|
|
2113
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1992
2114
|
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1993
2115
|
}
|
|
2116
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
2117
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2118
|
+
}
|
|
2119
|
+
function shouldPreserveMiniProgramImportShell(opts, file, css) {
|
|
2120
|
+
return (opts.appType === "taro" || opts.appType === "uni-app-vite" || opts.appType === "uni-app-x") && isMiniProgramStyleOutputFile(file) && opts.cssMatcher(file) && require_hmr_timing.isPureLocalCssImportWrapper(css);
|
|
2121
|
+
}
|
|
2122
|
+
function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
2123
|
+
if (opts.appType !== "taro") return;
|
|
2124
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2125
|
+
if (importedStyleFiles.size !== 1) return;
|
|
2126
|
+
const [importedFile] = importedStyleFiles;
|
|
2127
|
+
if (!importedFile) return;
|
|
2128
|
+
if (!isRootStyleOutputFile(importedFile)) return;
|
|
2129
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2130
|
+
if (output.type !== "asset") continue;
|
|
2131
|
+
const outputFile = getAssetFile$1(bundleFile, output);
|
|
2132
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
1994
2135
|
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
1995
|
-
const fileKey =
|
|
2136
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2137
|
+
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey)) return false;
|
|
2138
|
+
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
1996
2139
|
if (records.some((record) => {
|
|
1997
2140
|
if (record.injectIntoMain !== true) return false;
|
|
1998
|
-
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" &&
|
|
2141
|
+
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
1999
2142
|
})) return true;
|
|
2000
2143
|
if (records.some((record) => record.injectIntoMain === true)) return false;
|
|
2001
2144
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return true;
|
|
2002
2145
|
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
2003
2146
|
}
|
|
2004
2147
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2148
|
+
return importedStyleFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(record.file)) || typeof record.outputFile === "string" && importedStyleFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile));
|
|
2149
|
+
}
|
|
2150
|
+
function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, assetFiles) {
|
|
2151
|
+
for (const candidate of [record.file, record.outputFile]) {
|
|
2152
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
2153
|
+
const candidateKey = require_source_candidate_scan_signature.normalizeOutputPathKey(candidate);
|
|
2154
|
+
if (!importedStyleFiles.has(candidateKey)) continue;
|
|
2155
|
+
if (assetFiles.has(candidateKey)) return true;
|
|
2156
|
+
}
|
|
2157
|
+
return false;
|
|
2007
2158
|
}
|
|
2008
2159
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2009
2160
|
if (importedCssSources.length === 0) return css;
|
|
2010
|
-
const importedCss = importedCssSources.map((source) =>
|
|
2161
|
+
const importedCss = importedCssSources.map((source) => require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
2011
2162
|
if (importedCss.length === 0) return css;
|
|
2012
2163
|
return (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(importedCss, css);
|
|
2013
2164
|
}
|
|
@@ -2017,9 +2168,9 @@ function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
|
2017
2168
|
const importedSources = [];
|
|
2018
2169
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2019
2170
|
if (output.type !== "asset") continue;
|
|
2020
|
-
const file =
|
|
2171
|
+
const file = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2021
2172
|
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2022
|
-
importedSources.push(readAssetSource(output));
|
|
2173
|
+
importedSources.push(readAssetSource$2(output));
|
|
2023
2174
|
}
|
|
2024
2175
|
return importedSources;
|
|
2025
2176
|
}
|
|
@@ -2027,7 +2178,7 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2027
2178
|
const files = /* @__PURE__ */ new Set();
|
|
2028
2179
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2029
2180
|
if (output.type !== "asset") continue;
|
|
2030
|
-
files.add(
|
|
2181
|
+
files.add(require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2031
2182
|
}
|
|
2032
2183
|
return files;
|
|
2033
2184
|
}
|
|
@@ -2047,17 +2198,22 @@ function isCssImportOnlyBundleAsset(bundle, file, css) {
|
|
|
2047
2198
|
return collectImportedBundleCssSources(bundle, importedStyleFiles).length > 0;
|
|
2048
2199
|
}
|
|
2049
2200
|
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2050
|
-
const resolvedOutputFile =
|
|
2051
|
-
return resolvedOutputFile !==
|
|
2201
|
+
const resolvedOutputFile = require_source_candidate_scan_signature.normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2202
|
+
return resolvedOutputFile !== require_source_candidate_scan_signature.normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2203
|
+
}
|
|
2204
|
+
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2205
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2206
|
+
const outputFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
2207
|
+
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2052
2208
|
}
|
|
2053
2209
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
2054
2210
|
let collected = 0;
|
|
2055
2211
|
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
2056
2212
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2057
2213
|
if (output.type !== "asset") continue;
|
|
2058
|
-
const file = getAssetFile(bundleFile, output);
|
|
2214
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2059
2215
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
2060
|
-
const rawSource = readAssetSource(output);
|
|
2216
|
+
const rawSource = readAssetSource$2(output);
|
|
2061
2217
|
let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2062
2218
|
const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
|
|
2063
2219
|
if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
|
|
@@ -2065,22 +2221,22 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2065
2221
|
options.markCssAssetProcessed?.(output, file);
|
|
2066
2222
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2067
2223
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
2068
|
-
const shouldReplayIntoMainCss = options.opts != null && (options.opts.mainCssChunkMatcher(file, options.opts.appType) ||
|
|
2224
|
+
const shouldReplayIntoMainCss = options.opts != null && (isRootStyleOutputFile(file) && options.opts.mainCssChunkMatcher(file, options.opts.appType) || isSourceRootPrefixedOutputFile(file, resolvedOutputFile) && isRootStyleOutputFile(resolvedOutputFile) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType));
|
|
2069
2225
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2070
2226
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2071
2227
|
outputFile: resolvedOutputFile
|
|
2072
2228
|
});
|
|
2073
|
-
if (
|
|
2229
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, nextCss, {
|
|
2074
2230
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2075
2231
|
outputFile: resolvedOutputFile
|
|
2076
2232
|
});
|
|
2077
2233
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2078
|
-
if (
|
|
2234
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(markerFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(file)) continue;
|
|
2079
2235
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2080
2236
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2081
2237
|
outputFile: resolvedOutputFile
|
|
2082
2238
|
});
|
|
2083
|
-
if (
|
|
2239
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(markerFile) && require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, nextCss, {
|
|
2084
2240
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2085
2241
|
outputFile: resolvedOutputFile
|
|
2086
2242
|
});
|
|
@@ -2110,23 +2266,45 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2110
2266
|
};
|
|
2111
2267
|
}).filter((record) => record.css.length > 0);
|
|
2112
2268
|
let injected = 0;
|
|
2113
|
-
for (const [bundleFile,
|
|
2269
|
+
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2270
|
+
let output = bundleOutput;
|
|
2114
2271
|
if (output.type !== "asset") continue;
|
|
2115
|
-
|
|
2272
|
+
let file = getAssetFile$1(bundleFile, output);
|
|
2116
2273
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2117
|
-
|
|
2118
|
-
|
|
2274
|
+
let originalSource = readAssetSource$2(output);
|
|
2275
|
+
if (shouldPreserveMiniProgramImportShell(options.opts, file, originalSource)) {
|
|
2276
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options.opts, bundle, file, originalSource);
|
|
2277
|
+
if (typeof importedTargetFile === "string") {
|
|
2278
|
+
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2279
|
+
const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedTargetFile))?.[1];
|
|
2280
|
+
if (importedOutput?.type === "asset") {
|
|
2281
|
+
output = importedOutput;
|
|
2282
|
+
file = importedTargetFile;
|
|
2283
|
+
originalSource = readAssetSource$2(output);
|
|
2284
|
+
} else continue;
|
|
2285
|
+
} else {
|
|
2286
|
+
options.debug?.("preserve mini-program css import shell asset: %s", file);
|
|
2287
|
+
continue;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2291
|
+
const mainFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2119
2292
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2120
2293
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2121
2294
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2122
2295
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2123
2296
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2297
|
+
const bundleAssetFiles = collectBundleAssetFiles(bundle);
|
|
2298
|
+
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2299
|
+
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2300
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2126
2301
|
for (const record of viteCssResults) {
|
|
2302
|
+
if (!isRootStyleOutputFile(file)) {
|
|
2303
|
+
if (typeof record.outputFile !== "string" || require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2304
|
+
}
|
|
2127
2305
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2128
2306
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2129
|
-
let css =
|
|
2307
|
+
let css = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2130
2308
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2131
2309
|
if (css.length === 0) continue;
|
|
2132
2310
|
const mergedLayerCss = require_hmr_timing.mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
@@ -2135,6 +2313,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2135
2313
|
css = require_hmr_timing.extractMarkedUserLayerComponentsCss(css).rest.trim();
|
|
2136
2314
|
if (css.length === 0) continue;
|
|
2137
2315
|
}
|
|
2316
|
+
if ((0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, css) || (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, css).length === 0) continue;
|
|
2138
2317
|
if ((0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, css)) continue;
|
|
2139
2318
|
const mergedPreflightDeclarations = (0, _weapp_tailwindcss_postcss.mergeMiniProgramPreflightRuleDeclarations)(nextCss, css);
|
|
2140
2319
|
if (mergedPreflightDeclarations.changed) {
|
|
@@ -2156,7 +2335,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2156
2335
|
}
|
|
2157
2336
|
const missingCss = (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, css);
|
|
2158
2337
|
if (missingCss.length === 0 || (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, missingCss)) continue;
|
|
2159
|
-
nextCss = appendCss(nextCss, missingCss);
|
|
2338
|
+
nextCss = appendCss$1(nextCss, missingCss);
|
|
2160
2339
|
}
|
|
2161
2340
|
if (nextCss === originalSource) continue;
|
|
2162
2341
|
output.source = nextCss;
|
|
@@ -2166,13 +2345,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2166
2345
|
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2167
2346
|
for (const record of viteCssResults) {
|
|
2168
2347
|
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2169
|
-
const recordFileKey =
|
|
2348
|
+
const recordFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(record.file);
|
|
2170
2349
|
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2171
2350
|
if (candidateOutput.type !== "asset") continue;
|
|
2172
|
-
const candidateKey =
|
|
2351
|
+
const candidateKey = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2173
2352
|
const isRecordFile = candidateKey === recordFileKey;
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2353
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2354
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, candidateSource);
|
|
2355
|
+
if (!isRecordFile && !isProcessedSource || candidateKey === require_source_candidate_scan_signature.normalizeOutputPathKey(file)) continue;
|
|
2176
2356
|
clearAssetSource(candidateOutput);
|
|
2177
2357
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2178
2358
|
}
|
|
@@ -2193,31 +2373,84 @@ function normalizeBundleFileNameKeysForTest(bundle) {
|
|
|
2193
2373
|
}
|
|
2194
2374
|
}
|
|
2195
2375
|
//#endregion
|
|
2376
|
+
//#region src/bundlers/vite/generate-bundle/final-css-assets.ts
|
|
2377
|
+
function readAssetSource$1(output) {
|
|
2378
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
2379
|
+
}
|
|
2380
|
+
function shouldFinalizeMiniProgramCssAsset(source) {
|
|
2381
|
+
return source.includes(":hover") || source.includes("does-not-exist") || (0, _weapp_tailwindcss_postcss.hasMiniProgramCssSpecificityPlaceholders)(source);
|
|
2382
|
+
}
|
|
2383
|
+
async function finalizeMiniProgramCssAssets(bundle, options) {
|
|
2384
|
+
if (options.isWebGeneratorTarget) return 0;
|
|
2385
|
+
let updated = 0;
|
|
2386
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2387
|
+
if (output.type !== "asset") continue;
|
|
2388
|
+
const file = output.fileName || bundleFile;
|
|
2389
|
+
if (!options.cssMatcher(file)) continue;
|
|
2390
|
+
const rawSource = readAssetSource$1(output);
|
|
2391
|
+
if (rawSource.trim().length === 0) continue;
|
|
2392
|
+
if (options.lastCssResultByFile?.has(file)) {
|
|
2393
|
+
const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(rawSource);
|
|
2394
|
+
if (outputCss !== rawSource) {
|
|
2395
|
+
output.source = outputCss;
|
|
2396
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2397
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2398
|
+
options.debug?.("strip mini-program css specificity placeholders: %s bytes=%d", file, outputCss.length);
|
|
2399
|
+
updated++;
|
|
2400
|
+
}
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
if (!shouldFinalizeMiniProgramCssAsset(rawSource)) continue;
|
|
2404
|
+
const cssHandlerOptions = options.getCssHandlerOptions(file);
|
|
2405
|
+
const { css } = await options.styleHandler(rawSource, {
|
|
2406
|
+
...cssHandlerOptions,
|
|
2407
|
+
autoprefixer: false,
|
|
2408
|
+
cssOptions: {
|
|
2409
|
+
...cssHandlerOptions.cssOptions ?? {},
|
|
2410
|
+
autoprefixer: false,
|
|
2411
|
+
cssPresetEnv: {}
|
|
2412
|
+
},
|
|
2413
|
+
cssPresetEnv: {}
|
|
2414
|
+
});
|
|
2415
|
+
const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(css);
|
|
2416
|
+
if (outputCss === rawSource) continue;
|
|
2417
|
+
output.source = outputCss;
|
|
2418
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2419
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2420
|
+
options.debug?.("finalize mini-program css asset: %s bytes=%d", file, outputCss.length);
|
|
2421
|
+
updated++;
|
|
2422
|
+
}
|
|
2423
|
+
return updated;
|
|
2424
|
+
}
|
|
2425
|
+
//#endregion
|
|
2196
2426
|
//#region src/bundlers/vite/generate-bundle/memory-debug.ts
|
|
2197
|
-
function toMb(bytes) {
|
|
2427
|
+
function toMb$2(bytes) {
|
|
2198
2428
|
return Math.round(bytes / 1024 / 1024);
|
|
2199
2429
|
}
|
|
2200
|
-
function summarizeStringMapCache(map) {
|
|
2430
|
+
function summarizeStringMapCache$1(map) {
|
|
2201
2431
|
let bytes = 0;
|
|
2202
2432
|
for (const value of map.values()) bytes += value.length;
|
|
2203
2433
|
return {
|
|
2204
2434
|
bytes,
|
|
2205
|
-
mb: toMb(bytes),
|
|
2435
|
+
mb: toMb$2(bytes),
|
|
2206
2436
|
size: map.size
|
|
2207
2437
|
};
|
|
2208
2438
|
}
|
|
2209
2439
|
function resolveViteMemoryDebugStats(context) {
|
|
2210
2440
|
if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2211
2441
|
const memory = node_process.default.memoryUsage();
|
|
2442
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
2443
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
2212
2444
|
return {
|
|
2213
2445
|
phase: context.phase,
|
|
2214
2446
|
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2447
|
+
bundle: { hasOmittedKnownFiles: context.hasOmittedKnownFiles },
|
|
2215
2448
|
process: {
|
|
2216
|
-
rssMb: toMb(memory.rss),
|
|
2217
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
2218
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
2219
|
-
externalMb: toMb(memory.external),
|
|
2220
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
2449
|
+
rssMb: toMb$2(memory.rss),
|
|
2450
|
+
heapTotalMb: toMb$2(memory.heapTotal),
|
|
2451
|
+
heapUsedMb: toMb$2(memory.heapUsed),
|
|
2452
|
+
externalMb: toMb$2(memory.external),
|
|
2453
|
+
arrayBuffersMb: toMb$2(memory.arrayBuffers)
|
|
2221
2454
|
},
|
|
2222
2455
|
runtime: {
|
|
2223
2456
|
sourceCandidates: context.sourceCandidatesSize,
|
|
@@ -2226,19 +2459,21 @@ function resolveViteMemoryDebugStats(context) {
|
|
|
2226
2459
|
generatorRuntime: context.generatorRuntimeSize
|
|
2227
2460
|
},
|
|
2228
2461
|
processCache: {
|
|
2229
|
-
instance:
|
|
2230
|
-
hashMap:
|
|
2462
|
+
instance: processCacheInstanceSize,
|
|
2463
|
+
hashMap: processCacheHashMapSize,
|
|
2231
2464
|
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2232
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
2465
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
2466
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
2467
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
2468
|
+
pruned: context.processCachePruned,
|
|
2469
|
+
pruneSkipped: !context.processCachePruned,
|
|
2470
|
+
...context.processCachePruneSkipReason ? { pruneSkipReason: context.processCachePruneSkipReason } : {}
|
|
2233
2471
|
},
|
|
2234
2472
|
viteCss: {
|
|
2235
2473
|
...context.getViteCssCacheStats?.(),
|
|
2236
|
-
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2474
|
+
lastCssResultByFile: summarizeStringMapCache$1(context.lastCssResultByFile)
|
|
2237
2475
|
},
|
|
2238
|
-
tailwind: {
|
|
2239
|
-
v3: require_v3_engine.getTailwindV3IncrementalGenerateCacheStats(),
|
|
2240
|
-
v4: require_v3_engine.getTailwindV4IncrementalGenerateCacheStats()
|
|
2241
|
-
}
|
|
2476
|
+
tailwind: { v4: require_v4_engine.getTailwindV4IncrementalGenerateCacheStats() }
|
|
2242
2477
|
};
|
|
2243
2478
|
}
|
|
2244
2479
|
//#endregion
|
|
@@ -2277,6 +2512,27 @@ function formatMs(value) {
|
|
|
2277
2512
|
}
|
|
2278
2513
|
//#endregion
|
|
2279
2514
|
//#region src/bundlers/vite/generate-bundle/uni-app-x-postprocess.ts
|
|
2515
|
+
function appendCss(baseCss, css) {
|
|
2516
|
+
if (baseCss.length === 0) return css;
|
|
2517
|
+
if (css.length === 0) return baseCss;
|
|
2518
|
+
return `${baseCss}\n${css}`;
|
|
2519
|
+
}
|
|
2520
|
+
function injectHarmonyCssIntoMainAsset(bundle, cssSources, onUpdate, debug) {
|
|
2521
|
+
const output = bundle["main.css"];
|
|
2522
|
+
if (output?.type !== "asset" || cssSources.length === 0) return false;
|
|
2523
|
+
const currentSource = String(output.source);
|
|
2524
|
+
let nextSource = currentSource;
|
|
2525
|
+
for (const css of cssSources) {
|
|
2526
|
+
const trimmedCss = css.trim();
|
|
2527
|
+
if (trimmedCss.length === 0 || nextSource.includes(trimmedCss)) continue;
|
|
2528
|
+
nextSource = appendCss(nextSource, trimmedCss);
|
|
2529
|
+
}
|
|
2530
|
+
if (nextSource === currentSource) return false;
|
|
2531
|
+
output.source = nextSource;
|
|
2532
|
+
onUpdate("main.css", currentSource, nextSource);
|
|
2533
|
+
debug("uni-app-x harmony main css inject");
|
|
2534
|
+
return true;
|
|
2535
|
+
}
|
|
2280
2536
|
async function handleUniAppXPostCssTasks(options) {
|
|
2281
2537
|
const { bundle, debug, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler } = options;
|
|
2282
2538
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
@@ -2287,12 +2543,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2287
2543
|
if (isHarmonyAppStyleTarget && applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2288
2544
|
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2289
2545
|
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2290
|
-
const generated = await
|
|
2546
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
2291
2547
|
opts,
|
|
2292
2548
|
runtimeState,
|
|
2293
2549
|
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2294
2550
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2295
2551
|
file: outputFile,
|
|
2552
|
+
outputFile,
|
|
2296
2553
|
cssHandlerOptions,
|
|
2297
2554
|
cssUserHandlerOptions: {
|
|
2298
2555
|
...cssHandlerOptions,
|
|
@@ -2308,6 +2565,7 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2308
2565
|
}));
|
|
2309
2566
|
}
|
|
2310
2567
|
if (isHarmonyAppStyleTarget && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
2568
|
+
if (isHarmonyAppStyleTarget) injectHarmonyCssIntoMainAsset(bundle, viteProcessedCssSources, onUpdate, debug);
|
|
2311
2569
|
for (const [file, item] of Object.entries(bundle)) {
|
|
2312
2570
|
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
2313
2571
|
const currentSource = String(item.source);
|
|
@@ -2323,13 +2581,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2323
2581
|
//#endregion
|
|
2324
2582
|
//#region src/bundlers/vite/generate-bundle/vite-css-cache.ts
|
|
2325
2583
|
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2326
|
-
function resolveViteCssTaskConcurrency(
|
|
2584
|
+
function resolveViteCssTaskConcurrency(_useIncrementalMode, _majorVersion) {
|
|
2327
2585
|
const configured = Number.parseInt(node_process.default.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2328
2586
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2329
|
-
return
|
|
2587
|
+
return 1;
|
|
2330
2588
|
}
|
|
2331
2589
|
function normalizeViteCssCacheKey(file) {
|
|
2332
|
-
return
|
|
2590
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2333
2591
|
}
|
|
2334
2592
|
function rememberLastCssResult(resultByFile, sourceHashByFile, file, css, sourceHash) {
|
|
2335
2593
|
const key = normalizeViteCssCacheKey(file);
|
|
@@ -2367,13 +2625,88 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2367
2625
|
}
|
|
2368
2626
|
//#endregion
|
|
2369
2627
|
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
2628
|
+
function readAssetSource(asset) {
|
|
2629
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2630
|
+
}
|
|
2631
|
+
function getAssetFile(bundleFile, asset) {
|
|
2632
|
+
return asset.fileName || bundleFile;
|
|
2633
|
+
}
|
|
2634
|
+
function isRootMiniProgramStyleOutputFile(file) {
|
|
2635
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2636
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
2637
|
+
}
|
|
2638
|
+
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
2639
|
+
const normalizedTargetFile = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
2640
|
+
const normalizedImportedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
2641
|
+
const targetDir = node_path.default.posix.dirname(normalizedTargetFile);
|
|
2642
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
2643
|
+
const relative = node_path.default.posix.relative(baseDir, normalizedImportedFile);
|
|
2644
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2645
|
+
}
|
|
2646
|
+
function createCssImportShell(targetFile, importedFile) {
|
|
2647
|
+
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
2648
|
+
}
|
|
2649
|
+
function resolveRootMiniProgramOriginStyleFile(file) {
|
|
2650
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2651
|
+
if (!isRootMiniProgramStyleOutputFile(normalized)) return;
|
|
2652
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
2653
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
2654
|
+
}
|
|
2655
|
+
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
2656
|
+
let importedFile;
|
|
2657
|
+
try {
|
|
2658
|
+
_weapp_tailwindcss_postcss.postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
2659
|
+
if (importedFile !== void 0) return;
|
|
2660
|
+
const request = require_v4_engine.parseImportRequest(atRule.params);
|
|
2661
|
+
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
2662
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
2663
|
+
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
2664
|
+
const targetDir = node_path.default.posix.dirname(require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile));
|
|
2665
|
+
importedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2666
|
+
});
|
|
2667
|
+
} catch {}
|
|
2668
|
+
return importedFile;
|
|
2669
|
+
}
|
|
2670
|
+
function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
2671
|
+
if (options.appType !== "taro") return 0;
|
|
2672
|
+
let updated = 0;
|
|
2673
|
+
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
2674
|
+
if (rootOutput.type !== "asset") continue;
|
|
2675
|
+
const rootFile = getAssetFile(rootBundleFile, rootOutput);
|
|
2676
|
+
if (!isRootMiniProgramStyleOutputFile(rootFile) || !options.cssMatcher(rootFile)) continue;
|
|
2677
|
+
const originFile = resolveRootMiniProgramOriginStyleFile(rootFile);
|
|
2678
|
+
if (!originFile || !options.cssMatcher(originFile)) continue;
|
|
2679
|
+
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile(bundleFile, output)) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile))?.[1];
|
|
2680
|
+
if (originOutput?.type !== "asset") continue;
|
|
2681
|
+
const rootSource = readAssetSource(rootOutput);
|
|
2682
|
+
if (require_hmr_timing.isPureLocalCssImportWrapper(rootSource)) continue;
|
|
2683
|
+
const originSource = readAssetSource(originOutput);
|
|
2684
|
+
if (require_hmr_timing.isPureLocalCssImportWrapper(originSource)) {
|
|
2685
|
+
const importedFile = resolveSingleCssImportOutputFile(originFile, originSource);
|
|
2686
|
+
if (importedFile && require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(rootFile)) continue;
|
|
2687
|
+
} else if (originSource.trim().length > 0 && originSource.trim() !== rootSource.trim()) continue;
|
|
2688
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2689
|
+
if (rootSource === nextRootSource) continue;
|
|
2690
|
+
rootOutput.source = nextRootSource;
|
|
2691
|
+
originOutput.source = rootSource;
|
|
2692
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2693
|
+
options.recordCssAssetResult?.(originFile, rootSource);
|
|
2694
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2695
|
+
options.onUpdate?.(originFile, originSource, rootSource);
|
|
2696
|
+
options.debug("normalize taro root css import shell: %s -> %s", rootFile, originFile);
|
|
2697
|
+
updated++;
|
|
2698
|
+
}
|
|
2699
|
+
return updated;
|
|
2700
|
+
}
|
|
2370
2701
|
async function finalizeGenerateBundle(options) {
|
|
2371
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2702
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2703
|
+
const tasksStart = performance.now();
|
|
2372
2704
|
if (cssTaskFactories.length > 0) {
|
|
2373
|
-
const
|
|
2374
|
-
|
|
2705
|
+
const cssTask = require_hmr_timing.runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
2706
|
+
if (jsAfterCss) await cssTask;
|
|
2707
|
+
else tasks.push(cssTask);
|
|
2375
2708
|
}
|
|
2376
|
-
|
|
2709
|
+
if (jsTaskFactories.length > 0) tasks.push(require_hmr_timing.runWithConcurrency(jsTaskFactories).then(() => void 0));
|
|
2377
2710
|
await Promise.all(tasks);
|
|
2378
2711
|
recordTimingDetail("tasks", tasksStart);
|
|
2379
2712
|
for (const apply of pendingLinkedUpdates) apply();
|
|
@@ -2408,9 +2741,10 @@ async function finalizeGenerateBundle(options) {
|
|
|
2408
2741
|
getViteProcessedCssAssetResults,
|
|
2409
2742
|
markCssAssetProcessed,
|
|
2410
2743
|
recordCssAssetResult,
|
|
2411
|
-
shouldRemoveInjectedSourceAsset: (
|
|
2412
|
-
if (record.injectIntoMain
|
|
2413
|
-
|
|
2744
|
+
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2745
|
+
if (record.injectIntoMain === false) return false;
|
|
2746
|
+
const targetFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile);
|
|
2747
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(record.file) !== targetFileKey;
|
|
2414
2748
|
},
|
|
2415
2749
|
debug,
|
|
2416
2750
|
onUpdate
|
|
@@ -2421,6 +2755,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2421
2755
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
2422
2756
|
syncViteProcessedCssIntoMainCssAssets();
|
|
2423
2757
|
}
|
|
2758
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
2759
|
+
appType: opts.appType,
|
|
2760
|
+
cssMatcher: opts.cssMatcher,
|
|
2761
|
+
debug,
|
|
2762
|
+
onUpdate,
|
|
2763
|
+
recordCssAssetResult
|
|
2764
|
+
});
|
|
2424
2765
|
normalizeBundleFileNameKeysForTest(bundle);
|
|
2425
2766
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2426
2767
|
cssMatcher: opts.cssMatcher,
|
|
@@ -2430,18 +2771,33 @@ async function finalizeGenerateBundle(options) {
|
|
|
2430
2771
|
recordCssAssetResult,
|
|
2431
2772
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2432
2773
|
});
|
|
2774
|
+
await finalizeMiniProgramCssAssets(bundle, {
|
|
2775
|
+
cssMatcher: opts.cssMatcher,
|
|
2776
|
+
debug,
|
|
2777
|
+
getCssHandlerOptions,
|
|
2778
|
+
isWebGeneratorTarget,
|
|
2779
|
+
lastCssResultByFile,
|
|
2780
|
+
onUpdate,
|
|
2781
|
+
recordCssAssetResult,
|
|
2782
|
+
styleHandler
|
|
2783
|
+
});
|
|
2433
2784
|
const stateUpdateStart = performance.now();
|
|
2434
|
-
|
|
2785
|
+
require_source_candidate_scan_signature.updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2435
2786
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2436
|
-
|
|
2787
|
+
const shouldPruneTransientCaches = !snapshot.hasOmittedKnownFiles;
|
|
2788
|
+
const processCachePruned = useIncrementalMode && shouldPruneTransientCaches && typeof cache.prune === "function";
|
|
2789
|
+
const processCachePruneSkipReason = processCachePruned ? void 0 : !useIncrementalMode ? "full-mode" : !shouldPruneTransientCaches ? "omitted-known-files" : "cache-prune-unavailable";
|
|
2790
|
+
if (processCachePruned) cache.prune?.({
|
|
2437
2791
|
cacheKeys: activeProcessCacheKeys,
|
|
2438
2792
|
hashKeys: activeProcessHashKeys
|
|
2439
2793
|
});
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2794
|
+
if (shouldPruneTransientCaches) {
|
|
2795
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2796
|
+
pruneViteCssCaches?.({
|
|
2797
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2798
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2445
2801
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2446
2802
|
debug("metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)", formatIteration, formatMs(metrics.runtimeSet), metrics.html.total, metrics.html.transformed, metrics.html.cacheHits, formatCacheHitRate(metrics.html), formatMs(metrics.html.elapsed), metrics.js.total, metrics.js.transformed, metrics.js.cacheHits, formatCacheHitRate(metrics.js), formatMs(metrics.js.elapsed), metrics.css.total, metrics.css.transformed, metrics.css.cacheHits, formatCacheHitRate(metrics.css), formatMs(metrics.css.elapsed));
|
|
2447
2803
|
if (hmrTimingRecorder) {
|
|
@@ -2453,8 +2809,11 @@ async function finalizeGenerateBundle(options) {
|
|
|
2453
2809
|
cache,
|
|
2454
2810
|
generatorRuntimeSize: generatorRuntime.size,
|
|
2455
2811
|
getViteCssCacheStats,
|
|
2812
|
+
hasOmittedKnownFiles: snapshot.hasOmittedKnownFiles,
|
|
2456
2813
|
lastCssResultByFile,
|
|
2457
2814
|
phase: "generateBundle",
|
|
2815
|
+
processCachePruned,
|
|
2816
|
+
processCachePruneSkipReason,
|
|
2458
2817
|
runtimeSize: runtime.size,
|
|
2459
2818
|
sourceCandidatesSize: sourceCandidates.size,
|
|
2460
2819
|
transformRuntimeSize: transformRuntime.size,
|
|
@@ -2467,11 +2826,125 @@ async function finalizeGenerateBundle(options) {
|
|
|
2467
2826
|
debug("end");
|
|
2468
2827
|
}
|
|
2469
2828
|
//#endregion
|
|
2829
|
+
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
2830
|
+
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
2831
|
+
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
2832
|
+
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
2833
|
+
const MUSTACHE_OPEN = "{{";
|
|
2834
|
+
const MUSTACHE_CLOSE = "}}";
|
|
2835
|
+
function isUrlLikeCandidate(candidate) {
|
|
2836
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2837
|
+
}
|
|
2838
|
+
function isArbitraryValueCandidate(candidate) {
|
|
2839
|
+
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
2840
|
+
}
|
|
2841
|
+
function collectClassAttributeValues(source) {
|
|
2842
|
+
const values = [];
|
|
2843
|
+
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
2844
|
+
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2845
|
+
while (matched !== null) {
|
|
2846
|
+
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
2847
|
+
const quote = source[quoteIndex];
|
|
2848
|
+
if (quote !== "\"" && quote !== "'") {
|
|
2849
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
let expressionDepth = 0;
|
|
2853
|
+
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
2854
|
+
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
2855
|
+
expressionDepth++;
|
|
2856
|
+
index += 1;
|
|
2857
|
+
continue;
|
|
2858
|
+
}
|
|
2859
|
+
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
2860
|
+
expressionDepth--;
|
|
2861
|
+
index += 1;
|
|
2862
|
+
continue;
|
|
2863
|
+
}
|
|
2864
|
+
if (expressionDepth === 0 && source[index] === quote) {
|
|
2865
|
+
values.push(source.slice(quoteIndex + 1, index));
|
|
2866
|
+
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
2867
|
+
break;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2871
|
+
}
|
|
2872
|
+
return values;
|
|
2873
|
+
}
|
|
2874
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
2875
|
+
const matches = /* @__PURE__ */ new Set();
|
|
2876
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
2877
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
2878
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
2879
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2880
|
+
while (quoted !== null) {
|
|
2881
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
2882
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
|
|
2883
|
+
const normalized = candidate.trim();
|
|
2884
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
2885
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
2886
|
+
matches.add(normalized);
|
|
2887
|
+
}
|
|
2888
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
return [...matches];
|
|
2892
|
+
}
|
|
2893
|
+
//#endregion
|
|
2894
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
2895
|
+
function processHtmlBundleEntry(options) {
|
|
2896
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
2897
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
2898
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
2899
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
2900
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
|
|
2901
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
2902
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
2903
|
+
const hashKey = cacheKey;
|
|
2904
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
2905
|
+
tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
|
|
2906
|
+
cache,
|
|
2907
|
+
cacheKey,
|
|
2908
|
+
hashKey,
|
|
2909
|
+
hash: htmlProcessHash,
|
|
2910
|
+
applyResult(source) {
|
|
2911
|
+
originalSource.source = source;
|
|
2912
|
+
},
|
|
2913
|
+
onCacheHit() {
|
|
2914
|
+
metrics.html.cacheHits++;
|
|
2915
|
+
debug("html cache hit: %s", file);
|
|
2916
|
+
},
|
|
2917
|
+
async transform() {
|
|
2918
|
+
const start = performance.now();
|
|
2919
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
2920
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
2921
|
+
let retryRuntimeSet;
|
|
2922
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
2923
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
2924
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
2925
|
+
retryRuntimeSet = new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
2926
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
2927
|
+
}
|
|
2928
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
2929
|
+
_weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2930
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
2931
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
2932
|
+
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2933
|
+
}
|
|
2934
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
2935
|
+
metrics.html.transformed++;
|
|
2936
|
+
onUpdate(file, rawSource, transformed);
|
|
2937
|
+
debug("html handle: %s", file);
|
|
2938
|
+
return { result: transformed };
|
|
2939
|
+
}
|
|
2940
|
+
})));
|
|
2941
|
+
}
|
|
2942
|
+
//#endregion
|
|
2470
2943
|
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
2471
2944
|
function createJsEntryResolver(jsEntries) {
|
|
2472
2945
|
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
2473
|
-
for (const [id, entry] of jsEntries) normalizedJsEntries.set(
|
|
2474
|
-
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(
|
|
2946
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
|
|
2947
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
|
|
2475
2948
|
}
|
|
2476
2949
|
//#endregion
|
|
2477
2950
|
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
@@ -2481,6 +2954,7 @@ function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
|
2481
2954
|
function createJsHandlerOptionsFactory(options) {
|
|
2482
2955
|
return (absoluteFilename, extra) => ({
|
|
2483
2956
|
...extra,
|
|
2957
|
+
generateMap: false,
|
|
2484
2958
|
filename: absoluteFilename,
|
|
2485
2959
|
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
2486
2960
|
moduleGraph: options.moduleGraph,
|
|
@@ -2505,7 +2979,7 @@ function createLinkedUpdateHelpers(options) {
|
|
|
2505
2979
|
});
|
|
2506
2980
|
};
|
|
2507
2981
|
const applyLinkedUpdates = (linked) => {
|
|
2508
|
-
|
|
2982
|
+
require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
2509
2983
|
};
|
|
2510
2984
|
return {
|
|
2511
2985
|
applyLinkedUpdates,
|
|
@@ -2520,57 +2994,9 @@ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
|
2520
2994
|
}
|
|
2521
2995
|
}
|
|
2522
2996
|
//#endregion
|
|
2523
|
-
//#region src/bundlers/vite/generate-bundle/signatures.ts
|
|
2524
|
-
function summarizeStringDiff(previous, next) {
|
|
2525
|
-
if (previous === next) return "same";
|
|
2526
|
-
const previousLength = previous.length;
|
|
2527
|
-
const nextLength = next.length;
|
|
2528
|
-
const minLength = Math.min(previousLength, nextLength);
|
|
2529
|
-
let prefixLength = 0;
|
|
2530
|
-
while (prefixLength < minLength && previous.charCodeAt(prefixLength) === next.charCodeAt(prefixLength)) prefixLength += 1;
|
|
2531
|
-
let previousSuffixCursor = previousLength - 1;
|
|
2532
|
-
let nextSuffixCursor = nextLength - 1;
|
|
2533
|
-
while (previousSuffixCursor >= prefixLength && nextSuffixCursor >= prefixLength && previous.charCodeAt(previousSuffixCursor) === next.charCodeAt(nextSuffixCursor)) {
|
|
2534
|
-
previousSuffixCursor -= 1;
|
|
2535
|
-
nextSuffixCursor -= 1;
|
|
2536
|
-
}
|
|
2537
|
-
const previousChangedLength = previousSuffixCursor >= prefixLength ? previousSuffixCursor - prefixLength + 1 : 0;
|
|
2538
|
-
const nextChangedLength = nextSuffixCursor >= prefixLength ? nextSuffixCursor - prefixLength + 1 : 0;
|
|
2539
|
-
return `changed@${prefixLength} old=${previousChangedLength} new=${nextChangedLength} len=${previousLength}->${nextLength}`;
|
|
2540
|
-
}
|
|
2541
|
-
function createLinkedImpactSignature(entry, linkedImpactsByEntry, sourceHashByFile) {
|
|
2542
|
-
const changedLinkedFiles = linkedImpactsByEntry.get(entry);
|
|
2543
|
-
if (!changedLinkedFiles || changedLinkedFiles.size === 0) return;
|
|
2544
|
-
return [...changedLinkedFiles].sort().map((file) => {
|
|
2545
|
-
return `${file}:${sourceHashByFile.get(file) ?? "missing"}`;
|
|
2546
|
-
}).join(",");
|
|
2547
|
-
}
|
|
2548
|
-
function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
|
|
2549
|
-
if (!linkedImpactSignature) return runtimeSignature;
|
|
2550
|
-
return `${runtimeSignature}:linked:${linkedImpactSignature}`;
|
|
2551
|
-
}
|
|
2552
|
-
function createStableTextSignature(input) {
|
|
2553
|
-
let hash = 2166136261;
|
|
2554
|
-
for (let i = 0; i < input.length; i++) {
|
|
2555
|
-
hash ^= input.charCodeAt(i);
|
|
2556
|
-
hash = Math.imul(hash, 16777619);
|
|
2557
|
-
}
|
|
2558
|
-
return (hash >>> 0).toString(36);
|
|
2559
|
-
}
|
|
2560
|
-
function createCandidateSignature(candidates) {
|
|
2561
|
-
if (candidates.size === 0) return "empty";
|
|
2562
|
-
return createStableTextSignature([...candidates].sort().join("\n"));
|
|
2563
|
-
}
|
|
2564
|
-
function getSnapshotHash(snapshotMap, file, fallback) {
|
|
2565
|
-
return snapshotMap.get(file) ?? fallback;
|
|
2566
|
-
}
|
|
2567
|
-
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
2568
|
-
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
2569
|
-
}
|
|
2570
|
-
//#endregion
|
|
2571
2997
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2572
2998
|
function processJsBundleEntry(options) {
|
|
2573
|
-
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
2999
|
+
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, shouldSkipAstTransform, slowJsAstWarnMs, timeTask, transformRuntime, transformRuntimeSignature, transformFilterSignature, uniAppX, useIncrementalMode } = options;
|
|
2574
3000
|
const { file, output: originalSource, source: originalEntrySource } = entry;
|
|
2575
3001
|
metrics.js.total++;
|
|
2576
3002
|
const shouldTransformJs = !useIncrementalMode || processFiles.js.has(file);
|
|
@@ -2580,16 +3006,27 @@ function processJsBundleEntry(options) {
|
|
|
2580
3006
|
const initialRawSource = originalEntrySource;
|
|
2581
3007
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2582
3008
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
3009
|
+
const linkedImpactSignature = useIncrementalMode ? require_source_candidate_scan_signature.createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0;
|
|
3010
|
+
const hashSalt = require_source_candidate_scan_signature.createJsHashSalt(`${transformRuntimeSignature}:transform-filter:${transformFilterSignature}`, linkedImpactSignature);
|
|
3011
|
+
const hashKey = `${file}:js`;
|
|
3012
|
+
const processHash = `${require_source_candidate_scan_signature.getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`;
|
|
3013
|
+
rememberProcessCacheKey(file, hashKey);
|
|
3014
|
+
if (useIncrementalMode && !shouldTransformJs) {
|
|
3015
|
+
const cachedCode = cache.getHashValue(hashKey)?.hash === processHash ? cache.get(file) : void 0;
|
|
3016
|
+
if (cachedCode !== void 0) {
|
|
3017
|
+
originalSource.code = cachedCode;
|
|
3018
|
+
metrics.js.cacheHits++;
|
|
3019
|
+
debug("js direct replay hit: %s", file);
|
|
3020
|
+
return;
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
2583
3023
|
jsTaskFactories.push(async () => {
|
|
2584
3024
|
await timeTask("js", async () => {
|
|
2585
|
-
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2586
|
-
const hashKey = `${file}:js`;
|
|
2587
|
-
rememberProcessCacheKey(file, hashKey);
|
|
2588
3025
|
await require_hmr_timing.processCachedTask({
|
|
2589
3026
|
cache,
|
|
2590
3027
|
cacheKey: file,
|
|
2591
3028
|
hashKey,
|
|
2592
|
-
hash:
|
|
3029
|
+
hash: processHash,
|
|
2593
3030
|
applyResult(source) {
|
|
2594
3031
|
originalSource.code = source;
|
|
2595
3032
|
},
|
|
@@ -2601,15 +3038,24 @@ function processJsBundleEntry(options) {
|
|
|
2601
3038
|
const start = performance.now();
|
|
2602
3039
|
const rawSource = originalSource.code;
|
|
2603
3040
|
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
3041
|
+
if (shouldSkipAstTransform?.(originalSource)) {
|
|
3042
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
3043
|
+
metrics.js.transformed++;
|
|
3044
|
+
debug("js skip ast transform (filtered): %s", file);
|
|
3045
|
+
return { result: rawSource };
|
|
3046
|
+
}
|
|
2604
3047
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2605
|
-
if (!disableJsPrecheck &&
|
|
3048
|
+
if (!disableJsPrecheck && require_context.shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2606
3049
|
metrics.js.elapsed += measureElapsed(start);
|
|
2607
3050
|
metrics.js.transformed++;
|
|
2608
3051
|
return { result: rawSource };
|
|
2609
3052
|
}
|
|
3053
|
+
const handlerStart = performance.now();
|
|
2610
3054
|
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
3055
|
+
const handlerElapsed = measureElapsed(handlerStart);
|
|
2611
3056
|
metrics.js.elapsed += measureElapsed(start);
|
|
2612
3057
|
metrics.js.transformed++;
|
|
3058
|
+
if (handlerElapsed >= slowJsAstWarnMs) _weapp_tailwindcss_logger.logger.warn("JS AST 转译耗时较长: %s 用时 %sms,源码约 %d bytes。若这是大型生成 TS/JS chunk,请配置 weapp-tailwindcss 的 transform.exclude 排除 generated/openapi 等目录。", file, handlerElapsed.toFixed(1), rawSource.length);
|
|
2613
3059
|
onUpdate(file, rawSource, code);
|
|
2614
3060
|
debug("js handle: %s", file);
|
|
2615
3061
|
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
@@ -2631,7 +3077,7 @@ function processJsBundleEntry(options) {
|
|
|
2631
3077
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2632
3078
|
cache,
|
|
2633
3079
|
hashKey: uniAppXJsHashKey,
|
|
2634
|
-
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
3080
|
+
hashSalt: require_source_candidate_scan_signature.createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? require_source_candidate_scan_signature.createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2635
3081
|
createHandlerOptions,
|
|
2636
3082
|
debug,
|
|
2637
3083
|
getAssetSource: createUniAppXBundleAssetSourceGetter(bundle),
|
|
@@ -2659,7 +3105,7 @@ function processJsBundleEntry(options) {
|
|
|
2659
3105
|
sourceType: "unambiguous"
|
|
2660
3106
|
}
|
|
2661
3107
|
});
|
|
2662
|
-
if (!disableJsPrecheck &&
|
|
3108
|
+
if (!disableJsPrecheck && require_context.shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
2663
3109
|
metrics.js.elapsed += measureElapsed(start);
|
|
2664
3110
|
metrics.js.transformed++;
|
|
2665
3111
|
return;
|
|
@@ -2689,13 +3135,13 @@ function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffe
|
|
|
2689
3135
|
return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
|
|
2690
3136
|
}
|
|
2691
3137
|
function normalizeRememberedSourceIdentity(file) {
|
|
2692
|
-
return
|
|
3138
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2693
3139
|
}
|
|
2694
3140
|
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
2695
3141
|
if (!sources) return [];
|
|
2696
3142
|
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
2697
3143
|
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
2698
|
-
const markerFiles = new Set(
|
|
3144
|
+
const markerFiles = new Set(require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => require_source_candidate_scan_signature.normalizeOutputPathKey(block.file)));
|
|
2699
3145
|
if (markerFiles.size > 0) {
|
|
2700
3146
|
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeRememberedSourceIdentity(remembered.sourceFile)));
|
|
2701
3147
|
if (markerMatched.length > 0) return markerMatched;
|
|
@@ -2707,9 +3153,9 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
|
|
|
2707
3153
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
2708
3154
|
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeRememberedSourceIdentity(remembered.sourceFile) === normalizeRememberedSourceIdentity(originalFile)));
|
|
2709
3155
|
if (sourceMatched.length > 0) return sourceMatched;
|
|
2710
|
-
const outputMatched = rememberedSources.filter((remembered) =>
|
|
3156
|
+
const outputMatched = rememberedSources.filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile));
|
|
2711
3157
|
if (outputMatched.length > 0) return outputMatched;
|
|
2712
|
-
if (!
|
|
3158
|
+
if (!require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
|
|
2713
3159
|
const scoredMatches = rememberedSources.map((remembered) => ({
|
|
2714
3160
|
remembered,
|
|
2715
3161
|
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
@@ -2736,7 +3182,8 @@ function mergeRememberedCssSources(sources, outputFile) {
|
|
|
2736
3182
|
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
2737
3183
|
const groups = /* @__PURE__ */ new Map();
|
|
2738
3184
|
for (const [key, remembered] of sources ?? []) {
|
|
2739
|
-
const
|
|
3185
|
+
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3186
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(CSS_SOURCE_OUTPUT_EXT_RE.test(cleanSourceFile) ? resolveViteCssPipelineOutputFileFromSourceFile(remembered.sourceFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) : resolveViteCssPipelineOutputFileFromSourceFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles));
|
|
2740
3187
|
const group = groups.get(outputKey) ?? [];
|
|
2741
3188
|
group.push({
|
|
2742
3189
|
key,
|
|
@@ -2747,40 +3194,17 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
2747
3194
|
return groups;
|
|
2748
3195
|
}
|
|
2749
3196
|
//#endregion
|
|
2750
|
-
//#region src/bundlers/vite/generate-bundle/scoped-generator.ts
|
|
2751
|
-
function hasOwnSourceDirectives(rawSource) {
|
|
2752
|
-
return rawSource.includes("@source") || rawSource.includes("@config");
|
|
2753
|
-
}
|
|
2754
|
-
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
2755
|
-
if (!getSourceCandidatesForEntries || !hasOwnSourceDirectives(rawSource)) return fallbackSignature;
|
|
2756
|
-
const sourceBase = node_path.default.dirname(node_path.default.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2757
|
-
const resolved = options.majorVersion === 3 ? await require_v3_engine.resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await require_v3_engine.resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2758
|
-
if (resolved?.entries === void 0) return fallbackSignature;
|
|
2759
|
-
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
2760
|
-
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
2761
|
-
}
|
|
2762
|
-
async function createScopedGeneratorRuntime(options) {
|
|
2763
|
-
const { cssHandlerOptions, fallbackRuntime, getSourceCandidatesForEntries, majorVersion, outputFile, rawSource, shouldExcludeSubpackageSourceCandidates, sourceFile, scopedSourceCandidateGetter } = options;
|
|
2764
|
-
if (getSourceCandidatesForEntries && rawSource && sourceFile) {
|
|
2765
|
-
const sourceBase = node_path.default.dirname(node_path.default.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2766
|
-
const resolved = majorVersion === 3 ? await require_v3_engine.resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await require_v3_engine.resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2767
|
-
if (resolved?.entries !== void 0 && (resolved.entries.length > 0 || hasOwnSourceDirectives(rawSource))) return scopedSourceCandidateGetter?.(resolved.entries) ?? getSourceCandidatesForEntries(resolved.entries);
|
|
2768
|
-
}
|
|
2769
|
-
const scopedCandidates = scopedSourceCandidateGetter?.(void 0);
|
|
2770
|
-
if (scopedCandidates && (scopedCandidates.size > 0 || shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions))) return scopedCandidates;
|
|
2771
|
-
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return fallbackRuntime;
|
|
2772
|
-
return fallbackRuntime;
|
|
2773
|
-
}
|
|
2774
|
-
//#endregion
|
|
2775
3197
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
2776
3198
|
async function processRememberedCssReplay(options) {
|
|
2777
3199
|
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
2778
3200
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
2779
3201
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3202
|
+
if (require_source_candidate_scan_signature.isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
2780
3203
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2781
3204
|
key: item.key,
|
|
2782
3205
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2783
3206
|
})));
|
|
3207
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2784
3208
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2785
3209
|
if (!rememberedCssSource) continue;
|
|
2786
3210
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
@@ -2793,33 +3217,33 @@ async function processRememberedCssReplay(options) {
|
|
|
2793
3217
|
};
|
|
2794
3218
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2795
3219
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2796
|
-
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2797
|
-
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
2798
|
-
opts,
|
|
2799
|
-
tokenSources: sourceTraceTokenSources
|
|
2800
|
-
});
|
|
2801
3220
|
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, rawSource, sourceFile);
|
|
2802
|
-
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
3221
|
+
const cssRuntimeSignature = createCssRuntimeSignature(require_source_candidate_scan_signature.createCandidateSignature(scopedGeneratorRuntime), await require_source_candidate_scan_signature.createScopedGeneratorCandidateSignature(rawSource, sourceFile, require_source_candidate_scan_signature.createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
2803
3222
|
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
2804
|
-
majorVersion: runtimeState.
|
|
3223
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
2805
3224
|
}));
|
|
2806
|
-
const cssRuntimeAffectingHash = cache.computeHash(
|
|
3225
|
+
const cssRuntimeAffectingHash = cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2807
3226
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2808
3227
|
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2809
|
-
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2810
3228
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2811
3229
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3230
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3231
|
+
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
3232
|
+
opts,
|
|
3233
|
+
tokenSources: sourceTraceTokenSources
|
|
3234
|
+
});
|
|
2812
3235
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
2813
3236
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
2814
3237
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
2815
3238
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2816
3239
|
const start = performance.now();
|
|
2817
|
-
const generated = await
|
|
3240
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
2818
3241
|
opts,
|
|
2819
3242
|
runtimeState,
|
|
2820
3243
|
runtime: scopedGeneratorRuntime,
|
|
2821
3244
|
rawSource,
|
|
2822
3245
|
file: sourceFile,
|
|
3246
|
+
outputFile,
|
|
2823
3247
|
cssHandlerOptions,
|
|
2824
3248
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2825
3249
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
@@ -2842,7 +3266,7 @@ async function processRememberedCssReplay(options) {
|
|
|
2842
3266
|
}
|
|
2843
3267
|
if (shouldEmitRememberedReplayCssAsset) {
|
|
2844
3268
|
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
2845
|
-
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3269
|
+
if (replayAsset) markCssAssetProcessed?.(replayAsset, outputFile);
|
|
2846
3270
|
}
|
|
2847
3271
|
metrics.css.elapsed += measureElapsed(start);
|
|
2848
3272
|
metrics.css.transformed++;
|
|
@@ -2890,13 +3314,33 @@ function collectJsImportedCssFiles(snapshot) {
|
|
|
2890
3314
|
let match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2891
3315
|
while (match !== null) {
|
|
2892
3316
|
const request = match[1];
|
|
2893
|
-
if (request?.startsWith(".")) files.add(
|
|
3317
|
+
if (request?.startsWith(".")) files.add(require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.posix.join(node_path.default.posix.dirname(entry.file), request)));
|
|
2894
3318
|
match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2895
3319
|
}
|
|
2896
3320
|
}
|
|
2897
3321
|
return files;
|
|
2898
3322
|
}
|
|
2899
3323
|
//#endregion
|
|
3324
|
+
//#region src/bundlers/vite/generate-bundle/runtime-linked-source-memory.ts
|
|
3325
|
+
function rememberRuntimeLinkedCssSources(options) {
|
|
3326
|
+
const { bundleFiles, defaultStyleOutputExtension, debug, getConfiguredTailwindV4CssSourceEntries, getSourceCandidateSource, getSourceCandidateSources, isWebGeneratorTarget, jsImportedCssFiles, opts, outDir, rememberCssSource, rootDir, runtimeLinkedCssFiles, shouldPreserveAppCssExtension, snapshot, sourceRoot } = options;
|
|
3327
|
+
for (const file of runtimeLinkedCssFiles) {
|
|
3328
|
+
if (snapshot.sourceHashByFile.has(file)) {
|
|
3329
|
+
snapshot.processFiles.css.add(file);
|
|
3330
|
+
continue;
|
|
3331
|
+
}
|
|
3332
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3333
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
3334
|
+
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(node_path.default.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3335
|
+
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3336
|
+
rememberCssSource?.({
|
|
3337
|
+
outputFile,
|
|
3338
|
+
rawSource,
|
|
3339
|
+
sourceFile: inferredSourceStyle?.sourceFile ?? node_path.default.resolve(outDir, file)
|
|
3340
|
+
});
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
//#endregion
|
|
2900
3344
|
//#region src/bundlers/vite/generate-bundle/source-candidate-scope.ts
|
|
2901
3345
|
function intersectCandidateSets(left, right) {
|
|
2902
3346
|
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
@@ -2911,11 +3355,43 @@ function intersectCandidateSourceMaps(left, right) {
|
|
|
2911
3355
|
for (const [candidate, sources] of left) if (right.has(candidate)) matched.set(candidate, sources);
|
|
2912
3356
|
return matched;
|
|
2913
3357
|
}
|
|
3358
|
+
function normalizeSourceFile(file) {
|
|
3359
|
+
return node_path.default.resolve(file.replace(/[?#].*$/, ""));
|
|
3360
|
+
}
|
|
3361
|
+
function resolveSubpackageSourceRootFromFile(file, subpackageRoot) {
|
|
3362
|
+
const normalizedFile = normalizeSourceFile(file).split(node_path.default.sep).join("/");
|
|
3363
|
+
const normalizedRoot = subpackageRoot.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
3364
|
+
if (!normalizedRoot) return;
|
|
3365
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
3366
|
+
const rootIndex = normalizedFile.lastIndexOf(rootSegment);
|
|
3367
|
+
if (rootIndex < 0) return;
|
|
3368
|
+
return normalizedFile.slice(0, rootIndex);
|
|
3369
|
+
}
|
|
3370
|
+
function collectSubpackageSourceRootsFromCssSources(cssSourceFiles, subpackageRoots) {
|
|
3371
|
+
const sourceRootsByPackageRoot = /* @__PURE__ */ new Map();
|
|
3372
|
+
if (!cssSourceFiles || !subpackageRoots) return sourceRootsByPackageRoot;
|
|
3373
|
+
for (const file of cssSourceFiles) {
|
|
3374
|
+
if (typeof file !== "string" || file.length === 0) continue;
|
|
3375
|
+
for (const root of subpackageRoots) {
|
|
3376
|
+
const sourceRoot = resolveSubpackageSourceRootFromFile(file, root);
|
|
3377
|
+
if (!sourceRoot) continue;
|
|
3378
|
+
const roots = sourceRootsByPackageRoot.get(root) ?? /* @__PURE__ */ new Set();
|
|
3379
|
+
roots.add(sourceRoot);
|
|
3380
|
+
sourceRootsByPackageRoot.set(root, roots);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
return sourceRootsByPackageRoot;
|
|
3384
|
+
}
|
|
3385
|
+
function flattenSourceRoots(sourceRootsByPackageRoot) {
|
|
3386
|
+
return [...new Set([...sourceRootsByPackageRoot.values()].flatMap((roots) => [...roots]))];
|
|
3387
|
+
}
|
|
2914
3388
|
function createSubpackageSourceCandidateScope(options) {
|
|
3389
|
+
const cssSourceRootsByPackageRoot = collectSubpackageSourceRootsFromCssSources(options.cssSourceFiles, options.subpackageRoots);
|
|
2915
3390
|
const subpackageSourceExcludeEntries = options.subpackageRoots ? collectMiniProgramSubpackageSourceEntries(options.snapshot, options.subpackageRoots, [
|
|
2916
3391
|
options.rootDir,
|
|
2917
3392
|
options.tailwindcssBasedir,
|
|
2918
|
-
options.projectRoot
|
|
3393
|
+
options.projectRoot,
|
|
3394
|
+
...flattenSourceRoots(cssSourceRootsByPackageRoot)
|
|
2919
3395
|
]) : [];
|
|
2920
3396
|
const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
|
|
2921
3397
|
const resolveSubpackageOutputSourceEntries = (outputFile) => {
|
|
@@ -2924,6 +3400,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2924
3400
|
if (matchedRoots.length !== 1) return;
|
|
2925
3401
|
const root = matchedRoots[0];
|
|
2926
3402
|
if (!root) return;
|
|
3403
|
+
const configuredSourceRoots = cssSourceRootsByPackageRoot.get(root);
|
|
3404
|
+
if (configuredSourceRoots?.size === 1) return [{
|
|
3405
|
+
base: [...configuredSourceRoots][0],
|
|
3406
|
+
negated: false,
|
|
3407
|
+
pattern: `${root}/**/*`
|
|
3408
|
+
}];
|
|
2927
3409
|
return options.sourceRoot ? [{
|
|
2928
3410
|
base: options.sourceRoot,
|
|
2929
3411
|
negated: false,
|
|
@@ -2975,7 +3457,7 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2975
3457
|
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2976
3458
|
}) ?? /* @__PURE__ */ new Map();
|
|
2977
3459
|
};
|
|
2978
|
-
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
3460
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
2979
3461
|
return {
|
|
2980
3462
|
createScopedSourceCandidateGetter,
|
|
2981
3463
|
createScopedSourceCandidateSourceGetter,
|
|
@@ -2984,6 +3466,111 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2984
3466
|
};
|
|
2985
3467
|
}
|
|
2986
3468
|
//#endregion
|
|
3469
|
+
//#region src/bundlers/vite/generate-bundle/source-candidate-source.ts
|
|
3470
|
+
function normalizeSourceCandidatePathKey(file) {
|
|
3471
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve(file));
|
|
3472
|
+
}
|
|
3473
|
+
function resolveCurrentSourceCandidateSource(options) {
|
|
3474
|
+
const { file, getSourceCandidateSource, getSourceCandidateSources, outDir, rootDir, sourceRoot } = options;
|
|
3475
|
+
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
3476
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(cleanedFile);
|
|
3477
|
+
const absoluteFile = node_path.default.isAbsolute(cleanedFile) ? cleanedFile : node_path.default.resolve(rootDir, cleanedFile);
|
|
3478
|
+
const relativeFromOutDir = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.relative(outDir, absoluteFile));
|
|
3479
|
+
const sourceCandidates = [
|
|
3480
|
+
sourceRoot ? node_path.default.resolve(sourceRoot, file) : void 0,
|
|
3481
|
+
node_path.default.resolve(rootDir, file),
|
|
3482
|
+
node_path.default.resolve(node_path.default.dirname(outDir), file),
|
|
3483
|
+
node_path.default.resolve(outDir, file),
|
|
3484
|
+
!node_path.default.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? node_path.default.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3485
|
+
!node_path.default.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? node_path.default.resolve(node_path.default.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3486
|
+
file
|
|
3487
|
+
];
|
|
3488
|
+
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3489
|
+
if (source || !candidate) return source;
|
|
3490
|
+
return getSourceCandidateSource?.(candidate);
|
|
3491
|
+
}, void 0);
|
|
3492
|
+
if (explicitSource) return explicitSource;
|
|
3493
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3494
|
+
absolute: node_path.default.isAbsolute(candidate),
|
|
3495
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
3496
|
+
}));
|
|
3497
|
+
let bestSource;
|
|
3498
|
+
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3499
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3500
|
+
let score = 0;
|
|
3501
|
+
for (const candidate of normalizedSourceCandidates) if (normalizedSourceFile === candidate.key) {
|
|
3502
|
+
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3503
|
+
continue;
|
|
3504
|
+
}
|
|
3505
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3506
|
+
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3507
|
+
score,
|
|
3508
|
+
source
|
|
3509
|
+
};
|
|
3510
|
+
}
|
|
3511
|
+
return bestSource?.source;
|
|
3512
|
+
}
|
|
3513
|
+
//#endregion
|
|
3514
|
+
//#region src/bundlers/vite/generate-bundle/tailwind-v4-css-source.ts
|
|
3515
|
+
function collectTailwindV4SourceFingerprint(source) {
|
|
3516
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3517
|
+
const add = (prefix, value) => {
|
|
3518
|
+
tokens.add(`${prefix}:${value.trim()}`);
|
|
3519
|
+
};
|
|
3520
|
+
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3521
|
+
const configRequest = match[2];
|
|
3522
|
+
add("config", node_path.default.basename(configRequest));
|
|
3523
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3524
|
+
}
|
|
3525
|
+
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3526
|
+
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3527
|
+
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3528
|
+
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3529
|
+
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3530
|
+
return tokens;
|
|
3531
|
+
}
|
|
3532
|
+
function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
|
|
3533
|
+
if (!rawSource) return 0;
|
|
3534
|
+
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3535
|
+
if (rawTokens.size === 0) return 0;
|
|
3536
|
+
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3537
|
+
let score = 0;
|
|
3538
|
+
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3539
|
+
return score;
|
|
3540
|
+
}
|
|
3541
|
+
function resolveSubpackageRootForFile(file, subpackageRoots) {
|
|
3542
|
+
if (!file || !subpackageRoots) return;
|
|
3543
|
+
return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3544
|
+
}
|
|
3545
|
+
function isSameSubpackageScope(outputFile, sourceFile, subpackageRoots) {
|
|
3546
|
+
return resolveSubpackageRootForFile(outputFile, subpackageRoots) === resolveSubpackageRootForFile(sourceFile, subpackageRoots);
|
|
3547
|
+
}
|
|
3548
|
+
function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSource, subpackageRoots) {
|
|
3549
|
+
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3550
|
+
if (generationSources.length <= 1) return generationSources[0];
|
|
3551
|
+
const selectByRawSourceFingerprint = (candidates) => {
|
|
3552
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3553
|
+
entry,
|
|
3554
|
+
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3555
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3556
|
+
const bestScore = scoredSources[0]?.score;
|
|
3557
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3558
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3559
|
+
};
|
|
3560
|
+
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3561
|
+
if (rawSourceMatched) return rawSourceMatched;
|
|
3562
|
+
const scopedSources = subpackageRoots ? generationSources.filter((entry) => {
|
|
3563
|
+
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, subpackageRoots);
|
|
3564
|
+
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, subpackageRoots);
|
|
3565
|
+
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3566
|
+
return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3567
|
+
}) : generationSources;
|
|
3568
|
+
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3569
|
+
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3570
|
+
if (candidates.length === 1) return candidates[0];
|
|
3571
|
+
return selectByRawSourceFingerprint(candidates);
|
|
3572
|
+
}
|
|
3573
|
+
//#endregion
|
|
2987
3574
|
//#region src/bundlers/vite/generate-bundle/timing.ts
|
|
2988
3575
|
function createBundleTaskTimer(recordTimingDetail) {
|
|
2989
3576
|
return async (name, task) => {
|
|
@@ -2996,9 +3583,116 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
2996
3583
|
};
|
|
2997
3584
|
}
|
|
2998
3585
|
//#endregion
|
|
3586
|
+
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
3587
|
+
function toArray(value) {
|
|
3588
|
+
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
3589
|
+
}
|
|
3590
|
+
function normalizeSourceId(id) {
|
|
3591
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
3592
|
+
return node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : void 0;
|
|
3593
|
+
}
|
|
3594
|
+
function collectChunkModuleIds$1(chunk) {
|
|
3595
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3596
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
3597
|
+
const normalized = normalizeSourceId(id);
|
|
3598
|
+
if (normalized) ids.add(normalized);
|
|
3599
|
+
}
|
|
3600
|
+
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
3601
|
+
const normalized = normalizeSourceId(id);
|
|
3602
|
+
if (normalized) ids.add(normalized);
|
|
3603
|
+
}
|
|
3604
|
+
return ids;
|
|
3605
|
+
}
|
|
3606
|
+
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
3607
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3608
|
+
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
3609
|
+
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
3610
|
+
for (const candidate of candidates) {
|
|
3611
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
3612
|
+
const cleanCandidate = (0, _weapp_tailwindcss_shared.cleanUrl)(candidate);
|
|
3613
|
+
const resolved = node_path.default.isAbsolute(cleanCandidate) ? node_path.default.resolve(cleanCandidate) : node_path.default.resolve(rootDir, cleanCandidate);
|
|
3614
|
+
ids.add(resolved);
|
|
3615
|
+
}
|
|
3616
|
+
return ids;
|
|
3617
|
+
}
|
|
3618
|
+
function isStringRuleMatched(rule, id, rootDir) {
|
|
3619
|
+
const normalizedId = require_source_candidate_scan_signature.slash(id);
|
|
3620
|
+
const normalizedRule = require_source_candidate_scan_signature.slash(rule);
|
|
3621
|
+
if (node_path.default.isAbsolute(rule)) return micromatch.default.isMatch(normalizedId, normalizedRule);
|
|
3622
|
+
const relative = require_source_candidate_scan_signature.slash(node_path.default.relative(rootDir, id));
|
|
3623
|
+
return relative.length > 0 && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, normalizedRule);
|
|
3624
|
+
}
|
|
3625
|
+
function isRuleMatched(rule, id, rootDir) {
|
|
3626
|
+
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
3627
|
+
if (rule instanceof RegExp) {
|
|
3628
|
+
rule.lastIndex = 0;
|
|
3629
|
+
return rule.test(require_source_candidate_scan_signature.slash(id));
|
|
3630
|
+
}
|
|
3631
|
+
return rule(id) === true;
|
|
3632
|
+
}
|
|
3633
|
+
function createTransformMatcher(rules, rootDir) {
|
|
3634
|
+
const normalizedRules = toArray(rules);
|
|
3635
|
+
if (normalizedRules.length === 0) return;
|
|
3636
|
+
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
3637
|
+
}
|
|
3638
|
+
function shouldSkipSourceIds(sourceIds, filter) {
|
|
3639
|
+
if (sourceIds.size === 0) return false;
|
|
3640
|
+
if (filter.exclude) {
|
|
3641
|
+
let excluded = true;
|
|
3642
|
+
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
3643
|
+
excluded = false;
|
|
3644
|
+
break;
|
|
3645
|
+
}
|
|
3646
|
+
if (excluded) return true;
|
|
3647
|
+
}
|
|
3648
|
+
if (filter.include) {
|
|
3649
|
+
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
3650
|
+
return true;
|
|
3651
|
+
}
|
|
3652
|
+
return false;
|
|
3653
|
+
}
|
|
3654
|
+
function createTransformFilter(options, rootDir) {
|
|
3655
|
+
const include = createTransformMatcher(options?.include, rootDir);
|
|
3656
|
+
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
3657
|
+
if (!include && !exclude) return;
|
|
3658
|
+
return {
|
|
3659
|
+
include,
|
|
3660
|
+
exclude
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
3664
|
+
if (!filter) return false;
|
|
3665
|
+
return shouldSkipSourceIds(collectChunkModuleIds$1(chunk), filter);
|
|
3666
|
+
}
|
|
3667
|
+
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
3668
|
+
if (!filter) return false;
|
|
3669
|
+
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
3670
|
+
}
|
|
3671
|
+
function createRuleSignature(rules) {
|
|
3672
|
+
return toArray(rules).map((rule) => {
|
|
3673
|
+
if (typeof rule === "string") return `s:${rule}`;
|
|
3674
|
+
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
3675
|
+
return "f";
|
|
3676
|
+
}).join("|") || "none";
|
|
3677
|
+
}
|
|
3678
|
+
function createTransformFilterSignature(options) {
|
|
3679
|
+
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
3680
|
+
}
|
|
3681
|
+
//#endregion
|
|
2999
3682
|
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
3000
3683
|
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
3001
|
-
|
|
3684
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3685
|
+
if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3686
|
+
appType: opts.appType,
|
|
3687
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3688
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
3689
|
+
uniUtsPlatform
|
|
3690
|
+
}), {
|
|
3691
|
+
appType: opts.appType,
|
|
3692
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3693
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
3694
|
+
uniUtsPlatform
|
|
3695
|
+
})) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
|
|
3002
3696
|
return {
|
|
3003
3697
|
uniAppX: true,
|
|
3004
3698
|
uniAppXCssTarget: "uvue",
|
|
@@ -3017,7 +3711,7 @@ function resolveWeappViteSourceRoot(config, _appType) {
|
|
|
3017
3711
|
const root = typeof viteConfig?.root === "string" && viteConfig.root.length > 0 ? node_path.default.resolve(viteConfig.root) : node_process.default.cwd();
|
|
3018
3712
|
const configuredSrcRoot = resolveSourceRootCandidate(root, viteConfig?.weapp?.srcRoot);
|
|
3019
3713
|
if (configuredSrcRoot) return configuredSrcRoot;
|
|
3020
|
-
const envSrcRoot = resolveSourceRootCandidate(root, node_process.default.env
|
|
3714
|
+
const envSrcRoot = resolveSourceRootCandidate(root, node_process.default.env["UNI_INPUT_DIR"]) ?? resolveSourceRootCandidate(root, node_process.default.env["UNI_INPUT_ROOT"]) ?? resolveSourceRootCandidate(root, node_process.default.env["UNI_APP_INPUT_DIR"]);
|
|
3021
3715
|
if (envSrcRoot) return envSrcRoot;
|
|
3022
3716
|
}
|
|
3023
3717
|
function stripFileExtension(file) {
|
|
@@ -3033,12 +3727,12 @@ function collectChunkModuleIds(chunk) {
|
|
|
3033
3727
|
return ids;
|
|
3034
3728
|
}
|
|
3035
3729
|
function resolveSourceRootFromChunk(root, fileName, chunk) {
|
|
3036
|
-
const outputBase = stripFileExtension(
|
|
3730
|
+
const outputBase = stripFileExtension(require_source_candidate_scan_signature.normalizeOutputPathKey(fileName));
|
|
3037
3731
|
if (!outputBase.includes("/")) return;
|
|
3038
3732
|
for (const id of collectChunkModuleIds(chunk)) {
|
|
3039
3733
|
if (!isUsefulModuleId(id)) continue;
|
|
3040
3734
|
const cleanId = id.replace(/[?#].*$/, "");
|
|
3041
|
-
const relativeModule =
|
|
3735
|
+
const relativeModule = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.relative(root, cleanId));
|
|
3042
3736
|
if (relativeModule.length === 0 || relativeModule === "." || relativeModule.startsWith("../") || node_path.default.isAbsolute(relativeModule)) continue;
|
|
3043
3737
|
const moduleBase = stripFileExtension(relativeModule);
|
|
3044
3738
|
if (!moduleBase.endsWith(outputBase)) continue;
|
|
@@ -3062,7 +3756,7 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3062
3756
|
//#endregion
|
|
3063
3757
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
3064
3758
|
function createGenerateBundleHook(context) {
|
|
3065
|
-
const state =
|
|
3759
|
+
const state = require_source_candidate_scan_signature.createBundleBuildState();
|
|
3066
3760
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
3067
3761
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
3068
3762
|
let currentOutDir;
|
|
@@ -3070,7 +3764,7 @@ function createGenerateBundleHook(context) {
|
|
|
3070
3764
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
3071
3765
|
getAppType: () => context.opts.appType,
|
|
3072
3766
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
3073
|
-
getMajorVersion: () => context.runtimeState.
|
|
3767
|
+
getMajorVersion: () => context.runtimeState.tailwindRuntime.majorVersion,
|
|
3074
3768
|
getOutputRoot: () => currentOutDir,
|
|
3075
3769
|
getExtraOptions: (file) => ({
|
|
3076
3770
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -3087,15 +3781,27 @@ function createGenerateBundleHook(context) {
|
|
|
3087
3781
|
};
|
|
3088
3782
|
const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
|
|
3089
3783
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3090
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3091
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3092
3784
|
const resolvedConfig = getResolvedConfig();
|
|
3093
3785
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3786
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3787
|
+
appType: opts.appType,
|
|
3788
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3789
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3790
|
+
uniAppX,
|
|
3791
|
+
uniUtsPlatform
|
|
3792
|
+
}), {
|
|
3793
|
+
appType: opts.appType,
|
|
3794
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3795
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3796
|
+
uniAppX,
|
|
3797
|
+
uniUtsPlatform
|
|
3798
|
+
});
|
|
3799
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3094
3800
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp;
|
|
3095
3801
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3096
3802
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3097
3803
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3098
|
-
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget
|
|
3804
|
+
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3099
3805
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
3100
3806
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
3101
3807
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -3104,7 +3810,7 @@ function createGenerateBundleHook(context) {
|
|
|
3104
3810
|
await runtimeState.readyPromise;
|
|
3105
3811
|
debug("start");
|
|
3106
3812
|
onStart();
|
|
3107
|
-
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" &&
|
|
3813
|
+
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" && require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(output.source)).map(([file]) => file));
|
|
3108
3814
|
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
3109
3815
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
3110
3816
|
collectViteProcessedCssAssetResults(bundle, {
|
|
@@ -3128,18 +3834,42 @@ function createGenerateBundleHook(context) {
|
|
|
3128
3834
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
3129
3835
|
const bundleFiles = Object.keys(bundle);
|
|
3130
3836
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
3131
|
-
const
|
|
3837
|
+
const getConfiguredTailwindV4CssSourceEntries = () => collectConfiguredTailwindV4CssSourceEntries({
|
|
3838
|
+
...opts,
|
|
3839
|
+
tailwindcssRuntimeOptions: {
|
|
3840
|
+
...opts.tailwindcssRuntimeOptions ?? {},
|
|
3841
|
+
tailwindcss: {
|
|
3842
|
+
...require_v4_engine.resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions) ?? {},
|
|
3843
|
+
...require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options) ?? {}
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
}, opts.tailwindcssBasedir ?? rootDir);
|
|
3847
|
+
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
3848
|
+
const resolveMatchedCssSourceOutputFile = (sourceFile) => resolveOutputFileFromMatchedCssSource({
|
|
3849
|
+
bundleFiles,
|
|
3850
|
+
defaultStyleOutputExtension,
|
|
3851
|
+
isWebGeneratorTarget,
|
|
3852
|
+
opts,
|
|
3853
|
+
rootDir,
|
|
3854
|
+
shouldPreserveAppCssExtension: false,
|
|
3855
|
+
sourceFile,
|
|
3856
|
+
sourceRoot
|
|
3857
|
+
});
|
|
3858
|
+
const usedConfiguredTailwindV4CssSourceFiles = /* @__PURE__ */ new Set();
|
|
3132
3859
|
const buildCommand = resolvedConfig?.command === "build";
|
|
3133
3860
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
3134
3861
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
3135
3862
|
const useIncrementalMode = !buildCommand || hasPreviousBundleState || hasOmittedKnownFiles;
|
|
3136
3863
|
currentOutDir = outDir;
|
|
3137
3864
|
const snapshotStart = performance.now();
|
|
3138
|
-
const snapshot =
|
|
3865
|
+
const snapshot = require_source_candidate_scan_signature.buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
3866
|
+
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
3867
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file.replace(/[?#].*$/, ""))));
|
|
3139
3868
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
3869
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
3140
3870
|
getSourceCandidateSourcesForEntries,
|
|
3141
3871
|
getSourceCandidatesForEntries,
|
|
3142
|
-
projectRoot: opts.
|
|
3872
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
3143
3873
|
rootDir,
|
|
3144
3874
|
snapshot,
|
|
3145
3875
|
sourceRoot,
|
|
@@ -3148,8 +3878,8 @@ function createGenerateBundleHook(context) {
|
|
|
3148
3878
|
useIncrementalMode
|
|
3149
3879
|
});
|
|
3150
3880
|
recordTimingDetail("snapshot", snapshotStart);
|
|
3151
|
-
const useBundleRuntimeClassSet = !isWebGeneratorTarget
|
|
3152
|
-
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3881
|
+
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
3882
|
+
const forceRuntimeRefreshBySource = useIncrementalMode && require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3153
3883
|
const processFiles = snapshot.processFiles;
|
|
3154
3884
|
logBundleProcessPlan({
|
|
3155
3885
|
debug,
|
|
@@ -3161,11 +3891,11 @@ function createGenerateBundleHook(context) {
|
|
|
3161
3891
|
await waitForSourceCandidateSyncs?.();
|
|
3162
3892
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
3163
3893
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
3164
|
-
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => createScopedGeneratorRuntime({
|
|
3894
|
+
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => require_source_candidate_scan_signature.createScopedGeneratorRuntime({
|
|
3165
3895
|
cssHandlerOptions,
|
|
3166
3896
|
fallbackRuntime: runtime,
|
|
3167
3897
|
getSourceCandidatesForEntries,
|
|
3168
|
-
majorVersion: runtimeState.
|
|
3898
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3169
3899
|
outputFile,
|
|
3170
3900
|
rawSource,
|
|
3171
3901
|
shouldExcludeSubpackageSourceCandidates,
|
|
@@ -3174,98 +3904,84 @@ function createGenerateBundleHook(context) {
|
|
|
3174
3904
|
});
|
|
3175
3905
|
const jsEntries = snapshot.jsEntries;
|
|
3176
3906
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
3177
|
-
const
|
|
3178
|
-
const
|
|
3179
|
-
const
|
|
3180
|
-
const
|
|
3907
|
+
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
3908
|
+
const transformFilterSignature = createTransformFilterSignature(opts.transform);
|
|
3909
|
+
const moduleGraphOptions = require_source_candidate_scan_signature.createBundleModuleGraphOptions(outDir, jsEntries);
|
|
3910
|
+
const hasRuntimeAffectingChanges = require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3181
3911
|
const runtimeStart = performance.now();
|
|
3182
|
-
const
|
|
3183
|
-
const
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
3189
|
-
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
3912
|
+
const forceV4RuntimeRefreshBySource = forceRuntimeRefreshBySource;
|
|
3913
|
+
const runtime = isWebGeneratorTarget ? /* @__PURE__ */ new Set() : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv, {
|
|
3914
|
+
allowBaselineOnlyInitialSync: buildCommand,
|
|
3915
|
+
refreshBySource: forceV4RuntimeRefreshBySource
|
|
3916
|
+
}) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3917
|
+
const shouldFilterTailwindV4MiniProgramCandidates = require_generator.shouldUseMiniProgramCssBranch(generatorBranch);
|
|
3190
3918
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
3191
|
-
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ?
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
generatorRuntime = await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3196
|
-
transformRuntime = generatorRuntime;
|
|
3197
|
-
}
|
|
3919
|
+
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3920
|
+
const filteredSourceCandidates = shouldFilterTailwindV4MiniProgramCandidates ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceCandidates) : sourceCandidates;
|
|
3921
|
+
const transformRuntime = shouldFilterTailwindV4MiniProgramCandidates ? new Set(runtime) : new Set(filteredGeneratorCandidates);
|
|
3922
|
+
const generatorRuntime = filteredGeneratorCandidates;
|
|
3198
3923
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
if (mainCssEntry) {
|
|
3202
|
-
const validatedSourceRuntime = await require_hmr_timing.validateCandidatesByGenerator({
|
|
3203
|
-
opts,
|
|
3204
|
-
runtimeState,
|
|
3205
|
-
candidates: filteredGeneratorCandidates,
|
|
3206
|
-
rawSource: mainCssEntry.source,
|
|
3207
|
-
file: mainCssEntry.file,
|
|
3208
|
-
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3209
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3210
|
-
styleHandler,
|
|
3211
|
-
debug,
|
|
3212
|
-
skipGenerateFallback: true
|
|
3213
|
-
});
|
|
3214
|
-
if (validatedSourceRuntime.size > 0) transformRuntime = new Set([...transformRuntime, ...validatedSourceRuntime]);
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
if (runtimeState.twPatcher.majorVersion === 3 && useV3OxideSourceRuntime && generatorRuntime.size > 0 && (state.iteration === 0 || !hasRuntimeAffectingChanges) && cssEntries.length <= 1) {
|
|
3924
|
+
const hasMultipleConfiguredCssEntries = (opts.cssEntries?.length ?? 0) > 1;
|
|
3925
|
+
if (sourceCandidates.size > 0 && !hasMultipleConfiguredCssEntries) {
|
|
3218
3926
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3219
3927
|
if (mainCssEntry) {
|
|
3220
|
-
const
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3928
|
+
const mainCssRawSource = typeof mainCssEntry.output.source === "string" ? mainCssEntry.output.source : node_buffer.Buffer.from(mainCssEntry.output.source).toString();
|
|
3929
|
+
if (!require_v4_engine.hasTailwindApplyDirective(mainCssRawSource)) {
|
|
3930
|
+
const generatedCssSources = /* @__PURE__ */ new Set();
|
|
3931
|
+
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) if (typeof record === "string") generatedCssSources.add(record);
|
|
3932
|
+
else if (typeof record?.css === "string") generatedCssSources.add(record.css);
|
|
3933
|
+
const validatedSourceRuntime = await require_hmr_timing.validateCandidatesByGenerator({
|
|
3934
|
+
opts,
|
|
3935
|
+
runtimeState,
|
|
3936
|
+
candidates: filteredSourceCandidates,
|
|
3937
|
+
rawSource: mainCssRawSource,
|
|
3938
|
+
generatedCssSources,
|
|
3939
|
+
file: mainCssEntry.file,
|
|
3940
|
+
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3941
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3942
|
+
styleHandler,
|
|
3943
|
+
debug,
|
|
3944
|
+
skipGenerateFallback: false
|
|
3945
|
+
});
|
|
3946
|
+
if (validatedSourceRuntime.size > 0) for (const candidate of validatedSourceRuntime) transformRuntime.add(candidate);
|
|
3234
3947
|
}
|
|
3235
3948
|
}
|
|
3236
3949
|
}
|
|
3237
|
-
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
3950
|
+
const generatorCandidateSignature = require_source_candidate_scan_signature.createCandidateSignature(generatorRuntime);
|
|
3238
3951
|
const generatorCandidatesChanged = state.generatorCandidateSignature !== generatorCandidateSignature;
|
|
3239
3952
|
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
3240
3953
|
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
3241
3954
|
const runtimeLinkedCssFiles = new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3955
|
+
rememberRuntimeLinkedCssSources({
|
|
3956
|
+
bundleFiles,
|
|
3957
|
+
debug,
|
|
3958
|
+
defaultStyleOutputExtension,
|
|
3959
|
+
getConfiguredTailwindV4CssSourceEntries,
|
|
3960
|
+
getSourceCandidateSource,
|
|
3961
|
+
getSourceCandidateSources,
|
|
3962
|
+
isWebGeneratorTarget,
|
|
3963
|
+
jsImportedCssFiles,
|
|
3964
|
+
opts,
|
|
3965
|
+
outDir,
|
|
3966
|
+
rememberCssSource,
|
|
3967
|
+
rootDir,
|
|
3968
|
+
runtimeLinkedCssFiles,
|
|
3969
|
+
shouldPreserveAppCssExtension,
|
|
3970
|
+
snapshot,
|
|
3971
|
+
sourceRoot
|
|
3972
|
+
});
|
|
3257
3973
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
3258
3974
|
const dynamicRetryCandidates = new Set([
|
|
3259
3975
|
...sourceCandidates,
|
|
3260
3976
|
...generatorRuntime,
|
|
3261
3977
|
...transformRuntime
|
|
3262
3978
|
]);
|
|
3263
|
-
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
3264
3979
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
3265
3980
|
timingDetails["runtime"] = metrics.runtimeSet;
|
|
3266
3981
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
3267
3982
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
3268
|
-
const runtimeSignature =
|
|
3983
|
+
const runtimeSignature = require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime) ?? "runtime:missing";
|
|
3984
|
+
const transformRuntimeSignature = require_source_candidate_scan_signature.createCandidateSignature(transformRuntime);
|
|
3269
3985
|
const shouldProcessTailwindGeneration = !useIncrementalMode || hasRuntimeAffectingChanges || generatorCandidatesChanged || snapshot.processFiles.css.size > 0;
|
|
3270
3986
|
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
3271
3987
|
jsEntries,
|
|
@@ -3273,7 +3989,7 @@ function createGenerateBundleHook(context) {
|
|
|
3273
3989
|
debug
|
|
3274
3990
|
});
|
|
3275
3991
|
const createHandlerOptions = createJsHandlerOptionsFactory({
|
|
3276
|
-
getMajorVersion: () => runtimeState.
|
|
3992
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
3277
3993
|
moduleGraph: moduleGraphOptions
|
|
3278
3994
|
});
|
|
3279
3995
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
@@ -3295,69 +4011,86 @@ function createGenerateBundleHook(context) {
|
|
|
3295
4011
|
debug("html skip web target: %s", file);
|
|
3296
4012
|
continue;
|
|
3297
4013
|
}
|
|
4014
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4015
|
+
metrics.html.transformed++;
|
|
4016
|
+
debug("html skip transform (filtered): %s", file);
|
|
4017
|
+
continue;
|
|
4018
|
+
}
|
|
3298
4019
|
if (!processFiles.html.has(file)) continue;
|
|
3299
|
-
|
|
3300
|
-
const cacheKey = file;
|
|
3301
|
-
const hashKey = `${file}:html:${runtimeSignature}`;
|
|
3302
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3303
|
-
tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
|
|
4020
|
+
processHtmlBundleEntry({
|
|
3304
4021
|
cache,
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3329
|
-
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3330
|
-
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3331
|
-
}
|
|
3332
|
-
metrics.html.elapsed += measureElapsed(start);
|
|
3333
|
-
metrics.html.transformed++;
|
|
3334
|
-
onUpdate(file, rawSource, transformed);
|
|
3335
|
-
debug("html handle: %s", file);
|
|
3336
|
-
return { result: transformed };
|
|
3337
|
-
}
|
|
3338
|
-
})));
|
|
4022
|
+
context,
|
|
4023
|
+
debug,
|
|
4024
|
+
dynamicRetryCandidates,
|
|
4025
|
+
file,
|
|
4026
|
+
metrics,
|
|
4027
|
+
onUpdate,
|
|
4028
|
+
originalEntrySource,
|
|
4029
|
+
originalSource,
|
|
4030
|
+
rememberProcessCacheKey,
|
|
4031
|
+
resolveCurrentSourceCandidateSource: (file) => resolveCurrentSourceCandidateSource({
|
|
4032
|
+
file,
|
|
4033
|
+
getSourceCandidateSource,
|
|
4034
|
+
getSourceCandidateSources,
|
|
4035
|
+
outDir,
|
|
4036
|
+
rootDir,
|
|
4037
|
+
sourceRoot
|
|
4038
|
+
}),
|
|
4039
|
+
tasks,
|
|
4040
|
+
templateHandler,
|
|
4041
|
+
timeTask,
|
|
4042
|
+
transformRuntime,
|
|
4043
|
+
transformRuntimeSignature
|
|
4044
|
+
});
|
|
3339
4045
|
continue;
|
|
3340
4046
|
}
|
|
3341
4047
|
if (type === "css" && originalSource.type === "asset") {
|
|
3342
4048
|
metrics.css.total++;
|
|
3343
4049
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3344
4050
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3345
|
-
|
|
4051
|
+
let outputFile = resolveCssBundleOutputFile({
|
|
4052
|
+
bundleFiles,
|
|
4053
|
+
defaultStyleOutputExtension,
|
|
4054
|
+
file,
|
|
4055
|
+
isWebGeneratorTarget,
|
|
4056
|
+
opts,
|
|
4057
|
+
shouldPreserveAppCssExtension
|
|
4058
|
+
});
|
|
4059
|
+
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
4060
|
+
assetSourceFile,
|
|
4061
|
+
file,
|
|
4062
|
+
originalFileNames: originalSource.originalFileNames,
|
|
4063
|
+
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4064
|
+
});
|
|
3346
4065
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3347
|
-
if (outputFile
|
|
4066
|
+
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource)) {
|
|
3348
4067
|
delete bundle[file];
|
|
3349
4068
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
3350
4069
|
continue;
|
|
3351
4070
|
}
|
|
4071
|
+
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
4072
|
+
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3352
4073
|
const applyCssResult = (source) => {
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
4074
|
+
applyCssResultToBundle({
|
|
4075
|
+
appType: opts.appType,
|
|
4076
|
+
assetSourceFile,
|
|
4077
|
+
bundle,
|
|
4078
|
+
emitOrReplayCssAsset,
|
|
4079
|
+
file,
|
|
4080
|
+
originalSource,
|
|
4081
|
+
outputFile,
|
|
4082
|
+
source,
|
|
4083
|
+
viteProcessedCssAsset
|
|
4084
|
+
});
|
|
3360
4085
|
};
|
|
4086
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4087
|
+
applyCssResult(rawSource);
|
|
4088
|
+
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4089
|
+
onUpdate(outputFile, rawSource, rawSource);
|
|
4090
|
+
metrics.css.transformed++;
|
|
4091
|
+
debug("css skip transform (filtered): %s", outputFile);
|
|
4092
|
+
continue;
|
|
4093
|
+
}
|
|
3361
4094
|
if (isWebGeneratorTarget && !shouldGenerateWebCssByGenerator) {
|
|
3362
4095
|
applyCssResult(rawSource);
|
|
3363
4096
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -3365,31 +4098,72 @@ function createGenerateBundleHook(context) {
|
|
|
3365
4098
|
debug("css skip web target: %s", outputFile);
|
|
3366
4099
|
continue;
|
|
3367
4100
|
}
|
|
3368
|
-
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
3369
|
-
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3370
4101
|
const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
|
|
3371
4102
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
3372
4103
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
3373
|
-
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) =>
|
|
3374
|
-
|
|
4104
|
+
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => {
|
|
4105
|
+
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4106
|
+
}));
|
|
4107
|
+
let hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file));
|
|
3375
4108
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
3376
4109
|
if (inferredSfcStyleSource) {
|
|
3377
4110
|
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
3378
4111
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
3379
4112
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
3380
4113
|
}
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
4114
|
+
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4115
|
+
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile, currentSubpackageRoots))) {
|
|
4116
|
+
rememberedCssSources = [];
|
|
4117
|
+
hasUsableRememberedTailwindSource = false;
|
|
4118
|
+
}
|
|
4119
|
+
if (!hasUsableRememberedTailwindSource) {
|
|
4120
|
+
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4121
|
+
const inferredOriginalSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug) ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug));
|
|
4122
|
+
if (inferredOriginalSourceStyle) {
|
|
4123
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4124
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4125
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4126
|
+
rememberedCssSources = [{
|
|
4127
|
+
...inferredOriginalSourceStyle,
|
|
4128
|
+
outputFile
|
|
4129
|
+
}];
|
|
4130
|
+
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
4131
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file)));
|
|
4132
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, currentSubpackageRoots);
|
|
4133
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults)) {
|
|
4134
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
4135
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4136
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4137
|
+
usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(configuredGenerationSource.file));
|
|
4138
|
+
rememberedCssSources = [{
|
|
4139
|
+
outputFile,
|
|
4140
|
+
rawSource: configuredGenerationSource.source,
|
|
4141
|
+
sourceFile: configuredGenerationSource.file
|
|
4142
|
+
}];
|
|
4143
|
+
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4148
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")))) {
|
|
4149
|
+
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
4150
|
+
if (matchedOutputFile && require_source_candidate_scan_signature.normalizeOutputPathKey(matchedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile)) {
|
|
4151
|
+
outputFile = matchedOutputFile;
|
|
4152
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4153
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4154
|
+
rememberedCssSource = {
|
|
4155
|
+
...rememberedCssSource,
|
|
4156
|
+
outputFile
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
3384
4159
|
}
|
|
3385
|
-
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3386
4160
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
3387
|
-
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (
|
|
4161
|
+
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3388
4162
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
3389
4163
|
const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
3390
|
-
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null &&
|
|
4164
|
+
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && require_v4_engine.hasTailwindApplyDirective(generatorRawSource);
|
|
3391
4165
|
const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
|
|
3392
|
-
const hasCurrentTailwindGenerationDirective =
|
|
4166
|
+
const hasCurrentTailwindGenerationDirective = require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(rawSource);
|
|
3393
4167
|
if (shouldKeepImportedCssShell && !hasCurrentTailwindGenerationDirective) {
|
|
3394
4168
|
applyCssResult(rawSource);
|
|
3395
4169
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -3398,37 +4172,48 @@ function createGenerateBundleHook(context) {
|
|
|
3398
4172
|
debug("css preserve imported shell asset: %s", outputFile);
|
|
3399
4173
|
continue;
|
|
3400
4174
|
}
|
|
3401
|
-
const hasRememberedApplyDirective = rememberedCssSource != null &&
|
|
4175
|
+
const hasRememberedApplyDirective = rememberedCssSource != null && require_v4_engine.hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
3402
4176
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
3403
|
-
const
|
|
3404
|
-
const
|
|
4177
|
+
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
4178
|
+
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
4179
|
+
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
3405
4180
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
3406
|
-
|
|
4181
|
+
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(require_source_candidate_scan_signature.normalizeOutputPathKey(generatorSourceFile.replace(/[?#].*$/, "")))) usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(generatorSourceFile));
|
|
3407
4182
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
3408
4183
|
...getCssHandlerOptions(generatorSourceFile),
|
|
3409
4184
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
3410
4185
|
} : getCssHandlerOptions(file);
|
|
3411
|
-
const
|
|
3412
|
-
|
|
4186
|
+
const generatorCssHandlerOptions = {
|
|
4187
|
+
...cssHandlerOptions,
|
|
4188
|
+
sourceOptions: {
|
|
4189
|
+
...cssHandlerOptions.sourceOptions ?? {},
|
|
4190
|
+
sourceFile: generatorSourceFile,
|
|
4191
|
+
cssEntries: opts.cssEntries
|
|
4192
|
+
}
|
|
4193
|
+
};
|
|
4194
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
4195
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, generatorCssHandlerOptions);
|
|
3413
4196
|
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3414
4197
|
const sourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
3415
|
-
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile,
|
|
4198
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, generatorCssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
3416
4199
|
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
3417
4200
|
opts,
|
|
3418
4201
|
tokenSources: sourceTraceTokenSources
|
|
3419
4202
|
});
|
|
3420
|
-
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile,
|
|
4203
|
+
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
3421
4204
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
3422
|
-
const cssRuntimeAffectingSignature = vitePipelineCssAsset ?
|
|
4205
|
+
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
3423
4206
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
3424
|
-
const cssShareScope = createCssTransformShareScopeKey(opts,
|
|
3425
|
-
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) ||
|
|
4207
|
+
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
4208
|
+
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3426
4209
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
3427
4210
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
3428
4211
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
3429
|
-
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) ||
|
|
3430
|
-
|
|
3431
|
-
|
|
4212
|
+
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource));
|
|
4213
|
+
const strippedViteProcessedCss = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
4214
|
+
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !require_v4_engine.hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4215
|
+
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4216
|
+
const nextCss = strippedViteProcessedCss;
|
|
3432
4217
|
applyCssResult(nextCss);
|
|
3433
4218
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
3434
4219
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
@@ -3440,16 +4225,16 @@ function createGenerateBundleHook(context) {
|
|
|
3440
4225
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
3441
4226
|
continue;
|
|
3442
4227
|
}
|
|
3443
|
-
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
3444
|
-
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3445
|
-
includeFallbackSignature:
|
|
3446
|
-
majorVersion: runtimeState.
|
|
4228
|
+
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? require_source_candidate_scan_signature.createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
4229
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await require_source_candidate_scan_signature.createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
4230
|
+
includeFallbackSignature: generatorCssHandlerOptions.isMainChunk,
|
|
4231
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
3447
4232
|
}) : trackedGeneratorCandidateSignature;
|
|
3448
4233
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
3449
4234
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3450
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.
|
|
3451
|
-
const cssCacheKey =
|
|
3452
|
-
const cssHashKey = `${
|
|
4235
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
4236
|
+
const cssCacheKey = outputFile;
|
|
4237
|
+
const cssHashKey = `${outputFile}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
3453
4238
|
const cssLinkedImpactSignature = runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) ? [...[...snapshot.runtimeAffectingChangedByType.html].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? ""), ...[...snapshot.runtimeAffectingChangedByType.js].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? "")].join(":") : "";
|
|
3454
4239
|
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
3455
4240
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
@@ -3495,24 +4280,30 @@ function createGenerateBundleHook(context) {
|
|
|
3495
4280
|
const runTransform = async () => {
|
|
3496
4281
|
const start = performance.now();
|
|
3497
4282
|
await runtimeState.readyPromise;
|
|
3498
|
-
const
|
|
4283
|
+
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
4284
|
+
const generated = hasTailwindGenerationSource(generatorRawSource) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) ? await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3499
4285
|
opts,
|
|
3500
4286
|
runtimeState,
|
|
3501
4287
|
runtime: scopedGeneratorRuntime,
|
|
3502
4288
|
rawSource: generatorRawSource,
|
|
3503
4289
|
file: generatorSourceFile,
|
|
3504
|
-
|
|
4290
|
+
outputFile,
|
|
4291
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3505
4292
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3506
4293
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4294
|
+
sourceCandidates: scopedGeneratorRuntime,
|
|
3507
4295
|
styleHandler,
|
|
3508
4296
|
debug,
|
|
3509
|
-
previousCss
|
|
3510
|
-
|
|
4297
|
+
previousCss,
|
|
4298
|
+
...vitePipelineCssAsset && !require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile) } : {},
|
|
4299
|
+
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
4300
|
+
}) : void 0;
|
|
3511
4301
|
if (generated) {
|
|
3512
4302
|
const tracedCss = annotateCss(generated.css);
|
|
3513
4303
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
3514
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4304
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, require_source_candidate_scan_signature.summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3515
4305
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4306
|
+
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
3516
4307
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
3517
4308
|
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
3518
4309
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
@@ -3524,7 +4315,7 @@ function createGenerateBundleHook(context) {
|
|
|
3524
4315
|
});
|
|
3525
4316
|
metrics.css.elapsed += measureElapsed(start);
|
|
3526
4317
|
metrics.css.transformed++;
|
|
3527
|
-
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.
|
|
4318
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, outputFile);
|
|
3528
4319
|
return tracedCss;
|
|
3529
4320
|
}
|
|
3530
4321
|
if (isWebGeneratorTarget) {
|
|
@@ -3535,7 +4326,7 @@ function createGenerateBundleHook(context) {
|
|
|
3535
4326
|
}
|
|
3536
4327
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
3537
4328
|
const tracedCss = annotateCss(css);
|
|
3538
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4329
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, require_source_candidate_scan_signature.summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3539
4330
|
metrics.css.elapsed += measureElapsed(start);
|
|
3540
4331
|
metrics.css.transformed++;
|
|
3541
4332
|
return tracedCss;
|
|
@@ -3574,8 +4365,12 @@ function createGenerateBundleHook(context) {
|
|
|
3574
4365
|
rememberProcessCacheKey,
|
|
3575
4366
|
runtimeSignature,
|
|
3576
4367
|
snapshot,
|
|
4368
|
+
transformFilterSignature,
|
|
4369
|
+
shouldSkipAstTransform: transformFilter ? (chunk) => shouldSkipViteJsChunkTransform(chunk, transformFilter) : void 0,
|
|
4370
|
+
slowJsAstWarnMs: envFlags.slowJsAstWarnMs,
|
|
3577
4371
|
timeTask,
|
|
3578
4372
|
transformRuntime,
|
|
4373
|
+
transformRuntimeSignature,
|
|
3579
4374
|
uniAppX,
|
|
3580
4375
|
useIncrementalMode
|
|
3581
4376
|
});
|
|
@@ -3586,10 +4381,10 @@ function createGenerateBundleHook(context) {
|
|
|
3586
4381
|
bundle,
|
|
3587
4382
|
bundleFiles,
|
|
3588
4383
|
cache,
|
|
4384
|
+
cssTaskFactories,
|
|
3589
4385
|
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
3590
4386
|
createScopedSourceCandidateGetter,
|
|
3591
4387
|
createScopedSourceCandidateSourceGetter,
|
|
3592
|
-
cssTaskFactories,
|
|
3593
4388
|
debug,
|
|
3594
4389
|
defaultStyleOutputExtension,
|
|
3595
4390
|
emitOrReplayCssAsset,
|
|
@@ -3620,7 +4415,6 @@ function createGenerateBundleHook(context) {
|
|
|
3620
4415
|
timeTask,
|
|
3621
4416
|
useIncrementalMode
|
|
3622
4417
|
});
|
|
3623
|
-
require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
3624
4418
|
await finalizeGenerateBundle({
|
|
3625
4419
|
activeProcessCacheKeys,
|
|
3626
4420
|
activeProcessHashKeys,
|
|
@@ -3645,6 +4439,8 @@ function createGenerateBundleHook(context) {
|
|
|
3645
4439
|
isNativeAppStyleTarget,
|
|
3646
4440
|
isViteProcessedCssAsset,
|
|
3647
4441
|
isWebGeneratorTarget,
|
|
4442
|
+
jsAfterCss: shouldFilterTailwindV4MiniProgramCandidates && cssTaskFactories.length > 0,
|
|
4443
|
+
jsTaskFactories,
|
|
3648
4444
|
lastCssResultByFile,
|
|
3649
4445
|
lastCssSourceHashByFile,
|
|
3650
4446
|
linkedByEntry,
|
|
@@ -3698,16 +4494,20 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
3698
4494
|
...resolveUniAppXNativeCssHandlerOptions(opts),
|
|
3699
4495
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
3700
4496
|
postcssOptions: { options: { from: file } },
|
|
3701
|
-
...majorVersion === void 0 ? {} : { majorVersion }
|
|
4497
|
+
...require_context.normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
|
|
3702
4498
|
};
|
|
3703
4499
|
}
|
|
3704
|
-
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
3705
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
4500
|
+
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
4501
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4502
|
+
appType: opts.appType,
|
|
4503
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4504
|
+
tailwindcssMajorVersion: majorVersion,
|
|
4505
|
+
uniAppX: opts.uniAppX
|
|
4506
|
+
});
|
|
4507
|
+
if (require_v4_engine.hasLocalCssImport(rawSource)) return false;
|
|
4508
|
+
if (require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
4509
|
+
if (require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
4510
|
+
return processed && require_v4_engine.hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
|
|
3711
4511
|
}
|
|
3712
4512
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
3713
4513
|
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
@@ -3724,9 +4524,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3724
4524
|
async handler(_options, bundle) {
|
|
3725
4525
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
3726
4526
|
const resolvedConfig = getResolvedConfig();
|
|
3727
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3728
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3729
4527
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
4528
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4529
|
+
appType: opts.appType,
|
|
4530
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4531
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4532
|
+
uniAppX: opts.uniAppX,
|
|
4533
|
+
uniUtsPlatform
|
|
4534
|
+
}), {
|
|
4535
|
+
appType: opts.appType,
|
|
4536
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4537
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4538
|
+
uniAppX: opts.uniAppX,
|
|
4539
|
+
uniUtsPlatform
|
|
4540
|
+
});
|
|
4541
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3730
4542
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3731
4543
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3732
4544
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
@@ -3766,13 +4578,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3766
4578
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3767
4579
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
3768
4580
|
const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
|
|
3769
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
3770
|
-
const generated = await
|
|
4581
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
|
|
4582
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3771
4583
|
opts,
|
|
3772
4584
|
runtimeState,
|
|
3773
4585
|
runtime: harmonyRuntime,
|
|
3774
4586
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3775
4587
|
file: "uni-app-x-harmony-apply.css",
|
|
4588
|
+
outputFile: "uni-app-x-harmony-apply.css",
|
|
3776
4589
|
cssHandlerOptions: harmonyCssHandlerOptions,
|
|
3777
4590
|
cssUserHandlerOptions: {
|
|
3778
4591
|
...harmonyCssHandlerOptions,
|
|
@@ -3790,33 +4603,41 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3790
4603
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
|
|
3791
4604
|
};
|
|
3792
4605
|
const isCssOutputAssetEntry = (entry) => {
|
|
3793
|
-
const [, output] = entry;
|
|
3794
|
-
|
|
4606
|
+
const [bundleFile, output] = entry;
|
|
4607
|
+
const fileName = output.fileName || bundleFile;
|
|
4608
|
+
return output.type === "asset" && opts.cssMatcher(fileName) && !opts.htmlMatcher(fileName) && !require_source_candidate_scan_signature.isHTMLRequest(fileName) && !isCssAssetProcessed(output, fileName);
|
|
3795
4609
|
};
|
|
3796
4610
|
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
3797
4611
|
if (entries.length === 0) {
|
|
3798
4612
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
3799
4613
|
collectViteProcessedCssAssets();
|
|
3800
4614
|
injectViteProcessedCssIntoMainCss();
|
|
4615
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4616
|
+
appType: opts.appType,
|
|
4617
|
+
cssMatcher: opts.cssMatcher,
|
|
4618
|
+
debug,
|
|
4619
|
+
onUpdate: opts.onUpdate,
|
|
4620
|
+
recordCssAssetResult
|
|
4621
|
+
});
|
|
3801
4622
|
return;
|
|
3802
4623
|
}
|
|
3803
4624
|
await runtimeState.readyPromise;
|
|
3804
4625
|
await waitForSourceCandidateSyncs?.();
|
|
3805
4626
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
3806
4627
|
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
3807
|
-
const generatorRuntime =
|
|
4628
|
+
const generatorRuntime = require_generator.shouldUseMiniProgramCssBranch(generatorBranch) ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3808
4629
|
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
3809
4630
|
const file = output.fileName || bundleFile;
|
|
3810
4631
|
const rawSource = output.source.toString();
|
|
3811
4632
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
3812
|
-
const nextCss = annotateCss(
|
|
4633
|
+
const nextCss = annotateCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource));
|
|
3813
4634
|
output.source = nextCss;
|
|
3814
4635
|
markCssAssetProcessed(output, file);
|
|
3815
4636
|
recordCssAssetResult?.(file, nextCss);
|
|
3816
4637
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
3817
4638
|
return;
|
|
3818
4639
|
}
|
|
3819
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
4640
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file);
|
|
3820
4641
|
const cssUserHandlerOptions = {
|
|
3821
4642
|
...cssHandlerOptions,
|
|
3822
4643
|
isMainChunk: false
|
|
@@ -3825,24 +4646,25 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3825
4646
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
3826
4647
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
3827
4648
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
3828
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.
|
|
4649
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile) : cssHandlerOptions;
|
|
3829
4650
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
3830
4651
|
...generatorCssHandlerOptions,
|
|
3831
4652
|
isMainChunk: false
|
|
3832
4653
|
} : cssUserHandlerOptions;
|
|
3833
|
-
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await
|
|
4654
|
+
const generated = shouldGenerateCssByGenerator(opts, runtimeState.tailwindRuntime.majorVersion, file, generatorRawSource, processed) ? await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3834
4655
|
opts,
|
|
3835
4656
|
runtimeState,
|
|
3836
4657
|
runtime: generatorRuntime,
|
|
3837
4658
|
rawSource: generatorRawSource,
|
|
3838
4659
|
file: generatorSourceFile,
|
|
4660
|
+
outputFile: file,
|
|
3839
4661
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3840
4662
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3841
4663
|
getSourceCandidatesForEntries,
|
|
3842
4664
|
styleHandler: opts.styleHandler,
|
|
3843
4665
|
debug
|
|
3844
4666
|
}) : void 0;
|
|
3845
|
-
const nextCss = annotateCss(generated?.css ?? (
|
|
4667
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
3846
4668
|
if (generated) {
|
|
3847
4669
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
3848
4670
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -3857,6 +4679,13 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3857
4679
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
3858
4680
|
collectViteProcessedCssAssets();
|
|
3859
4681
|
injectViteProcessedCssIntoMainCss();
|
|
4682
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4683
|
+
appType: opts.appType,
|
|
4684
|
+
cssMatcher: opts.cssMatcher,
|
|
4685
|
+
debug,
|
|
4686
|
+
onUpdate: opts.onUpdate,
|
|
4687
|
+
recordCssAssetResult
|
|
4688
|
+
});
|
|
3860
4689
|
}
|
|
3861
4690
|
}
|
|
3862
4691
|
};
|
|
@@ -3881,6 +4710,27 @@ const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
|
3881
4710
|
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3882
4711
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3883
4712
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
4713
|
+
function toMb$1(bytes) {
|
|
4714
|
+
return Math.round(bytes / 1024 / 1024);
|
|
4715
|
+
}
|
|
4716
|
+
function summarizeStringMapCache(map) {
|
|
4717
|
+
let bytes = 0;
|
|
4718
|
+
for (const value of map.values()) bytes += value.length;
|
|
4719
|
+
return {
|
|
4720
|
+
bytes,
|
|
4721
|
+
mb: toMb$1(bytes),
|
|
4722
|
+
size: map.size
|
|
4723
|
+
};
|
|
4724
|
+
}
|
|
4725
|
+
function summarizeRememberedCssSources(map) {
|
|
4726
|
+
let bytes = 0;
|
|
4727
|
+
for (const value of map.values()) bytes += value.rawSource.length;
|
|
4728
|
+
return {
|
|
4729
|
+
bytes,
|
|
4730
|
+
mb: toMb$1(bytes),
|
|
4731
|
+
size: map.size
|
|
4732
|
+
};
|
|
4733
|
+
}
|
|
3884
4734
|
function stripSourceHash(sourceFile) {
|
|
3885
4735
|
const hashIndex = sourceFile.indexOf("#");
|
|
3886
4736
|
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
@@ -3888,9 +4738,9 @@ function stripSourceHash(sourceFile) {
|
|
|
3888
4738
|
function normalizeCssSourceIdentity(sourceFile) {
|
|
3889
4739
|
const cleanSourceFile = stripSourceHash(sourceFile);
|
|
3890
4740
|
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
3891
|
-
const normalizedFile =
|
|
4741
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(filename);
|
|
3892
4742
|
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
3893
|
-
return
|
|
4743
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(require_source_candidate_scan_signature.stripRequestQuery(cleanSourceFile));
|
|
3894
4744
|
}
|
|
3895
4745
|
function hasSfcStyleBlocks(source) {
|
|
3896
4746
|
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
@@ -3919,7 +4769,7 @@ function extractSfcStyleSource(source, index) {
|
|
|
3919
4769
|
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
3920
4770
|
}
|
|
3921
4771
|
function normalizeKnownSfcSourceKey(file) {
|
|
3922
|
-
return
|
|
4772
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(file)));
|
|
3923
4773
|
}
|
|
3924
4774
|
function shouldCollectTransformedSourceCandidates(id) {
|
|
3925
4775
|
if (id.search(/[?#]/) < 0) return true;
|
|
@@ -3929,6 +4779,7 @@ function shouldCollectTransformedSourceCandidates(id) {
|
|
|
3929
4779
|
function createViteCssMemory(options) {
|
|
3930
4780
|
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
3931
4781
|
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
4782
|
+
const knownCssSources = /* @__PURE__ */ new Map();
|
|
3932
4783
|
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
3933
4784
|
const rememberKnownSfcSource = (id, code) => {
|
|
3934
4785
|
if (id.search(/[?#]/) >= 0) return;
|
|
@@ -3947,7 +4798,7 @@ function createViteCssMemory(options) {
|
|
|
3947
4798
|
return source;
|
|
3948
4799
|
};
|
|
3949
4800
|
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3950
|
-
const outputKey =
|
|
4801
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(entry.outputFile);
|
|
3951
4802
|
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
3952
4803
|
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3953
4804
|
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
@@ -3980,21 +4831,38 @@ function createViteCssMemory(options) {
|
|
|
3980
4831
|
return nextRemembered;
|
|
3981
4832
|
};
|
|
3982
4833
|
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
4834
|
+
touchMapEntry(knownCssSources, normalizeCssSourceIdentity(sourceFile), rawSource);
|
|
3983
4835
|
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
3984
4836
|
const relatedRememberedEntries = [...rememberedCssSources].filter(([, remembered]) => normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
3985
4837
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
3986
4838
|
};
|
|
3987
4839
|
const resolveCachedStyleSource = (sourceFile) => {
|
|
3988
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
4840
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(sourceFile));
|
|
3989
4841
|
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
3990
|
-
if (
|
|
4842
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
4843
|
+
};
|
|
4844
|
+
const resolveCurrentStyleSource = async (sourceFile) => {
|
|
4845
|
+
const cached = resolveCachedStyleSource(sourceFile);
|
|
4846
|
+
if (cached != null) return cached;
|
|
4847
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(sourceFile));
|
|
4848
|
+
const knownSource = knownCssSources.get(normalizeCssSourceIdentity(sourceFile));
|
|
4849
|
+
if (knownSource != null) return knownSource;
|
|
4850
|
+
const candidateSource = options.getSourceCandidateSource(file);
|
|
4851
|
+
if (candidateSource != null) return candidateSource;
|
|
4852
|
+
if (!require_source_candidate_scan_signature.isSourceStyleRequest(file)) return;
|
|
4853
|
+
try {
|
|
4854
|
+
return await (0, node_fs_promises.readFile)(file, "utf8");
|
|
4855
|
+
} catch (error) {
|
|
4856
|
+
options.debug("refresh remembered css source read failed: %s %O", file, error);
|
|
4857
|
+
return;
|
|
4858
|
+
}
|
|
3991
4859
|
};
|
|
3992
4860
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
3993
4861
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(sourceFile);
|
|
3994
|
-
const normalizedSourceFile =
|
|
3995
|
-
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) =>
|
|
4862
|
+
const normalizedSourceFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
4863
|
+
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(require_source_candidate_scan_signature.stripRequestQuery((0, _weapp_tailwindcss_shared.cleanUrl)(remembered.sourceFile))) === normalizedSourceFile);
|
|
3996
4864
|
if (matchedRememberedSources.length === 0) return;
|
|
3997
|
-
const source =
|
|
4865
|
+
const source = await resolveCurrentStyleSource(file);
|
|
3998
4866
|
if (source == null) {
|
|
3999
4867
|
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
4000
4868
|
return;
|
|
@@ -4007,13 +4875,13 @@ function createViteCssMemory(options) {
|
|
|
4007
4875
|
}
|
|
4008
4876
|
return;
|
|
4009
4877
|
}
|
|
4010
|
-
if (
|
|
4878
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
4011
4879
|
};
|
|
4012
4880
|
const refreshRememberedCssSource = async (remembered) => {
|
|
4013
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
4881
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(remembered.sourceFile));
|
|
4014
4882
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4015
4883
|
if (!rememberedKey || !node_path.default.isAbsolute(file)) return;
|
|
4016
|
-
const source =
|
|
4884
|
+
const source = await resolveCurrentStyleSource(file);
|
|
4017
4885
|
if (source == null) {
|
|
4018
4886
|
options.debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4019
4887
|
return;
|
|
@@ -4023,13 +4891,13 @@ function createViteCssMemory(options) {
|
|
|
4023
4891
|
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4024
4892
|
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
4025
4893
|
}
|
|
4026
|
-
if (
|
|
4894
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
4027
4895
|
};
|
|
4028
4896
|
const prune = (pruneOptions) => {
|
|
4029
|
-
const activeFiles = new Set([...pruneOptions.activeFiles].map(
|
|
4897
|
+
const activeFiles = new Set([...pruneOptions.activeFiles].map(require_source_candidate_scan_signature.normalizeOutputPathKey));
|
|
4030
4898
|
for (const [key, remembered] of rememberedCssSources) {
|
|
4031
|
-
const outputKey =
|
|
4032
|
-
const sourceKey =
|
|
4899
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.outputFile);
|
|
4900
|
+
const sourceKey = require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.sourceFile);
|
|
4033
4901
|
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
4034
4902
|
rememberedCssSources.delete(key);
|
|
4035
4903
|
rememberedCssSignatureByFile.delete(key);
|
|
@@ -4042,17 +4910,22 @@ function createViteCssMemory(options) {
|
|
|
4042
4910
|
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4043
4911
|
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4044
4912
|
});
|
|
4913
|
+
pruneMapToMaxSize(knownCssSources, VITE_REMEMBERED_CSS_CACHE_MAX);
|
|
4045
4914
|
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4046
4915
|
};
|
|
4047
4916
|
return {
|
|
4048
4917
|
getKnownSfcSource,
|
|
4049
|
-
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(
|
|
4050
|
-
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(
|
|
4918
|
+
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file)),
|
|
4919
|
+
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file)),
|
|
4051
4920
|
getRememberedCssSources: () => rememberedCssSources,
|
|
4052
4921
|
getStats: () => ({
|
|
4053
4922
|
rememberedCssSources: rememberedCssSources.size,
|
|
4923
|
+
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
4054
4924
|
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4055
|
-
|
|
4925
|
+
knownCssSources: knownCssSources.size,
|
|
4926
|
+
knownCssSourcesRaw: summarizeStringMapCache(knownCssSources),
|
|
4927
|
+
knownSfcSources: knownSfcSources.size,
|
|
4928
|
+
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
4056
4929
|
}),
|
|
4057
4930
|
rememberCssSource,
|
|
4058
4931
|
rememberKnownSfcSource,
|
|
@@ -4060,7 +4933,7 @@ function createViteCssMemory(options) {
|
|
|
4060
4933
|
refreshRememberedCssSourceByCurrentFile,
|
|
4061
4934
|
refreshRememberedCssSourceBySourceFile,
|
|
4062
4935
|
setRememberedCssSignature: (file, cssRuntimeSignature) => {
|
|
4063
|
-
rememberedCssSignatureByFile.set(
|
|
4936
|
+
rememberedCssSignatureByFile.set(require_source_candidate_scan_signature.normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
4064
4937
|
},
|
|
4065
4938
|
prune
|
|
4066
4939
|
};
|
|
@@ -4072,7 +4945,7 @@ function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
|
4072
4945
|
const seenModules = /* @__PURE__ */ new Set();
|
|
4073
4946
|
const collectModule = (mod) => {
|
|
4074
4947
|
if (mod == null || seenModules.has(mod)) return;
|
|
4075
|
-
if (!
|
|
4948
|
+
if (!require_source_candidate_scan_signature.isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
4076
4949
|
seenModules.add(mod);
|
|
4077
4950
|
ctx.server.moduleGraph.invalidateModule(mod);
|
|
4078
4951
|
modules.push(mod);
|
|
@@ -4102,7 +4975,7 @@ function includesHotModule(modules, target) {
|
|
|
4102
4975
|
}
|
|
4103
4976
|
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
4104
4977
|
return modules.some((mod) => {
|
|
4105
|
-
return !
|
|
4978
|
+
return !require_source_candidate_scan_signature.isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
4106
4979
|
});
|
|
4107
4980
|
}
|
|
4108
4981
|
function sendSupplementalCssHotUpdates(ctx, cssModules) {
|
|
@@ -4177,6 +5050,35 @@ function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
|
4177
5050
|
return removed;
|
|
4178
5051
|
}
|
|
4179
5052
|
//#endregion
|
|
5053
|
+
//#region src/bundlers/vite/plugin-cache.ts
|
|
5054
|
+
function isMissingInternalCssSource(file, packageDir) {
|
|
5055
|
+
return !(0, node_fs.existsSync)(file) && node_path.default.resolve(file).startsWith(`${packageDir}${node_path.default.sep}`);
|
|
5056
|
+
}
|
|
5057
|
+
function normalizeVitePersistentCacheKey(file) {
|
|
5058
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
5059
|
+
}
|
|
5060
|
+
function toMb(bytes) {
|
|
5061
|
+
return Math.round(bytes / 1024 / 1024);
|
|
5062
|
+
}
|
|
5063
|
+
function summarizeStringCache(map) {
|
|
5064
|
+
let bytes = 0;
|
|
5065
|
+
for (const value of map.values()) bytes += value.length;
|
|
5066
|
+
return {
|
|
5067
|
+
bytes,
|
|
5068
|
+
mb: toMb(bytes),
|
|
5069
|
+
size: map.size
|
|
5070
|
+
};
|
|
5071
|
+
}
|
|
5072
|
+
function summarizeViteProcessedCssResults(map) {
|
|
5073
|
+
let bytes = 0;
|
|
5074
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
5075
|
+
return {
|
|
5076
|
+
bytes,
|
|
5077
|
+
mb: toMb(bytes),
|
|
5078
|
+
size: map.size
|
|
5079
|
+
};
|
|
5080
|
+
}
|
|
5081
|
+
//#endregion
|
|
4180
5082
|
//#region src/bundlers/shared/css-imports.ts
|
|
4181
5083
|
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
4182
5084
|
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
@@ -4213,7 +5115,7 @@ function joinPosixPath(base, subpath) {
|
|
|
4213
5115
|
function isCssLikeImporter(importer) {
|
|
4214
5116
|
if (!importer) return false;
|
|
4215
5117
|
const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
|
|
4216
|
-
return
|
|
5118
|
+
return require_source_candidate_scan_signature.isSourceStyleRequest(importer) || require_source_candidate_scan_signature.isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
4217
5119
|
}
|
|
4218
5120
|
function stripTailwindConfigDirectives(code) {
|
|
4219
5121
|
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
@@ -4223,7 +5125,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4223
5125
|
const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
|
|
4224
5126
|
const resolveAppType = () => getAppType?.() ?? appType;
|
|
4225
5127
|
return [{
|
|
4226
|
-
name: `${
|
|
5128
|
+
name: `${require_context.vitePluginName}:rewrite-css-imports`,
|
|
4227
5129
|
enforce: "pre",
|
|
4228
5130
|
resolveId(id, importer) {
|
|
4229
5131
|
if (!options.shouldRewrite) return null;
|
|
@@ -4237,20 +5139,27 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4237
5139
|
return replacement;
|
|
4238
5140
|
},
|
|
4239
5141
|
async transform(code, id) {
|
|
4240
|
-
if (!
|
|
5142
|
+
if (!require_source_candidate_scan_signature.isCSSRequest(id)) return null;
|
|
4241
5143
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
4242
|
-
const normalizedCode =
|
|
5144
|
+
const normalizedCode = require_v4_engine.hasTailwindRootDirectives(code) || code.includes("@config") ? require_v4_engine.normalizeTailwindConfigDirectives(code, node_path.default.dirname(file)) : code;
|
|
4243
5145
|
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
4244
|
-
const hasTailwindRoot =
|
|
5146
|
+
const hasTailwindRoot = require_v4_engine.hasTailwindRootDirectives(normalizedCode);
|
|
4245
5147
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
4246
|
-
|
|
5148
|
+
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
5149
|
+
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
4247
5150
|
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
|
|
4248
5151
|
if (generatedCss !== void 0) return {
|
|
4249
5152
|
code: generatedCss,
|
|
4250
5153
|
map: null
|
|
4251
5154
|
};
|
|
4252
5155
|
}
|
|
4253
|
-
if (!options.shouldRewrite)
|
|
5156
|
+
if (!options.shouldRewrite) {
|
|
5157
|
+
if (normalizedCode !== code) return {
|
|
5158
|
+
code: normalizedCode,
|
|
5159
|
+
map: null
|
|
5160
|
+
};
|
|
5161
|
+
return null;
|
|
5162
|
+
}
|
|
4254
5163
|
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
4255
5164
|
join: joinPosixPath,
|
|
4256
5165
|
appType: resolveAppType(),
|
|
@@ -4266,16 +5175,16 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4266
5175
|
}];
|
|
4267
5176
|
}
|
|
4268
5177
|
function hasVitePipelineTailwindGenerationDirective(code) {
|
|
4269
|
-
return
|
|
5178
|
+
return require_v4_engine.hasTailwindRootDirectives(code) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
4270
5179
|
}
|
|
4271
5180
|
//#endregion
|
|
4272
5181
|
//#region src/bundlers/vite/runtime-class-set.ts
|
|
4273
5182
|
function createViteRuntimeClassSet(options) {
|
|
4274
|
-
const { opts,
|
|
5183
|
+
const { opts, initialTailwindRuntime, refreshTailwindcssRuntime, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
4275
5184
|
const runtimeState = {
|
|
4276
|
-
|
|
4277
|
-
readyPromise:
|
|
4278
|
-
|
|
5185
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
5186
|
+
readyPromise: require_context.createTailwindRuntimeReadyPromise(initialTailwindRuntime),
|
|
5187
|
+
refreshTailwindcssRuntime
|
|
4279
5188
|
};
|
|
4280
5189
|
const bundleRuntimeClassSetManager = require_hmr_timing.createBundleRuntimeClassSetManager({
|
|
4281
5190
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
@@ -4290,8 +5199,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
4290
5199
|
let runtimeRefreshSignature;
|
|
4291
5200
|
let runtimeRefreshOptionsKey;
|
|
4292
5201
|
function resolveRuntimeRefreshOptions() {
|
|
4293
|
-
const configPath =
|
|
4294
|
-
const signature =
|
|
5202
|
+
const configPath = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.config;
|
|
5203
|
+
const signature = require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
4295
5204
|
const optionsKey = JSON.stringify({
|
|
4296
5205
|
appType: opts.appType,
|
|
4297
5206
|
uniAppX: uniAppXEnabled,
|
|
@@ -4310,7 +5219,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4310
5219
|
}
|
|
4311
5220
|
async function refreshRuntimeState(force) {
|
|
4312
5221
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4313
|
-
const refreshed = await
|
|
5222
|
+
const refreshed = await require_context.refreshTailwindRuntimeState(runtimeState, {
|
|
4314
5223
|
force: force || invalidation.changed,
|
|
4315
5224
|
clearCache: force || invalidation.changed
|
|
4316
5225
|
});
|
|
@@ -4327,7 +5236,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4327
5236
|
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
4328
5237
|
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
4329
5238
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4330
|
-
runtimeSetPromise =
|
|
5239
|
+
runtimeSetPromise = require_context.collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4331
5240
|
force: forceRuntimeRefresh || invalidation.changed,
|
|
4332
5241
|
skipRefresh: forceRuntimeRefresh,
|
|
4333
5242
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4344,51 +5253,33 @@ function createViteRuntimeClassSet(options) {
|
|
|
4344
5253
|
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
|
|
4345
5254
|
const forceRuntimeRefresh = forceRefresh || node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
4346
5255
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4347
|
-
const
|
|
5256
|
+
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
4348
5257
|
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
4349
|
-
await refreshRuntimeState(
|
|
5258
|
+
await refreshRuntimeState(shouldRefreshRuntime);
|
|
4350
5259
|
await runtimeState.readyPromise;
|
|
4351
|
-
if (
|
|
5260
|
+
if (shouldRefreshRuntime) {
|
|
4352
5261
|
runtimeSet = void 0;
|
|
4353
5262
|
runtimeSetPromise = void 0;
|
|
4354
5263
|
await bundleRuntimeClassSetManager.reset();
|
|
4355
5264
|
await transformRuntimeClassSetManager.reset();
|
|
4356
5265
|
}
|
|
4357
|
-
if (
|
|
4358
|
-
const
|
|
5266
|
+
if (!forceRuntimeRefresh) try {
|
|
5267
|
+
const baseClassSet = options.baseClassSet ?? runtimeSet ?? await require_context.collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
5268
|
+
force: invalidation.changed,
|
|
5269
|
+
clearCache: invalidation.changed
|
|
5270
|
+
});
|
|
5271
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
|
|
5272
|
+
baseClassSet,
|
|
5273
|
+
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync
|
|
5274
|
+
});
|
|
4359
5275
|
runtimeSet = nextRuntimeSet;
|
|
4360
5276
|
return nextRuntimeSet;
|
|
4361
5277
|
} catch (error) {
|
|
4362
5278
|
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4363
5279
|
await bundleRuntimeClassSetManager.reset();
|
|
4364
5280
|
}
|
|
4365
|
-
if (runtimeState.twPatcher.majorVersion === 3 && !forceRuntimeRefresh) {
|
|
4366
|
-
if (options.transformOnly) try {
|
|
4367
|
-
return await transformRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
4368
|
-
} catch (error) {
|
|
4369
|
-
debug("incremental transform runtime set sync failed, fallback to full collect: %O", error);
|
|
4370
|
-
await transformRuntimeClassSetManager.reset();
|
|
4371
|
-
}
|
|
4372
|
-
try {
|
|
4373
|
-
let baseClassSet = options.baseClassSet;
|
|
4374
|
-
if (!baseClassSet && (!runtimeSet || shouldRefreshPatcher)) baseClassSet = await require_precheck.collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
4375
|
-
force: true,
|
|
4376
|
-
skipRefresh: shouldRefreshPatcher,
|
|
4377
|
-
clearCache: shouldRefreshPatcher
|
|
4378
|
-
});
|
|
4379
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot, {
|
|
4380
|
-
baseClassSet: baseClassSet ?? (options.allowBaselineOnlyInitialSync === true ? runtimeSet : void 0),
|
|
4381
|
-
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync === true && Boolean(runtimeSet)
|
|
4382
|
-
});
|
|
4383
|
-
runtimeSet = nextRuntimeSet;
|
|
4384
|
-
return nextRuntimeSet;
|
|
4385
|
-
} catch (error) {
|
|
4386
|
-
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4387
|
-
await bundleRuntimeClassSetManager.reset();
|
|
4388
|
-
}
|
|
4389
|
-
}
|
|
4390
5281
|
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
4391
|
-
const task =
|
|
5282
|
+
const task = require_context.collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4392
5283
|
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
4393
5284
|
skipRefresh: forceRuntimeRefresh,
|
|
4394
5285
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4441,22 +5332,22 @@ function replaceViteCssHmrModuleCss(code, css) {
|
|
|
4441
5332
|
return `${code.slice(0, extracted.start)}${encodeJsStringLiteral(css)}${code.slice(extracted.end)}`;
|
|
4442
5333
|
}
|
|
4443
5334
|
function isViteServeStyleRequest(id, command) {
|
|
4444
|
-
return command === "serve" &&
|
|
5335
|
+
return command === "serve" && require_source_candidate_scan_signature.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
4445
5336
|
}
|
|
4446
5337
|
function isViteServeCssRootRequest(id, command) {
|
|
4447
|
-
return command === "serve" &&
|
|
5338
|
+
return command === "serve" && require_source_candidate_scan_signature.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
4448
5339
|
}
|
|
4449
5340
|
function isViteCssHmrModule(code, id, command) {
|
|
4450
5341
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
|
|
4451
5342
|
}
|
|
4452
5343
|
function createViteServeCssGenerationPlugins(options) {
|
|
4453
5344
|
return [{
|
|
4454
|
-
name: `${
|
|
5345
|
+
name: `${require_context.vitePluginName}:generate:serve`,
|
|
4455
5346
|
apply: "serve",
|
|
4456
5347
|
enforce: "pre",
|
|
4457
5348
|
async transform(code, id) {
|
|
4458
5349
|
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
4459
|
-
if (!
|
|
5350
|
+
if (!require_v4_engine.hasTailwindRootDirectives(code)) return;
|
|
4460
5351
|
await options.onTailwindRootCss?.(id, code);
|
|
4461
5352
|
const generatedCss = await options.generateCss(id, code, this);
|
|
4462
5353
|
if (generatedCss === void 0 || generatedCss === code) return;
|
|
@@ -4466,7 +5357,7 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4466
5357
|
};
|
|
4467
5358
|
}
|
|
4468
5359
|
}, {
|
|
4469
|
-
name: `${
|
|
5360
|
+
name: `${require_context.vitePluginName}:generate:serve-hmr`,
|
|
4470
5361
|
apply: "serve",
|
|
4471
5362
|
enforce: "post",
|
|
4472
5363
|
async transform(code, id) {
|
|
@@ -4486,35 +5377,6 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4486
5377
|
}];
|
|
4487
5378
|
}
|
|
4488
5379
|
//#endregion
|
|
4489
|
-
//#region src/bundlers/vite/source-candidate-scan-signature.ts
|
|
4490
|
-
function normalizeSignaturePath(value) {
|
|
4491
|
-
return require_bundle_state.slash(node_path.default.resolve(value));
|
|
4492
|
-
}
|
|
4493
|
-
function serializeInlineCandidates(inlineCandidates) {
|
|
4494
|
-
return {
|
|
4495
|
-
excluded: [...inlineCandidates?.excluded ?? []].sort(),
|
|
4496
|
-
included: [...inlineCandidates?.included ?? []].sort()
|
|
4497
|
-
};
|
|
4498
|
-
}
|
|
4499
|
-
function serializeSourceEntries(entries) {
|
|
4500
|
-
return (entries ?? []).map((entry) => ({
|
|
4501
|
-
base: normalizeSignaturePath(entry.base),
|
|
4502
|
-
negated: entry.negated,
|
|
4503
|
-
pattern: entry.pattern
|
|
4504
|
-
})).sort((a, b) => `${a.base}\0${a.pattern}\0${a.negated}`.localeCompare(`${b.base}\0${b.pattern}\0${b.negated}`));
|
|
4505
|
-
}
|
|
4506
|
-
function createSourceCandidateScanSignature(input) {
|
|
4507
|
-
return JSON.stringify({
|
|
4508
|
-
inlineCandidates: serializeInlineCandidates(input.inlineCandidates),
|
|
4509
|
-
outDir: input.outDir ? normalizeSignaturePath(input.outDir) : void 0,
|
|
4510
|
-
roots: input.roots.map((root) => ({
|
|
4511
|
-
entries: serializeSourceEntries(root.entries),
|
|
4512
|
-
root: normalizeSignaturePath(root.root)
|
|
4513
|
-
})),
|
|
4514
|
-
scanAllSources: input.scanAllSources ?? false
|
|
4515
|
-
});
|
|
4516
|
-
}
|
|
4517
|
-
//#endregion
|
|
4518
5380
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
4519
5381
|
const PACKAGE_JSON_FILE = "package.json";
|
|
4520
5382
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -4528,22 +5390,19 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
4528
5390
|
if (parent === current) break;
|
|
4529
5391
|
current = parent;
|
|
4530
5392
|
}
|
|
4531
|
-
const tailwindConfigPath =
|
|
5393
|
+
const tailwindConfigPath = require_tailwindcss.findTailwindConfig(searchRoots);
|
|
4532
5394
|
if (tailwindConfigPath) return node_path.default.dirname(tailwindConfigPath);
|
|
4533
|
-
const packageRoot =
|
|
5395
|
+
const packageRoot = require_v4_engine.findNearestPackageRoot(resolvedRoot);
|
|
4534
5396
|
if (packageRoot && (0, node_fs.existsSync)(node_path.default.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
4535
5397
|
return resolvedRoot;
|
|
4536
5398
|
}
|
|
4537
5399
|
//#endregion
|
|
4538
5400
|
//#region src/bundlers/vite/index.ts
|
|
4539
|
-
const debug =
|
|
4540
|
-
const weappTailwindcssPackageDir =
|
|
4541
|
-
const weappTailwindcssDirPosix =
|
|
5401
|
+
const debug = require_context.createDebug();
|
|
5402
|
+
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
5403
|
+
const weappTailwindcssDirPosix = require_source_candidate_scan_signature.slash(weappTailwindcssPackageDir);
|
|
4542
5404
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
4543
5405
|
const sourceCandidateScanSnapshotCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4544
|
-
function normalizeVitePersistentCacheKey(file) {
|
|
4545
|
-
return require_bundle_state.normalizeOutputPathKey(file);
|
|
4546
|
-
}
|
|
4547
5406
|
/**
|
|
4548
5407
|
* @name WeappTailwindcss
|
|
4549
5408
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -4552,11 +5411,11 @@ function normalizeVitePersistentCacheKey(file) {
|
|
|
4552
5411
|
function WeappTailwindcss(options = {}) {
|
|
4553
5412
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
4554
5413
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
4555
|
-
const opts =
|
|
5414
|
+
const opts = require_context.getCompilerContext({
|
|
4556
5415
|
...options,
|
|
4557
5416
|
__internalDeferMissingCssEntriesWarning: true
|
|
4558
5417
|
});
|
|
4559
|
-
const normalizedCssEntries =
|
|
5418
|
+
const normalizedCssEntries = require_v4_engine.normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? node_process.default.cwd());
|
|
4560
5419
|
if (normalizedCssEntries) opts.cssEntries ?? (opts.cssEntries = normalizedCssEntries);
|
|
4561
5420
|
if (opts.cssEntries?.length) {
|
|
4562
5421
|
var _opts$tailwindcss, _opts$tailwindcss$v;
|
|
@@ -4564,15 +5423,29 @@ function WeappTailwindcss(options = {}) {
|
|
|
4564
5423
|
(_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
|
|
4565
5424
|
(_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
|
|
4566
5425
|
}
|
|
4567
|
-
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler,
|
|
5426
|
+
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
5427
|
+
const initialTailwindRuntime = tailwindRuntime;
|
|
5428
|
+
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
4568
5429
|
const uniAppXEnabled = require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
4569
|
-
const disabledOptions =
|
|
4570
|
-
const tailwindcssMajorVersion =
|
|
5430
|
+
const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
|
|
5431
|
+
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
5432
|
+
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
4571
5433
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
4572
|
-
const shouldRewriteCssImports =
|
|
4573
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4574
|
-
|
|
4575
|
-
|
|
5434
|
+
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5435
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
5436
|
+
appType: opts.appType,
|
|
5437
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5438
|
+
tailwindcssMajorVersion,
|
|
5439
|
+
uniAppX
|
|
5440
|
+
});
|
|
5441
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5442
|
+
appType: opts.appType,
|
|
5443
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5444
|
+
tailwindcssMajorVersion,
|
|
5445
|
+
uniAppX
|
|
5446
|
+
});
|
|
5447
|
+
const shouldInferAppType = !hasExplicitAppType && !generatorBranch.isWeb;
|
|
5448
|
+
const hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots({
|
|
4576
5449
|
...options,
|
|
4577
5450
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
4578
5451
|
});
|
|
@@ -4582,16 +5455,19 @@ function WeappTailwindcss(options = {}) {
|
|
|
4582
5455
|
let autoCssSourcesRefresh;
|
|
4583
5456
|
let autoCssSourcesDiscovered = false;
|
|
4584
5457
|
const syncTailwindCssSourceCandidates = async (id, css) => {
|
|
5458
|
+
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource((0, _weapp_tailwindcss_shared.cleanUrl)(id), weappTailwindcssPackageDir)) return;
|
|
4585
5459
|
await sourceCandidateCollector.syncCss(id, css);
|
|
4586
5460
|
cacheCurrentSourceCandidateScan();
|
|
4587
5461
|
};
|
|
4588
5462
|
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
4589
|
-
if (
|
|
5463
|
+
if (!shouldOwnTailwindGeneration) return;
|
|
4590
5464
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
4591
5465
|
if (!node_path.default.isAbsolute(file)) return;
|
|
5466
|
+
if (!require_v4_engine.isTailwindV4CssEntry(file)) return;
|
|
5467
|
+
if (isMissingInternalCssSource(file, weappTailwindcssPackageDir)) return;
|
|
4592
5468
|
const sourceFile = node_path.default.normalize(file);
|
|
4593
5469
|
const sourceBase = node_path.default.dirname(sourceFile);
|
|
4594
|
-
const sourceCss =
|
|
5470
|
+
const sourceCss = require_v4_engine.normalizeTailwindSourceForGenerator(require_v4_engine.normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
4595
5471
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
|
|
4596
5472
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
4597
5473
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
@@ -4605,10 +5481,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
4605
5481
|
transientAutoCssSources.set(sourceFile, transientSource);
|
|
4606
5482
|
return;
|
|
4607
5483
|
}
|
|
4608
|
-
const dependencies = await
|
|
5484
|
+
const dependencies = await require_tailwindcss.resolveViteTailwindV4CssDependencies(sourceCss, sourceBase);
|
|
4609
5485
|
transientSource.dependencies = dependencies;
|
|
4610
5486
|
transientAutoCssSources.set(sourceFile, transientSource);
|
|
4611
|
-
if (!
|
|
5487
|
+
if (!require_v4_engine.upsertTailwindV4CssSource(opts, {
|
|
4612
5488
|
file: sourceFile,
|
|
4613
5489
|
base: sourceBase,
|
|
4614
5490
|
css: sourceCss,
|
|
@@ -4624,36 +5500,32 @@ function WeappTailwindcss(options = {}) {
|
|
|
4624
5500
|
await autoCssSourcesRefresh;
|
|
4625
5501
|
};
|
|
4626
5502
|
const discoverAndRegisterAutoCssSources = async () => {
|
|
4627
|
-
if (
|
|
4628
|
-
const cssEntries = await
|
|
5503
|
+
if (!shouldOwnTailwindGeneration || hasInitialTailwindCssRoots || !resolvedConfig?.root) return;
|
|
5504
|
+
const cssEntries = await require_tailwindcss.discoverTailwindV4CssEntries(resolvedConfig.root, resolvedConfig.build?.outDir);
|
|
4629
5505
|
autoCssSourcesDiscovered = true;
|
|
4630
5506
|
let changed = false;
|
|
4631
5507
|
for (const cssEntry of cssEntries) {
|
|
4632
5508
|
const sourceFile = node_path.default.resolve(cssEntry);
|
|
4633
5509
|
const sourceBase = node_path.default.dirname(sourceFile);
|
|
4634
|
-
const sourceCss =
|
|
5510
|
+
const sourceCss = require_v4_engine.normalizeTailwindSourceForGenerator(require_v4_engine.normalizeTailwindConfigDirectives(await (0, node_fs_promises.readFile)(sourceFile, "utf8"), sourceBase), { importFallback: true });
|
|
4635
5511
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) continue;
|
|
4636
5512
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
4637
5513
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
4638
|
-
changed =
|
|
5514
|
+
changed = require_v4_engine.upsertTailwindV4CssSource(opts, {
|
|
4639
5515
|
file: sourceFile,
|
|
4640
5516
|
base: sourceBase,
|
|
4641
5517
|
css: sourceCss,
|
|
4642
|
-
dependencies: (await
|
|
5518
|
+
dependencies: (await require_tailwindcss.resolveTailwindV4EntriesFromCssCached(sourceCss, sourceBase))?.dependencies ?? []
|
|
4643
5519
|
}) || changed;
|
|
4644
5520
|
}
|
|
4645
5521
|
if (!changed) return;
|
|
4646
5522
|
invalidateSourceCandidateScan();
|
|
4647
5523
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
4648
5524
|
};
|
|
4649
|
-
const customAttributesEntities =
|
|
5525
|
+
const customAttributesEntities = require_context.toCustomAttributesEntities(customAttributes);
|
|
4650
5526
|
let resolvedConfig;
|
|
4651
5527
|
let recordedGeneratorCandidates;
|
|
4652
|
-
const
|
|
4653
|
-
const sourceCandidateCollector = require_hmr_timing.createSourceCandidateCollector({
|
|
4654
|
-
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
4655
|
-
extractor: sourceCandidateExtractor
|
|
4656
|
-
});
|
|
5528
|
+
const sourceCandidateCollector = require_hmr_timing.createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
4657
5529
|
const sourceCandidateScanCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4658
5530
|
let sourceScanEntries;
|
|
4659
5531
|
let sourceScanMatcher;
|
|
@@ -4674,8 +5546,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4674
5546
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
4675
5547
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
4676
5548
|
opts,
|
|
4677
|
-
|
|
4678
|
-
|
|
5549
|
+
initialTailwindRuntime,
|
|
5550
|
+
refreshTailwindcssRuntime: refreshTailwindRuntime,
|
|
4679
5551
|
uniAppXEnabled,
|
|
4680
5552
|
customAttributesEntities,
|
|
4681
5553
|
disabledDefaultTemplateHandler,
|
|
@@ -4691,7 +5563,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4691
5563
|
const isCssAssetProcessed = (asset, file) => {
|
|
4692
5564
|
if (processedCssAssets.has(asset)) return true;
|
|
4693
5565
|
if (!file) return false;
|
|
4694
|
-
const record = viteProcessedCssAssetResults.get(
|
|
5566
|
+
const record = viteProcessedCssAssetResults.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file));
|
|
4695
5567
|
if (!record) return false;
|
|
4696
5568
|
return (typeof asset.source === "string" ? asset.source : asset.source instanceof Uint8Array ? node_buffer.Buffer.from(asset.source).toString() : String(asset.source ?? "")) === record.css;
|
|
4697
5569
|
};
|
|
@@ -4703,7 +5575,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4703
5575
|
recordedGeneratorCandidates = void 0;
|
|
4704
5576
|
};
|
|
4705
5577
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
4706
|
-
const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
|
|
5578
|
+
const getSourceCandidatesForEntries = (entries, options) => sourceCandidateCollector.valuesForEntries(entries, options);
|
|
4707
5579
|
const getSourceCandidateSourcesForEntries = (entries, options) => sourceCandidateCollector.sourcesForEntries(entries, options);
|
|
4708
5580
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
4709
5581
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
@@ -4732,6 +5604,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4732
5604
|
seenRoots.add(basedir);
|
|
4733
5605
|
}
|
|
4734
5606
|
for (const cssEntry of opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
5607
|
+
if (!require_v4_engine.isTailwindV4CssEntry(cssEntry)) continue;
|
|
4735
5608
|
const cssEntryRoot = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
4736
5609
|
if (seenRoots.has(cssEntryRoot)) continue;
|
|
4737
5610
|
roots.push({ root: cssEntryRoot });
|
|
@@ -4766,16 +5639,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
4766
5639
|
}
|
|
4767
5640
|
const root = resolvedConfig?.root ?? node_process.default.cwd();
|
|
4768
5641
|
const outDir = resolvedConfig?.build?.outDir;
|
|
4769
|
-
const sourceScan = await
|
|
5642
|
+
const sourceScan = await require_tailwindcss.resolveViteSourceScanEntries(opts, runtimeState.tailwindRuntime, {
|
|
4770
5643
|
outDir,
|
|
4771
5644
|
root
|
|
4772
5645
|
});
|
|
4773
5646
|
sourceScanEntries = sourceScan?.entries;
|
|
4774
5647
|
sourceScanExplicit = sourceScan?.explicit ?? false;
|
|
4775
|
-
sourceScanMatcher =
|
|
5648
|
+
sourceScanMatcher = require_tailwindcss.createViteSourceScanMatcher(sourceScanEntries);
|
|
4776
5649
|
sourceScanDependencies = new Set((sourceScan?.dependencies ?? []).map(normalizeSourceScanDependency));
|
|
4777
5650
|
const roots = collectSourceCandidateScanRoots(root, sourceScanEntries);
|
|
4778
|
-
const nextScanSignature = createSourceCandidateScanSignature({
|
|
5651
|
+
const nextScanSignature = require_source_candidate_scan_signature.createSourceCandidateScanSignature({
|
|
4779
5652
|
inlineCandidates: sourceScan?.inlineCandidates,
|
|
4780
5653
|
outDir,
|
|
4781
5654
|
roots,
|
|
@@ -4817,6 +5690,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4817
5690
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
4818
5691
|
sourceCandidateCollector.remove(file);
|
|
4819
5692
|
cacheCurrentSourceCandidateScan();
|
|
5693
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return (0, node_fs_promises.readFile)(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
5694
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ENOENT") debug("remembered css source watch refresh failed: %s %O", file, error);
|
|
5695
|
+
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4820
5696
|
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
4821
5697
|
}
|
|
4822
5698
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
@@ -4849,7 +5725,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4849
5725
|
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
4850
5726
|
const getViteCssCacheStats = () => ({
|
|
4851
5727
|
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
5728
|
+
viteGeneratedCssByFileRaw: summarizeStringCache(viteGeneratedCssByFile),
|
|
4852
5729
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
5730
|
+
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(viteProcessedCssAssetResults),
|
|
4853
5731
|
...cssMemory.getStats(),
|
|
4854
5732
|
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4855
5733
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
@@ -4885,7 +5763,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4885
5763
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
4886
5764
|
};
|
|
4887
5765
|
const isViteProcessedCssAsset = (asset, file) => {
|
|
4888
|
-
if (
|
|
5766
|
+
if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(asset.source)) return true;
|
|
4889
5767
|
return [
|
|
4890
5768
|
file,
|
|
4891
5769
|
asset.originalFileName,
|
|
@@ -4895,7 +5773,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4895
5773
|
const transformCssHandlerOptions = createCssHandlerOptionsCache({
|
|
4896
5774
|
getAppType: () => opts.appType,
|
|
4897
5775
|
mainCssChunkMatcher,
|
|
4898
|
-
getMajorVersion: () => runtimeState.
|
|
5776
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4899
5777
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? node_path.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
4900
5778
|
getExtraOptions: (file) => ({
|
|
4901
5779
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -4907,11 +5785,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4907
5785
|
await runtimeState.readyPromise;
|
|
4908
5786
|
await waitForSourceCandidateSyncs();
|
|
4909
5787
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
5788
|
+
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id : file;
|
|
5789
|
+
if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
|
|
4910
5790
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
4911
5791
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4912
5792
|
const isNativeAppStyleTarget = require_utils.resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4913
5793
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
4914
|
-
const outputFile = resolveViteCssPipelineOutputFile(
|
|
5794
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, generatorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
4915
5795
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4916
5796
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4917
5797
|
const cssHandlerOptions = {
|
|
@@ -4919,13 +5799,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
4919
5799
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
4920
5800
|
};
|
|
4921
5801
|
const transientCssSource = transientAutoCssSources.get(file);
|
|
4922
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk &&
|
|
4923
|
-
const generated = await
|
|
5802
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(code));
|
|
5803
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
4924
5804
|
opts,
|
|
4925
5805
|
runtimeState,
|
|
4926
5806
|
runtime,
|
|
4927
5807
|
rawSource: code,
|
|
4928
5808
|
file,
|
|
5809
|
+
outputFile,
|
|
4929
5810
|
cssHandlerOptions,
|
|
4930
5811
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
4931
5812
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
@@ -4942,7 +5823,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4942
5823
|
});
|
|
4943
5824
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
4944
5825
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
4945
|
-
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) ||
|
|
5826
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || require_v4_engine.hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }) && !require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile).includes("/");
|
|
4946
5827
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
4947
5828
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
4948
5829
|
outputFile
|
|
@@ -4965,7 +5846,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4965
5846
|
sourceFile: id
|
|
4966
5847
|
});
|
|
4967
5848
|
debug("css generated for vite postcss pipeline: %s bytes=%d", file, tracedCss.length);
|
|
4968
|
-
return `${
|
|
5849
|
+
return `${require_source_candidate_scan_signature.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
4969
5850
|
};
|
|
4970
5851
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
4971
5852
|
getAppType: () => opts.appType,
|
|
@@ -4974,6 +5855,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4974
5855
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
4975
5856
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
4976
5857
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
5858
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && require_v4_engine.hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }),
|
|
4977
5859
|
shouldOwnTailwindGeneration,
|
|
4978
5860
|
shouldRewrite: shouldRewriteCssImports,
|
|
4979
5861
|
weappTailwindcssDirPosix
|
|
@@ -5056,7 +5938,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5056
5938
|
const plugins = [
|
|
5057
5939
|
...rewritePlugins,
|
|
5058
5940
|
{
|
|
5059
|
-
name: `${
|
|
5941
|
+
name: `${require_context.vitePluginName}:source-candidates`,
|
|
5060
5942
|
enforce: "pre",
|
|
5061
5943
|
async transform(code, id) {
|
|
5062
5944
|
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, code);
|
|
@@ -5091,7 +5973,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5091
5973
|
await syncChangedSourceCandidateFile(ctx.file);
|
|
5092
5974
|
if (isSourceCandidateHotUpdate) invalidateRecordedGeneratorCandidates();
|
|
5093
5975
|
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
5094
|
-
if (isSourceCandidateHotUpdate && !
|
|
5976
|
+
if (isSourceCandidateHotUpdate && !require_source_candidate_scan_signature.isSourceStyleRequest(ctx.file) && (!hasSelfAcceptingNonStyleHotModule(ctx.modules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
5095
5977
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
5096
5978
|
return [];
|
|
5097
5979
|
}
|
|
@@ -5112,7 +5994,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5112
5994
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
5113
5995
|
}),
|
|
5114
5996
|
{
|
|
5115
|
-
name: `${
|
|
5997
|
+
name: `${require_context.vitePluginName}:post`,
|
|
5116
5998
|
enforce: "post",
|
|
5117
5999
|
config(config) {
|
|
5118
6000
|
if (!shouldOwnTailwindGeneration) return;
|
|
@@ -5173,11 +6055,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5173
6055
|
const removed = (0, _weapp_tailwindcss_postcss.removeTailwindPostcssPlugins)(postcssPlugins);
|
|
5174
6056
|
if (removed > 0) debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
5175
6057
|
}
|
|
5176
|
-
const idx = postcssPlugins.findIndex((x) => (0, _weapp_tailwindcss_postcss.getPostcssPluginName)(x) === "postcss-html-transform");
|
|
5177
|
-
if (idx > -1) {
|
|
5178
|
-
postcssPlugins.splice(idx, 1, (0, _weapp_tailwindcss_postcss_html_transform.default)());
|
|
5179
|
-
debug("remove postcss-html-transform plugin from vite config");
|
|
5180
|
-
}
|
|
5181
6058
|
}
|
|
5182
6059
|
}, { emit: false });
|
|
5183
6060
|
},
|