weapp-tailwindcss 5.0.13 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.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/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +21 -9
- 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 +1 -1
- 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/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 +10 -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-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- 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/types.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +3 -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/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
- 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 +24 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -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 +124 -437
- package/dist/cli.mjs +120 -433
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +4 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-BHxLe743.js} +391 -153
- package/dist/{precheck-CRI90iL1.mjs → context-Mbzkek1q.mjs} +368 -137
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-C_J_kBpw.js → defaults-CVcKbXBG.js} +4 -15
- package/dist/{defaults-Bqx18S1f.mjs → defaults-ZElj1zKc.mjs} +5 -10
- package/dist/defaults.d.ts +1 -7
- 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-9rUz4Hcb.js +170 -0
- package/dist/generator-Dc4qaPmT.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-B_sdP6dx.js} +47 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-uM36oIJs.mjs} +40 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-BXMLsF4b.mjs} +1145 -842
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CogqkFaF.js} +1262 -881
- 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-CKWeTEhv.js → source-candidate-scan-signature-2ybpptAK.js} +261 -19
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
- 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 +86 -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 +23 -6
- package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-DHIYcqXT.js +1523 -0
- package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
- package/dist/{transform-YmrmxuF3.js → transform-CQVOgmzM.js} +17 -17
- package/dist/{transform-DfcEjsZF.mjs → transform-tExdt40m.mjs} +2 -2
- 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/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
- package/dist/v4-engine-D4ubP7N5.js +2778 -0
- package/dist/{vite-CXHVsHmX.js → vite-CP0ylSxZ.js} +1081 -542
- package/dist/{vite-DjI09vVN.mjs → vite-CPO83EhA.mjs} +916 -376
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5350 -4165
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-Bsek8VhR.js +2094 -0
- package/dist/webpack-BzqhJ8yK.mjs +2082 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +4 -5
- 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-D4ubP7N5.js");
|
|
4
|
+
const require_generator = require("./generator-9rUz4Hcb.js");
|
|
6
5
|
const require_utils = require("./utils-BCa37Wqj.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
const require_context = require("./context-BHxLe743.js");
|
|
7
|
+
const require_tailwindcss = require("./tailwindcss-DHIYcqXT.js");
|
|
8
|
+
const require_hmr_timing = require("./hmr-timing-CogqkFaF.js");
|
|
9
|
+
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-2ybpptAK.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,12 @@ 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");
|
|
22
21
|
let node_buffer = require("node:buffer");
|
|
23
|
-
let
|
|
24
|
-
_weapp_tailwindcss_postcss_html_transform = require_chunk.__toESM(_weapp_tailwindcss_postcss_html_transform);
|
|
22
|
+
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
25
23
|
let comment_json = require("comment-json");
|
|
26
24
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
27
25
|
//#region src/uni-app-x/harmony.ts
|
|
@@ -130,7 +128,7 @@ function collectUsedClassNames(code, entries) {
|
|
|
130
128
|
for (const literalMatch of code.matchAll(STRING_LITERAL_RE)) {
|
|
131
129
|
const literal = literalMatch[2];
|
|
132
130
|
if (!literal) continue;
|
|
133
|
-
for (const candidate of (0,
|
|
131
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) if (entries.has(candidate)) used.add(candidate);
|
|
134
132
|
}
|
|
135
133
|
return used;
|
|
136
134
|
}
|
|
@@ -166,7 +164,7 @@ function cssToStyleExport(source) {
|
|
|
166
164
|
result[match[1]] = { "": declarations };
|
|
167
165
|
const className = unescapeCssClassSelector(match[1]);
|
|
168
166
|
result[className] = { "": declarations };
|
|
169
|
-
result[
|
|
167
|
+
result[require_context.replaceWxml(className)] = { "": declarations };
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
});
|
|
@@ -203,15 +201,15 @@ function createStyleValueFromApplySources(sources, utilityStyles) {
|
|
|
203
201
|
const className = selector.trim().match(CLASS_SELECTOR_PREFIX_RE)?.[1];
|
|
204
202
|
if (!className) continue;
|
|
205
203
|
const declarations = {};
|
|
206
|
-
for (const applyRule of applyRules) for (const utility of (0,
|
|
207
|
-
const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[
|
|
204
|
+
for (const applyRule of applyRules) for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(applyRule.params)) {
|
|
205
|
+
const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[require_context.replaceWxml(utility)]?.[""];
|
|
208
206
|
if (utilityDeclarations) Object.assign(declarations, utilityDeclarations);
|
|
209
207
|
}
|
|
210
208
|
if (Object.keys(declarations).length > 0) {
|
|
211
209
|
const unescapedClassName = unescapeCssClassSelector(className);
|
|
212
210
|
result[className] = { "": declarations };
|
|
213
211
|
result[unescapedClassName] = { "": declarations };
|
|
214
|
-
result[
|
|
212
|
+
result[require_context.replaceWxml(unescapedClassName)] = { "": declarations };
|
|
215
213
|
}
|
|
216
214
|
}
|
|
217
215
|
});
|
|
@@ -232,7 +230,7 @@ function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) {
|
|
|
232
230
|
continue;
|
|
233
231
|
}
|
|
234
232
|
root.walkAtRules("apply", (rule) => {
|
|
235
|
-
for (const utility of (0,
|
|
233
|
+
for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
236
234
|
});
|
|
237
235
|
}
|
|
238
236
|
return utilities;
|
|
@@ -359,18 +357,13 @@ function findFirstStyleObjectDecl(source) {
|
|
|
359
357
|
varName
|
|
360
358
|
};
|
|
361
359
|
}
|
|
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;
|
|
360
|
+
function resolveCssFallbackFiles(styleAssetFiles = []) {
|
|
361
|
+
const files = /* @__PURE__ */ new Set();
|
|
362
|
+
for (const assetFile of styleAssetFiles) if (assetFile) files.add(assetFile);
|
|
363
|
+
return [...files];
|
|
364
|
+
}
|
|
365
|
+
function resolveStyleAssetFilesForChunk(file, styleAssetFiles) {
|
|
366
|
+
return typeof styleAssetFiles === "function" ? styleAssetFiles(file) : styleAssetFiles;
|
|
374
367
|
}
|
|
375
368
|
function resolveSourceMapFiles(file) {
|
|
376
369
|
return [
|
|
@@ -380,7 +373,7 @@ function resolveSourceMapFiles(file) {
|
|
|
380
373
|
].filter((item) => typeof item === "string");
|
|
381
374
|
}
|
|
382
375
|
function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) {
|
|
383
|
-
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(file).map((cssFile) => {
|
|
376
|
+
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(resolveStyleAssetFilesForChunk(file, options.styleAssetFiles)).map((cssFile) => {
|
|
384
377
|
const source = getBundleSource?.(cssFile);
|
|
385
378
|
return source ? cssSourceToStyleValue(source) : void 0;
|
|
386
379
|
}));
|
|
@@ -431,12 +424,15 @@ function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options =
|
|
|
431
424
|
}
|
|
432
425
|
function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
433
426
|
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
427
|
+
const styleAssetFilesByChunk = collectUniAppXBundleStyleAssetFilesByChunk(bundle);
|
|
428
|
+
const resolveStyleAssetFiles = typeof options.styleAssetFiles === "function" ? options.styleAssetFiles : (file) => [...options.styleAssetFiles ?? [], ...styleAssetFilesByChunk.get(file) ?? []];
|
|
434
429
|
let changed = false;
|
|
435
430
|
for (const [file, item] of Object.entries(bundle)) {
|
|
436
431
|
if (item.type !== "chunk" || !file.endsWith(".js")) continue;
|
|
437
432
|
const currentSource = item.code;
|
|
438
433
|
const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, {
|
|
439
434
|
...options,
|
|
435
|
+
styleAssetFiles: resolveStyleAssetFiles,
|
|
440
436
|
mapSources: collectChunkMapSourcesContent(item)
|
|
441
437
|
});
|
|
442
438
|
if (nextSource !== currentSource) {
|
|
@@ -446,6 +442,41 @@ function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
|
446
442
|
}
|
|
447
443
|
return changed;
|
|
448
444
|
}
|
|
445
|
+
function collectUniAppXBundleStyleAssetFilesByChunk(bundle) {
|
|
446
|
+
const styleAssetFilesByChunk = /* @__PURE__ */ new Map();
|
|
447
|
+
const appStyleAssetFiles = /* @__PURE__ */ new Set();
|
|
448
|
+
const assetFiles = new Set(Object.entries(bundle).filter(([, item]) => item.type === "asset").map(([file]) => file).filter(isStyleAssetFile));
|
|
449
|
+
for (const [chunkFile, item] of Object.entries(bundle)) {
|
|
450
|
+
if (item.type !== "chunk") continue;
|
|
451
|
+
const chunk = item;
|
|
452
|
+
for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
|
|
453
|
+
if (!assetFiles.has(cssFile)) continue;
|
|
454
|
+
if (APP_JS_RE.test(chunk.fileName ?? chunkFile) || APP_JS_RE.test(chunkFile)) {
|
|
455
|
+
appStyleAssetFiles.add(cssFile);
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(chunkFile);
|
|
459
|
+
if (!styleAssetFiles) {
|
|
460
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
461
|
+
styleAssetFilesByChunk.set(chunkFile, styleAssetFiles);
|
|
462
|
+
}
|
|
463
|
+
styleAssetFiles.add(cssFile);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (appStyleAssetFiles.size > 0) for (const [file, item] of Object.entries(bundle)) {
|
|
467
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
468
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(file);
|
|
469
|
+
if (!styleAssetFiles) {
|
|
470
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
471
|
+
styleAssetFilesByChunk.set(file, styleAssetFiles);
|
|
472
|
+
}
|
|
473
|
+
for (const appStyleAssetFile of appStyleAssetFiles) styleAssetFiles.add(appStyleAssetFile);
|
|
474
|
+
}
|
|
475
|
+
return styleAssetFilesByChunk;
|
|
476
|
+
}
|
|
477
|
+
function isStyleAssetFile(file) {
|
|
478
|
+
return /\.(?:acss|css|jxss|qss|ttss|wxss)$/i.test(file);
|
|
479
|
+
}
|
|
449
480
|
function isUniAppXHarmonyBundle(bundle) {
|
|
450
481
|
for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true;
|
|
451
482
|
return false;
|
|
@@ -482,7 +513,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
482
513
|
//#region src/uni-app-x/vite.ts
|
|
483
514
|
let transformUVuePromise;
|
|
484
515
|
function loadTransformUVue() {
|
|
485
|
-
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-
|
|
516
|
+
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-CQVOgmzM.js")).then((mod) => mod.transformUVue));
|
|
486
517
|
return transformUVuePromise;
|
|
487
518
|
}
|
|
488
519
|
const preprocessorLangs = new Set([
|
|
@@ -554,16 +585,16 @@ function createUniAppXPlugins(options) {
|
|
|
554
585
|
}
|
|
555
586
|
async function transformStyle(code, id, query, hookContext) {
|
|
556
587
|
const parsed = query ?? parseVueRequest(id).query;
|
|
557
|
-
if (
|
|
588
|
+
if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
558
589
|
if (isCssModuleExport(code)) return;
|
|
559
|
-
const shouldGenerateCss =
|
|
590
|
+
const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
560
591
|
rememberHarmonyApplySource(code);
|
|
561
592
|
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
562
593
|
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
563
594
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
564
595
|
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
565
596
|
if (!styleHandlerOptions) {
|
|
566
|
-
styleHandlerOptions =
|
|
597
|
+
styleHandlerOptions = require_v4_engine.omitUndefined({
|
|
567
598
|
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
568
599
|
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
569
600
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
@@ -581,7 +612,7 @@ function createUniAppXPlugins(options) {
|
|
|
581
612
|
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
582
613
|
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
583
614
|
for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
|
|
584
|
-
const postcssMap = await
|
|
615
|
+
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
616
|
return {
|
|
586
617
|
code: postcssResult.css,
|
|
587
618
|
map: postcssMap
|
|
@@ -622,7 +653,7 @@ function createUniAppXPlugins(options) {
|
|
|
622
653
|
const transformUVue = await loadTransformUVue();
|
|
623
654
|
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
624
655
|
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
625
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet,
|
|
656
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
|
|
626
657
|
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
627
658
|
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
628
659
|
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
@@ -685,7 +716,7 @@ function createUniAppXPlugins(options) {
|
|
|
685
716
|
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
686
717
|
return async () => {
|
|
687
718
|
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
688
|
-
const absoluteFile =
|
|
719
|
+
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
|
|
689
720
|
const rawSource = originalSource.source.toString();
|
|
690
721
|
await require_hmr_timing.processCachedTask({
|
|
691
722
|
cache,
|
|
@@ -770,7 +801,7 @@ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
|
770
801
|
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
771
802
|
while (quoted !== null) {
|
|
772
803
|
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
773
|
-
for (const candidate of (0,
|
|
804
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
|
|
774
805
|
const normalized = candidate.trim();
|
|
775
806
|
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
776
807
|
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
@@ -781,25 +812,25 @@ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
|
781
812
|
}
|
|
782
813
|
return [...matches];
|
|
783
814
|
}
|
|
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
815
|
//#endregion
|
|
790
816
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
791
817
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
792
|
-
const
|
|
793
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...
|
|
818
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
819
|
+
return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
794
820
|
}
|
|
795
821
|
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
796
822
|
const entries = [];
|
|
823
|
+
const seen = /* @__PURE__ */ new Set();
|
|
797
824
|
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
798
825
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
799
|
-
const base =
|
|
826
|
+
const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
800
827
|
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
|
|
828
|
+
const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
|
|
829
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
830
|
+
if (seen.has(key)) continue;
|
|
831
|
+
seen.add(key);
|
|
801
832
|
entries.push({
|
|
802
|
-
file:
|
|
833
|
+
file: resolvedFile,
|
|
803
834
|
source: cssSource.css
|
|
804
835
|
});
|
|
805
836
|
}
|
|
@@ -896,17 +927,32 @@ function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
|
896
927
|
if (!cssMatcher || !stem) return;
|
|
897
928
|
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
898
929
|
}
|
|
930
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
931
|
+
const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
|
|
932
|
+
const stemSuffix = `/${cleanStem}`;
|
|
933
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
934
|
+
for (const file of files ?? []) {
|
|
935
|
+
const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
936
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
937
|
+
const extension = node_path.default.extname(cleanFile);
|
|
938
|
+
if (!extension || extension === ".css") continue;
|
|
939
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
940
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
941
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix)) matchedFiles.add(cleanFile);
|
|
942
|
+
}
|
|
943
|
+
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
944
|
+
}
|
|
899
945
|
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
900
|
-
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ??
|
|
946
|
+
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
947
|
}
|
|
902
948
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
903
|
-
const normalizedFile =
|
|
904
|
-
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return
|
|
949
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.isAbsolute(file) ? node_path.default.relative(rootDir, file) : file);
|
|
950
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.basename(file));
|
|
905
951
|
return normalizedFile;
|
|
906
952
|
}
|
|
907
953
|
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
908
954
|
if (typeof sourceRoot !== "string" || sourceRoot.trim().length === 0) return;
|
|
909
|
-
return
|
|
955
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.isAbsolute(sourceRoot) ? node_path.default.relative(rootDir, sourceRoot) : sourceRoot).replace(/\/+$/, "");
|
|
910
956
|
}
|
|
911
957
|
function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
912
958
|
const outputFile = resolveReplayCssOutputFile(rootDir, file);
|
|
@@ -917,7 +963,7 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
917
963
|
return outputFile;
|
|
918
964
|
}
|
|
919
965
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
920
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !
|
|
966
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !require_source_candidate_scan_signature.isCSSRequest(file)) return file;
|
|
921
967
|
const stem = file.replace(/[?#].*$/, "").replace(SOURCE_STYLE_OUTPUT_EXT_RE, "");
|
|
922
968
|
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
923
969
|
cssMatcher: opts.cssMatcher,
|
|
@@ -931,12 +977,27 @@ function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTar
|
|
|
931
977
|
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
932
978
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
933
979
|
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) || !
|
|
980
|
+
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);
|
|
981
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !require_source_candidate_scan_signature.isCSSRequest(normalizedFile)) return normalizedFile;
|
|
936
982
|
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
937
983
|
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(normalizedFile)) return normalizedFile;
|
|
938
984
|
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
939
985
|
}
|
|
986
|
+
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
987
|
+
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot);
|
|
988
|
+
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
989
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !require_source_candidate_scan_signature.isCSSRequest(normalizedFile)) return normalizedFile;
|
|
990
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
991
|
+
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
992
|
+
if (matchedStyleFile) return matchedStyleFile;
|
|
993
|
+
const styleExtension = resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? resolveMiniProgramStyleOutputExtension({
|
|
994
|
+
cssMatcher: opts.cssMatcher,
|
|
995
|
+
fallback: styleOutputExtension,
|
|
996
|
+
files: styleOutputFiles,
|
|
997
|
+
stem
|
|
998
|
+
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
999
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
1000
|
+
}
|
|
940
1001
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
941
1002
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
942
1003
|
try {
|
|
@@ -963,7 +1024,7 @@ function collectStyleFileMatchBases(file, roots) {
|
|
|
963
1024
|
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
964
1025
|
const bases = /* @__PURE__ */ new Set();
|
|
965
1026
|
const addBase = (candidate) => {
|
|
966
|
-
const base =
|
|
1027
|
+
const base = require_source_candidate_scan_signature.slash(stripStyleFileExtension(candidate));
|
|
967
1028
|
if (base.length > 0) bases.add(base);
|
|
968
1029
|
};
|
|
969
1030
|
addBase(normalizedFile);
|
|
@@ -993,7 +1054,7 @@ function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRo
|
|
|
993
1054
|
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
994
1055
|
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
995
1056
|
let bestScore = 0;
|
|
996
|
-
const hasDirectorySegment = (value) =>
|
|
1057
|
+
const hasDirectorySegment = (value) => require_source_candidate_scan_signature.slash(value).includes("/");
|
|
997
1058
|
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
998
1059
|
else if (hasDirectorySegment(sourceBase) && outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
999
1060
|
else if (hasDirectorySegment(outputBase) && sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
@@ -1009,11 +1070,11 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1009
1070
|
return node_path.default.resolve(file.replace(/[?#].*$/, ""));
|
|
1010
1071
|
}
|
|
1011
1072
|
function collectConfiguredCssEntries(opts) {
|
|
1012
|
-
const
|
|
1073
|
+
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1013
1074
|
return [
|
|
1014
1075
|
...opts.cssEntries ?? [],
|
|
1015
1076
|
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
1016
|
-
...
|
|
1077
|
+
...runtimeCssEntries ?? []
|
|
1017
1078
|
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1018
1079
|
}
|
|
1019
1080
|
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
@@ -1028,9 +1089,9 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1028
1089
|
};
|
|
1029
1090
|
addCandidate(node_path.default.dirname(node_path.default.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
1030
1091
|
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
1031
|
-
const
|
|
1032
|
-
const sourceBaseFallback = opts.tailwindcss?.v4?.base ??
|
|
1033
|
-
const sourceRoot = opts.tailwindcssBasedir ??
|
|
1092
|
+
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1093
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1094
|
+
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1034
1095
|
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1035
1096
|
for (const cssEntry of configuredCssEntries) {
|
|
1036
1097
|
const resolvedCssEntry = node_path.default.resolve(cssEntry);
|
|
@@ -1041,7 +1102,7 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1041
1102
|
const cssSourceCss = typeof cssSource.css === "string" ? normalizeCssSourceForCompare(cssSource.css) : void 0;
|
|
1042
1103
|
if (cssSourceFile && !isMatchingCssSourceFile(file, cssSourceFile, outputRoot) && cssSourceCss !== normalizedSource) continue;
|
|
1043
1104
|
addCandidate(cssSourceFile ? node_path.default.dirname(cssSourceFile) : void 0);
|
|
1044
|
-
addCandidate(
|
|
1105
|
+
addCandidate(require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback));
|
|
1045
1106
|
}
|
|
1046
1107
|
return candidates;
|
|
1047
1108
|
}
|
|
@@ -1052,7 +1113,7 @@ function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
|
1052
1113
|
if (node_path.default.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
1053
1114
|
for (const base of baseCandidates) {
|
|
1054
1115
|
const configFile = node_path.default.resolve(base, request);
|
|
1055
|
-
if ((0, node_fs.existsSync)(configFile)) return `@config ${quote}${
|
|
1116
|
+
if ((0, node_fs.existsSync)(configFile)) return `@config ${quote}${require_source_candidate_scan_signature.slash(configFile)}${quote};`;
|
|
1056
1117
|
}
|
|
1057
1118
|
return full;
|
|
1058
1119
|
});
|
|
@@ -1060,7 +1121,7 @@ function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
|
1060
1121
|
//#endregion
|
|
1061
1122
|
//#region src/bundlers/vite/generate-bundle/css-handler-options.ts
|
|
1062
1123
|
function resolveViteCssHandlerExtraOptions(file) {
|
|
1063
|
-
return
|
|
1124
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, "")).includes("/") ? { isMainChunk: false } : {};
|
|
1064
1125
|
}
|
|
1065
1126
|
function createCssHandlerOptionsCache(options) {
|
|
1066
1127
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -1070,7 +1131,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1070
1131
|
const appType = options.getAppType();
|
|
1071
1132
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
1072
1133
|
const outputRoot = options.getOutputRoot?.();
|
|
1073
|
-
const from = outputRoot ? node_path.default.resolve(outputRoot, file) : file;
|
|
1134
|
+
const from = node_path.default.isAbsolute(file) ? file : outputRoot ? node_path.default.resolve(outputRoot, file) : file;
|
|
1074
1135
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
1075
1136
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
|
|
1076
1137
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
@@ -1122,13 +1183,13 @@ function hasPathDependentCssUrl(rawSource) {
|
|
|
1122
1183
|
return false;
|
|
1123
1184
|
}
|
|
1124
1185
|
function createCssTransformShareScope(file, rawSource) {
|
|
1125
|
-
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${
|
|
1186
|
+
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.dirname(file))}`;
|
|
1126
1187
|
return "global";
|
|
1127
1188
|
}
|
|
1128
1189
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
1129
|
-
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${
|
|
1190
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_source_candidate_scan_signature.normalizeOutputPathKey(file)}`;
|
|
1130
1191
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1131
|
-
if (
|
|
1192
|
+
if (require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${require_source_candidate_scan_signature.normalizeOutputPathKey(file)}`;
|
|
1132
1193
|
return createCssTransformShareScope(file, rawSource);
|
|
1133
1194
|
}
|
|
1134
1195
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -1148,8 +1209,7 @@ function resolveGenerateBundleEnvFlags() {
|
|
|
1148
1209
|
forceRuntimeRefreshByEnv: node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1149
1210
|
disableDirtyOptimization: node_process.default.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1150
1211
|
disableJsPrecheck: node_process.default.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1",
|
|
1151
|
-
debugCssDiff: node_process.default.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1"
|
|
1152
|
-
disableV3OxideSourceRuntime: node_process.default.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1"
|
|
1212
|
+
debugCssDiff: node_process.default.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1"
|
|
1153
1213
|
};
|
|
1154
1214
|
}
|
|
1155
1215
|
//#endregion
|
|
@@ -1621,8 +1681,14 @@ function extractSfcStyleSources(source) {
|
|
|
1621
1681
|
function hasSfcStyleSources(source) {
|
|
1622
1682
|
return extractSfcStyleSources(source).length > 0;
|
|
1623
1683
|
}
|
|
1624
|
-
function hasTailwindGenerationSource(source) {
|
|
1625
|
-
|
|
1684
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
1685
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1686
|
+
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);
|
|
1687
|
+
}
|
|
1688
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1689
|
+
if (require_v4_engine.isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1690
|
+
if (require_v4_engine.hasTailwindRootImportDirectives(source, { importFallback: true })) return false;
|
|
1691
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1626
1692
|
}
|
|
1627
1693
|
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1628
1694
|
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
@@ -1636,7 +1702,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1636
1702
|
return;
|
|
1637
1703
|
}
|
|
1638
1704
|
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1639
|
-
if (!rawSource || !
|
|
1705
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1640
1706
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1641
1707
|
return;
|
|
1642
1708
|
}
|
|
@@ -1648,7 +1714,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1648
1714
|
};
|
|
1649
1715
|
}
|
|
1650
1716
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1651
|
-
return
|
|
1717
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1652
1718
|
}
|
|
1653
1719
|
function collectChunkModuleIds$1(output) {
|
|
1654
1720
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
@@ -1684,8 +1750,8 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1684
1750
|
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1685
1751
|
return;
|
|
1686
1752
|
}
|
|
1687
|
-
const normalizedSiblingJsFile =
|
|
1688
|
-
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" &&
|
|
1753
|
+
const normalizedSiblingJsFile = require_source_candidate_scan_signature.normalizeOutputPathKey(siblingJsFile);
|
|
1754
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1689
1755
|
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1690
1756
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1691
1757
|
return;
|
|
@@ -1715,8 +1781,8 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1715
1781
|
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1716
1782
|
return;
|
|
1717
1783
|
}
|
|
1718
|
-
const normalizedSiblingJsFile =
|
|
1719
|
-
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" &&
|
|
1784
|
+
const normalizedSiblingJsFile = require_source_candidate_scan_signature.normalizeOutputPathKey(siblingJsFile);
|
|
1785
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1720
1786
|
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1721
1787
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1722
1788
|
return;
|
|
@@ -1743,8 +1809,8 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1743
1809
|
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1744
1810
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1745
1811
|
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) &&
|
|
1812
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1813
|
+
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1748
1814
|
file,
|
|
1749
1815
|
source,
|
|
1750
1816
|
score: scoreMatchingStyleFileBase(outputFile, file, outputRoot, sourceRoot)
|
|
@@ -1758,7 +1824,7 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1758
1824
|
}
|
|
1759
1825
|
}
|
|
1760
1826
|
if (!sourceFile || !rawSource) return;
|
|
1761
|
-
if (!
|
|
1827
|
+
if (!hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1762
1828
|
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1763
1829
|
return;
|
|
1764
1830
|
}
|
|
@@ -1775,7 +1841,7 @@ function readBundleAssetSource(output) {
|
|
|
1775
1841
|
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
1776
1842
|
}
|
|
1777
1843
|
function normalizePackageRoot(root) {
|
|
1778
|
-
return
|
|
1844
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
1779
1845
|
}
|
|
1780
1846
|
function collectMiniProgramSubpackageRoots(bundle) {
|
|
1781
1847
|
let hasAppJson = false;
|
|
@@ -1798,12 +1864,12 @@ function collectMiniProgramSubpackageRoots(bundle) {
|
|
|
1798
1864
|
return hasAppJson ? roots : void 0;
|
|
1799
1865
|
}
|
|
1800
1866
|
function isSubpackageOutputFile(file, subpackageRoots) {
|
|
1801
|
-
const normalizedFile =
|
|
1867
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1802
1868
|
for (const root of subpackageRoots) if (root.length > 0 && (normalizedFile === root || normalizedFile.startsWith(`${root}/`) || normalizedFile.endsWith(`/${root}`) || normalizedFile.includes(`/${root}/`))) return true;
|
|
1803
1869
|
return false;
|
|
1804
1870
|
}
|
|
1805
1871
|
function resolveSubpackageSourceRootFromModuleId(moduleId, subpackageRoot) {
|
|
1806
|
-
const file =
|
|
1872
|
+
const file = require_source_candidate_scan_signature.slash(node_path.default.resolve(moduleId.replace(/[?#].*$/, "")));
|
|
1807
1873
|
const normalizedRoot = normalizePackageRoot(subpackageRoot);
|
|
1808
1874
|
const rootSegment = `/${normalizedRoot}/`;
|
|
1809
1875
|
const rootIndex = file.lastIndexOf(rootSegment);
|
|
@@ -1843,10 +1909,10 @@ const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
|
1843
1909
|
function isCssOutputFile(file) {
|
|
1844
1910
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1845
1911
|
}
|
|
1846
|
-
function getAssetFile(bundleFile, asset) {
|
|
1912
|
+
function getAssetFile$1(bundleFile, asset) {
|
|
1847
1913
|
return asset.fileName || bundleFile;
|
|
1848
1914
|
}
|
|
1849
|
-
function readAssetSource(asset) {
|
|
1915
|
+
function readAssetSource$2(asset) {
|
|
1850
1916
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1851
1917
|
}
|
|
1852
1918
|
function clearAssetSource(asset) {
|
|
@@ -1880,7 +1946,7 @@ function removeTailwindSourceMediaWrappers(css) {
|
|
|
1880
1946
|
}
|
|
1881
1947
|
}
|
|
1882
1948
|
function removeTailwindEntryDirectivesFromCss(css) {
|
|
1883
|
-
return
|
|
1949
|
+
return require_v4_engine.removeTailwindSourceDirectives(removeTailwindSourceMediaWrappers(css));
|
|
1884
1950
|
}
|
|
1885
1951
|
function stripStyleExtension(file) {
|
|
1886
1952
|
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
@@ -1891,15 +1957,15 @@ function isStyleImportRequest(request) {
|
|
|
1891
1957
|
function resolveImportedStyleFile(targetFile, request) {
|
|
1892
1958
|
if (!isStyleImportRequest(request)) return;
|
|
1893
1959
|
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
1894
|
-
if (cleanRequest.startsWith("/")) return
|
|
1895
|
-
const targetDir = posix.posix.dirname(
|
|
1896
|
-
return
|
|
1960
|
+
if (cleanRequest.startsWith("/")) return require_source_candidate_scan_signature.normalizeOutputPathKey(cleanRequest.slice(1));
|
|
1961
|
+
const targetDir = posix.posix.dirname(require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile));
|
|
1962
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1897
1963
|
}
|
|
1898
1964
|
function collectImportedStyleFiles(css, targetFile) {
|
|
1899
1965
|
const imports = /* @__PURE__ */ new Set();
|
|
1900
1966
|
try {
|
|
1901
1967
|
_weapp_tailwindcss_postcss.postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
1902
|
-
const importedFile = resolveImportedStyleFile(targetFile,
|
|
1968
|
+
const importedFile = resolveImportedStyleFile(targetFile, require_v4_engine.parseImportRequest(atRule.params));
|
|
1903
1969
|
if (importedFile) imports.add(importedFile);
|
|
1904
1970
|
});
|
|
1905
1971
|
} catch {}
|
|
@@ -1910,31 +1976,31 @@ function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile
|
|
|
1910
1976
|
}
|
|
1911
1977
|
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
1912
1978
|
if (!markerFile) return false;
|
|
1913
|
-
return
|
|
1979
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(targetFile)) === require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
1914
1980
|
}
|
|
1915
1981
|
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1916
|
-
const blocks =
|
|
1917
|
-
if (blocks.length <= 1) return
|
|
1982
|
+
const blocks = require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1983
|
+
if (blocks.length <= 1) return require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1918
1984
|
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1919
|
-
return matchedCss.length > 0 ? matchedCss.join("\n") :
|
|
1985
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1920
1986
|
}
|
|
1921
1987
|
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1922
|
-
return
|
|
1988
|
+
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
1989
|
}
|
|
1924
1990
|
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1925
1991
|
const sources = [];
|
|
1926
|
-
const excludedFileKey =
|
|
1992
|
+
const excludedFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(excludedFile);
|
|
1927
1993
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1928
1994
|
if (output.type !== "asset") continue;
|
|
1929
|
-
const file =
|
|
1995
|
+
const file = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1930
1996
|
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1931
|
-
const source =
|
|
1997
|
+
const source = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1932
1998
|
if (source.length > 0) sources.push(source);
|
|
1933
1999
|
}
|
|
1934
2000
|
return sources;
|
|
1935
2001
|
}
|
|
1936
2002
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
1937
|
-
const blocks =
|
|
2003
|
+
const blocks = require_source_candidate_scan_signature.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1938
2004
|
if (blocks.length !== 1) return;
|
|
1939
2005
|
const file = blocks[0]?.file;
|
|
1940
2006
|
return typeof file === "string" && file.length > 0 ? file : void 0;
|
|
@@ -1968,9 +2034,9 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1968
2034
|
let updated = 0;
|
|
1969
2035
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1970
2036
|
if (output.type !== "asset") continue;
|
|
1971
|
-
const file = getAssetFile(bundleFile, output);
|
|
2037
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1972
2038
|
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
1973
|
-
const rawSource = readAssetSource(output);
|
|
2039
|
+
const rawSource = readAssetSource$2(output);
|
|
1974
2040
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
1975
2041
|
if (nextCss === rawSource) continue;
|
|
1976
2042
|
output.source = nextCss;
|
|
@@ -1982,32 +2048,60 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1982
2048
|
return updated;
|
|
1983
2049
|
}
|
|
1984
2050
|
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
1985
|
-
if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" &&
|
|
2051
|
+
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
2052
|
if (options.injectIntoMain === false) return false;
|
|
1987
|
-
const targetFileKey =
|
|
1988
|
-
return
|
|
2053
|
+
const targetFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile);
|
|
2054
|
+
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
2055
|
}
|
|
1990
2056
|
function isRootStyleOutputFile(file) {
|
|
1991
|
-
const normalized =
|
|
2057
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1992
2058
|
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1993
2059
|
}
|
|
2060
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
2061
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2062
|
+
}
|
|
2063
|
+
function shouldPreserveMiniProgramImportShell(opts, file, css) {
|
|
2064
|
+
return (opts.appType === "taro" || opts.appType === "uni-app-vite" || opts.appType === "uni-app-x") && isMiniProgramStyleOutputFile(file) && opts.cssMatcher(file) && require_hmr_timing.isPureLocalCssImportWrapper(css);
|
|
2065
|
+
}
|
|
2066
|
+
function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
2067
|
+
if (opts.appType !== "taro") return;
|
|
2068
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2069
|
+
if (importedStyleFiles.size !== 1) return;
|
|
2070
|
+
const [importedFile] = importedStyleFiles;
|
|
2071
|
+
if (!isRootStyleOutputFile(importedFile)) return;
|
|
2072
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2073
|
+
if (output.type !== "asset") continue;
|
|
2074
|
+
const outputFile = getAssetFile$1(bundleFile, output);
|
|
2075
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
1994
2078
|
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
1995
|
-
const fileKey =
|
|
2079
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2080
|
+
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey)) return false;
|
|
2081
|
+
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
1996
2082
|
if (records.some((record) => {
|
|
1997
2083
|
if (record.injectIntoMain !== true) return false;
|
|
1998
|
-
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" &&
|
|
2084
|
+
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
1999
2085
|
})) return true;
|
|
2000
2086
|
if (records.some((record) => record.injectIntoMain === true)) return false;
|
|
2001
2087
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return true;
|
|
2002
2088
|
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
2003
2089
|
}
|
|
2004
2090
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2091
|
+
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));
|
|
2092
|
+
}
|
|
2093
|
+
function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, assetFiles) {
|
|
2094
|
+
for (const candidate of [record.file, record.outputFile]) {
|
|
2095
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
2096
|
+
const candidateKey = require_source_candidate_scan_signature.normalizeOutputPathKey(candidate);
|
|
2097
|
+
if (!importedStyleFiles.has(candidateKey)) continue;
|
|
2098
|
+
if (assetFiles.has(candidateKey)) return true;
|
|
2099
|
+
}
|
|
2100
|
+
return false;
|
|
2007
2101
|
}
|
|
2008
2102
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2009
2103
|
if (importedCssSources.length === 0) return css;
|
|
2010
|
-
const importedCss = importedCssSources.map((source) =>
|
|
2104
|
+
const importedCss = importedCssSources.map((source) => require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
2011
2105
|
if (importedCss.length === 0) return css;
|
|
2012
2106
|
return (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(importedCss, css);
|
|
2013
2107
|
}
|
|
@@ -2017,9 +2111,9 @@ function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
|
2017
2111
|
const importedSources = [];
|
|
2018
2112
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2019
2113
|
if (output.type !== "asset") continue;
|
|
2020
|
-
const file =
|
|
2114
|
+
const file = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2021
2115
|
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2022
|
-
importedSources.push(readAssetSource(output));
|
|
2116
|
+
importedSources.push(readAssetSource$2(output));
|
|
2023
2117
|
}
|
|
2024
2118
|
return importedSources;
|
|
2025
2119
|
}
|
|
@@ -2027,7 +2121,7 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2027
2121
|
const files = /* @__PURE__ */ new Set();
|
|
2028
2122
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2029
2123
|
if (output.type !== "asset") continue;
|
|
2030
|
-
files.add(
|
|
2124
|
+
files.add(require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2031
2125
|
}
|
|
2032
2126
|
return files;
|
|
2033
2127
|
}
|
|
@@ -2047,17 +2141,22 @@ function isCssImportOnlyBundleAsset(bundle, file, css) {
|
|
|
2047
2141
|
return collectImportedBundleCssSources(bundle, importedStyleFiles).length > 0;
|
|
2048
2142
|
}
|
|
2049
2143
|
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2050
|
-
const resolvedOutputFile =
|
|
2051
|
-
return resolvedOutputFile !==
|
|
2144
|
+
const resolvedOutputFile = require_source_candidate_scan_signature.normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2145
|
+
return resolvedOutputFile !== require_source_candidate_scan_signature.normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2146
|
+
}
|
|
2147
|
+
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2148
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2149
|
+
const outputFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
2150
|
+
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2052
2151
|
}
|
|
2053
2152
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
2054
2153
|
let collected = 0;
|
|
2055
2154
|
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
2056
2155
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2057
2156
|
if (output.type !== "asset") continue;
|
|
2058
|
-
const file = getAssetFile(bundleFile, output);
|
|
2157
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2059
2158
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
2060
|
-
const rawSource = readAssetSource(output);
|
|
2159
|
+
const rawSource = readAssetSource$2(output);
|
|
2061
2160
|
let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2062
2161
|
const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
|
|
2063
2162
|
if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
|
|
@@ -2065,22 +2164,22 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2065
2164
|
options.markCssAssetProcessed?.(output, file);
|
|
2066
2165
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2067
2166
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
2068
|
-
const shouldReplayIntoMainCss = options.opts != null && (options.opts.mainCssChunkMatcher(file, options.opts.appType) ||
|
|
2167
|
+
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
2168
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2070
2169
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2071
2170
|
outputFile: resolvedOutputFile
|
|
2072
2171
|
});
|
|
2073
|
-
if (
|
|
2172
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, nextCss, {
|
|
2074
2173
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2075
2174
|
outputFile: resolvedOutputFile
|
|
2076
2175
|
});
|
|
2077
2176
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2078
|
-
if (
|
|
2177
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(markerFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(file)) continue;
|
|
2079
2178
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2080
2179
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2081
2180
|
outputFile: resolvedOutputFile
|
|
2082
2181
|
});
|
|
2083
|
-
if (
|
|
2182
|
+
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
2183
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2085
2184
|
outputFile: resolvedOutputFile
|
|
2086
2185
|
});
|
|
@@ -2110,25 +2209,48 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2110
2209
|
};
|
|
2111
2210
|
}).filter((record) => record.css.length > 0);
|
|
2112
2211
|
let injected = 0;
|
|
2113
|
-
for (const [bundleFile,
|
|
2212
|
+
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2213
|
+
let output = bundleOutput;
|
|
2114
2214
|
if (output.type !== "asset") continue;
|
|
2115
|
-
|
|
2215
|
+
let file = getAssetFile$1(bundleFile, output);
|
|
2116
2216
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2117
|
-
|
|
2118
|
-
|
|
2217
|
+
let originalSource = readAssetSource$2(output);
|
|
2218
|
+
if (shouldPreserveMiniProgramImportShell(options.opts, file, originalSource)) {
|
|
2219
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options.opts, bundle, file, originalSource);
|
|
2220
|
+
if (typeof importedTargetFile === "string") {
|
|
2221
|
+
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2222
|
+
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];
|
|
2223
|
+
if (importedOutput?.type === "asset") {
|
|
2224
|
+
output = importedOutput;
|
|
2225
|
+
file = importedTargetFile;
|
|
2226
|
+
originalSource = readAssetSource$2(output);
|
|
2227
|
+
} else continue;
|
|
2228
|
+
} else {
|
|
2229
|
+
options.debug?.("preserve mini-program css import shell asset: %s", file);
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2234
|
+
const mainFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2119
2235
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2120
2236
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2121
2237
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2122
2238
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2123
2239
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2240
|
+
const bundleAssetFiles = collectBundleAssetFiles(bundle);
|
|
2241
|
+
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2242
|
+
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2243
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2126
2244
|
for (const record of viteCssResults) {
|
|
2245
|
+
if (!isRootStyleOutputFile(file)) {
|
|
2246
|
+
if (typeof record.outputFile !== "string" || require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2247
|
+
}
|
|
2127
2248
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2128
2249
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2129
|
-
let css =
|
|
2250
|
+
let css = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2130
2251
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2131
2252
|
if (css.length === 0) continue;
|
|
2253
|
+
if ((0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, css) || (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, css).length === 0) continue;
|
|
2132
2254
|
const mergedLayerCss = require_hmr_timing.mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
2133
2255
|
if (mergedLayerCss.merged) {
|
|
2134
2256
|
nextCss = mergedLayerCss.css;
|
|
@@ -2166,13 +2288,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2166
2288
|
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2167
2289
|
for (const record of viteCssResults) {
|
|
2168
2290
|
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2169
|
-
const recordFileKey =
|
|
2291
|
+
const recordFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(record.file);
|
|
2170
2292
|
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2171
2293
|
if (candidateOutput.type !== "asset") continue;
|
|
2172
|
-
const candidateKey =
|
|
2294
|
+
const candidateKey = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2173
2295
|
const isRecordFile = candidateKey === recordFileKey;
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2296
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2297
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(nextCss, candidateSource);
|
|
2298
|
+
if (!isRecordFile && !isProcessedSource || candidateKey === require_source_candidate_scan_signature.normalizeOutputPathKey(file)) continue;
|
|
2176
2299
|
clearAssetSource(candidateOutput);
|
|
2177
2300
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2178
2301
|
}
|
|
@@ -2193,31 +2316,84 @@ function normalizeBundleFileNameKeysForTest(bundle) {
|
|
|
2193
2316
|
}
|
|
2194
2317
|
}
|
|
2195
2318
|
//#endregion
|
|
2319
|
+
//#region src/bundlers/vite/generate-bundle/final-css-assets.ts
|
|
2320
|
+
function readAssetSource$1(output) {
|
|
2321
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
2322
|
+
}
|
|
2323
|
+
function shouldFinalizeMiniProgramCssAsset(source) {
|
|
2324
|
+
return source.includes(":hover") || source.includes("does-not-exist") || (0, _weapp_tailwindcss_postcss.hasMiniProgramCssSpecificityPlaceholders)(source);
|
|
2325
|
+
}
|
|
2326
|
+
async function finalizeMiniProgramCssAssets(bundle, options) {
|
|
2327
|
+
if (options.isWebGeneratorTarget) return 0;
|
|
2328
|
+
let updated = 0;
|
|
2329
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2330
|
+
if (output.type !== "asset") continue;
|
|
2331
|
+
const file = output.fileName || bundleFile;
|
|
2332
|
+
if (!options.cssMatcher(file)) continue;
|
|
2333
|
+
const rawSource = readAssetSource$1(output);
|
|
2334
|
+
if (rawSource.trim().length === 0) continue;
|
|
2335
|
+
if (options.lastCssResultByFile?.has(file)) {
|
|
2336
|
+
const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(rawSource);
|
|
2337
|
+
if (outputCss !== rawSource) {
|
|
2338
|
+
output.source = outputCss;
|
|
2339
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2340
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2341
|
+
options.debug?.("strip mini-program css specificity placeholders: %s bytes=%d", file, outputCss.length);
|
|
2342
|
+
updated++;
|
|
2343
|
+
}
|
|
2344
|
+
continue;
|
|
2345
|
+
}
|
|
2346
|
+
if (!shouldFinalizeMiniProgramCssAsset(rawSource)) continue;
|
|
2347
|
+
const cssHandlerOptions = options.getCssHandlerOptions(file);
|
|
2348
|
+
const { css } = await options.styleHandler(rawSource, {
|
|
2349
|
+
...cssHandlerOptions,
|
|
2350
|
+
autoprefixer: false,
|
|
2351
|
+
cssOptions: {
|
|
2352
|
+
...cssHandlerOptions.cssOptions ?? {},
|
|
2353
|
+
autoprefixer: false,
|
|
2354
|
+
cssPresetEnv: false
|
|
2355
|
+
},
|
|
2356
|
+
cssPresetEnv: false
|
|
2357
|
+
});
|
|
2358
|
+
const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(css);
|
|
2359
|
+
if (outputCss === rawSource) continue;
|
|
2360
|
+
output.source = outputCss;
|
|
2361
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2362
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2363
|
+
options.debug?.("finalize mini-program css asset: %s bytes=%d", file, outputCss.length);
|
|
2364
|
+
updated++;
|
|
2365
|
+
}
|
|
2366
|
+
return updated;
|
|
2367
|
+
}
|
|
2368
|
+
//#endregion
|
|
2196
2369
|
//#region src/bundlers/vite/generate-bundle/memory-debug.ts
|
|
2197
|
-
function toMb(bytes) {
|
|
2370
|
+
function toMb$2(bytes) {
|
|
2198
2371
|
return Math.round(bytes / 1024 / 1024);
|
|
2199
2372
|
}
|
|
2200
|
-
function summarizeStringMapCache(map) {
|
|
2373
|
+
function summarizeStringMapCache$1(map) {
|
|
2201
2374
|
let bytes = 0;
|
|
2202
2375
|
for (const value of map.values()) bytes += value.length;
|
|
2203
2376
|
return {
|
|
2204
2377
|
bytes,
|
|
2205
|
-
mb: toMb(bytes),
|
|
2378
|
+
mb: toMb$2(bytes),
|
|
2206
2379
|
size: map.size
|
|
2207
2380
|
};
|
|
2208
2381
|
}
|
|
2209
2382
|
function resolveViteMemoryDebugStats(context) {
|
|
2210
2383
|
if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2211
2384
|
const memory = node_process.default.memoryUsage();
|
|
2385
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
2386
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
2212
2387
|
return {
|
|
2213
2388
|
phase: context.phase,
|
|
2214
2389
|
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2390
|
+
bundle: { hasOmittedKnownFiles: context.hasOmittedKnownFiles },
|
|
2215
2391
|
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)
|
|
2392
|
+
rssMb: toMb$2(memory.rss),
|
|
2393
|
+
heapTotalMb: toMb$2(memory.heapTotal),
|
|
2394
|
+
heapUsedMb: toMb$2(memory.heapUsed),
|
|
2395
|
+
externalMb: toMb$2(memory.external),
|
|
2396
|
+
arrayBuffersMb: toMb$2(memory.arrayBuffers)
|
|
2221
2397
|
},
|
|
2222
2398
|
runtime: {
|
|
2223
2399
|
sourceCandidates: context.sourceCandidatesSize,
|
|
@@ -2226,19 +2402,21 @@ function resolveViteMemoryDebugStats(context) {
|
|
|
2226
2402
|
generatorRuntime: context.generatorRuntimeSize
|
|
2227
2403
|
},
|
|
2228
2404
|
processCache: {
|
|
2229
|
-
instance:
|
|
2230
|
-
hashMap:
|
|
2405
|
+
instance: processCacheInstanceSize,
|
|
2406
|
+
hashMap: processCacheHashMapSize,
|
|
2231
2407
|
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2232
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
2408
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
2409
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
2410
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
2411
|
+
pruned: context.processCachePruned,
|
|
2412
|
+
pruneSkipped: !context.processCachePruned,
|
|
2413
|
+
...context.processCachePruneSkipReason ? { pruneSkipReason: context.processCachePruneSkipReason } : {}
|
|
2233
2414
|
},
|
|
2234
2415
|
viteCss: {
|
|
2235
2416
|
...context.getViteCssCacheStats?.(),
|
|
2236
|
-
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2417
|
+
lastCssResultByFile: summarizeStringMapCache$1(context.lastCssResultByFile)
|
|
2237
2418
|
},
|
|
2238
|
-
tailwind: {
|
|
2239
|
-
v3: require_v3_engine.getTailwindV3IncrementalGenerateCacheStats(),
|
|
2240
|
-
v4: require_v3_engine.getTailwindV4IncrementalGenerateCacheStats()
|
|
2241
|
-
}
|
|
2419
|
+
tailwind: { v4: require_v4_engine.getTailwindV4IncrementalGenerateCacheStats() }
|
|
2242
2420
|
};
|
|
2243
2421
|
}
|
|
2244
2422
|
//#endregion
|
|
@@ -2287,12 +2465,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2287
2465
|
if (isHarmonyAppStyleTarget && applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2288
2466
|
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2289
2467
|
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2290
|
-
const generated = await
|
|
2468
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
2291
2469
|
opts,
|
|
2292
2470
|
runtimeState,
|
|
2293
2471
|
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2294
2472
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2295
2473
|
file: outputFile,
|
|
2474
|
+
outputFile,
|
|
2296
2475
|
cssHandlerOptions,
|
|
2297
2476
|
cssUserHandlerOptions: {
|
|
2298
2477
|
...cssHandlerOptions,
|
|
@@ -2323,13 +2502,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2323
2502
|
//#endregion
|
|
2324
2503
|
//#region src/bundlers/vite/generate-bundle/vite-css-cache.ts
|
|
2325
2504
|
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2326
|
-
function resolveViteCssTaskConcurrency(
|
|
2505
|
+
function resolveViteCssTaskConcurrency(_useIncrementalMode, _majorVersion) {
|
|
2327
2506
|
const configured = Number.parseInt(node_process.default.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2328
2507
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2329
|
-
return
|
|
2508
|
+
return 1;
|
|
2330
2509
|
}
|
|
2331
2510
|
function normalizeViteCssCacheKey(file) {
|
|
2332
|
-
return
|
|
2511
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2333
2512
|
}
|
|
2334
2513
|
function rememberLastCssResult(resultByFile, sourceHashByFile, file, css, sourceHash) {
|
|
2335
2514
|
const key = normalizeViteCssCacheKey(file);
|
|
@@ -2367,10 +2546,83 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2367
2546
|
}
|
|
2368
2547
|
//#endregion
|
|
2369
2548
|
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
2549
|
+
function readAssetSource(asset) {
|
|
2550
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2551
|
+
}
|
|
2552
|
+
function getAssetFile(bundleFile, asset) {
|
|
2553
|
+
return asset.fileName || bundleFile;
|
|
2554
|
+
}
|
|
2555
|
+
function isRootMiniProgramStyleOutputFile$1(file) {
|
|
2556
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2557
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
2558
|
+
}
|
|
2559
|
+
function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
2560
|
+
const normalizedTargetFile = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
2561
|
+
const normalizedImportedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
2562
|
+
const targetDir = node_path.default.posix.dirname(normalizedTargetFile);
|
|
2563
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
2564
|
+
const relative = node_path.default.posix.relative(baseDir, normalizedImportedFile);
|
|
2565
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2566
|
+
}
|
|
2567
|
+
function createCssImportShell$1(targetFile, importedFile) {
|
|
2568
|
+
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
2569
|
+
}
|
|
2570
|
+
function resolveRootMiniProgramOriginStyleFile(file) {
|
|
2571
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2572
|
+
if (!isRootMiniProgramStyleOutputFile$1(normalized)) return;
|
|
2573
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
2574
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
2575
|
+
}
|
|
2576
|
+
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
2577
|
+
let importedFile;
|
|
2578
|
+
try {
|
|
2579
|
+
_weapp_tailwindcss_postcss.postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
2580
|
+
if (importedFile !== void 0) return;
|
|
2581
|
+
const request = require_v4_engine.parseImportRequest(atRule.params);
|
|
2582
|
+
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
2583
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
2584
|
+
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
2585
|
+
const targetDir = node_path.default.posix.dirname(require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile));
|
|
2586
|
+
importedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2587
|
+
});
|
|
2588
|
+
} catch {}
|
|
2589
|
+
return importedFile;
|
|
2590
|
+
}
|
|
2591
|
+
function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
2592
|
+
if (options.appType !== "taro") return 0;
|
|
2593
|
+
let updated = 0;
|
|
2594
|
+
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
2595
|
+
if (rootOutput.type !== "asset") continue;
|
|
2596
|
+
const rootFile = getAssetFile(rootBundleFile, rootOutput);
|
|
2597
|
+
if (!isRootMiniProgramStyleOutputFile$1(rootFile) || !options.cssMatcher(rootFile)) continue;
|
|
2598
|
+
const originFile = resolveRootMiniProgramOriginStyleFile(rootFile);
|
|
2599
|
+
if (!originFile || !options.cssMatcher(originFile)) continue;
|
|
2600
|
+
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];
|
|
2601
|
+
if (originOutput?.type !== "asset") continue;
|
|
2602
|
+
const rootSource = readAssetSource(rootOutput);
|
|
2603
|
+
if (require_hmr_timing.isPureLocalCssImportWrapper(rootSource)) continue;
|
|
2604
|
+
const originSource = readAssetSource(originOutput);
|
|
2605
|
+
if (require_hmr_timing.isPureLocalCssImportWrapper(originSource)) {
|
|
2606
|
+
const importedFile = resolveSingleCssImportOutputFile(originFile, originSource);
|
|
2607
|
+
if (importedFile && require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(rootFile)) continue;
|
|
2608
|
+
} else if (originSource.trim().length > 0 && originSource.trim() !== rootSource.trim()) continue;
|
|
2609
|
+
const nextRootSource = createCssImportShell$1(rootFile, originFile);
|
|
2610
|
+
if (rootSource === nextRootSource) continue;
|
|
2611
|
+
rootOutput.source = nextRootSource;
|
|
2612
|
+
originOutput.source = rootSource;
|
|
2613
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2614
|
+
options.recordCssAssetResult?.(originFile, rootSource);
|
|
2615
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2616
|
+
options.onUpdate?.(originFile, originSource, rootSource);
|
|
2617
|
+
options.debug("normalize taro root css import shell: %s -> %s", rootFile, originFile);
|
|
2618
|
+
updated++;
|
|
2619
|
+
}
|
|
2620
|
+
return updated;
|
|
2621
|
+
}
|
|
2370
2622
|
async function finalizeGenerateBundle(options) {
|
|
2371
2623
|
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;
|
|
2372
2624
|
if (cssTaskFactories.length > 0) {
|
|
2373
|
-
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2625
|
+
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion);
|
|
2374
2626
|
tasks.push(require_hmr_timing.runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2375
2627
|
}
|
|
2376
2628
|
const tasksStart = performance.now();
|
|
@@ -2408,9 +2660,10 @@ async function finalizeGenerateBundle(options) {
|
|
|
2408
2660
|
getViteProcessedCssAssetResults,
|
|
2409
2661
|
markCssAssetProcessed,
|
|
2410
2662
|
recordCssAssetResult,
|
|
2411
|
-
shouldRemoveInjectedSourceAsset: (
|
|
2412
|
-
if (record.injectIntoMain
|
|
2413
|
-
|
|
2663
|
+
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2664
|
+
if (record.injectIntoMain === false) return false;
|
|
2665
|
+
const targetFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile);
|
|
2666
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(record.file) !== targetFileKey;
|
|
2414
2667
|
},
|
|
2415
2668
|
debug,
|
|
2416
2669
|
onUpdate
|
|
@@ -2421,6 +2674,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2421
2674
|
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
2675
|
syncViteProcessedCssIntoMainCssAssets();
|
|
2423
2676
|
}
|
|
2677
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
2678
|
+
appType: opts.appType,
|
|
2679
|
+
cssMatcher: opts.cssMatcher,
|
|
2680
|
+
debug,
|
|
2681
|
+
onUpdate,
|
|
2682
|
+
recordCssAssetResult
|
|
2683
|
+
});
|
|
2424
2684
|
normalizeBundleFileNameKeysForTest(bundle);
|
|
2425
2685
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2426
2686
|
cssMatcher: opts.cssMatcher,
|
|
@@ -2430,18 +2690,33 @@ async function finalizeGenerateBundle(options) {
|
|
|
2430
2690
|
recordCssAssetResult,
|
|
2431
2691
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2432
2692
|
});
|
|
2693
|
+
await finalizeMiniProgramCssAssets(bundle, {
|
|
2694
|
+
cssMatcher: opts.cssMatcher,
|
|
2695
|
+
debug,
|
|
2696
|
+
getCssHandlerOptions,
|
|
2697
|
+
isWebGeneratorTarget,
|
|
2698
|
+
lastCssResultByFile,
|
|
2699
|
+
onUpdate,
|
|
2700
|
+
recordCssAssetResult,
|
|
2701
|
+
styleHandler
|
|
2702
|
+
});
|
|
2433
2703
|
const stateUpdateStart = performance.now();
|
|
2434
|
-
|
|
2704
|
+
require_source_candidate_scan_signature.updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2435
2705
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2436
|
-
|
|
2706
|
+
const shouldPruneTransientCaches = !snapshot.hasOmittedKnownFiles;
|
|
2707
|
+
const processCachePruned = useIncrementalMode && shouldPruneTransientCaches && typeof cache.prune === "function";
|
|
2708
|
+
const processCachePruneSkipReason = processCachePruned ? void 0 : !useIncrementalMode ? "full-mode" : !shouldPruneTransientCaches ? "omitted-known-files" : "cache-prune-unavailable";
|
|
2709
|
+
if (processCachePruned) cache.prune?.({
|
|
2437
2710
|
cacheKeys: activeProcessCacheKeys,
|
|
2438
2711
|
hashKeys: activeProcessHashKeys
|
|
2439
2712
|
});
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2713
|
+
if (shouldPruneTransientCaches) {
|
|
2714
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2715
|
+
pruneViteCssCaches?.({
|
|
2716
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2717
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2445
2720
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2446
2721
|
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
2722
|
if (hmrTimingRecorder) {
|
|
@@ -2453,8 +2728,11 @@ async function finalizeGenerateBundle(options) {
|
|
|
2453
2728
|
cache,
|
|
2454
2729
|
generatorRuntimeSize: generatorRuntime.size,
|
|
2455
2730
|
getViteCssCacheStats,
|
|
2731
|
+
hasOmittedKnownFiles: snapshot.hasOmittedKnownFiles,
|
|
2456
2732
|
lastCssResultByFile,
|
|
2457
2733
|
phase: "generateBundle",
|
|
2734
|
+
processCachePruned,
|
|
2735
|
+
processCachePruneSkipReason,
|
|
2458
2736
|
runtimeSize: runtime.size,
|
|
2459
2737
|
sourceCandidatesSize: sourceCandidates.size,
|
|
2460
2738
|
transformRuntimeSize: transformRuntime.size,
|
|
@@ -2470,8 +2748,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
2470
2748
|
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
2471
2749
|
function createJsEntryResolver(jsEntries) {
|
|
2472
2750
|
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
2473
|
-
for (const [id, entry] of jsEntries) normalizedJsEntries.set(
|
|
2474
|
-
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(
|
|
2751
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
|
|
2752
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
|
|
2475
2753
|
}
|
|
2476
2754
|
//#endregion
|
|
2477
2755
|
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
@@ -2481,6 +2759,7 @@ function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
|
2481
2759
|
function createJsHandlerOptionsFactory(options) {
|
|
2482
2760
|
return (absoluteFilename, extra) => ({
|
|
2483
2761
|
...extra,
|
|
2762
|
+
generateMap: false,
|
|
2484
2763
|
filename: absoluteFilename,
|
|
2485
2764
|
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
2486
2765
|
moduleGraph: options.moduleGraph,
|
|
@@ -2505,7 +2784,7 @@ function createLinkedUpdateHelpers(options) {
|
|
|
2505
2784
|
});
|
|
2506
2785
|
};
|
|
2507
2786
|
const applyLinkedUpdates = (linked) => {
|
|
2508
|
-
|
|
2787
|
+
require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
2509
2788
|
};
|
|
2510
2789
|
return {
|
|
2511
2790
|
applyLinkedUpdates,
|
|
@@ -2520,54 +2799,6 @@ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
|
2520
2799
|
}
|
|
2521
2800
|
}
|
|
2522
2801
|
//#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
2802
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2572
2803
|
function processJsBundleEntry(options) {
|
|
2573
2804
|
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
@@ -2580,16 +2811,26 @@ function processJsBundleEntry(options) {
|
|
|
2580
2811
|
const initialRawSource = originalEntrySource;
|
|
2581
2812
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2582
2813
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2814
|
+
const hashSalt = require_source_candidate_scan_signature.createJsHashSalt(runtimeSignature, useIncrementalMode ? require_source_candidate_scan_signature.createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2815
|
+
const hashKey = `${file}:js`;
|
|
2816
|
+
const processHash = `${require_source_candidate_scan_signature.getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`;
|
|
2817
|
+
rememberProcessCacheKey(file, hashKey);
|
|
2818
|
+
if (useIncrementalMode && !shouldTransformJs) {
|
|
2819
|
+
const cachedCode = cache.getHashValue(hashKey)?.hash === processHash ? cache.get(file) : void 0;
|
|
2820
|
+
if (cachedCode !== void 0) {
|
|
2821
|
+
originalSource.code = cachedCode;
|
|
2822
|
+
metrics.js.cacheHits++;
|
|
2823
|
+
debug("js direct replay hit: %s", file);
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2583
2827
|
jsTaskFactories.push(async () => {
|
|
2584
2828
|
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
2829
|
await require_hmr_timing.processCachedTask({
|
|
2589
2830
|
cache,
|
|
2590
2831
|
cacheKey: file,
|
|
2591
2832
|
hashKey,
|
|
2592
|
-
hash:
|
|
2833
|
+
hash: processHash,
|
|
2593
2834
|
applyResult(source) {
|
|
2594
2835
|
originalSource.code = source;
|
|
2595
2836
|
},
|
|
@@ -2602,7 +2843,7 @@ function processJsBundleEntry(options) {
|
|
|
2602
2843
|
const rawSource = originalSource.code;
|
|
2603
2844
|
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
2604
2845
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2605
|
-
if (!disableJsPrecheck &&
|
|
2846
|
+
if (!disableJsPrecheck && require_context.shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2606
2847
|
metrics.js.elapsed += measureElapsed(start);
|
|
2607
2848
|
metrics.js.transformed++;
|
|
2608
2849
|
return { result: rawSource };
|
|
@@ -2631,7 +2872,7 @@ function processJsBundleEntry(options) {
|
|
|
2631
2872
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2632
2873
|
cache,
|
|
2633
2874
|
hashKey: uniAppXJsHashKey,
|
|
2634
|
-
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2875
|
+
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
2876
|
createHandlerOptions,
|
|
2636
2877
|
debug,
|
|
2637
2878
|
getAssetSource: createUniAppXBundleAssetSourceGetter(bundle),
|
|
@@ -2659,7 +2900,7 @@ function processJsBundleEntry(options) {
|
|
|
2659
2900
|
sourceType: "unambiguous"
|
|
2660
2901
|
}
|
|
2661
2902
|
});
|
|
2662
|
-
if (!disableJsPrecheck &&
|
|
2903
|
+
if (!disableJsPrecheck && require_context.shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
2663
2904
|
metrics.js.elapsed += measureElapsed(start);
|
|
2664
2905
|
metrics.js.transformed++;
|
|
2665
2906
|
return;
|
|
@@ -2689,13 +2930,13 @@ function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffe
|
|
|
2689
2930
|
return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
|
|
2690
2931
|
}
|
|
2691
2932
|
function normalizeRememberedSourceIdentity(file) {
|
|
2692
|
-
return
|
|
2933
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2693
2934
|
}
|
|
2694
2935
|
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
2695
2936
|
if (!sources) return [];
|
|
2696
2937
|
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
2697
2938
|
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
2698
|
-
const markerFiles = new Set(
|
|
2939
|
+
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
2940
|
if (markerFiles.size > 0) {
|
|
2700
2941
|
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeRememberedSourceIdentity(remembered.sourceFile)));
|
|
2701
2942
|
if (markerMatched.length > 0) return markerMatched;
|
|
@@ -2707,9 +2948,9 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
|
|
|
2707
2948
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
2708
2949
|
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeRememberedSourceIdentity(remembered.sourceFile) === normalizeRememberedSourceIdentity(originalFile)));
|
|
2709
2950
|
if (sourceMatched.length > 0) return sourceMatched;
|
|
2710
|
-
const outputMatched = rememberedSources.filter((remembered) =>
|
|
2951
|
+
const outputMatched = rememberedSources.filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile));
|
|
2711
2952
|
if (outputMatched.length > 0) return outputMatched;
|
|
2712
|
-
if (!
|
|
2953
|
+
if (!require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
|
|
2713
2954
|
const scoredMatches = rememberedSources.map((remembered) => ({
|
|
2714
2955
|
remembered,
|
|
2715
2956
|
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
@@ -2736,7 +2977,7 @@ function mergeRememberedCssSources(sources, outputFile) {
|
|
|
2736
2977
|
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
2737
2978
|
const groups = /* @__PURE__ */ new Map();
|
|
2738
2979
|
for (const [key, remembered] of sources ?? []) {
|
|
2739
|
-
const outputKey =
|
|
2980
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles));
|
|
2740
2981
|
const group = groups.get(outputKey) ?? [];
|
|
2741
2982
|
group.push({
|
|
2742
2983
|
key,
|
|
@@ -2747,40 +2988,17 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
2747
2988
|
return groups;
|
|
2748
2989
|
}
|
|
2749
2990
|
//#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
2991
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
2776
2992
|
async function processRememberedCssReplay(options) {
|
|
2777
2993
|
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
2994
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
2779
2995
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2996
|
+
if (require_source_candidate_scan_signature.isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
2780
2997
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2781
2998
|
key: item.key,
|
|
2782
2999
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2783
3000
|
})));
|
|
3001
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2784
3002
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2785
3003
|
if (!rememberedCssSource) continue;
|
|
2786
3004
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
@@ -2793,33 +3011,33 @@ async function processRememberedCssReplay(options) {
|
|
|
2793
3011
|
};
|
|
2794
3012
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2795
3013
|
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
3014
|
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, rawSource, sourceFile);
|
|
2802
|
-
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
3015
|
+
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
3016
|
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
2804
|
-
majorVersion: runtimeState.
|
|
3017
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
2805
3018
|
}));
|
|
2806
|
-
const cssRuntimeAffectingHash = cache.computeHash(
|
|
3019
|
+
const cssRuntimeAffectingHash = cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2807
3020
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2808
3021
|
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2809
|
-
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2810
3022
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2811
3023
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3024
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3025
|
+
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
3026
|
+
opts,
|
|
3027
|
+
tokenSources: sourceTraceTokenSources
|
|
3028
|
+
});
|
|
2812
3029
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
2813
3030
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
2814
3031
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
2815
3032
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2816
3033
|
const start = performance.now();
|
|
2817
|
-
const generated = await
|
|
3034
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
2818
3035
|
opts,
|
|
2819
3036
|
runtimeState,
|
|
2820
3037
|
runtime: scopedGeneratorRuntime,
|
|
2821
3038
|
rawSource,
|
|
2822
3039
|
file: sourceFile,
|
|
3040
|
+
outputFile,
|
|
2823
3041
|
cssHandlerOptions,
|
|
2824
3042
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2825
3043
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
@@ -2890,7 +3108,7 @@ function collectJsImportedCssFiles(snapshot) {
|
|
|
2890
3108
|
let match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2891
3109
|
while (match !== null) {
|
|
2892
3110
|
const request = match[1];
|
|
2893
|
-
if (request?.startsWith(".")) files.add(
|
|
3111
|
+
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
3112
|
match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2895
3113
|
}
|
|
2896
3114
|
}
|
|
@@ -2911,11 +3129,43 @@ function intersectCandidateSourceMaps(left, right) {
|
|
|
2911
3129
|
for (const [candidate, sources] of left) if (right.has(candidate)) matched.set(candidate, sources);
|
|
2912
3130
|
return matched;
|
|
2913
3131
|
}
|
|
3132
|
+
function normalizeSourceFile(file) {
|
|
3133
|
+
return node_path.default.resolve(file.replace(/[?#].*$/, ""));
|
|
3134
|
+
}
|
|
3135
|
+
function resolveSubpackageSourceRootFromFile(file, subpackageRoot) {
|
|
3136
|
+
const normalizedFile = normalizeSourceFile(file).split(node_path.default.sep).join("/");
|
|
3137
|
+
const normalizedRoot = subpackageRoot.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
3138
|
+
if (!normalizedRoot) return;
|
|
3139
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
3140
|
+
const rootIndex = normalizedFile.lastIndexOf(rootSegment);
|
|
3141
|
+
if (rootIndex < 0) return;
|
|
3142
|
+
return normalizedFile.slice(0, rootIndex);
|
|
3143
|
+
}
|
|
3144
|
+
function collectSubpackageSourceRootsFromCssSources(cssSourceFiles, subpackageRoots) {
|
|
3145
|
+
const sourceRootsByPackageRoot = /* @__PURE__ */ new Map();
|
|
3146
|
+
if (!cssSourceFiles || !subpackageRoots) return sourceRootsByPackageRoot;
|
|
3147
|
+
for (const file of cssSourceFiles) {
|
|
3148
|
+
if (typeof file !== "string" || file.length === 0) continue;
|
|
3149
|
+
for (const root of subpackageRoots) {
|
|
3150
|
+
const sourceRoot = resolveSubpackageSourceRootFromFile(file, root);
|
|
3151
|
+
if (!sourceRoot) continue;
|
|
3152
|
+
const roots = sourceRootsByPackageRoot.get(root) ?? /* @__PURE__ */ new Set();
|
|
3153
|
+
roots.add(sourceRoot);
|
|
3154
|
+
sourceRootsByPackageRoot.set(root, roots);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
return sourceRootsByPackageRoot;
|
|
3158
|
+
}
|
|
3159
|
+
function flattenSourceRoots(sourceRootsByPackageRoot) {
|
|
3160
|
+
return [...new Set([...sourceRootsByPackageRoot.values()].flatMap((roots) => [...roots]))];
|
|
3161
|
+
}
|
|
2914
3162
|
function createSubpackageSourceCandidateScope(options) {
|
|
3163
|
+
const cssSourceRootsByPackageRoot = collectSubpackageSourceRootsFromCssSources(options.cssSourceFiles, options.subpackageRoots);
|
|
2915
3164
|
const subpackageSourceExcludeEntries = options.subpackageRoots ? collectMiniProgramSubpackageSourceEntries(options.snapshot, options.subpackageRoots, [
|
|
2916
3165
|
options.rootDir,
|
|
2917
3166
|
options.tailwindcssBasedir,
|
|
2918
|
-
options.projectRoot
|
|
3167
|
+
options.projectRoot,
|
|
3168
|
+
...flattenSourceRoots(cssSourceRootsByPackageRoot)
|
|
2919
3169
|
]) : [];
|
|
2920
3170
|
const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
|
|
2921
3171
|
const resolveSubpackageOutputSourceEntries = (outputFile) => {
|
|
@@ -2924,6 +3174,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2924
3174
|
if (matchedRoots.length !== 1) return;
|
|
2925
3175
|
const root = matchedRoots[0];
|
|
2926
3176
|
if (!root) return;
|
|
3177
|
+
const configuredSourceRoots = cssSourceRootsByPackageRoot.get(root);
|
|
3178
|
+
if (configuredSourceRoots?.size === 1) return [{
|
|
3179
|
+
base: [...configuredSourceRoots][0],
|
|
3180
|
+
negated: false,
|
|
3181
|
+
pattern: `${root}/**/*`
|
|
3182
|
+
}];
|
|
2927
3183
|
return options.sourceRoot ? [{
|
|
2928
3184
|
base: options.sourceRoot,
|
|
2929
3185
|
negated: false,
|
|
@@ -2975,7 +3231,7 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2975
3231
|
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2976
3232
|
}) ?? /* @__PURE__ */ new Map();
|
|
2977
3233
|
};
|
|
2978
|
-
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
3234
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
2979
3235
|
return {
|
|
2980
3236
|
createScopedSourceCandidateGetter,
|
|
2981
3237
|
createScopedSourceCandidateSourceGetter,
|
|
@@ -2998,7 +3254,18 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
2998
3254
|
//#endregion
|
|
2999
3255
|
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
3000
3256
|
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
3001
|
-
|
|
3257
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3258
|
+
if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3259
|
+
appType: opts.appType,
|
|
3260
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3261
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
3262
|
+
uniUtsPlatform
|
|
3263
|
+
}), {
|
|
3264
|
+
appType: opts.appType,
|
|
3265
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3266
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
3267
|
+
uniUtsPlatform
|
|
3268
|
+
})) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
|
|
3002
3269
|
return {
|
|
3003
3270
|
uniAppX: true,
|
|
3004
3271
|
uniAppXCssTarget: "uvue",
|
|
@@ -3033,12 +3300,12 @@ function collectChunkModuleIds(chunk) {
|
|
|
3033
3300
|
return ids;
|
|
3034
3301
|
}
|
|
3035
3302
|
function resolveSourceRootFromChunk(root, fileName, chunk) {
|
|
3036
|
-
const outputBase = stripFileExtension(
|
|
3303
|
+
const outputBase = stripFileExtension(require_source_candidate_scan_signature.normalizeOutputPathKey(fileName));
|
|
3037
3304
|
if (!outputBase.includes("/")) return;
|
|
3038
3305
|
for (const id of collectChunkModuleIds(chunk)) {
|
|
3039
3306
|
if (!isUsefulModuleId(id)) continue;
|
|
3040
3307
|
const cleanId = id.replace(/[?#].*$/, "");
|
|
3041
|
-
const relativeModule =
|
|
3308
|
+
const relativeModule = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.relative(root, cleanId));
|
|
3042
3309
|
if (relativeModule.length === 0 || relativeModule === "." || relativeModule.startsWith("../") || node_path.default.isAbsolute(relativeModule)) continue;
|
|
3043
3310
|
const moduleBase = stripFileExtension(relativeModule);
|
|
3044
3311
|
if (!moduleBase.endsWith(outputBase)) continue;
|
|
@@ -3061,8 +3328,34 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3061
3328
|
}
|
|
3062
3329
|
//#endregion
|
|
3063
3330
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
3331
|
+
function isRootMiniProgramStyleOutputFile(file) {
|
|
3332
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3333
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
3334
|
+
}
|
|
3335
|
+
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
3336
|
+
const normalizedTargetFile = require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
3337
|
+
const normalizedImportedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
3338
|
+
const targetDir = node_path.default.posix.dirname(normalizedTargetFile);
|
|
3339
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
3340
|
+
const relative = node_path.default.posix.relative(baseDir, normalizedImportedFile);
|
|
3341
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
3342
|
+
}
|
|
3343
|
+
function createCssImportShell(targetFile, importedFile) {
|
|
3344
|
+
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
3345
|
+
}
|
|
3346
|
+
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
3347
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3348
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
3349
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
3350
|
+
}
|
|
3351
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
3352
|
+
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
3353
|
+
}
|
|
3354
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
3355
|
+
return appType === "taro";
|
|
3356
|
+
}
|
|
3064
3357
|
function createGenerateBundleHook(context) {
|
|
3065
|
-
const state =
|
|
3358
|
+
const state = require_source_candidate_scan_signature.createBundleBuildState();
|
|
3066
3359
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
3067
3360
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
3068
3361
|
let currentOutDir;
|
|
@@ -3070,7 +3363,7 @@ function createGenerateBundleHook(context) {
|
|
|
3070
3363
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
3071
3364
|
getAppType: () => context.opts.appType,
|
|
3072
3365
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
3073
|
-
getMajorVersion: () => context.runtimeState.
|
|
3366
|
+
getMajorVersion: () => context.runtimeState.tailwindRuntime.majorVersion,
|
|
3074
3367
|
getOutputRoot: () => currentOutDir,
|
|
3075
3368
|
getExtraOptions: (file) => ({
|
|
3076
3369
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -3087,15 +3380,27 @@ function createGenerateBundleHook(context) {
|
|
|
3087
3380
|
};
|
|
3088
3381
|
const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
|
|
3089
3382
|
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
3383
|
const resolvedConfig = getResolvedConfig();
|
|
3093
3384
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3385
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3386
|
+
appType: opts.appType,
|
|
3387
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3388
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3389
|
+
uniAppX,
|
|
3390
|
+
uniUtsPlatform
|
|
3391
|
+
}), {
|
|
3392
|
+
appType: opts.appType,
|
|
3393
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3394
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3395
|
+
uniAppX,
|
|
3396
|
+
uniUtsPlatform
|
|
3397
|
+
});
|
|
3398
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3094
3399
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp;
|
|
3095
3400
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3096
3401
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3097
3402
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3098
|
-
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget
|
|
3403
|
+
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3099
3404
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
3100
3405
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
3101
3406
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -3104,7 +3409,7 @@ function createGenerateBundleHook(context) {
|
|
|
3104
3409
|
await runtimeState.readyPromise;
|
|
3105
3410
|
debug("start");
|
|
3106
3411
|
onStart();
|
|
3107
|
-
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" &&
|
|
3412
|
+
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" && require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(output.source)).map(([file]) => file));
|
|
3108
3413
|
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
3109
3414
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
3110
3415
|
collectViteProcessedCssAssetResults(bundle, {
|
|
@@ -3128,18 +3433,144 @@ function createGenerateBundleHook(context) {
|
|
|
3128
3433
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
3129
3434
|
const bundleFiles = Object.keys(bundle);
|
|
3130
3435
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
3131
|
-
const
|
|
3436
|
+
const getConfiguredTailwindV4CssSourceEntries = () => collectConfiguredTailwindV4CssSourceEntries({
|
|
3437
|
+
...opts,
|
|
3438
|
+
tailwindcssRuntimeOptions: {
|
|
3439
|
+
...opts.tailwindcssRuntimeOptions ?? {},
|
|
3440
|
+
tailwindcss: {
|
|
3441
|
+
...require_v4_engine.resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions) ?? {},
|
|
3442
|
+
...require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options) ?? {}
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}, opts.tailwindcssBasedir ?? rootDir);
|
|
3446
|
+
const collectTailwindV4SourceFingerprint = (source) => {
|
|
3447
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3448
|
+
const add = (prefix, value) => {
|
|
3449
|
+
const normalized = value?.trim();
|
|
3450
|
+
if (normalized) tokens.add(`${prefix}:${normalized}`);
|
|
3451
|
+
};
|
|
3452
|
+
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3453
|
+
const configRequest = match[2] ?? "";
|
|
3454
|
+
add("config", node_path.default.basename(configRequest));
|
|
3455
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3456
|
+
}
|
|
3457
|
+
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3458
|
+
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3459
|
+
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3460
|
+
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3461
|
+
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3462
|
+
return tokens;
|
|
3463
|
+
};
|
|
3464
|
+
const scoreConfiguredTailwindV4SourceForRawSource = (rawSource, entrySource) => {
|
|
3465
|
+
if (!rawSource) return 0;
|
|
3466
|
+
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3467
|
+
if (rawTokens.size === 0) return 0;
|
|
3468
|
+
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3469
|
+
let score = 0;
|
|
3470
|
+
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3471
|
+
return score;
|
|
3472
|
+
};
|
|
3473
|
+
const selectTailwindV4GenerationCssSourceForOutput = (outputFile, entries, rawSource) => {
|
|
3474
|
+
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3475
|
+
if (generationSources.length <= 1) return generationSources[0];
|
|
3476
|
+
const selectByRawSourceFingerprint = (candidates) => {
|
|
3477
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3478
|
+
entry,
|
|
3479
|
+
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3480
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3481
|
+
const bestScore = scoredSources[0]?.score;
|
|
3482
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3483
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3484
|
+
};
|
|
3485
|
+
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3486
|
+
if (rawSourceMatched) return rawSourceMatched;
|
|
3487
|
+
const scopedSources = currentSubpackageRoots ? generationSources.filter((entry) => {
|
|
3488
|
+
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, currentSubpackageRoots);
|
|
3489
|
+
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, currentSubpackageRoots);
|
|
3490
|
+
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3491
|
+
return sourceMatchesSubpackage && [...currentSubpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3492
|
+
}) : generationSources;
|
|
3493
|
+
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3494
|
+
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3495
|
+
if (candidates.length === 1) return candidates[0];
|
|
3496
|
+
return selectByRawSourceFingerprint(candidates);
|
|
3497
|
+
};
|
|
3498
|
+
const resolveSubpackageRootForFile = (file) => {
|
|
3499
|
+
if (!file || !currentSubpackageRoots) return;
|
|
3500
|
+
return [...currentSubpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3501
|
+
};
|
|
3502
|
+
const isSameSubpackageScope = (outputFile, sourceFile) => {
|
|
3503
|
+
return resolveSubpackageRootForFile(outputFile) === resolveSubpackageRootForFile(sourceFile);
|
|
3504
|
+
};
|
|
3505
|
+
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
3506
|
+
const normalizeSourceCandidatePathKey = (file) => require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve(file));
|
|
3507
|
+
const resolveCurrentSourceCandidateSource = (file) => {
|
|
3508
|
+
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
3509
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(cleanedFile);
|
|
3510
|
+
const absoluteFile = node_path.default.isAbsolute(cleanedFile) ? cleanedFile : node_path.default.resolve(rootDir, cleanedFile);
|
|
3511
|
+
const relativeFromOutDir = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.relative(outDir, absoluteFile));
|
|
3512
|
+
const sourceCandidates = [
|
|
3513
|
+
sourceRoot ? node_path.default.resolve(sourceRoot, file) : void 0,
|
|
3514
|
+
node_path.default.resolve(rootDir, file),
|
|
3515
|
+
node_path.default.resolve(node_path.default.dirname(outDir), file),
|
|
3516
|
+
node_path.default.resolve(outDir, file),
|
|
3517
|
+
!node_path.default.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? node_path.default.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3518
|
+
!node_path.default.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? node_path.default.resolve(node_path.default.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3519
|
+
file
|
|
3520
|
+
];
|
|
3521
|
+
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3522
|
+
if (source || !candidate) return source;
|
|
3523
|
+
return getSourceCandidateSource?.(candidate);
|
|
3524
|
+
}, void 0);
|
|
3525
|
+
if (explicitSource) return explicitSource;
|
|
3526
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3527
|
+
absolute: node_path.default.isAbsolute(candidate),
|
|
3528
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
3529
|
+
}));
|
|
3530
|
+
let bestSource;
|
|
3531
|
+
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3532
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3533
|
+
let score = 0;
|
|
3534
|
+
for (const candidate of normalizedSourceCandidates) {
|
|
3535
|
+
if (normalizedSourceFile === candidate.key) {
|
|
3536
|
+
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3537
|
+
continue;
|
|
3538
|
+
}
|
|
3539
|
+
if (normalizedSourceFile.endsWith(`/${candidate.key}`)) score = Math.max(score, candidate.absolute ? 60 : 40);
|
|
3540
|
+
}
|
|
3541
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3542
|
+
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3543
|
+
score,
|
|
3544
|
+
source
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
return bestSource?.source;
|
|
3548
|
+
};
|
|
3549
|
+
const resolveOutputFileFromMatchedCssSource = (sourceFile) => {
|
|
3550
|
+
if (!sourceFile) return;
|
|
3551
|
+
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, false, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3552
|
+
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
3553
|
+
};
|
|
3554
|
+
const hasViteProcessedCssResultForSource = (sourceFile) => {
|
|
3555
|
+
const sourceKey = require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile);
|
|
3556
|
+
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (require_source_candidate_scan_signature.normalizeOutputPathKey(file) === sourceKey) return true;
|
|
3557
|
+
return false;
|
|
3558
|
+
};
|
|
3559
|
+
const usedConfiguredTailwindV4CssSourceFiles = /* @__PURE__ */ new Set();
|
|
3132
3560
|
const buildCommand = resolvedConfig?.command === "build";
|
|
3133
3561
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
3134
3562
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
3135
3563
|
const useIncrementalMode = !buildCommand || hasPreviousBundleState || hasOmittedKnownFiles;
|
|
3136
3564
|
currentOutDir = outDir;
|
|
3137
3565
|
const snapshotStart = performance.now();
|
|
3138
|
-
const snapshot =
|
|
3566
|
+
const snapshot = require_source_candidate_scan_signature.buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
3567
|
+
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
3568
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file.replace(/[?#].*$/, ""))));
|
|
3139
3569
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
3570
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
3140
3571
|
getSourceCandidateSourcesForEntries,
|
|
3141
3572
|
getSourceCandidatesForEntries,
|
|
3142
|
-
projectRoot: opts.
|
|
3573
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
3143
3574
|
rootDir,
|
|
3144
3575
|
snapshot,
|
|
3145
3576
|
sourceRoot,
|
|
@@ -3148,8 +3579,8 @@ function createGenerateBundleHook(context) {
|
|
|
3148
3579
|
useIncrementalMode
|
|
3149
3580
|
});
|
|
3150
3581
|
recordTimingDetail("snapshot", snapshotStart);
|
|
3151
|
-
const useBundleRuntimeClassSet = !isWebGeneratorTarget
|
|
3152
|
-
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3582
|
+
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
3583
|
+
const forceRuntimeRefreshBySource = useIncrementalMode && require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3153
3584
|
const processFiles = snapshot.processFiles;
|
|
3154
3585
|
logBundleProcessPlan({
|
|
3155
3586
|
debug,
|
|
@@ -3161,11 +3592,11 @@ function createGenerateBundleHook(context) {
|
|
|
3161
3592
|
await waitForSourceCandidateSyncs?.();
|
|
3162
3593
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
3163
3594
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
3164
|
-
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => createScopedGeneratorRuntime({
|
|
3595
|
+
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => require_source_candidate_scan_signature.createScopedGeneratorRuntime({
|
|
3165
3596
|
cssHandlerOptions,
|
|
3166
3597
|
fallbackRuntime: runtime,
|
|
3167
3598
|
getSourceCandidatesForEntries,
|
|
3168
|
-
majorVersion: runtimeState.
|
|
3599
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3169
3600
|
outputFile,
|
|
3170
3601
|
rawSource,
|
|
3171
3602
|
shouldExcludeSubpackageSourceCandidates,
|
|
@@ -3174,29 +3605,18 @@ function createGenerateBundleHook(context) {
|
|
|
3174
3605
|
});
|
|
3175
3606
|
const jsEntries = snapshot.jsEntries;
|
|
3176
3607
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
3177
|
-
const moduleGraphOptions =
|
|
3178
|
-
const
|
|
3179
|
-
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3180
|
-
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !envFlags.forceRuntimeRefreshByEnv && !envFlags.disableV3OxideSourceRuntime;
|
|
3608
|
+
const moduleGraphOptions = require_source_candidate_scan_signature.createBundleModuleGraphOptions(outDir, jsEntries);
|
|
3609
|
+
const hasRuntimeAffectingChanges = require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3181
3610
|
const runtimeStart = performance.now();
|
|
3182
|
-
const
|
|
3183
|
-
const
|
|
3184
|
-
const
|
|
3185
|
-
allowBaselineOnlyInitialSync: true,
|
|
3186
|
-
baseClassSet: sourceCandidates
|
|
3187
|
-
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
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";
|
|
3611
|
+
const forceV4RuntimeRefreshBySource = forceRuntimeRefreshBySource;
|
|
3612
|
+
const runtime = isWebGeneratorTarget && !shouldGenerateWebCssByGenerator ? /* @__PURE__ */ new Set() : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3613
|
+
const shouldFilterTailwindV4MiniProgramCandidates = require_generator.shouldUseMiniProgramCssBranch(generatorBranch);
|
|
3190
3614
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
3191
|
-
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ?
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size === 0) {
|
|
3195
|
-
generatorRuntime = await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3196
|
-
transformRuntime = generatorRuntime;
|
|
3197
|
-
}
|
|
3615
|
+
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3616
|
+
const transformRuntime = runtime;
|
|
3617
|
+
const generatorRuntime = filteredGeneratorCandidates;
|
|
3198
3618
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3199
|
-
if (
|
|
3619
|
+
if (sourceCandidates.size > 0 && jsEntries.size > 0) {
|
|
3200
3620
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3201
3621
|
if (mainCssEntry) {
|
|
3202
3622
|
const validatedSourceRuntime = await require_hmr_timing.validateCandidatesByGenerator({
|
|
@@ -3211,30 +3631,10 @@ function createGenerateBundleHook(context) {
|
|
|
3211
3631
|
debug,
|
|
3212
3632
|
skipGenerateFallback: true
|
|
3213
3633
|
});
|
|
3214
|
-
if (validatedSourceRuntime.size > 0)
|
|
3634
|
+
if (validatedSourceRuntime.size > 0) for (const candidate of validatedSourceRuntime) transformRuntime.add(candidate);
|
|
3215
3635
|
}
|
|
3216
3636
|
}
|
|
3217
|
-
|
|
3218
|
-
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3219
|
-
if (mainCssEntry) {
|
|
3220
|
-
const validatedRuntime = await require_hmr_timing.validateCandidatesByGenerator({
|
|
3221
|
-
opts,
|
|
3222
|
-
runtimeState,
|
|
3223
|
-
candidates: generatorRuntime,
|
|
3224
|
-
rawSource: mainCssEntry.source,
|
|
3225
|
-
file: mainCssEntry.file,
|
|
3226
|
-
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3227
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3228
|
-
styleHandler,
|
|
3229
|
-
debug
|
|
3230
|
-
});
|
|
3231
|
-
if (validatedRuntime.size > 0) {
|
|
3232
|
-
generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, validatedRuntime);
|
|
3233
|
-
transformRuntime = generatorRuntime;
|
|
3234
|
-
}
|
|
3235
|
-
}
|
|
3236
|
-
}
|
|
3237
|
-
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
3637
|
+
const generatorCandidateSignature = require_source_candidate_scan_signature.createCandidateSignature(generatorRuntime);
|
|
3238
3638
|
const generatorCandidatesChanged = state.generatorCandidateSignature !== generatorCandidateSignature;
|
|
3239
3639
|
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
3240
3640
|
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
@@ -3245,7 +3645,7 @@ function createGenerateBundleHook(context) {
|
|
|
3245
3645
|
continue;
|
|
3246
3646
|
}
|
|
3247
3647
|
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3248
|
-
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0,
|
|
3648
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
3249
3649
|
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(node_path.default.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3250
3650
|
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3251
3651
|
rememberCssSource?.({
|
|
@@ -3260,12 +3660,12 @@ function createGenerateBundleHook(context) {
|
|
|
3260
3660
|
...generatorRuntime,
|
|
3261
3661
|
...transformRuntime
|
|
3262
3662
|
]);
|
|
3263
|
-
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
3264
3663
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
3265
3664
|
timingDetails["runtime"] = metrics.runtimeSet;
|
|
3266
3665
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
3267
3666
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
3268
|
-
const runtimeSignature =
|
|
3667
|
+
const runtimeSignature = require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime) ?? "runtime:missing";
|
|
3668
|
+
const transformRuntimeSignature = require_source_candidate_scan_signature.createCandidateSignature(transformRuntime);
|
|
3269
3669
|
const shouldProcessTailwindGeneration = !useIncrementalMode || hasRuntimeAffectingChanges || generatorCandidatesChanged || snapshot.processFiles.css.size > 0;
|
|
3270
3670
|
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
3271
3671
|
jsEntries,
|
|
@@ -3273,7 +3673,7 @@ function createGenerateBundleHook(context) {
|
|
|
3273
3673
|
debug
|
|
3274
3674
|
});
|
|
3275
3675
|
const createHandlerOptions = createJsHandlerOptionsFactory({
|
|
3276
|
-
getMajorVersion: () => runtimeState.
|
|
3676
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
3277
3677
|
moduleGraph: moduleGraphOptions
|
|
3278
3678
|
});
|
|
3279
3679
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
@@ -3296,15 +3696,19 @@ function createGenerateBundleHook(context) {
|
|
|
3296
3696
|
continue;
|
|
3297
3697
|
}
|
|
3298
3698
|
if (!processFiles.html.has(file)) continue;
|
|
3299
|
-
const rawSource = originalEntrySource;
|
|
3300
|
-
const
|
|
3301
|
-
const
|
|
3699
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
3700
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3701
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3702
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
|
|
3703
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3704
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3705
|
+
const hashKey = cacheKey;
|
|
3302
3706
|
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3303
3707
|
tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
|
|
3304
3708
|
cache,
|
|
3305
3709
|
cacheKey,
|
|
3306
3710
|
hashKey,
|
|
3307
|
-
hash:
|
|
3711
|
+
hash: htmlProcessHash,
|
|
3308
3712
|
applyResult(source) {
|
|
3309
3713
|
originalSource.source = source;
|
|
3310
3714
|
},
|
|
@@ -3314,7 +3718,7 @@ function createGenerateBundleHook(context) {
|
|
|
3314
3718
|
},
|
|
3315
3719
|
async transform() {
|
|
3316
3720
|
const start = performance.now();
|
|
3317
|
-
let transformed = await templateHandler(rawSource,
|
|
3721
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
3318
3722
|
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3319
3723
|
let retryRuntimeSet;
|
|
3320
3724
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
@@ -3342,7 +3746,14 @@ function createGenerateBundleHook(context) {
|
|
|
3342
3746
|
metrics.css.total++;
|
|
3343
3747
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3344
3748
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3345
|
-
|
|
3749
|
+
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
3750
|
+
if (outputFile !== file && (originalSource.originalFileNames?.length ?? 0) > 0 && opts.cssMatcher(file)) outputFile = file;
|
|
3751
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
3752
|
+
const resolveMatchedOutputFileForCurrentAsset = (sourceFile) => {
|
|
3753
|
+
if (!sourceFile) return;
|
|
3754
|
+
if (require_source_candidate_scan_signature.normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalSource.originalFileNames?.some((originalFile) => require_source_candidate_scan_signature.normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
|
|
3755
|
+
return resolveOutputFileFromMatchedCssSource(sourceFile);
|
|
3756
|
+
};
|
|
3346
3757
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3347
3758
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
3348
3759
|
delete bundle[file];
|
|
@@ -3351,9 +3762,19 @@ function createGenerateBundleHook(context) {
|
|
|
3351
3762
|
}
|
|
3352
3763
|
const applyCssResult = (source) => {
|
|
3353
3764
|
if (outputFile !== file) {
|
|
3354
|
-
|
|
3765
|
+
const importShellSource = isRootMiniProgramStyleOutputFile(file) && isRootMiniProgramStyleOutputFile(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(opts.appType) ? createCssImportShell(file, outputFile) : void 0;
|
|
3766
|
+
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
3767
|
+
const existingOutput = bundle[outputFile];
|
|
3768
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
3769
|
+
else emitOrReplayCssAsset(outputFile, source);
|
|
3770
|
+
originalSource.source = importShellSource ?? source;
|
|
3771
|
+
return;
|
|
3772
|
+
}
|
|
3773
|
+
const existingOutput = bundle[outputFile];
|
|
3774
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
3775
|
+
else emitOrReplayCssAsset(outputFile, source);
|
|
3355
3776
|
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
3356
|
-
else originalSource.source = "";
|
|
3777
|
+
else originalSource.source = importShellSource ?? "";
|
|
3357
3778
|
return;
|
|
3358
3779
|
}
|
|
3359
3780
|
originalSource.source = source;
|
|
@@ -3371,25 +3792,66 @@ function createGenerateBundleHook(context) {
|
|
|
3371
3792
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
3372
3793
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
3373
3794
|
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => await refreshRememberedCssSource?.(remembered) ?? remembered));
|
|
3374
|
-
|
|
3795
|
+
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
3796
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
3376
3797
|
if (inferredSfcStyleSource) {
|
|
3377
3798
|
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
3378
3799
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
3379
3800
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
3380
3801
|
}
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3802
|
+
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3803
|
+
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile))) {
|
|
3804
|
+
rememberedCssSources = [];
|
|
3805
|
+
hasUsableRememberedTailwindSource = false;
|
|
3806
|
+
}
|
|
3807
|
+
if (!hasUsableRememberedTailwindSource) {
|
|
3808
|
+
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
3809
|
+
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));
|
|
3810
|
+
if (inferredOriginalSourceStyle) {
|
|
3811
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
3812
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3813
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3814
|
+
rememberedCssSources = [{
|
|
3815
|
+
...inferredOriginalSourceStyle,
|
|
3816
|
+
outputFile
|
|
3817
|
+
}];
|
|
3818
|
+
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
3819
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(entry.file)));
|
|
3820
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource);
|
|
3821
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file)) {
|
|
3822
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
3823
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3824
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3825
|
+
usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(configuredGenerationSource.file));
|
|
3826
|
+
rememberedCssSources = [{
|
|
3827
|
+
outputFile,
|
|
3828
|
+
rawSource: configuredGenerationSource.source,
|
|
3829
|
+
sourceFile: configuredGenerationSource.file
|
|
3830
|
+
}];
|
|
3831
|
+
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3836
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")))) {
|
|
3837
|
+
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
3838
|
+
if (matchedOutputFile && require_source_candidate_scan_signature.normalizeOutputPathKey(matchedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile)) {
|
|
3839
|
+
outputFile = matchedOutputFile;
|
|
3840
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3841
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3842
|
+
rememberedCssSource = {
|
|
3843
|
+
...rememberedCssSource,
|
|
3844
|
+
outputFile
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3384
3847
|
}
|
|
3385
|
-
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3386
3848
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
3387
|
-
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (
|
|
3849
|
+
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
3850
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
3389
3851
|
const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
3390
|
-
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null &&
|
|
3852
|
+
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && require_v4_engine.hasTailwindApplyDirective(generatorRawSource);
|
|
3391
3853
|
const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
|
|
3392
|
-
const hasCurrentTailwindGenerationDirective =
|
|
3854
|
+
const hasCurrentTailwindGenerationDirective = require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(rawSource);
|
|
3393
3855
|
if (shouldKeepImportedCssShell && !hasCurrentTailwindGenerationDirective) {
|
|
3394
3856
|
applyCssResult(rawSource);
|
|
3395
3857
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -3398,37 +3860,46 @@ function createGenerateBundleHook(context) {
|
|
|
3398
3860
|
debug("css preserve imported shell asset: %s", outputFile);
|
|
3399
3861
|
continue;
|
|
3400
3862
|
}
|
|
3401
|
-
const hasRememberedApplyDirective = rememberedCssSource != null &&
|
|
3863
|
+
const hasRememberedApplyDirective = rememberedCssSource != null && require_v4_engine.hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
3402
3864
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
3403
|
-
const
|
|
3404
|
-
const
|
|
3865
|
+
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);
|
|
3866
|
+
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
3867
|
+
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
3405
3868
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
3406
|
-
|
|
3869
|
+
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
3870
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
3408
3871
|
...getCssHandlerOptions(generatorSourceFile),
|
|
3409
3872
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
3410
3873
|
} : getCssHandlerOptions(file);
|
|
3411
|
-
const
|
|
3412
|
-
|
|
3874
|
+
const generatorCssHandlerOptions = {
|
|
3875
|
+
...cssHandlerOptions,
|
|
3876
|
+
sourceOptions: {
|
|
3877
|
+
...cssHandlerOptions.sourceOptions ?? {},
|
|
3878
|
+
sourceFile: generatorSourceFile,
|
|
3879
|
+
cssEntries: opts.cssEntries
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
3883
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, generatorCssHandlerOptions);
|
|
3413
3884
|
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3414
3885
|
const sourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
3415
|
-
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile,
|
|
3886
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, generatorCssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
3416
3887
|
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
3417
3888
|
opts,
|
|
3418
3889
|
tokenSources: sourceTraceTokenSources
|
|
3419
3890
|
});
|
|
3420
|
-
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile,
|
|
3891
|
+
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
3421
3892
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
3422
|
-
const cssRuntimeAffectingSignature = vitePipelineCssAsset ?
|
|
3893
|
+
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
3423
3894
|
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) ||
|
|
3895
|
+
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
3896
|
+
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3426
3897
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
3427
3898
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
3428
3899
|
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) ||
|
|
3900
|
+
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource));
|
|
3430
3901
|
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && !hasStaleViteProcessedCssSource && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
3431
|
-
const nextCss =
|
|
3902
|
+
const nextCss = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
3432
3903
|
applyCssResult(nextCss);
|
|
3433
3904
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
3434
3905
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
@@ -3440,16 +3911,16 @@ function createGenerateBundleHook(context) {
|
|
|
3440
3911
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
3441
3912
|
continue;
|
|
3442
3913
|
}
|
|
3443
|
-
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
3444
|
-
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3445
|
-
includeFallbackSignature:
|
|
3446
|
-
majorVersion: runtimeState.
|
|
3914
|
+
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? require_source_candidate_scan_signature.createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
3915
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await require_source_candidate_scan_signature.createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3916
|
+
includeFallbackSignature: generatorCssHandlerOptions.isMainChunk,
|
|
3917
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
3447
3918
|
}) : trackedGeneratorCandidateSignature;
|
|
3448
3919
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
3449
3920
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3450
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.
|
|
3921
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
3451
3922
|
const cssCacheKey = file;
|
|
3452
|
-
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.
|
|
3923
|
+
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
3453
3924
|
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
3925
|
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
3455
3926
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
@@ -3495,23 +3966,28 @@ function createGenerateBundleHook(context) {
|
|
|
3495
3966
|
const runTransform = async () => {
|
|
3496
3967
|
const start = performance.now();
|
|
3497
3968
|
await runtimeState.readyPromise;
|
|
3498
|
-
const
|
|
3969
|
+
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
3970
|
+
const generated = hasTailwindGenerationSource(generatorRawSource) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) ? await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3499
3971
|
opts,
|
|
3500
3972
|
runtimeState,
|
|
3501
3973
|
runtime: scopedGeneratorRuntime,
|
|
3502
3974
|
rawSource: generatorRawSource,
|
|
3503
3975
|
file: generatorSourceFile,
|
|
3504
|
-
|
|
3976
|
+
outputFile,
|
|
3977
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3505
3978
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3506
3979
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3980
|
+
sourceCandidates: scopedGeneratorRuntime,
|
|
3507
3981
|
styleHandler,
|
|
3508
3982
|
debug,
|
|
3509
|
-
previousCss
|
|
3510
|
-
|
|
3983
|
+
previousCss,
|
|
3984
|
+
...vitePipelineCssAsset && !require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile) } : {},
|
|
3985
|
+
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
3986
|
+
}) : void 0;
|
|
3511
3987
|
if (generated) {
|
|
3512
3988
|
const tracedCss = annotateCss(generated.css);
|
|
3513
3989
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
3514
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3990
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, require_source_candidate_scan_signature.summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3515
3991
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
3516
3992
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
3517
3993
|
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
@@ -3524,7 +4000,7 @@ function createGenerateBundleHook(context) {
|
|
|
3524
4000
|
});
|
|
3525
4001
|
metrics.css.elapsed += measureElapsed(start);
|
|
3526
4002
|
metrics.css.transformed++;
|
|
3527
|
-
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.
|
|
4003
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, outputFile);
|
|
3528
4004
|
return tracedCss;
|
|
3529
4005
|
}
|
|
3530
4006
|
if (isWebGeneratorTarget) {
|
|
@@ -3535,7 +4011,7 @@ function createGenerateBundleHook(context) {
|
|
|
3535
4011
|
}
|
|
3536
4012
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
3537
4013
|
const tracedCss = annotateCss(css);
|
|
3538
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4014
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, require_source_candidate_scan_signature.summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3539
4015
|
metrics.css.elapsed += measureElapsed(start);
|
|
3540
4016
|
metrics.css.transformed++;
|
|
3541
4017
|
return tracedCss;
|
|
@@ -3701,13 +4177,17 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
3701
4177
|
...majorVersion === void 0 ? {} : { majorVersion }
|
|
3702
4178
|
};
|
|
3703
4179
|
}
|
|
3704
|
-
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
3705
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
4180
|
+
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
4181
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4182
|
+
appType: opts.appType,
|
|
4183
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4184
|
+
tailwindcssMajorVersion: majorVersion,
|
|
4185
|
+
uniAppX: opts.uniAppX
|
|
4186
|
+
});
|
|
4187
|
+
if (require_v4_engine.hasLocalCssImport(rawSource)) return false;
|
|
4188
|
+
if (require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
4189
|
+
if (require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
4190
|
+
return processed && require_v4_engine.hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
|
|
3711
4191
|
}
|
|
3712
4192
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
3713
4193
|
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
@@ -3724,9 +4204,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3724
4204
|
async handler(_options, bundle) {
|
|
3725
4205
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
3726
4206
|
const resolvedConfig = getResolvedConfig();
|
|
3727
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3728
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3729
4207
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
4208
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4209
|
+
appType: opts.appType,
|
|
4210
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4211
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4212
|
+
uniAppX: opts.uniAppX,
|
|
4213
|
+
uniUtsPlatform
|
|
4214
|
+
}), {
|
|
4215
|
+
appType: opts.appType,
|
|
4216
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4217
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4218
|
+
uniAppX: opts.uniAppX,
|
|
4219
|
+
uniUtsPlatform
|
|
4220
|
+
});
|
|
4221
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3730
4222
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3731
4223
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3732
4224
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
@@ -3766,13 +4258,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3766
4258
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3767
4259
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
3768
4260
|
const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
|
|
3769
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
3770
|
-
const generated = await
|
|
4261
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
|
|
4262
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3771
4263
|
opts,
|
|
3772
4264
|
runtimeState,
|
|
3773
4265
|
runtime: harmonyRuntime,
|
|
3774
4266
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3775
4267
|
file: "uni-app-x-harmony-apply.css",
|
|
4268
|
+
outputFile: "uni-app-x-harmony-apply.css",
|
|
3776
4269
|
cssHandlerOptions: harmonyCssHandlerOptions,
|
|
3777
4270
|
cssUserHandlerOptions: {
|
|
3778
4271
|
...harmonyCssHandlerOptions,
|
|
@@ -3790,33 +4283,41 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3790
4283
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
|
|
3791
4284
|
};
|
|
3792
4285
|
const isCssOutputAssetEntry = (entry) => {
|
|
3793
|
-
const [, output] = entry;
|
|
3794
|
-
|
|
4286
|
+
const [bundleFile, output] = entry;
|
|
4287
|
+
const fileName = output.fileName || bundleFile;
|
|
4288
|
+
return output.type === "asset" && opts.cssMatcher(fileName) && !opts.htmlMatcher(fileName) && !require_source_candidate_scan_signature.isHTMLRequest(fileName) && !isCssAssetProcessed(output, fileName);
|
|
3795
4289
|
};
|
|
3796
4290
|
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
3797
4291
|
if (entries.length === 0) {
|
|
3798
4292
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
3799
4293
|
collectViteProcessedCssAssets();
|
|
3800
4294
|
injectViteProcessedCssIntoMainCss();
|
|
4295
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4296
|
+
appType: opts.appType,
|
|
4297
|
+
cssMatcher: opts.cssMatcher,
|
|
4298
|
+
debug,
|
|
4299
|
+
onUpdate: opts.onUpdate,
|
|
4300
|
+
recordCssAssetResult
|
|
4301
|
+
});
|
|
3801
4302
|
return;
|
|
3802
4303
|
}
|
|
3803
4304
|
await runtimeState.readyPromise;
|
|
3804
4305
|
await waitForSourceCandidateSyncs?.();
|
|
3805
4306
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
3806
4307
|
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
3807
|
-
const generatorRuntime =
|
|
4308
|
+
const generatorRuntime = require_generator.shouldUseMiniProgramCssBranch(generatorBranch) ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3808
4309
|
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
3809
4310
|
const file = output.fileName || bundleFile;
|
|
3810
4311
|
const rawSource = output.source.toString();
|
|
3811
4312
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
3812
|
-
const nextCss = annotateCss(
|
|
4313
|
+
const nextCss = annotateCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource));
|
|
3813
4314
|
output.source = nextCss;
|
|
3814
4315
|
markCssAssetProcessed(output, file);
|
|
3815
4316
|
recordCssAssetResult?.(file, nextCss);
|
|
3816
4317
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
3817
4318
|
return;
|
|
3818
4319
|
}
|
|
3819
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
4320
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file);
|
|
3820
4321
|
const cssUserHandlerOptions = {
|
|
3821
4322
|
...cssHandlerOptions,
|
|
3822
4323
|
isMainChunk: false
|
|
@@ -3825,24 +4326,25 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3825
4326
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
3826
4327
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
3827
4328
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
3828
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.
|
|
4329
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile) : cssHandlerOptions;
|
|
3829
4330
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
3830
4331
|
...generatorCssHandlerOptions,
|
|
3831
4332
|
isMainChunk: false
|
|
3832
4333
|
} : cssUserHandlerOptions;
|
|
3833
|
-
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await
|
|
4334
|
+
const generated = shouldGenerateCssByGenerator(opts, runtimeState.tailwindRuntime.majorVersion, file, generatorRawSource, processed) ? await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
3834
4335
|
opts,
|
|
3835
4336
|
runtimeState,
|
|
3836
4337
|
runtime: generatorRuntime,
|
|
3837
4338
|
rawSource: generatorRawSource,
|
|
3838
4339
|
file: generatorSourceFile,
|
|
4340
|
+
outputFile: file,
|
|
3839
4341
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3840
4342
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3841
4343
|
getSourceCandidatesForEntries,
|
|
3842
4344
|
styleHandler: opts.styleHandler,
|
|
3843
4345
|
debug
|
|
3844
4346
|
}) : void 0;
|
|
3845
|
-
const nextCss = annotateCss(generated?.css ?? (
|
|
4347
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
3846
4348
|
if (generated) {
|
|
3847
4349
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
3848
4350
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -3857,6 +4359,13 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3857
4359
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
3858
4360
|
collectViteProcessedCssAssets();
|
|
3859
4361
|
injectViteProcessedCssIntoMainCss();
|
|
4362
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4363
|
+
appType: opts.appType,
|
|
4364
|
+
cssMatcher: opts.cssMatcher,
|
|
4365
|
+
debug,
|
|
4366
|
+
onUpdate: opts.onUpdate,
|
|
4367
|
+
recordCssAssetResult
|
|
4368
|
+
});
|
|
3860
4369
|
}
|
|
3861
4370
|
}
|
|
3862
4371
|
};
|
|
@@ -3881,6 +4390,27 @@ const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
|
3881
4390
|
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3882
4391
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3883
4392
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
4393
|
+
function toMb$1(bytes) {
|
|
4394
|
+
return Math.round(bytes / 1024 / 1024);
|
|
4395
|
+
}
|
|
4396
|
+
function summarizeStringMapCache(map) {
|
|
4397
|
+
let bytes = 0;
|
|
4398
|
+
for (const value of map.values()) bytes += value.length;
|
|
4399
|
+
return {
|
|
4400
|
+
bytes,
|
|
4401
|
+
mb: toMb$1(bytes),
|
|
4402
|
+
size: map.size
|
|
4403
|
+
};
|
|
4404
|
+
}
|
|
4405
|
+
function summarizeRememberedCssSources(map) {
|
|
4406
|
+
let bytes = 0;
|
|
4407
|
+
for (const value of map.values()) bytes += value.rawSource.length;
|
|
4408
|
+
return {
|
|
4409
|
+
bytes,
|
|
4410
|
+
mb: toMb$1(bytes),
|
|
4411
|
+
size: map.size
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
3884
4414
|
function stripSourceHash(sourceFile) {
|
|
3885
4415
|
const hashIndex = sourceFile.indexOf("#");
|
|
3886
4416
|
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
@@ -3888,9 +4418,9 @@ function stripSourceHash(sourceFile) {
|
|
|
3888
4418
|
function normalizeCssSourceIdentity(sourceFile) {
|
|
3889
4419
|
const cleanSourceFile = stripSourceHash(sourceFile);
|
|
3890
4420
|
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
3891
|
-
const normalizedFile =
|
|
4421
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(filename);
|
|
3892
4422
|
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
3893
|
-
return
|
|
4423
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(require_source_candidate_scan_signature.stripRequestQuery(cleanSourceFile));
|
|
3894
4424
|
}
|
|
3895
4425
|
function hasSfcStyleBlocks(source) {
|
|
3896
4426
|
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
@@ -3919,7 +4449,7 @@ function extractSfcStyleSource(source, index) {
|
|
|
3919
4449
|
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
3920
4450
|
}
|
|
3921
4451
|
function normalizeKnownSfcSourceKey(file) {
|
|
3922
|
-
return
|
|
4452
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(file)));
|
|
3923
4453
|
}
|
|
3924
4454
|
function shouldCollectTransformedSourceCandidates(id) {
|
|
3925
4455
|
if (id.search(/[?#]/) < 0) return true;
|
|
@@ -3947,7 +4477,7 @@ function createViteCssMemory(options) {
|
|
|
3947
4477
|
return source;
|
|
3948
4478
|
};
|
|
3949
4479
|
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3950
|
-
const outputKey =
|
|
4480
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(entry.outputFile);
|
|
3951
4481
|
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
3952
4482
|
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3953
4483
|
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
@@ -3985,16 +4515,28 @@ function createViteCssMemory(options) {
|
|
|
3985
4515
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
3986
4516
|
};
|
|
3987
4517
|
const resolveCachedStyleSource = (sourceFile) => {
|
|
3988
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
4518
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(sourceFile));
|
|
3989
4519
|
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
3990
|
-
if (
|
|
4520
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
4521
|
+
};
|
|
4522
|
+
const resolveCurrentStyleSource = async (sourceFile) => {
|
|
4523
|
+
const cached = resolveCachedStyleSource(sourceFile);
|
|
4524
|
+
if (cached != null) return cached;
|
|
4525
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(sourceFile));
|
|
4526
|
+
if (!require_source_candidate_scan_signature.isSourceStyleRequest(file)) return;
|
|
4527
|
+
try {
|
|
4528
|
+
return await (0, node_fs_promises.readFile)(file, "utf8");
|
|
4529
|
+
} catch (error) {
|
|
4530
|
+
options.debug("refresh remembered css source read failed: %s %O", file, error);
|
|
4531
|
+
return;
|
|
4532
|
+
}
|
|
3991
4533
|
};
|
|
3992
4534
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
3993
4535
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(sourceFile);
|
|
3994
|
-
const normalizedSourceFile =
|
|
3995
|
-
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) =>
|
|
4536
|
+
const normalizedSourceFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
4537
|
+
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
4538
|
if (matchedRememberedSources.length === 0) return;
|
|
3997
|
-
const source =
|
|
4539
|
+
const source = await resolveCurrentStyleSource(file);
|
|
3998
4540
|
if (source == null) {
|
|
3999
4541
|
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
4000
4542
|
return;
|
|
@@ -4007,13 +4549,13 @@ function createViteCssMemory(options) {
|
|
|
4007
4549
|
}
|
|
4008
4550
|
return;
|
|
4009
4551
|
}
|
|
4010
|
-
if (
|
|
4552
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
4011
4553
|
};
|
|
4012
4554
|
const refreshRememberedCssSource = async (remembered) => {
|
|
4013
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
4555
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_source_candidate_scan_signature.stripRequestQuery(remembered.sourceFile));
|
|
4014
4556
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4015
4557
|
if (!rememberedKey || !node_path.default.isAbsolute(file)) return;
|
|
4016
|
-
const source =
|
|
4558
|
+
const source = await resolveCurrentStyleSource(file);
|
|
4017
4559
|
if (source == null) {
|
|
4018
4560
|
options.debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4019
4561
|
return;
|
|
@@ -4023,13 +4565,13 @@ function createViteCssMemory(options) {
|
|
|
4023
4565
|
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4024
4566
|
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
4025
4567
|
}
|
|
4026
|
-
if (
|
|
4568
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
4027
4569
|
};
|
|
4028
4570
|
const prune = (pruneOptions) => {
|
|
4029
|
-
const activeFiles = new Set([...pruneOptions.activeFiles].map(
|
|
4571
|
+
const activeFiles = new Set([...pruneOptions.activeFiles].map(require_source_candidate_scan_signature.normalizeOutputPathKey));
|
|
4030
4572
|
for (const [key, remembered] of rememberedCssSources) {
|
|
4031
|
-
const outputKey =
|
|
4032
|
-
const sourceKey =
|
|
4573
|
+
const outputKey = require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.outputFile);
|
|
4574
|
+
const sourceKey = require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.sourceFile);
|
|
4033
4575
|
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
4034
4576
|
rememberedCssSources.delete(key);
|
|
4035
4577
|
rememberedCssSignatureByFile.delete(key);
|
|
@@ -4046,13 +4588,15 @@ function createViteCssMemory(options) {
|
|
|
4046
4588
|
};
|
|
4047
4589
|
return {
|
|
4048
4590
|
getKnownSfcSource,
|
|
4049
|
-
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(
|
|
4050
|
-
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(
|
|
4591
|
+
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file)),
|
|
4592
|
+
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file)),
|
|
4051
4593
|
getRememberedCssSources: () => rememberedCssSources,
|
|
4052
4594
|
getStats: () => ({
|
|
4053
4595
|
rememberedCssSources: rememberedCssSources.size,
|
|
4596
|
+
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
4054
4597
|
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4055
|
-
knownSfcSources: knownSfcSources.size
|
|
4598
|
+
knownSfcSources: knownSfcSources.size,
|
|
4599
|
+
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
4056
4600
|
}),
|
|
4057
4601
|
rememberCssSource,
|
|
4058
4602
|
rememberKnownSfcSource,
|
|
@@ -4060,7 +4604,7 @@ function createViteCssMemory(options) {
|
|
|
4060
4604
|
refreshRememberedCssSourceByCurrentFile,
|
|
4061
4605
|
refreshRememberedCssSourceBySourceFile,
|
|
4062
4606
|
setRememberedCssSignature: (file, cssRuntimeSignature) => {
|
|
4063
|
-
rememberedCssSignatureByFile.set(
|
|
4607
|
+
rememberedCssSignatureByFile.set(require_source_candidate_scan_signature.normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
4064
4608
|
},
|
|
4065
4609
|
prune
|
|
4066
4610
|
};
|
|
@@ -4072,7 +4616,7 @@ function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
|
4072
4616
|
const seenModules = /* @__PURE__ */ new Set();
|
|
4073
4617
|
const collectModule = (mod) => {
|
|
4074
4618
|
if (mod == null || seenModules.has(mod)) return;
|
|
4075
|
-
if (!
|
|
4619
|
+
if (!require_source_candidate_scan_signature.isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
4076
4620
|
seenModules.add(mod);
|
|
4077
4621
|
ctx.server.moduleGraph.invalidateModule(mod);
|
|
4078
4622
|
modules.push(mod);
|
|
@@ -4102,7 +4646,7 @@ function includesHotModule(modules, target) {
|
|
|
4102
4646
|
}
|
|
4103
4647
|
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
4104
4648
|
return modules.some((mod) => {
|
|
4105
|
-
return !
|
|
4649
|
+
return !require_source_candidate_scan_signature.isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
4106
4650
|
});
|
|
4107
4651
|
}
|
|
4108
4652
|
function sendSupplementalCssHotUpdates(ctx, cssModules) {
|
|
@@ -4213,7 +4757,7 @@ function joinPosixPath(base, subpath) {
|
|
|
4213
4757
|
function isCssLikeImporter(importer) {
|
|
4214
4758
|
if (!importer) return false;
|
|
4215
4759
|
const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
|
|
4216
|
-
return
|
|
4760
|
+
return require_source_candidate_scan_signature.isSourceStyleRequest(importer) || require_source_candidate_scan_signature.isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
4217
4761
|
}
|
|
4218
4762
|
function stripTailwindConfigDirectives(code) {
|
|
4219
4763
|
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
@@ -4223,7 +4767,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4223
4767
|
const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
|
|
4224
4768
|
const resolveAppType = () => getAppType?.() ?? appType;
|
|
4225
4769
|
return [{
|
|
4226
|
-
name: `${
|
|
4770
|
+
name: `${require_context.vitePluginName}:rewrite-css-imports`,
|
|
4227
4771
|
enforce: "pre",
|
|
4228
4772
|
resolveId(id, importer) {
|
|
4229
4773
|
if (!options.shouldRewrite) return null;
|
|
@@ -4237,20 +4781,27 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4237
4781
|
return replacement;
|
|
4238
4782
|
},
|
|
4239
4783
|
async transform(code, id) {
|
|
4240
|
-
if (!
|
|
4784
|
+
if (!require_source_candidate_scan_signature.isCSSRequest(id)) return null;
|
|
4241
4785
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
4242
|
-
const normalizedCode =
|
|
4786
|
+
const normalizedCode = require_v4_engine.hasTailwindRootDirectives(code) || code.includes("@config") ? require_v4_engine.normalizeTailwindConfigDirectives(code, node_path.default.dirname(file)) : code;
|
|
4243
4787
|
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
4244
|
-
const hasTailwindRoot =
|
|
4788
|
+
const hasTailwindRoot = require_v4_engine.hasTailwindRootDirectives(normalizedCode);
|
|
4245
4789
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
4246
|
-
|
|
4790
|
+
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
4791
|
+
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
4247
4792
|
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
|
|
4248
4793
|
if (generatedCss !== void 0) return {
|
|
4249
4794
|
code: generatedCss,
|
|
4250
4795
|
map: null
|
|
4251
4796
|
};
|
|
4252
4797
|
}
|
|
4253
|
-
if (!options.shouldRewrite)
|
|
4798
|
+
if (!options.shouldRewrite) {
|
|
4799
|
+
if (normalizedCode !== code) return {
|
|
4800
|
+
code: normalizedCode,
|
|
4801
|
+
map: null
|
|
4802
|
+
};
|
|
4803
|
+
return null;
|
|
4804
|
+
}
|
|
4254
4805
|
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
4255
4806
|
join: joinPosixPath,
|
|
4256
4807
|
appType: resolveAppType(),
|
|
@@ -4266,16 +4817,16 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4266
4817
|
}];
|
|
4267
4818
|
}
|
|
4268
4819
|
function hasVitePipelineTailwindGenerationDirective(code) {
|
|
4269
|
-
return
|
|
4820
|
+
return require_v4_engine.hasTailwindRootDirectives(code) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
4270
4821
|
}
|
|
4271
4822
|
//#endregion
|
|
4272
4823
|
//#region src/bundlers/vite/runtime-class-set.ts
|
|
4273
4824
|
function createViteRuntimeClassSet(options) {
|
|
4274
|
-
const { opts,
|
|
4825
|
+
const { opts, initialTailwindRuntime, refreshTailwindcssRuntime, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
4275
4826
|
const runtimeState = {
|
|
4276
|
-
|
|
4277
|
-
readyPromise:
|
|
4278
|
-
|
|
4827
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
4828
|
+
readyPromise: require_context.createTailwindRuntimeReadyPromise(initialTailwindRuntime),
|
|
4829
|
+
refreshTailwindcssRuntime
|
|
4279
4830
|
};
|
|
4280
4831
|
const bundleRuntimeClassSetManager = require_hmr_timing.createBundleRuntimeClassSetManager({
|
|
4281
4832
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
@@ -4290,8 +4841,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
4290
4841
|
let runtimeRefreshSignature;
|
|
4291
4842
|
let runtimeRefreshOptionsKey;
|
|
4292
4843
|
function resolveRuntimeRefreshOptions() {
|
|
4293
|
-
const configPath =
|
|
4294
|
-
const signature =
|
|
4844
|
+
const configPath = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.config;
|
|
4845
|
+
const signature = require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
4295
4846
|
const optionsKey = JSON.stringify({
|
|
4296
4847
|
appType: opts.appType,
|
|
4297
4848
|
uniAppX: uniAppXEnabled,
|
|
@@ -4310,7 +4861,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4310
4861
|
}
|
|
4311
4862
|
async function refreshRuntimeState(force) {
|
|
4312
4863
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4313
|
-
const refreshed = await
|
|
4864
|
+
const refreshed = await require_context.refreshTailwindRuntimeState(runtimeState, {
|
|
4314
4865
|
force: force || invalidation.changed,
|
|
4315
4866
|
clearCache: force || invalidation.changed
|
|
4316
4867
|
});
|
|
@@ -4327,7 +4878,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4327
4878
|
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
4328
4879
|
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
4329
4880
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4330
|
-
runtimeSetPromise =
|
|
4881
|
+
runtimeSetPromise = require_context.collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4331
4882
|
force: forceRuntimeRefresh || invalidation.changed,
|
|
4332
4883
|
skipRefresh: forceRuntimeRefresh,
|
|
4333
4884
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4341,54 +4892,29 @@ function createViteRuntimeClassSet(options) {
|
|
|
4341
4892
|
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
4342
4893
|
}
|
|
4343
4894
|
}
|
|
4344
|
-
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false,
|
|
4895
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, _options = {}) {
|
|
4345
4896
|
const forceRuntimeRefresh = forceRefresh || node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
4346
4897
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4347
|
-
const
|
|
4898
|
+
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
4348
4899
|
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
4349
|
-
await refreshRuntimeState(
|
|
4900
|
+
await refreshRuntimeState(shouldRefreshRuntime);
|
|
4350
4901
|
await runtimeState.readyPromise;
|
|
4351
|
-
if (
|
|
4902
|
+
if (shouldRefreshRuntime) {
|
|
4352
4903
|
runtimeSet = void 0;
|
|
4353
4904
|
runtimeSetPromise = void 0;
|
|
4354
4905
|
await bundleRuntimeClassSetManager.reset();
|
|
4355
4906
|
await transformRuntimeClassSetManager.reset();
|
|
4356
4907
|
}
|
|
4357
|
-
if (
|
|
4358
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.
|
|
4908
|
+
if (!forceRuntimeRefresh) try {
|
|
4909
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot);
|
|
4359
4910
|
runtimeSet = nextRuntimeSet;
|
|
4360
4911
|
return nextRuntimeSet;
|
|
4361
4912
|
} catch (error) {
|
|
4362
4913
|
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4363
4914
|
await bundleRuntimeClassSetManager.reset();
|
|
4364
4915
|
}
|
|
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
4916
|
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
4391
|
-
const task =
|
|
4917
|
+
const task = require_context.collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4392
4918
|
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
4393
4919
|
skipRefresh: forceRuntimeRefresh,
|
|
4394
4920
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4441,22 +4967,22 @@ function replaceViteCssHmrModuleCss(code, css) {
|
|
|
4441
4967
|
return `${code.slice(0, extracted.start)}${encodeJsStringLiteral(css)}${code.slice(extracted.end)}`;
|
|
4442
4968
|
}
|
|
4443
4969
|
function isViteServeStyleRequest(id, command) {
|
|
4444
|
-
return command === "serve" &&
|
|
4970
|
+
return command === "serve" && require_source_candidate_scan_signature.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
4445
4971
|
}
|
|
4446
4972
|
function isViteServeCssRootRequest(id, command) {
|
|
4447
|
-
return command === "serve" &&
|
|
4973
|
+
return command === "serve" && require_source_candidate_scan_signature.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
4448
4974
|
}
|
|
4449
4975
|
function isViteCssHmrModule(code, id, command) {
|
|
4450
4976
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
|
|
4451
4977
|
}
|
|
4452
4978
|
function createViteServeCssGenerationPlugins(options) {
|
|
4453
4979
|
return [{
|
|
4454
|
-
name: `${
|
|
4980
|
+
name: `${require_context.vitePluginName}:generate:serve`,
|
|
4455
4981
|
apply: "serve",
|
|
4456
4982
|
enforce: "pre",
|
|
4457
4983
|
async transform(code, id) {
|
|
4458
4984
|
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
4459
|
-
if (!
|
|
4985
|
+
if (!require_v4_engine.hasTailwindRootDirectives(code)) return;
|
|
4460
4986
|
await options.onTailwindRootCss?.(id, code);
|
|
4461
4987
|
const generatedCss = await options.generateCss(id, code, this);
|
|
4462
4988
|
if (generatedCss === void 0 || generatedCss === code) return;
|
|
@@ -4466,7 +4992,7 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4466
4992
|
};
|
|
4467
4993
|
}
|
|
4468
4994
|
}, {
|
|
4469
|
-
name: `${
|
|
4995
|
+
name: `${require_context.vitePluginName}:generate:serve-hmr`,
|
|
4470
4996
|
apply: "serve",
|
|
4471
4997
|
enforce: "post",
|
|
4472
4998
|
async transform(code, id) {
|
|
@@ -4486,35 +5012,6 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4486
5012
|
}];
|
|
4487
5013
|
}
|
|
4488
5014
|
//#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
5015
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
4519
5016
|
const PACKAGE_JSON_FILE = "package.json";
|
|
4520
5017
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -4528,21 +5025,45 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
4528
5025
|
if (parent === current) break;
|
|
4529
5026
|
current = parent;
|
|
4530
5027
|
}
|
|
4531
|
-
const tailwindConfigPath =
|
|
5028
|
+
const tailwindConfigPath = require_tailwindcss.findTailwindConfig(searchRoots);
|
|
4532
5029
|
if (tailwindConfigPath) return node_path.default.dirname(tailwindConfigPath);
|
|
4533
|
-
const packageRoot =
|
|
5030
|
+
const packageRoot = require_v4_engine.findNearestPackageRoot(resolvedRoot);
|
|
4534
5031
|
if (packageRoot && (0, node_fs.existsSync)(node_path.default.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
4535
5032
|
return resolvedRoot;
|
|
4536
5033
|
}
|
|
4537
5034
|
//#endregion
|
|
4538
5035
|
//#region src/bundlers/vite/index.ts
|
|
4539
|
-
const debug =
|
|
4540
|
-
const weappTailwindcssPackageDir =
|
|
4541
|
-
const weappTailwindcssDirPosix =
|
|
5036
|
+
const debug = require_context.createDebug();
|
|
5037
|
+
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
5038
|
+
const weappTailwindcssDirPosix = require_source_candidate_scan_signature.slash(weappTailwindcssPackageDir);
|
|
4542
5039
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
4543
5040
|
const sourceCandidateScanSnapshotCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
5041
|
+
function isMissingInternalCssSource(file) {
|
|
5042
|
+
return !(0, node_fs.existsSync)(file) && node_path.default.resolve(file).startsWith(`${weappTailwindcssPackageDir}${node_path.default.sep}`);
|
|
5043
|
+
}
|
|
4544
5044
|
function normalizeVitePersistentCacheKey(file) {
|
|
4545
|
-
return
|
|
5045
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
5046
|
+
}
|
|
5047
|
+
function toMb(bytes) {
|
|
5048
|
+
return Math.round(bytes / 1024 / 1024);
|
|
5049
|
+
}
|
|
5050
|
+
function summarizeStringCache(map) {
|
|
5051
|
+
let bytes = 0;
|
|
5052
|
+
for (const value of map.values()) bytes += value.length;
|
|
5053
|
+
return {
|
|
5054
|
+
bytes,
|
|
5055
|
+
mb: toMb(bytes),
|
|
5056
|
+
size: map.size
|
|
5057
|
+
};
|
|
5058
|
+
}
|
|
5059
|
+
function summarizeViteProcessedCssResults(map) {
|
|
5060
|
+
let bytes = 0;
|
|
5061
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
5062
|
+
return {
|
|
5063
|
+
bytes,
|
|
5064
|
+
mb: toMb(bytes),
|
|
5065
|
+
size: map.size
|
|
5066
|
+
};
|
|
4546
5067
|
}
|
|
4547
5068
|
/**
|
|
4548
5069
|
* @name WeappTailwindcss
|
|
@@ -4552,11 +5073,11 @@ function normalizeVitePersistentCacheKey(file) {
|
|
|
4552
5073
|
function WeappTailwindcss(options = {}) {
|
|
4553
5074
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
4554
5075
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
4555
|
-
const opts =
|
|
5076
|
+
const opts = require_context.getCompilerContext({
|
|
4556
5077
|
...options,
|
|
4557
5078
|
__internalDeferMissingCssEntriesWarning: true
|
|
4558
5079
|
});
|
|
4559
|
-
const normalizedCssEntries =
|
|
5080
|
+
const normalizedCssEntries = require_v4_engine.normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? node_process.default.cwd());
|
|
4560
5081
|
if (normalizedCssEntries) opts.cssEntries ?? (opts.cssEntries = normalizedCssEntries);
|
|
4561
5082
|
if (opts.cssEntries?.length) {
|
|
4562
5083
|
var _opts$tailwindcss, _opts$tailwindcss$v;
|
|
@@ -4564,15 +5085,29 @@ function WeappTailwindcss(options = {}) {
|
|
|
4564
5085
|
(_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
|
|
4565
5086
|
(_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
|
|
4566
5087
|
}
|
|
4567
|
-
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler,
|
|
5088
|
+
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
5089
|
+
const initialTailwindRuntime = tailwindRuntime;
|
|
5090
|
+
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
4568
5091
|
const uniAppXEnabled = require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
4569
|
-
const disabledOptions =
|
|
4570
|
-
const tailwindcssMajorVersion =
|
|
5092
|
+
const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
|
|
5093
|
+
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
5094
|
+
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
4571
5095
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
4572
|
-
const shouldRewriteCssImports =
|
|
4573
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4574
|
-
|
|
4575
|
-
|
|
5096
|
+
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5097
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
5098
|
+
appType: opts.appType,
|
|
5099
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5100
|
+
tailwindcssMajorVersion,
|
|
5101
|
+
uniAppX
|
|
5102
|
+
});
|
|
5103
|
+
const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5104
|
+
appType: opts.appType,
|
|
5105
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5106
|
+
tailwindcssMajorVersion,
|
|
5107
|
+
uniAppX
|
|
5108
|
+
});
|
|
5109
|
+
const shouldInferAppType = !hasExplicitAppType && !generatorBranch.isWeb;
|
|
5110
|
+
const hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots({
|
|
4576
5111
|
...options,
|
|
4577
5112
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
4578
5113
|
});
|
|
@@ -4582,16 +5117,19 @@ function WeappTailwindcss(options = {}) {
|
|
|
4582
5117
|
let autoCssSourcesRefresh;
|
|
4583
5118
|
let autoCssSourcesDiscovered = false;
|
|
4584
5119
|
const syncTailwindCssSourceCandidates = async (id, css) => {
|
|
5120
|
+
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource((0, _weapp_tailwindcss_shared.cleanUrl)(id))) return;
|
|
4585
5121
|
await sourceCandidateCollector.syncCss(id, css);
|
|
4586
5122
|
cacheCurrentSourceCandidateScan();
|
|
4587
5123
|
};
|
|
4588
5124
|
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
4589
|
-
if (
|
|
5125
|
+
if (!shouldOwnTailwindGeneration) return;
|
|
4590
5126
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
4591
5127
|
if (!node_path.default.isAbsolute(file)) return;
|
|
5128
|
+
if (!require_v4_engine.isTailwindV4CssEntry(file)) return;
|
|
5129
|
+
if (isMissingInternalCssSource(file)) return;
|
|
4592
5130
|
const sourceFile = node_path.default.normalize(file);
|
|
4593
5131
|
const sourceBase = node_path.default.dirname(sourceFile);
|
|
4594
|
-
const sourceCss =
|
|
5132
|
+
const sourceCss = require_v4_engine.normalizeTailwindSourceForGenerator(require_v4_engine.normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
4595
5133
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
|
|
4596
5134
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
4597
5135
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
@@ -4605,10 +5143,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
4605
5143
|
transientAutoCssSources.set(sourceFile, transientSource);
|
|
4606
5144
|
return;
|
|
4607
5145
|
}
|
|
4608
|
-
const dependencies = await
|
|
5146
|
+
const dependencies = await require_tailwindcss.resolveViteTailwindV4CssDependencies(sourceCss, sourceBase);
|
|
4609
5147
|
transientSource.dependencies = dependencies;
|
|
4610
5148
|
transientAutoCssSources.set(sourceFile, transientSource);
|
|
4611
|
-
if (!
|
|
5149
|
+
if (!require_v4_engine.upsertTailwindV4CssSource(opts, {
|
|
4612
5150
|
file: sourceFile,
|
|
4613
5151
|
base: sourceBase,
|
|
4614
5152
|
css: sourceCss,
|
|
@@ -4624,36 +5162,32 @@ function WeappTailwindcss(options = {}) {
|
|
|
4624
5162
|
await autoCssSourcesRefresh;
|
|
4625
5163
|
};
|
|
4626
5164
|
const discoverAndRegisterAutoCssSources = async () => {
|
|
4627
|
-
if (
|
|
4628
|
-
const cssEntries = await
|
|
5165
|
+
if (!shouldOwnTailwindGeneration || hasInitialTailwindCssRoots || !resolvedConfig?.root) return;
|
|
5166
|
+
const cssEntries = await require_tailwindcss.discoverTailwindV4CssEntries(resolvedConfig.root, resolvedConfig.build?.outDir);
|
|
4629
5167
|
autoCssSourcesDiscovered = true;
|
|
4630
5168
|
let changed = false;
|
|
4631
5169
|
for (const cssEntry of cssEntries) {
|
|
4632
5170
|
const sourceFile = node_path.default.resolve(cssEntry);
|
|
4633
5171
|
const sourceBase = node_path.default.dirname(sourceFile);
|
|
4634
|
-
const sourceCss =
|
|
5172
|
+
const sourceCss = require_v4_engine.normalizeTailwindSourceForGenerator(require_v4_engine.normalizeTailwindConfigDirectives(await (0, node_fs_promises.readFile)(sourceFile, "utf8"), sourceBase), { importFallback: true });
|
|
4635
5173
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) continue;
|
|
4636
5174
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
4637
5175
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
4638
|
-
changed =
|
|
5176
|
+
changed = require_v4_engine.upsertTailwindV4CssSource(opts, {
|
|
4639
5177
|
file: sourceFile,
|
|
4640
5178
|
base: sourceBase,
|
|
4641
5179
|
css: sourceCss,
|
|
4642
|
-
dependencies: (await
|
|
5180
|
+
dependencies: (await require_tailwindcss.resolveTailwindV4EntriesFromCssCached(sourceCss, sourceBase))?.dependencies ?? []
|
|
4643
5181
|
}) || changed;
|
|
4644
5182
|
}
|
|
4645
5183
|
if (!changed) return;
|
|
4646
5184
|
invalidateSourceCandidateScan();
|
|
4647
5185
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
4648
5186
|
};
|
|
4649
|
-
const customAttributesEntities =
|
|
5187
|
+
const customAttributesEntities = require_context.toCustomAttributesEntities(customAttributes);
|
|
4650
5188
|
let resolvedConfig;
|
|
4651
5189
|
let recordedGeneratorCandidates;
|
|
4652
|
-
const
|
|
4653
|
-
const sourceCandidateCollector = require_hmr_timing.createSourceCandidateCollector({
|
|
4654
|
-
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
4655
|
-
extractor: sourceCandidateExtractor
|
|
4656
|
-
});
|
|
5190
|
+
const sourceCandidateCollector = require_hmr_timing.createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
4657
5191
|
const sourceCandidateScanCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4658
5192
|
let sourceScanEntries;
|
|
4659
5193
|
let sourceScanMatcher;
|
|
@@ -4674,8 +5208,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4674
5208
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
4675
5209
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
4676
5210
|
opts,
|
|
4677
|
-
|
|
4678
|
-
|
|
5211
|
+
initialTailwindRuntime,
|
|
5212
|
+
refreshTailwindcssRuntime: refreshTailwindRuntime,
|
|
4679
5213
|
uniAppXEnabled,
|
|
4680
5214
|
customAttributesEntities,
|
|
4681
5215
|
disabledDefaultTemplateHandler,
|
|
@@ -4691,7 +5225,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4691
5225
|
const isCssAssetProcessed = (asset, file) => {
|
|
4692
5226
|
if (processedCssAssets.has(asset)) return true;
|
|
4693
5227
|
if (!file) return false;
|
|
4694
|
-
const record = viteProcessedCssAssetResults.get(
|
|
5228
|
+
const record = viteProcessedCssAssetResults.get(require_source_candidate_scan_signature.normalizeOutputPathKey(file));
|
|
4695
5229
|
if (!record) return false;
|
|
4696
5230
|
return (typeof asset.source === "string" ? asset.source : asset.source instanceof Uint8Array ? node_buffer.Buffer.from(asset.source).toString() : String(asset.source ?? "")) === record.css;
|
|
4697
5231
|
};
|
|
@@ -4732,6 +5266,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4732
5266
|
seenRoots.add(basedir);
|
|
4733
5267
|
}
|
|
4734
5268
|
for (const cssEntry of opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
5269
|
+
if (!require_v4_engine.isTailwindV4CssEntry(cssEntry)) continue;
|
|
4735
5270
|
const cssEntryRoot = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
4736
5271
|
if (seenRoots.has(cssEntryRoot)) continue;
|
|
4737
5272
|
roots.push({ root: cssEntryRoot });
|
|
@@ -4766,16 +5301,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
4766
5301
|
}
|
|
4767
5302
|
const root = resolvedConfig?.root ?? node_process.default.cwd();
|
|
4768
5303
|
const outDir = resolvedConfig?.build?.outDir;
|
|
4769
|
-
const sourceScan = await
|
|
5304
|
+
const sourceScan = await require_tailwindcss.resolveViteSourceScanEntries(opts, runtimeState.tailwindRuntime, {
|
|
4770
5305
|
outDir,
|
|
4771
5306
|
root
|
|
4772
5307
|
});
|
|
4773
5308
|
sourceScanEntries = sourceScan?.entries;
|
|
4774
5309
|
sourceScanExplicit = sourceScan?.explicit ?? false;
|
|
4775
|
-
sourceScanMatcher =
|
|
5310
|
+
sourceScanMatcher = require_tailwindcss.createViteSourceScanMatcher(sourceScanEntries);
|
|
4776
5311
|
sourceScanDependencies = new Set((sourceScan?.dependencies ?? []).map(normalizeSourceScanDependency));
|
|
4777
5312
|
const roots = collectSourceCandidateScanRoots(root, sourceScanEntries);
|
|
4778
|
-
const nextScanSignature = createSourceCandidateScanSignature({
|
|
5313
|
+
const nextScanSignature = require_source_candidate_scan_signature.createSourceCandidateScanSignature({
|
|
4779
5314
|
inlineCandidates: sourceScan?.inlineCandidates,
|
|
4780
5315
|
outDir,
|
|
4781
5316
|
roots,
|
|
@@ -4817,6 +5352,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4817
5352
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
4818
5353
|
sourceCandidateCollector.remove(file);
|
|
4819
5354
|
cacheCurrentSourceCandidateScan();
|
|
5355
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(file)) return (0, node_fs_promises.readFile)(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
5356
|
+
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);
|
|
5357
|
+
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4820
5358
|
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
4821
5359
|
}
|
|
4822
5360
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
@@ -4849,7 +5387,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4849
5387
|
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
4850
5388
|
const getViteCssCacheStats = () => ({
|
|
4851
5389
|
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
5390
|
+
viteGeneratedCssByFileRaw: summarizeStringCache(viteGeneratedCssByFile),
|
|
4852
5391
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
5392
|
+
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(viteProcessedCssAssetResults),
|
|
4853
5393
|
...cssMemory.getStats(),
|
|
4854
5394
|
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4855
5395
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
@@ -4885,7 +5425,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4885
5425
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
4886
5426
|
};
|
|
4887
5427
|
const isViteProcessedCssAsset = (asset, file) => {
|
|
4888
|
-
if (
|
|
5428
|
+
if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(asset.source)) return true;
|
|
4889
5429
|
return [
|
|
4890
5430
|
file,
|
|
4891
5431
|
asset.originalFileName,
|
|
@@ -4895,7 +5435,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4895
5435
|
const transformCssHandlerOptions = createCssHandlerOptionsCache({
|
|
4896
5436
|
getAppType: () => opts.appType,
|
|
4897
5437
|
mainCssChunkMatcher,
|
|
4898
|
-
getMajorVersion: () => runtimeState.
|
|
5438
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4899
5439
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? node_path.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
4900
5440
|
getExtraOptions: (file) => ({
|
|
4901
5441
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -4907,11 +5447,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4907
5447
|
await runtimeState.readyPromise;
|
|
4908
5448
|
await waitForSourceCandidateSyncs();
|
|
4909
5449
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
5450
|
+
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id : file;
|
|
5451
|
+
if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
|
|
4910
5452
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
4911
5453
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4912
5454
|
const isNativeAppStyleTarget = require_utils.resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4913
5455
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
4914
|
-
const outputFile = resolveViteCssPipelineOutputFile(
|
|
5456
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, generatorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
4915
5457
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4916
5458
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4917
5459
|
const cssHandlerOptions = {
|
|
@@ -4919,13 +5461,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
4919
5461
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
4920
5462
|
};
|
|
4921
5463
|
const transientCssSource = transientAutoCssSources.get(file);
|
|
4922
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk &&
|
|
4923
|
-
const generated = await
|
|
5464
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(code));
|
|
5465
|
+
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
4924
5466
|
opts,
|
|
4925
5467
|
runtimeState,
|
|
4926
5468
|
runtime,
|
|
4927
5469
|
rawSource: code,
|
|
4928
5470
|
file,
|
|
5471
|
+
outputFile,
|
|
4929
5472
|
cssHandlerOptions,
|
|
4930
5473
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
4931
5474
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
@@ -4942,7 +5485,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4942
5485
|
});
|
|
4943
5486
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
4944
5487
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
4945
|
-
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) ||
|
|
5488
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || require_v4_engine.hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }) && !require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile).includes("/");
|
|
4946
5489
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
4947
5490
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
4948
5491
|
outputFile
|
|
@@ -4965,7 +5508,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4965
5508
|
sourceFile: id
|
|
4966
5509
|
});
|
|
4967
5510
|
debug("css generated for vite postcss pipeline: %s bytes=%d", file, tracedCss.length);
|
|
4968
|
-
return `${
|
|
5511
|
+
return `${require_source_candidate_scan_signature.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
4969
5512
|
};
|
|
4970
5513
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
4971
5514
|
getAppType: () => opts.appType,
|
|
@@ -4974,6 +5517,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4974
5517
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
4975
5518
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
4976
5519
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
5520
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && require_v4_engine.hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }),
|
|
4977
5521
|
shouldOwnTailwindGeneration,
|
|
4978
5522
|
shouldRewrite: shouldRewriteCssImports,
|
|
4979
5523
|
weappTailwindcssDirPosix
|
|
@@ -5056,7 +5600,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5056
5600
|
const plugins = [
|
|
5057
5601
|
...rewritePlugins,
|
|
5058
5602
|
{
|
|
5059
|
-
name: `${
|
|
5603
|
+
name: `${require_context.vitePluginName}:source-candidates`,
|
|
5060
5604
|
enforce: "pre",
|
|
5061
5605
|
async transform(code, id) {
|
|
5062
5606
|
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, code);
|
|
@@ -5091,7 +5635,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5091
5635
|
await syncChangedSourceCandidateFile(ctx.file);
|
|
5092
5636
|
if (isSourceCandidateHotUpdate) invalidateRecordedGeneratorCandidates();
|
|
5093
5637
|
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
5094
|
-
if (isSourceCandidateHotUpdate && !
|
|
5638
|
+
if (isSourceCandidateHotUpdate && !require_source_candidate_scan_signature.isSourceStyleRequest(ctx.file) && (!hasSelfAcceptingNonStyleHotModule(ctx.modules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
5095
5639
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
5096
5640
|
return [];
|
|
5097
5641
|
}
|
|
@@ -5112,7 +5656,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5112
5656
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
5113
5657
|
}),
|
|
5114
5658
|
{
|
|
5115
|
-
name: `${
|
|
5659
|
+
name: `${require_context.vitePluginName}:post`,
|
|
5116
5660
|
enforce: "post",
|
|
5117
5661
|
config(config) {
|
|
5118
5662
|
if (!shouldOwnTailwindGeneration) return;
|
|
@@ -5173,11 +5717,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5173
5717
|
const removed = (0, _weapp_tailwindcss_postcss.removeTailwindPostcssPlugins)(postcssPlugins);
|
|
5174
5718
|
if (removed > 0) debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
5175
5719
|
}
|
|
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
5720
|
}
|
|
5182
5721
|
}, { emit: false });
|
|
5183
5722
|
},
|