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,22 +1,21 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
4
|
-
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, p as replaceWxml, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-CRI90iL1.mjs";
|
|
2
|
+
import { A as removeTailwindSourceDirectives, C as hasTailwindRootDirectives, E as normalizeTailwindConfigDirectives, I as hasTailwindGeneratedCssMarkers, K as getTailwindV4IncrementalGenerateCacheStats, O as normalizeTailwindSourceForGenerator, S as hasTailwindNonRootGenerationDirectives, T as hasTailwindSourceDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, b as hasLocalCssImport, ct as omitUndefined, d as normalizeCssEntries, f as findNearestPackageRoot, it as resolveTailwindV4CssSourceBase, k as parseImportRequest, o as hasConfiguredTailwindV4CssRoots, s as upsertTailwindV4CssSource, st as filterUnsupportedMiniProgramTailwindV4Candidates, u as isTailwindV4CssEntry, w as hasTailwindRootImportDirectives, x as hasTailwindApplyDirective } from "./v4-engine-CF9zt4Cw.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-Dc4qaPmT.mjs";
|
|
5
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { _ as
|
|
8
|
-
import {
|
|
5
|
+
import { _ as collectRuntimeClassSet, b as refreshTailwindRuntimeState, c as shouldSkipJsTransform, g as toCustomAttributesEntities, i as vitePluginName, p as replaceWxml, t as getCompilerContext, v as createTailwindRuntimeReadyPromise, x as createDebug } from "./context-Mbzkek1q.mjs";
|
|
6
|
+
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-wyUHrfil.mjs";
|
|
7
|
+
import { A as stripMiniProgramCssSpecificityPlaceholders, F as processCachedTask, M as createCssSourceTraceCacheSignature, N as createCssTokenSourceMap, O as hasMiniProgramCssSpecificityPlaceholders, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, f as pushConcurrentTaskFactories, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, j as annotateCssSourceTrace, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder } from "./hmr-timing-BXMLsF4b.mjs";
|
|
8
|
+
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-Cvb5z1ha.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
10
|
import fs, { existsSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
13
|
-
import {
|
|
13
|
+
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
|
+
import { containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
|
|
14
15
|
import { LRUCache } from "lru-cache";
|
|
15
|
-
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
16
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
17
16
|
import { readFile } from "node:fs/promises";
|
|
18
17
|
import { Buffer } from "node:buffer";
|
|
19
|
-
import
|
|
18
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
20
19
|
import { parse } from "comment-json";
|
|
21
20
|
//#region src/uni-app-x/harmony.ts
|
|
22
21
|
function isUniAppXHarmonyOutDir(outDir) {
|
|
@@ -353,18 +352,13 @@ function findFirstStyleObjectDecl(source) {
|
|
|
353
352
|
varName
|
|
354
353
|
};
|
|
355
354
|
}
|
|
356
|
-
function resolveCssFallbackFiles(
|
|
357
|
-
const files =
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (file.startsWith("assets/") && file.endsWith(".js")) {
|
|
364
|
-
const withoutAssets = file.slice(7).replace(/\.js$/, "");
|
|
365
|
-
files.push(`${withoutAssets}.wxss`, `${withoutAssets}.css`);
|
|
366
|
-
}
|
|
367
|
-
return files;
|
|
355
|
+
function resolveCssFallbackFiles(styleAssetFiles = []) {
|
|
356
|
+
const files = /* @__PURE__ */ new Set();
|
|
357
|
+
for (const assetFile of styleAssetFiles) if (assetFile) files.add(assetFile);
|
|
358
|
+
return [...files];
|
|
359
|
+
}
|
|
360
|
+
function resolveStyleAssetFilesForChunk(file, styleAssetFiles) {
|
|
361
|
+
return typeof styleAssetFiles === "function" ? styleAssetFiles(file) : styleAssetFiles;
|
|
368
362
|
}
|
|
369
363
|
function resolveSourceMapFiles(file) {
|
|
370
364
|
return [
|
|
@@ -374,7 +368,7 @@ function resolveSourceMapFiles(file) {
|
|
|
374
368
|
].filter((item) => typeof item === "string");
|
|
375
369
|
}
|
|
376
370
|
function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) {
|
|
377
|
-
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(file).map((cssFile) => {
|
|
371
|
+
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(resolveStyleAssetFilesForChunk(file, options.styleAssetFiles)).map((cssFile) => {
|
|
378
372
|
const source = getBundleSource?.(cssFile);
|
|
379
373
|
return source ? cssSourceToStyleValue(source) : void 0;
|
|
380
374
|
}));
|
|
@@ -425,12 +419,15 @@ function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options =
|
|
|
425
419
|
}
|
|
426
420
|
function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
427
421
|
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
422
|
+
const styleAssetFilesByChunk = collectUniAppXBundleStyleAssetFilesByChunk(bundle);
|
|
423
|
+
const resolveStyleAssetFiles = typeof options.styleAssetFiles === "function" ? options.styleAssetFiles : (file) => [...options.styleAssetFiles ?? [], ...styleAssetFilesByChunk.get(file) ?? []];
|
|
428
424
|
let changed = false;
|
|
429
425
|
for (const [file, item] of Object.entries(bundle)) {
|
|
430
426
|
if (item.type !== "chunk" || !file.endsWith(".js")) continue;
|
|
431
427
|
const currentSource = item.code;
|
|
432
428
|
const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, {
|
|
433
429
|
...options,
|
|
430
|
+
styleAssetFiles: resolveStyleAssetFiles,
|
|
434
431
|
mapSources: collectChunkMapSourcesContent(item)
|
|
435
432
|
});
|
|
436
433
|
if (nextSource !== currentSource) {
|
|
@@ -440,6 +437,41 @@ function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
|
440
437
|
}
|
|
441
438
|
return changed;
|
|
442
439
|
}
|
|
440
|
+
function collectUniAppXBundleStyleAssetFilesByChunk(bundle) {
|
|
441
|
+
const styleAssetFilesByChunk = /* @__PURE__ */ new Map();
|
|
442
|
+
const appStyleAssetFiles = /* @__PURE__ */ new Set();
|
|
443
|
+
const assetFiles = new Set(Object.entries(bundle).filter(([, item]) => item.type === "asset").map(([file]) => file).filter(isStyleAssetFile));
|
|
444
|
+
for (const [chunkFile, item] of Object.entries(bundle)) {
|
|
445
|
+
if (item.type !== "chunk") continue;
|
|
446
|
+
const chunk = item;
|
|
447
|
+
for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
|
|
448
|
+
if (!assetFiles.has(cssFile)) continue;
|
|
449
|
+
if (APP_JS_RE.test(chunk.fileName ?? chunkFile) || APP_JS_RE.test(chunkFile)) {
|
|
450
|
+
appStyleAssetFiles.add(cssFile);
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(chunkFile);
|
|
454
|
+
if (!styleAssetFiles) {
|
|
455
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
456
|
+
styleAssetFilesByChunk.set(chunkFile, styleAssetFiles);
|
|
457
|
+
}
|
|
458
|
+
styleAssetFiles.add(cssFile);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (appStyleAssetFiles.size > 0) for (const [file, item] of Object.entries(bundle)) {
|
|
462
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
463
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(file);
|
|
464
|
+
if (!styleAssetFiles) {
|
|
465
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
466
|
+
styleAssetFilesByChunk.set(file, styleAssetFiles);
|
|
467
|
+
}
|
|
468
|
+
for (const appStyleAssetFile of appStyleAssetFiles) styleAssetFiles.add(appStyleAssetFile);
|
|
469
|
+
}
|
|
470
|
+
return styleAssetFilesByChunk;
|
|
471
|
+
}
|
|
472
|
+
function isStyleAssetFile(file) {
|
|
473
|
+
return /\.(?:acss|css|jxss|qss|ttss|wxss)$/i.test(file);
|
|
474
|
+
}
|
|
443
475
|
function isUniAppXHarmonyBundle(bundle) {
|
|
444
476
|
for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true;
|
|
445
477
|
return false;
|
|
@@ -476,7 +508,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
476
508
|
//#region src/uni-app-x/vite.ts
|
|
477
509
|
let transformUVuePromise;
|
|
478
510
|
function loadTransformUVue() {
|
|
479
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
511
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-tExdt40m.mjs").then((mod) => mod.transformUVue));
|
|
480
512
|
return transformUVuePromise;
|
|
481
513
|
}
|
|
482
514
|
const preprocessorLangs = new Set([
|
|
@@ -775,25 +807,25 @@ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
|
775
807
|
}
|
|
776
808
|
return [...matches];
|
|
777
809
|
}
|
|
778
|
-
function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
779
|
-
if (candidates.has("container")) return candidates;
|
|
780
|
-
if (!sourceCandidates.has("container")) return candidates;
|
|
781
|
-
return new Set([...candidates, "container"]);
|
|
782
|
-
}
|
|
783
810
|
//#endregion
|
|
784
811
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
785
812
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
786
|
-
const
|
|
787
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...
|
|
813
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
814
|
+
return filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
788
815
|
}
|
|
789
816
|
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
790
817
|
const entries = [];
|
|
818
|
+
const seen = /* @__PURE__ */ new Set();
|
|
791
819
|
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
792
820
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
793
821
|
const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
794
822
|
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : path.join(base, "tailwind.css");
|
|
823
|
+
const resolvedFile = path.isAbsolute(file) ? path.resolve(file) : path.resolve(base, file);
|
|
824
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
825
|
+
if (seen.has(key)) continue;
|
|
826
|
+
seen.add(key);
|
|
795
827
|
entries.push({
|
|
796
|
-
file:
|
|
828
|
+
file: resolvedFile,
|
|
797
829
|
source: cssSource.css
|
|
798
830
|
});
|
|
799
831
|
}
|
|
@@ -890,8 +922,23 @@ function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
|
890
922
|
if (!cssMatcher || !stem) return;
|
|
891
923
|
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
892
924
|
}
|
|
925
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
926
|
+
const cleanStem = normalizeOutputPathKey(stem);
|
|
927
|
+
const stemSuffix = `/${cleanStem}`;
|
|
928
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
929
|
+
for (const file of files ?? []) {
|
|
930
|
+
const cleanFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
931
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
932
|
+
const extension = path.extname(cleanFile);
|
|
933
|
+
if (!extension || extension === ".css") continue;
|
|
934
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
935
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
936
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix)) matchedFiles.add(cleanFile);
|
|
937
|
+
}
|
|
938
|
+
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
939
|
+
}
|
|
893
940
|
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
894
|
-
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ??
|
|
941
|
+
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;
|
|
895
942
|
}
|
|
896
943
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
897
944
|
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
@@ -931,6 +978,21 @@ function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTar
|
|
|
931
978
|
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(normalizedFile)) return normalizedFile;
|
|
932
979
|
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
933
980
|
}
|
|
981
|
+
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
982
|
+
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot);
|
|
983
|
+
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
984
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
985
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
986
|
+
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
987
|
+
if (matchedStyleFile) return matchedStyleFile;
|
|
988
|
+
const styleExtension = resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? resolveMiniProgramStyleOutputExtension({
|
|
989
|
+
cssMatcher: opts.cssMatcher,
|
|
990
|
+
fallback: styleOutputExtension,
|
|
991
|
+
files: styleOutputFiles,
|
|
992
|
+
stem
|
|
993
|
+
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
994
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
995
|
+
}
|
|
934
996
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
935
997
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
936
998
|
try {
|
|
@@ -1003,11 +1065,11 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1003
1065
|
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
1004
1066
|
}
|
|
1005
1067
|
function collectConfiguredCssEntries(opts) {
|
|
1006
|
-
const
|
|
1068
|
+
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1007
1069
|
return [
|
|
1008
1070
|
...opts.cssEntries ?? [],
|
|
1009
1071
|
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
1010
|
-
...
|
|
1072
|
+
...runtimeCssEntries ?? []
|
|
1011
1073
|
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1012
1074
|
}
|
|
1013
1075
|
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
@@ -1022,9 +1084,9 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1022
1084
|
};
|
|
1023
1085
|
addCandidate(path.dirname(path.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
1024
1086
|
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
1025
|
-
const
|
|
1026
|
-
const sourceBaseFallback = opts.tailwindcss?.v4?.base ??
|
|
1027
|
-
const sourceRoot = opts.tailwindcssBasedir ??
|
|
1087
|
+
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1088
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1089
|
+
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1028
1090
|
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1029
1091
|
for (const cssEntry of configuredCssEntries) {
|
|
1030
1092
|
const resolvedCssEntry = path.resolve(cssEntry);
|
|
@@ -1064,7 +1126,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1064
1126
|
const appType = options.getAppType();
|
|
1065
1127
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
1066
1128
|
const outputRoot = options.getOutputRoot?.();
|
|
1067
|
-
const from = outputRoot ? path.resolve(outputRoot, file) : file;
|
|
1129
|
+
const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
|
|
1068
1130
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
1069
1131
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
|
|
1070
1132
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
@@ -1122,7 +1184,7 @@ function createCssTransformShareScope(file, rawSource) {
|
|
|
1122
1184
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
1123
1185
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${normalizeOutputPathKey(file)}`;
|
|
1124
1186
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1125
|
-
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })
|
|
1187
|
+
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${normalizeOutputPathKey(file)}`;
|
|
1126
1188
|
return createCssTransformShareScope(file, rawSource);
|
|
1127
1189
|
}
|
|
1128
1190
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -1142,8 +1204,7 @@ function resolveGenerateBundleEnvFlags() {
|
|
|
1142
1204
|
forceRuntimeRefreshByEnv: process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1143
1205
|
disableDirtyOptimization: process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1144
1206
|
disableJsPrecheck: process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1",
|
|
1145
|
-
debugCssDiff: process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1"
|
|
1146
|
-
disableV3OxideSourceRuntime: process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1"
|
|
1207
|
+
debugCssDiff: process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1"
|
|
1147
1208
|
};
|
|
1148
1209
|
}
|
|
1149
1210
|
//#endregion
|
|
@@ -1615,8 +1676,14 @@ function extractSfcStyleSources(source) {
|
|
|
1615
1676
|
function hasSfcStyleSources(source) {
|
|
1616
1677
|
return extractSfcStyleSources(source).length > 0;
|
|
1617
1678
|
}
|
|
1618
|
-
function hasTailwindGenerationSource(source) {
|
|
1619
|
-
|
|
1679
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
1680
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1681
|
+
return hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1682
|
+
}
|
|
1683
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1684
|
+
if (isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1685
|
+
if (hasTailwindRootImportDirectives(source, { importFallback: true })) return false;
|
|
1686
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1620
1687
|
}
|
|
1621
1688
|
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1622
1689
|
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
@@ -1630,7 +1697,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1630
1697
|
return;
|
|
1631
1698
|
}
|
|
1632
1699
|
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1633
|
-
if (!rawSource || !
|
|
1700
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1634
1701
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1635
1702
|
return;
|
|
1636
1703
|
}
|
|
@@ -1737,8 +1804,8 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1737
1804
|
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1738
1805
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1739
1806
|
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1740
|
-
if (!rawSource || !
|
|
1741
|
-
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) &&
|
|
1807
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1808
|
+
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1742
1809
|
file,
|
|
1743
1810
|
source,
|
|
1744
1811
|
score: scoreMatchingStyleFileBase(outputFile, file, outputRoot, sourceRoot)
|
|
@@ -1752,7 +1819,7 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1752
1819
|
}
|
|
1753
1820
|
}
|
|
1754
1821
|
if (!sourceFile || !rawSource) return;
|
|
1755
|
-
if (!
|
|
1822
|
+
if (!hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1756
1823
|
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1757
1824
|
return;
|
|
1758
1825
|
}
|
|
@@ -1837,10 +1904,10 @@ const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
|
1837
1904
|
function isCssOutputFile(file) {
|
|
1838
1905
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1839
1906
|
}
|
|
1840
|
-
function getAssetFile(bundleFile, asset) {
|
|
1907
|
+
function getAssetFile$1(bundleFile, asset) {
|
|
1841
1908
|
return asset.fileName || bundleFile;
|
|
1842
1909
|
}
|
|
1843
|
-
function readAssetSource(asset) {
|
|
1910
|
+
function readAssetSource$2(asset) {
|
|
1844
1911
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1845
1912
|
}
|
|
1846
1913
|
function clearAssetSource(asset) {
|
|
@@ -1920,9 +1987,9 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
1920
1987
|
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
1921
1988
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1922
1989
|
if (output.type !== "asset") continue;
|
|
1923
|
-
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
1990
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1924
1991
|
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1925
|
-
const source = stripBundlerGeneratedCssMarkers(readAssetSource(output)).trim();
|
|
1992
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1926
1993
|
if (source.length > 0) sources.push(source);
|
|
1927
1994
|
}
|
|
1928
1995
|
return sources;
|
|
@@ -1962,9 +2029,9 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1962
2029
|
let updated = 0;
|
|
1963
2030
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1964
2031
|
if (output.type !== "asset") continue;
|
|
1965
|
-
const file = getAssetFile(bundleFile, output);
|
|
2032
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1966
2033
|
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
1967
|
-
const rawSource = readAssetSource(output);
|
|
2034
|
+
const rawSource = readAssetSource$2(output);
|
|
1968
2035
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
1969
2036
|
if (nextCss === rawSource) continue;
|
|
1970
2037
|
output.source = nextCss;
|
|
@@ -1985,8 +2052,28 @@ function isRootStyleOutputFile(file) {
|
|
|
1985
2052
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1986
2053
|
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1987
2054
|
}
|
|
2055
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
2056
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2057
|
+
}
|
|
2058
|
+
function shouldPreserveMiniProgramImportShell(opts, file, css) {
|
|
2059
|
+
return (opts.appType === "taro" || opts.appType === "uni-app-vite" || opts.appType === "uni-app-x") && isMiniProgramStyleOutputFile(file) && opts.cssMatcher(file) && isPureLocalCssImportWrapper(css);
|
|
2060
|
+
}
|
|
2061
|
+
function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
2062
|
+
if (opts.appType !== "taro") return;
|
|
2063
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2064
|
+
if (importedStyleFiles.size !== 1) return;
|
|
2065
|
+
const [importedFile] = importedStyleFiles;
|
|
2066
|
+
if (!isRootStyleOutputFile(importedFile)) return;
|
|
2067
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2068
|
+
if (output.type !== "asset") continue;
|
|
2069
|
+
const outputFile = getAssetFile$1(bundleFile, output);
|
|
2070
|
+
if (normalizeOutputPathKey(outputFile) === normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
1988
2073
|
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
1989
2074
|
const fileKey = normalizeOutputPathKey(file);
|
|
2075
|
+
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return false;
|
|
2076
|
+
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
1990
2077
|
if (records.some((record) => {
|
|
1991
2078
|
if (record.injectIntoMain !== true) return false;
|
|
1992
2079
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
@@ -1996,8 +2083,16 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
|
1996
2083
|
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
1997
2084
|
}
|
|
1998
2085
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
1999
|
-
|
|
2000
|
-
|
|
2086
|
+
return importedStyleFiles.has(normalizeOutputPathKey(record.file)) || typeof record.outputFile === "string" && importedStyleFiles.has(normalizeOutputPathKey(record.outputFile));
|
|
2087
|
+
}
|
|
2088
|
+
function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, assetFiles) {
|
|
2089
|
+
for (const candidate of [record.file, record.outputFile]) {
|
|
2090
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
2091
|
+
const candidateKey = normalizeOutputPathKey(candidate);
|
|
2092
|
+
if (!importedStyleFiles.has(candidateKey)) continue;
|
|
2093
|
+
if (assetFiles.has(candidateKey)) return true;
|
|
2094
|
+
}
|
|
2095
|
+
return false;
|
|
2001
2096
|
}
|
|
2002
2097
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2003
2098
|
if (importedCssSources.length === 0) return css;
|
|
@@ -2011,9 +2106,9 @@ function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
|
2011
2106
|
const importedSources = [];
|
|
2012
2107
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2013
2108
|
if (output.type !== "asset") continue;
|
|
2014
|
-
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
2109
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2015
2110
|
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2016
|
-
importedSources.push(readAssetSource(output));
|
|
2111
|
+
importedSources.push(readAssetSource$2(output));
|
|
2017
2112
|
}
|
|
2018
2113
|
return importedSources;
|
|
2019
2114
|
}
|
|
@@ -2021,7 +2116,7 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2021
2116
|
const files = /* @__PURE__ */ new Set();
|
|
2022
2117
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2023
2118
|
if (output.type !== "asset") continue;
|
|
2024
|
-
files.add(normalizeOutputPathKey(getAssetFile(bundleFile, output)));
|
|
2119
|
+
files.add(normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2025
2120
|
}
|
|
2026
2121
|
return files;
|
|
2027
2122
|
}
|
|
@@ -2044,14 +2139,19 @@ function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveVite
|
|
|
2044
2139
|
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2045
2140
|
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2046
2141
|
}
|
|
2142
|
+
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2143
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2144
|
+
const outputFileKey = normalizeOutputPathKey(outputFile);
|
|
2145
|
+
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2146
|
+
}
|
|
2047
2147
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
2048
2148
|
let collected = 0;
|
|
2049
2149
|
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
2050
2150
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2051
2151
|
if (output.type !== "asset") continue;
|
|
2052
|
-
const file = getAssetFile(bundleFile, output);
|
|
2152
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2053
2153
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
2054
|
-
const rawSource = readAssetSource(output);
|
|
2154
|
+
const rawSource = readAssetSource$2(output);
|
|
2055
2155
|
let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2056
2156
|
const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
|
|
2057
2157
|
if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
|
|
@@ -2059,7 +2159,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2059
2159
|
options.markCssAssetProcessed?.(output, file);
|
|
2060
2160
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2061
2161
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
2062
|
-
const shouldReplayIntoMainCss = options.opts != null && (options.opts.mainCssChunkMatcher(file, options.opts.appType) ||
|
|
2162
|
+
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));
|
|
2063
2163
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2064
2164
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2065
2165
|
outputFile: resolvedOutputFile
|
|
@@ -2104,25 +2204,48 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2104
2204
|
};
|
|
2105
2205
|
}).filter((record) => record.css.length > 0);
|
|
2106
2206
|
let injected = 0;
|
|
2107
|
-
for (const [bundleFile,
|
|
2207
|
+
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2208
|
+
let output = bundleOutput;
|
|
2108
2209
|
if (output.type !== "asset") continue;
|
|
2109
|
-
|
|
2210
|
+
let file = getAssetFile$1(bundleFile, output);
|
|
2110
2211
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2212
|
+
let originalSource = readAssetSource$2(output);
|
|
2213
|
+
if (shouldPreserveMiniProgramImportShell(options.opts, file, originalSource)) {
|
|
2214
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options.opts, bundle, file, originalSource);
|
|
2215
|
+
if (typeof importedTargetFile === "string") {
|
|
2216
|
+
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2217
|
+
const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === normalizeOutputPathKey(importedTargetFile))?.[1];
|
|
2218
|
+
if (importedOutput?.type === "asset") {
|
|
2219
|
+
output = importedOutput;
|
|
2220
|
+
file = importedTargetFile;
|
|
2221
|
+
originalSource = readAssetSource$2(output);
|
|
2222
|
+
} else continue;
|
|
2223
|
+
} else {
|
|
2224
|
+
options.debug?.("preserve mini-program css import shell asset: %s", file);
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2111
2229
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2112
|
-
const originalSource = readAssetSource(output);
|
|
2113
2230
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2114
2231
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2115
2232
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2116
2233
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2117
2234
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2235
|
+
const bundleAssetFiles = collectBundleAssetFiles(bundle);
|
|
2236
|
+
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2237
|
+
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2238
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2120
2239
|
for (const record of viteCssResults) {
|
|
2240
|
+
if (!isRootStyleOutputFile(file)) {
|
|
2241
|
+
if (typeof record.outputFile !== "string" || normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2242
|
+
}
|
|
2121
2243
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2122
2244
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2123
2245
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2124
2246
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2125
2247
|
if (css.length === 0) continue;
|
|
2248
|
+
if (containsCssAfterMinify(nextCss, css) || filterExistingCssRules(nextCss, css).length === 0) continue;
|
|
2126
2249
|
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
2127
2250
|
if (mergedLayerCss.merged) {
|
|
2128
2251
|
nextCss = mergedLayerCss.css;
|
|
@@ -2163,9 +2286,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2163
2286
|
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2164
2287
|
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2165
2288
|
if (candidateOutput.type !== "asset") continue;
|
|
2166
|
-
const candidateKey = normalizeOutputPathKey(getAssetFile(candidateFile, candidateOutput));
|
|
2289
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2167
2290
|
const isRecordFile = candidateKey === recordFileKey;
|
|
2168
|
-
const
|
|
2291
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2292
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(nextCss, candidateSource);
|
|
2169
2293
|
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2170
2294
|
clearAssetSource(candidateOutput);
|
|
2171
2295
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
@@ -2187,31 +2311,84 @@ function normalizeBundleFileNameKeysForTest(bundle) {
|
|
|
2187
2311
|
}
|
|
2188
2312
|
}
|
|
2189
2313
|
//#endregion
|
|
2314
|
+
//#region src/bundlers/vite/generate-bundle/final-css-assets.ts
|
|
2315
|
+
function readAssetSource$1(output) {
|
|
2316
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
2317
|
+
}
|
|
2318
|
+
function shouldFinalizeMiniProgramCssAsset(source) {
|
|
2319
|
+
return source.includes(":hover") || source.includes("does-not-exist") || hasMiniProgramCssSpecificityPlaceholders(source);
|
|
2320
|
+
}
|
|
2321
|
+
async function finalizeMiniProgramCssAssets(bundle, options) {
|
|
2322
|
+
if (options.isWebGeneratorTarget) return 0;
|
|
2323
|
+
let updated = 0;
|
|
2324
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2325
|
+
if (output.type !== "asset") continue;
|
|
2326
|
+
const file = output.fileName || bundleFile;
|
|
2327
|
+
if (!options.cssMatcher(file)) continue;
|
|
2328
|
+
const rawSource = readAssetSource$1(output);
|
|
2329
|
+
if (rawSource.trim().length === 0) continue;
|
|
2330
|
+
if (options.lastCssResultByFile?.has(file)) {
|
|
2331
|
+
const outputCss = stripMiniProgramCssSpecificityPlaceholders(rawSource);
|
|
2332
|
+
if (outputCss !== rawSource) {
|
|
2333
|
+
output.source = outputCss;
|
|
2334
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2335
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2336
|
+
options.debug?.("strip mini-program css specificity placeholders: %s bytes=%d", file, outputCss.length);
|
|
2337
|
+
updated++;
|
|
2338
|
+
}
|
|
2339
|
+
continue;
|
|
2340
|
+
}
|
|
2341
|
+
if (!shouldFinalizeMiniProgramCssAsset(rawSource)) continue;
|
|
2342
|
+
const cssHandlerOptions = options.getCssHandlerOptions(file);
|
|
2343
|
+
const { css } = await options.styleHandler(rawSource, {
|
|
2344
|
+
...cssHandlerOptions,
|
|
2345
|
+
autoprefixer: false,
|
|
2346
|
+
cssOptions: {
|
|
2347
|
+
...cssHandlerOptions.cssOptions ?? {},
|
|
2348
|
+
autoprefixer: false,
|
|
2349
|
+
cssPresetEnv: false
|
|
2350
|
+
},
|
|
2351
|
+
cssPresetEnv: false
|
|
2352
|
+
});
|
|
2353
|
+
const outputCss = stripMiniProgramCssSpecificityPlaceholders(css);
|
|
2354
|
+
if (outputCss === rawSource) continue;
|
|
2355
|
+
output.source = outputCss;
|
|
2356
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2357
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2358
|
+
options.debug?.("finalize mini-program css asset: %s bytes=%d", file, outputCss.length);
|
|
2359
|
+
updated++;
|
|
2360
|
+
}
|
|
2361
|
+
return updated;
|
|
2362
|
+
}
|
|
2363
|
+
//#endregion
|
|
2190
2364
|
//#region src/bundlers/vite/generate-bundle/memory-debug.ts
|
|
2191
|
-
function toMb(bytes) {
|
|
2365
|
+
function toMb$2(bytes) {
|
|
2192
2366
|
return Math.round(bytes / 1024 / 1024);
|
|
2193
2367
|
}
|
|
2194
|
-
function summarizeStringMapCache(map) {
|
|
2368
|
+
function summarizeStringMapCache$1(map) {
|
|
2195
2369
|
let bytes = 0;
|
|
2196
2370
|
for (const value of map.values()) bytes += value.length;
|
|
2197
2371
|
return {
|
|
2198
2372
|
bytes,
|
|
2199
|
-
mb: toMb(bytes),
|
|
2373
|
+
mb: toMb$2(bytes),
|
|
2200
2374
|
size: map.size
|
|
2201
2375
|
};
|
|
2202
2376
|
}
|
|
2203
2377
|
function resolveViteMemoryDebugStats(context) {
|
|
2204
2378
|
if (process$1.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2205
2379
|
const memory = process$1.memoryUsage();
|
|
2380
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
2381
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
2206
2382
|
return {
|
|
2207
2383
|
phase: context.phase,
|
|
2208
2384
|
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2385
|
+
bundle: { hasOmittedKnownFiles: context.hasOmittedKnownFiles },
|
|
2209
2386
|
process: {
|
|
2210
|
-
rssMb: toMb(memory.rss),
|
|
2211
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
2212
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
2213
|
-
externalMb: toMb(memory.external),
|
|
2214
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
2387
|
+
rssMb: toMb$2(memory.rss),
|
|
2388
|
+
heapTotalMb: toMb$2(memory.heapTotal),
|
|
2389
|
+
heapUsedMb: toMb$2(memory.heapUsed),
|
|
2390
|
+
externalMb: toMb$2(memory.external),
|
|
2391
|
+
arrayBuffersMb: toMb$2(memory.arrayBuffers)
|
|
2215
2392
|
},
|
|
2216
2393
|
runtime: {
|
|
2217
2394
|
sourceCandidates: context.sourceCandidatesSize,
|
|
@@ -2220,19 +2397,21 @@ function resolveViteMemoryDebugStats(context) {
|
|
|
2220
2397
|
generatorRuntime: context.generatorRuntimeSize
|
|
2221
2398
|
},
|
|
2222
2399
|
processCache: {
|
|
2223
|
-
instance:
|
|
2224
|
-
hashMap:
|
|
2400
|
+
instance: processCacheInstanceSize,
|
|
2401
|
+
hashMap: processCacheHashMapSize,
|
|
2225
2402
|
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2226
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
2403
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
2404
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
2405
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
2406
|
+
pruned: context.processCachePruned,
|
|
2407
|
+
pruneSkipped: !context.processCachePruned,
|
|
2408
|
+
...context.processCachePruneSkipReason ? { pruneSkipReason: context.processCachePruneSkipReason } : {}
|
|
2227
2409
|
},
|
|
2228
2410
|
viteCss: {
|
|
2229
2411
|
...context.getViteCssCacheStats?.(),
|
|
2230
|
-
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2412
|
+
lastCssResultByFile: summarizeStringMapCache$1(context.lastCssResultByFile)
|
|
2231
2413
|
},
|
|
2232
|
-
tailwind: {
|
|
2233
|
-
v3: getTailwindV3IncrementalGenerateCacheStats(),
|
|
2234
|
-
v4: getTailwindV4IncrementalGenerateCacheStats()
|
|
2235
|
-
}
|
|
2414
|
+
tailwind: { v4: getTailwindV4IncrementalGenerateCacheStats() }
|
|
2236
2415
|
};
|
|
2237
2416
|
}
|
|
2238
2417
|
//#endregion
|
|
@@ -2281,12 +2460,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2281
2460
|
if (isHarmonyAppStyleTarget && applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2282
2461
|
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2283
2462
|
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2284
|
-
const generated = await
|
|
2463
|
+
const generated = await generateTailwindV4Css({
|
|
2285
2464
|
opts,
|
|
2286
2465
|
runtimeState,
|
|
2287
2466
|
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2288
2467
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2289
2468
|
file: outputFile,
|
|
2469
|
+
outputFile,
|
|
2290
2470
|
cssHandlerOptions,
|
|
2291
2471
|
cssUserHandlerOptions: {
|
|
2292
2472
|
...cssHandlerOptions,
|
|
@@ -2317,10 +2497,10 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2317
2497
|
//#endregion
|
|
2318
2498
|
//#region src/bundlers/vite/generate-bundle/vite-css-cache.ts
|
|
2319
2499
|
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2320
|
-
function resolveViteCssTaskConcurrency(
|
|
2500
|
+
function resolveViteCssTaskConcurrency(_useIncrementalMode, _majorVersion) {
|
|
2321
2501
|
const configured = Number.parseInt(process$1.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2322
2502
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2323
|
-
return
|
|
2503
|
+
return 1;
|
|
2324
2504
|
}
|
|
2325
2505
|
function normalizeViteCssCacheKey(file) {
|
|
2326
2506
|
return normalizeOutputPathKey(file);
|
|
@@ -2361,10 +2541,83 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2361
2541
|
}
|
|
2362
2542
|
//#endregion
|
|
2363
2543
|
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
2544
|
+
function readAssetSource(asset) {
|
|
2545
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2546
|
+
}
|
|
2547
|
+
function getAssetFile(bundleFile, asset) {
|
|
2548
|
+
return asset.fileName || bundleFile;
|
|
2549
|
+
}
|
|
2550
|
+
function isRootMiniProgramStyleOutputFile$1(file) {
|
|
2551
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2552
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
2553
|
+
}
|
|
2554
|
+
function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
2555
|
+
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
2556
|
+
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
2557
|
+
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
2558
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
2559
|
+
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
2560
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2561
|
+
}
|
|
2562
|
+
function createCssImportShell$1(targetFile, importedFile) {
|
|
2563
|
+
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
2564
|
+
}
|
|
2565
|
+
function resolveRootMiniProgramOriginStyleFile(file) {
|
|
2566
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2567
|
+
if (!isRootMiniProgramStyleOutputFile$1(normalized)) return;
|
|
2568
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
2569
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
2570
|
+
}
|
|
2571
|
+
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
2572
|
+
let importedFile;
|
|
2573
|
+
try {
|
|
2574
|
+
postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
2575
|
+
if (importedFile !== void 0) return;
|
|
2576
|
+
const request = parseImportRequest(atRule.params);
|
|
2577
|
+
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
2578
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
2579
|
+
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
2580
|
+
const targetDir = path.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
2581
|
+
importedFile = normalizeOutputPathKey(path.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2582
|
+
});
|
|
2583
|
+
} catch {}
|
|
2584
|
+
return importedFile;
|
|
2585
|
+
}
|
|
2586
|
+
function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
2587
|
+
if (options.appType !== "taro") return 0;
|
|
2588
|
+
let updated = 0;
|
|
2589
|
+
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
2590
|
+
if (rootOutput.type !== "asset") continue;
|
|
2591
|
+
const rootFile = getAssetFile(rootBundleFile, rootOutput);
|
|
2592
|
+
if (!isRootMiniProgramStyleOutputFile$1(rootFile) || !options.cssMatcher(rootFile)) continue;
|
|
2593
|
+
const originFile = resolveRootMiniProgramOriginStyleFile(rootFile);
|
|
2594
|
+
if (!originFile || !options.cssMatcher(originFile)) continue;
|
|
2595
|
+
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && normalizeOutputPathKey(getAssetFile(bundleFile, output)) === normalizeOutputPathKey(originFile))?.[1];
|
|
2596
|
+
if (originOutput?.type !== "asset") continue;
|
|
2597
|
+
const rootSource = readAssetSource(rootOutput);
|
|
2598
|
+
if (isPureLocalCssImportWrapper(rootSource)) continue;
|
|
2599
|
+
const originSource = readAssetSource(originOutput);
|
|
2600
|
+
if (isPureLocalCssImportWrapper(originSource)) {
|
|
2601
|
+
const importedFile = resolveSingleCssImportOutputFile(originFile, originSource);
|
|
2602
|
+
if (importedFile && normalizeOutputPathKey(importedFile) !== normalizeOutputPathKey(rootFile)) continue;
|
|
2603
|
+
} else if (originSource.trim().length > 0 && originSource.trim() !== rootSource.trim()) continue;
|
|
2604
|
+
const nextRootSource = createCssImportShell$1(rootFile, originFile);
|
|
2605
|
+
if (rootSource === nextRootSource) continue;
|
|
2606
|
+
rootOutput.source = nextRootSource;
|
|
2607
|
+
originOutput.source = rootSource;
|
|
2608
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2609
|
+
options.recordCssAssetResult?.(originFile, rootSource);
|
|
2610
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2611
|
+
options.onUpdate?.(originFile, originSource, rootSource);
|
|
2612
|
+
options.debug("normalize taro root css import shell: %s -> %s", rootFile, originFile);
|
|
2613
|
+
updated++;
|
|
2614
|
+
}
|
|
2615
|
+
return updated;
|
|
2616
|
+
}
|
|
2364
2617
|
async function finalizeGenerateBundle(options) {
|
|
2365
2618
|
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;
|
|
2366
2619
|
if (cssTaskFactories.length > 0) {
|
|
2367
|
-
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2620
|
+
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion);
|
|
2368
2621
|
tasks.push(runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2369
2622
|
}
|
|
2370
2623
|
const tasksStart = performance.now();
|
|
@@ -2402,9 +2655,10 @@ async function finalizeGenerateBundle(options) {
|
|
|
2402
2655
|
getViteProcessedCssAssetResults,
|
|
2403
2656
|
markCssAssetProcessed,
|
|
2404
2657
|
recordCssAssetResult,
|
|
2405
|
-
shouldRemoveInjectedSourceAsset: (
|
|
2406
|
-
if (record.injectIntoMain
|
|
2407
|
-
|
|
2658
|
+
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2659
|
+
if (record.injectIntoMain === false) return false;
|
|
2660
|
+
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
2661
|
+
return normalizeOutputPathKey(record.file) !== targetFileKey;
|
|
2408
2662
|
},
|
|
2409
2663
|
debug,
|
|
2410
2664
|
onUpdate
|
|
@@ -2415,6 +2669,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2415
2669
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
2416
2670
|
syncViteProcessedCssIntoMainCssAssets();
|
|
2417
2671
|
}
|
|
2672
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
2673
|
+
appType: opts.appType,
|
|
2674
|
+
cssMatcher: opts.cssMatcher,
|
|
2675
|
+
debug,
|
|
2676
|
+
onUpdate,
|
|
2677
|
+
recordCssAssetResult
|
|
2678
|
+
});
|
|
2418
2679
|
normalizeBundleFileNameKeysForTest(bundle);
|
|
2419
2680
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2420
2681
|
cssMatcher: opts.cssMatcher,
|
|
@@ -2424,18 +2685,33 @@ async function finalizeGenerateBundle(options) {
|
|
|
2424
2685
|
recordCssAssetResult,
|
|
2425
2686
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2426
2687
|
});
|
|
2688
|
+
await finalizeMiniProgramCssAssets(bundle, {
|
|
2689
|
+
cssMatcher: opts.cssMatcher,
|
|
2690
|
+
debug,
|
|
2691
|
+
getCssHandlerOptions,
|
|
2692
|
+
isWebGeneratorTarget,
|
|
2693
|
+
lastCssResultByFile,
|
|
2694
|
+
onUpdate,
|
|
2695
|
+
recordCssAssetResult,
|
|
2696
|
+
styleHandler
|
|
2697
|
+
});
|
|
2427
2698
|
const stateUpdateStart = performance.now();
|
|
2428
2699
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2429
2700
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2430
|
-
|
|
2701
|
+
const shouldPruneTransientCaches = !snapshot.hasOmittedKnownFiles;
|
|
2702
|
+
const processCachePruned = useIncrementalMode && shouldPruneTransientCaches && typeof cache.prune === "function";
|
|
2703
|
+
const processCachePruneSkipReason = processCachePruned ? void 0 : !useIncrementalMode ? "full-mode" : !shouldPruneTransientCaches ? "omitted-known-files" : "cache-prune-unavailable";
|
|
2704
|
+
if (processCachePruned) cache.prune?.({
|
|
2431
2705
|
cacheKeys: activeProcessCacheKeys,
|
|
2432
2706
|
hashKeys: activeProcessHashKeys
|
|
2433
2707
|
});
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2708
|
+
if (shouldPruneTransientCaches) {
|
|
2709
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2710
|
+
pruneViteCssCaches?.({
|
|
2711
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2712
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2439
2715
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2440
2716
|
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));
|
|
2441
2717
|
if (hmrTimingRecorder) {
|
|
@@ -2447,8 +2723,11 @@ async function finalizeGenerateBundle(options) {
|
|
|
2447
2723
|
cache,
|
|
2448
2724
|
generatorRuntimeSize: generatorRuntime.size,
|
|
2449
2725
|
getViteCssCacheStats,
|
|
2726
|
+
hasOmittedKnownFiles: snapshot.hasOmittedKnownFiles,
|
|
2450
2727
|
lastCssResultByFile,
|
|
2451
2728
|
phase: "generateBundle",
|
|
2729
|
+
processCachePruned,
|
|
2730
|
+
processCachePruneSkipReason,
|
|
2452
2731
|
runtimeSize: runtime.size,
|
|
2453
2732
|
sourceCandidatesSize: sourceCandidates.size,
|
|
2454
2733
|
transformRuntimeSize: transformRuntime.size,
|
|
@@ -2475,6 +2754,7 @@ function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
|
2475
2754
|
function createJsHandlerOptionsFactory(options) {
|
|
2476
2755
|
return (absoluteFilename, extra) => ({
|
|
2477
2756
|
...extra,
|
|
2757
|
+
generateMap: false,
|
|
2478
2758
|
filename: absoluteFilename,
|
|
2479
2759
|
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
2480
2760
|
moduleGraph: options.moduleGraph,
|
|
@@ -2514,54 +2794,6 @@ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
|
2514
2794
|
}
|
|
2515
2795
|
}
|
|
2516
2796
|
//#endregion
|
|
2517
|
-
//#region src/bundlers/vite/generate-bundle/signatures.ts
|
|
2518
|
-
function summarizeStringDiff(previous, next) {
|
|
2519
|
-
if (previous === next) return "same";
|
|
2520
|
-
const previousLength = previous.length;
|
|
2521
|
-
const nextLength = next.length;
|
|
2522
|
-
const minLength = Math.min(previousLength, nextLength);
|
|
2523
|
-
let prefixLength = 0;
|
|
2524
|
-
while (prefixLength < minLength && previous.charCodeAt(prefixLength) === next.charCodeAt(prefixLength)) prefixLength += 1;
|
|
2525
|
-
let previousSuffixCursor = previousLength - 1;
|
|
2526
|
-
let nextSuffixCursor = nextLength - 1;
|
|
2527
|
-
while (previousSuffixCursor >= prefixLength && nextSuffixCursor >= prefixLength && previous.charCodeAt(previousSuffixCursor) === next.charCodeAt(nextSuffixCursor)) {
|
|
2528
|
-
previousSuffixCursor -= 1;
|
|
2529
|
-
nextSuffixCursor -= 1;
|
|
2530
|
-
}
|
|
2531
|
-
const previousChangedLength = previousSuffixCursor >= prefixLength ? previousSuffixCursor - prefixLength + 1 : 0;
|
|
2532
|
-
const nextChangedLength = nextSuffixCursor >= prefixLength ? nextSuffixCursor - prefixLength + 1 : 0;
|
|
2533
|
-
return `changed@${prefixLength} old=${previousChangedLength} new=${nextChangedLength} len=${previousLength}->${nextLength}`;
|
|
2534
|
-
}
|
|
2535
|
-
function createLinkedImpactSignature(entry, linkedImpactsByEntry, sourceHashByFile) {
|
|
2536
|
-
const changedLinkedFiles = linkedImpactsByEntry.get(entry);
|
|
2537
|
-
if (!changedLinkedFiles || changedLinkedFiles.size === 0) return;
|
|
2538
|
-
return [...changedLinkedFiles].sort().map((file) => {
|
|
2539
|
-
return `${file}:${sourceHashByFile.get(file) ?? "missing"}`;
|
|
2540
|
-
}).join(",");
|
|
2541
|
-
}
|
|
2542
|
-
function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
|
|
2543
|
-
if (!linkedImpactSignature) return runtimeSignature;
|
|
2544
|
-
return `${runtimeSignature}:linked:${linkedImpactSignature}`;
|
|
2545
|
-
}
|
|
2546
|
-
function createStableTextSignature(input) {
|
|
2547
|
-
let hash = 2166136261;
|
|
2548
|
-
for (let i = 0; i < input.length; i++) {
|
|
2549
|
-
hash ^= input.charCodeAt(i);
|
|
2550
|
-
hash = Math.imul(hash, 16777619);
|
|
2551
|
-
}
|
|
2552
|
-
return (hash >>> 0).toString(36);
|
|
2553
|
-
}
|
|
2554
|
-
function createCandidateSignature(candidates) {
|
|
2555
|
-
if (candidates.size === 0) return "empty";
|
|
2556
|
-
return createStableTextSignature([...candidates].sort().join("\n"));
|
|
2557
|
-
}
|
|
2558
|
-
function getSnapshotHash(snapshotMap, file, fallback) {
|
|
2559
|
-
return snapshotMap.get(file) ?? fallback;
|
|
2560
|
-
}
|
|
2561
|
-
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
2562
|
-
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
2563
|
-
}
|
|
2564
|
-
//#endregion
|
|
2565
2797
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2566
2798
|
function processJsBundleEntry(options) {
|
|
2567
2799
|
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
@@ -2574,16 +2806,26 @@ function processJsBundleEntry(options) {
|
|
|
2574
2806
|
const initialRawSource = originalEntrySource;
|
|
2575
2807
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2576
2808
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2809
|
+
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2810
|
+
const hashKey = `${file}:js`;
|
|
2811
|
+
const processHash = `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`;
|
|
2812
|
+
rememberProcessCacheKey(file, hashKey);
|
|
2813
|
+
if (useIncrementalMode && !shouldTransformJs) {
|
|
2814
|
+
const cachedCode = cache.getHashValue(hashKey)?.hash === processHash ? cache.get(file) : void 0;
|
|
2815
|
+
if (cachedCode !== void 0) {
|
|
2816
|
+
originalSource.code = cachedCode;
|
|
2817
|
+
metrics.js.cacheHits++;
|
|
2818
|
+
debug("js direct replay hit: %s", file);
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2577
2822
|
jsTaskFactories.push(async () => {
|
|
2578
2823
|
await timeTask("js", async () => {
|
|
2579
|
-
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2580
|
-
const hashKey = `${file}:js`;
|
|
2581
|
-
rememberProcessCacheKey(file, hashKey);
|
|
2582
2824
|
await processCachedTask({
|
|
2583
2825
|
cache,
|
|
2584
2826
|
cacheKey: file,
|
|
2585
2827
|
hashKey,
|
|
2586
|
-
hash:
|
|
2828
|
+
hash: processHash,
|
|
2587
2829
|
applyResult(source) {
|
|
2588
2830
|
originalSource.code = source;
|
|
2589
2831
|
},
|
|
@@ -2741,40 +2983,17 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
2741
2983
|
return groups;
|
|
2742
2984
|
}
|
|
2743
2985
|
//#endregion
|
|
2744
|
-
//#region src/bundlers/vite/generate-bundle/scoped-generator.ts
|
|
2745
|
-
function hasOwnSourceDirectives(rawSource) {
|
|
2746
|
-
return rawSource.includes("@source") || rawSource.includes("@config");
|
|
2747
|
-
}
|
|
2748
|
-
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
2749
|
-
if (!getSourceCandidatesForEntries || !hasOwnSourceDirectives(rawSource)) return fallbackSignature;
|
|
2750
|
-
const sourceBase = path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2751
|
-
const resolved = options.majorVersion === 3 ? await resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2752
|
-
if (resolved?.entries === void 0) return fallbackSignature;
|
|
2753
|
-
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
2754
|
-
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
2755
|
-
}
|
|
2756
|
-
async function createScopedGeneratorRuntime(options) {
|
|
2757
|
-
const { cssHandlerOptions, fallbackRuntime, getSourceCandidatesForEntries, majorVersion, outputFile, rawSource, shouldExcludeSubpackageSourceCandidates, sourceFile, scopedSourceCandidateGetter } = options;
|
|
2758
|
-
if (getSourceCandidatesForEntries && rawSource && sourceFile) {
|
|
2759
|
-
const sourceBase = path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2760
|
-
const resolved = majorVersion === 3 ? await resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2761
|
-
if (resolved?.entries !== void 0 && (resolved.entries.length > 0 || hasOwnSourceDirectives(rawSource))) return scopedSourceCandidateGetter?.(resolved.entries) ?? getSourceCandidatesForEntries(resolved.entries);
|
|
2762
|
-
}
|
|
2763
|
-
const scopedCandidates = scopedSourceCandidateGetter?.(void 0);
|
|
2764
|
-
if (scopedCandidates && (scopedCandidates.size > 0 || shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions))) return scopedCandidates;
|
|
2765
|
-
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return fallbackRuntime;
|
|
2766
|
-
return fallbackRuntime;
|
|
2767
|
-
}
|
|
2768
|
-
//#endregion
|
|
2769
2986
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
2770
2987
|
async function processRememberedCssReplay(options) {
|
|
2771
2988
|
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;
|
|
2772
2989
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
2773
2990
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2991
|
+
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
2774
2992
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2775
2993
|
key: item.key,
|
|
2776
2994
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2777
2995
|
})));
|
|
2996
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2778
2997
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2779
2998
|
if (!rememberedCssSource) continue;
|
|
2780
2999
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
@@ -2787,33 +3006,33 @@ async function processRememberedCssReplay(options) {
|
|
|
2787
3006
|
};
|
|
2788
3007
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2789
3008
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2790
|
-
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2791
|
-
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2792
|
-
opts,
|
|
2793
|
-
tokenSources: sourceTraceTokenSources
|
|
2794
|
-
});
|
|
2795
3009
|
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, rawSource, sourceFile);
|
|
2796
3010
|
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
2797
3011
|
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
2798
|
-
majorVersion: runtimeState.
|
|
3012
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
2799
3013
|
}));
|
|
2800
3014
|
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2801
3015
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2802
3016
|
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2803
|
-
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2804
3017
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2805
3018
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3019
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3020
|
+
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3021
|
+
opts,
|
|
3022
|
+
tokenSources: sourceTraceTokenSources
|
|
3023
|
+
});
|
|
2806
3024
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
2807
3025
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
2808
3026
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
2809
3027
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2810
3028
|
const start = performance.now();
|
|
2811
|
-
const generated = await
|
|
3029
|
+
const generated = await generateTailwindV4Css({
|
|
2812
3030
|
opts,
|
|
2813
3031
|
runtimeState,
|
|
2814
3032
|
runtime: scopedGeneratorRuntime,
|
|
2815
3033
|
rawSource,
|
|
2816
3034
|
file: sourceFile,
|
|
3035
|
+
outputFile,
|
|
2817
3036
|
cssHandlerOptions,
|
|
2818
3037
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2819
3038
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
@@ -2905,11 +3124,43 @@ function intersectCandidateSourceMaps(left, right) {
|
|
|
2905
3124
|
for (const [candidate, sources] of left) if (right.has(candidate)) matched.set(candidate, sources);
|
|
2906
3125
|
return matched;
|
|
2907
3126
|
}
|
|
3127
|
+
function normalizeSourceFile(file) {
|
|
3128
|
+
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
3129
|
+
}
|
|
3130
|
+
function resolveSubpackageSourceRootFromFile(file, subpackageRoot) {
|
|
3131
|
+
const normalizedFile = normalizeSourceFile(file).split(path.sep).join("/");
|
|
3132
|
+
const normalizedRoot = subpackageRoot.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
3133
|
+
if (!normalizedRoot) return;
|
|
3134
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
3135
|
+
const rootIndex = normalizedFile.lastIndexOf(rootSegment);
|
|
3136
|
+
if (rootIndex < 0) return;
|
|
3137
|
+
return normalizedFile.slice(0, rootIndex);
|
|
3138
|
+
}
|
|
3139
|
+
function collectSubpackageSourceRootsFromCssSources(cssSourceFiles, subpackageRoots) {
|
|
3140
|
+
const sourceRootsByPackageRoot = /* @__PURE__ */ new Map();
|
|
3141
|
+
if (!cssSourceFiles || !subpackageRoots) return sourceRootsByPackageRoot;
|
|
3142
|
+
for (const file of cssSourceFiles) {
|
|
3143
|
+
if (typeof file !== "string" || file.length === 0) continue;
|
|
3144
|
+
for (const root of subpackageRoots) {
|
|
3145
|
+
const sourceRoot = resolveSubpackageSourceRootFromFile(file, root);
|
|
3146
|
+
if (!sourceRoot) continue;
|
|
3147
|
+
const roots = sourceRootsByPackageRoot.get(root) ?? /* @__PURE__ */ new Set();
|
|
3148
|
+
roots.add(sourceRoot);
|
|
3149
|
+
sourceRootsByPackageRoot.set(root, roots);
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
return sourceRootsByPackageRoot;
|
|
3153
|
+
}
|
|
3154
|
+
function flattenSourceRoots(sourceRootsByPackageRoot) {
|
|
3155
|
+
return [...new Set([...sourceRootsByPackageRoot.values()].flatMap((roots) => [...roots]))];
|
|
3156
|
+
}
|
|
2908
3157
|
function createSubpackageSourceCandidateScope(options) {
|
|
3158
|
+
const cssSourceRootsByPackageRoot = collectSubpackageSourceRootsFromCssSources(options.cssSourceFiles, options.subpackageRoots);
|
|
2909
3159
|
const subpackageSourceExcludeEntries = options.subpackageRoots ? collectMiniProgramSubpackageSourceEntries(options.snapshot, options.subpackageRoots, [
|
|
2910
3160
|
options.rootDir,
|
|
2911
3161
|
options.tailwindcssBasedir,
|
|
2912
|
-
options.projectRoot
|
|
3162
|
+
options.projectRoot,
|
|
3163
|
+
...flattenSourceRoots(cssSourceRootsByPackageRoot)
|
|
2913
3164
|
]) : [];
|
|
2914
3165
|
const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
|
|
2915
3166
|
const resolveSubpackageOutputSourceEntries = (outputFile) => {
|
|
@@ -2918,6 +3169,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2918
3169
|
if (matchedRoots.length !== 1) return;
|
|
2919
3170
|
const root = matchedRoots[0];
|
|
2920
3171
|
if (!root) return;
|
|
3172
|
+
const configuredSourceRoots = cssSourceRootsByPackageRoot.get(root);
|
|
3173
|
+
if (configuredSourceRoots?.size === 1) return [{
|
|
3174
|
+
base: [...configuredSourceRoots][0],
|
|
3175
|
+
negated: false,
|
|
3176
|
+
pattern: `${root}/**/*`
|
|
3177
|
+
}];
|
|
2921
3178
|
return options.sourceRoot ? [{
|
|
2922
3179
|
base: options.sourceRoot,
|
|
2923
3180
|
negated: false,
|
|
@@ -2969,7 +3226,7 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2969
3226
|
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2970
3227
|
}) ?? /* @__PURE__ */ new Map();
|
|
2971
3228
|
};
|
|
2972
|
-
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
3229
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
2973
3230
|
return {
|
|
2974
3231
|
createScopedSourceCandidateGetter,
|
|
2975
3232
|
createScopedSourceCandidateSourceGetter,
|
|
@@ -2992,7 +3249,18 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
2992
3249
|
//#endregion
|
|
2993
3250
|
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
2994
3251
|
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
2995
|
-
|
|
3252
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3253
|
+
if (!shouldUseNativeAppCssBranch(resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3254
|
+
appType: opts.appType,
|
|
3255
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3256
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
3257
|
+
uniUtsPlatform
|
|
3258
|
+
}), {
|
|
3259
|
+
appType: opts.appType,
|
|
3260
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3261
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
3262
|
+
uniUtsPlatform
|
|
3263
|
+
})) || !isUniAppXEnabled(opts.uniAppX)) return {};
|
|
2996
3264
|
return {
|
|
2997
3265
|
uniAppX: true,
|
|
2998
3266
|
uniAppXCssTarget: "uvue",
|
|
@@ -3055,6 +3323,32 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3055
3323
|
}
|
|
3056
3324
|
//#endregion
|
|
3057
3325
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
3326
|
+
function isRootMiniProgramStyleOutputFile(file) {
|
|
3327
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3328
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
3329
|
+
}
|
|
3330
|
+
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
3331
|
+
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
3332
|
+
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
3333
|
+
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
3334
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
3335
|
+
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
3336
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
3337
|
+
}
|
|
3338
|
+
function createCssImportShell(targetFile, importedFile) {
|
|
3339
|
+
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
3340
|
+
}
|
|
3341
|
+
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
3342
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3343
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
3344
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
3345
|
+
}
|
|
3346
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
3347
|
+
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
3348
|
+
}
|
|
3349
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
3350
|
+
return appType === "taro";
|
|
3351
|
+
}
|
|
3058
3352
|
function createGenerateBundleHook(context) {
|
|
3059
3353
|
const state = createBundleBuildState();
|
|
3060
3354
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -3064,7 +3358,7 @@ function createGenerateBundleHook(context) {
|
|
|
3064
3358
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
3065
3359
|
getAppType: () => context.opts.appType,
|
|
3066
3360
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
3067
|
-
getMajorVersion: () => context.runtimeState.
|
|
3361
|
+
getMajorVersion: () => context.runtimeState.tailwindRuntime.majorVersion,
|
|
3068
3362
|
getOutputRoot: () => currentOutDir,
|
|
3069
3363
|
getExtraOptions: (file) => ({
|
|
3070
3364
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -3081,15 +3375,27 @@ function createGenerateBundleHook(context) {
|
|
|
3081
3375
|
};
|
|
3082
3376
|
const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
|
|
3083
3377
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3084
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3085
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3086
3378
|
const resolvedConfig = getResolvedConfig();
|
|
3087
3379
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3380
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3381
|
+
appType: opts.appType,
|
|
3382
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3383
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3384
|
+
uniAppX,
|
|
3385
|
+
uniUtsPlatform
|
|
3386
|
+
}), {
|
|
3387
|
+
appType: opts.appType,
|
|
3388
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3389
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3390
|
+
uniAppX,
|
|
3391
|
+
uniUtsPlatform
|
|
3392
|
+
});
|
|
3393
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3088
3394
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp;
|
|
3089
3395
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3090
3396
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3091
3397
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3092
|
-
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget
|
|
3398
|
+
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3093
3399
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
3094
3400
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3095
3401
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -3122,7 +3428,130 @@ function createGenerateBundleHook(context) {
|
|
|
3122
3428
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
3123
3429
|
const bundleFiles = Object.keys(bundle);
|
|
3124
3430
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
3125
|
-
const
|
|
3431
|
+
const getConfiguredTailwindV4CssSourceEntries = () => collectConfiguredTailwindV4CssSourceEntries({
|
|
3432
|
+
...opts,
|
|
3433
|
+
tailwindcssRuntimeOptions: {
|
|
3434
|
+
...opts.tailwindcssRuntimeOptions ?? {},
|
|
3435
|
+
tailwindcss: {
|
|
3436
|
+
...resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions) ?? {},
|
|
3437
|
+
...resolveTailwindcssOptions(runtimeState.tailwindRuntime.options) ?? {}
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
}, opts.tailwindcssBasedir ?? rootDir);
|
|
3441
|
+
const collectTailwindV4SourceFingerprint = (source) => {
|
|
3442
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3443
|
+
const add = (prefix, value) => {
|
|
3444
|
+
const normalized = value?.trim();
|
|
3445
|
+
if (normalized) tokens.add(`${prefix}:${normalized}`);
|
|
3446
|
+
};
|
|
3447
|
+
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3448
|
+
const configRequest = match[2] ?? "";
|
|
3449
|
+
add("config", path.basename(configRequest));
|
|
3450
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3451
|
+
}
|
|
3452
|
+
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3453
|
+
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3454
|
+
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3455
|
+
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3456
|
+
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3457
|
+
return tokens;
|
|
3458
|
+
};
|
|
3459
|
+
const scoreConfiguredTailwindV4SourceForRawSource = (rawSource, entrySource) => {
|
|
3460
|
+
if (!rawSource) return 0;
|
|
3461
|
+
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3462
|
+
if (rawTokens.size === 0) return 0;
|
|
3463
|
+
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3464
|
+
let score = 0;
|
|
3465
|
+
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3466
|
+
return score;
|
|
3467
|
+
};
|
|
3468
|
+
const selectTailwindV4GenerationCssSourceForOutput = (outputFile, entries, rawSource) => {
|
|
3469
|
+
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3470
|
+
if (generationSources.length <= 1) return generationSources[0];
|
|
3471
|
+
const selectByRawSourceFingerprint = (candidates) => {
|
|
3472
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3473
|
+
entry,
|
|
3474
|
+
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3475
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3476
|
+
const bestScore = scoredSources[0]?.score;
|
|
3477
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3478
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3479
|
+
};
|
|
3480
|
+
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3481
|
+
if (rawSourceMatched) return rawSourceMatched;
|
|
3482
|
+
const scopedSources = currentSubpackageRoots ? generationSources.filter((entry) => {
|
|
3483
|
+
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, currentSubpackageRoots);
|
|
3484
|
+
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, currentSubpackageRoots);
|
|
3485
|
+
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3486
|
+
return sourceMatchesSubpackage && [...currentSubpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3487
|
+
}) : generationSources;
|
|
3488
|
+
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3489
|
+
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3490
|
+
if (candidates.length === 1) return candidates[0];
|
|
3491
|
+
return selectByRawSourceFingerprint(candidates);
|
|
3492
|
+
};
|
|
3493
|
+
const resolveSubpackageRootForFile = (file) => {
|
|
3494
|
+
if (!file || !currentSubpackageRoots) return;
|
|
3495
|
+
return [...currentSubpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3496
|
+
};
|
|
3497
|
+
const isSameSubpackageScope = (outputFile, sourceFile) => {
|
|
3498
|
+
return resolveSubpackageRootForFile(outputFile) === resolveSubpackageRootForFile(sourceFile);
|
|
3499
|
+
};
|
|
3500
|
+
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
3501
|
+
const normalizeSourceCandidatePathKey = (file) => normalizeOutputPathKey(path.resolve(file));
|
|
3502
|
+
const resolveCurrentSourceCandidateSource = (file) => {
|
|
3503
|
+
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
3504
|
+
const normalizedFile = normalizeOutputPathKey(cleanedFile);
|
|
3505
|
+
const absoluteFile = path.isAbsolute(cleanedFile) ? cleanedFile : path.resolve(rootDir, cleanedFile);
|
|
3506
|
+
const relativeFromOutDir = normalizeOutputPathKey(path.relative(outDir, absoluteFile));
|
|
3507
|
+
const sourceCandidates = [
|
|
3508
|
+
sourceRoot ? path.resolve(sourceRoot, file) : void 0,
|
|
3509
|
+
path.resolve(rootDir, file),
|
|
3510
|
+
path.resolve(path.dirname(outDir), file),
|
|
3511
|
+
path.resolve(outDir, file),
|
|
3512
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3513
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(path.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3514
|
+
file
|
|
3515
|
+
];
|
|
3516
|
+
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3517
|
+
if (source || !candidate) return source;
|
|
3518
|
+
return getSourceCandidateSource?.(candidate);
|
|
3519
|
+
}, void 0);
|
|
3520
|
+
if (explicitSource) return explicitSource;
|
|
3521
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3522
|
+
absolute: path.isAbsolute(candidate),
|
|
3523
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
3524
|
+
}));
|
|
3525
|
+
let bestSource;
|
|
3526
|
+
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3527
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3528
|
+
let score = 0;
|
|
3529
|
+
for (const candidate of normalizedSourceCandidates) {
|
|
3530
|
+
if (normalizedSourceFile === candidate.key) {
|
|
3531
|
+
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3532
|
+
continue;
|
|
3533
|
+
}
|
|
3534
|
+
if (normalizedSourceFile.endsWith(`/${candidate.key}`)) score = Math.max(score, candidate.absolute ? 60 : 40);
|
|
3535
|
+
}
|
|
3536
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3537
|
+
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3538
|
+
score,
|
|
3539
|
+
source
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3542
|
+
return bestSource?.source;
|
|
3543
|
+
};
|
|
3544
|
+
const resolveOutputFileFromMatchedCssSource = (sourceFile) => {
|
|
3545
|
+
if (!sourceFile) return;
|
|
3546
|
+
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, false, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3547
|
+
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
3548
|
+
};
|
|
3549
|
+
const hasViteProcessedCssResultForSource = (sourceFile) => {
|
|
3550
|
+
const sourceKey = normalizeOutputPathKey(sourceFile);
|
|
3551
|
+
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (normalizeOutputPathKey(file) === sourceKey) return true;
|
|
3552
|
+
return false;
|
|
3553
|
+
};
|
|
3554
|
+
const usedConfiguredTailwindV4CssSourceFiles = /* @__PURE__ */ new Set();
|
|
3126
3555
|
const buildCommand = resolvedConfig?.command === "build";
|
|
3127
3556
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
3128
3557
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
@@ -3130,10 +3559,13 @@ function createGenerateBundleHook(context) {
|
|
|
3130
3559
|
currentOutDir = outDir;
|
|
3131
3560
|
const snapshotStart = performance.now();
|
|
3132
3561
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
3562
|
+
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
3563
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => normalizeOutputPathKey(entry.file.replace(/[?#].*$/, ""))));
|
|
3133
3564
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
3565
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
3134
3566
|
getSourceCandidateSourcesForEntries,
|
|
3135
3567
|
getSourceCandidatesForEntries,
|
|
3136
|
-
projectRoot: opts.
|
|
3568
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
3137
3569
|
rootDir,
|
|
3138
3570
|
snapshot,
|
|
3139
3571
|
sourceRoot,
|
|
@@ -3142,7 +3574,7 @@ function createGenerateBundleHook(context) {
|
|
|
3142
3574
|
useIncrementalMode
|
|
3143
3575
|
});
|
|
3144
3576
|
recordTimingDetail("snapshot", snapshotStart);
|
|
3145
|
-
const useBundleRuntimeClassSet = !isWebGeneratorTarget
|
|
3577
|
+
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
3146
3578
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3147
3579
|
const processFiles = snapshot.processFiles;
|
|
3148
3580
|
logBundleProcessPlan({
|
|
@@ -3159,7 +3591,7 @@ function createGenerateBundleHook(context) {
|
|
|
3159
3591
|
cssHandlerOptions,
|
|
3160
3592
|
fallbackRuntime: runtime,
|
|
3161
3593
|
getSourceCandidatesForEntries,
|
|
3162
|
-
majorVersion: runtimeState.
|
|
3594
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3163
3595
|
outputFile,
|
|
3164
3596
|
rawSource,
|
|
3165
3597
|
shouldExcludeSubpackageSourceCandidates,
|
|
@@ -3169,28 +3601,17 @@ function createGenerateBundleHook(context) {
|
|
|
3169
3601
|
const jsEntries = snapshot.jsEntries;
|
|
3170
3602
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
3171
3603
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
3172
|
-
const hasCssAssetEntry = snapshot.entries.some((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3173
3604
|
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3174
|
-
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !envFlags.forceRuntimeRefreshByEnv && !envFlags.disableV3OxideSourceRuntime;
|
|
3175
3605
|
const runtimeStart = performance.now();
|
|
3176
|
-
const
|
|
3177
|
-
const
|
|
3178
|
-
const
|
|
3179
|
-
allowBaselineOnlyInitialSync: true,
|
|
3180
|
-
baseClassSet: sourceCandidates
|
|
3181
|
-
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3182
|
-
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
3183
|
-
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
3606
|
+
const forceV4RuntimeRefreshBySource = forceRuntimeRefreshBySource;
|
|
3607
|
+
const runtime = isWebGeneratorTarget && !shouldGenerateWebCssByGenerator ? /* @__PURE__ */ new Set() : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3608
|
+
const shouldFilterTailwindV4MiniProgramCandidates = shouldUseMiniProgramCssBranch(generatorBranch);
|
|
3184
3609
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
3185
3610
|
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size === 0) {
|
|
3189
|
-
generatorRuntime = await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3190
|
-
transformRuntime = generatorRuntime;
|
|
3191
|
-
}
|
|
3611
|
+
const transformRuntime = runtime;
|
|
3612
|
+
const generatorRuntime = filteredGeneratorCandidates;
|
|
3192
3613
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3193
|
-
if (
|
|
3614
|
+
if (sourceCandidates.size > 0 && jsEntries.size > 0) {
|
|
3194
3615
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3195
3616
|
if (mainCssEntry) {
|
|
3196
3617
|
const validatedSourceRuntime = await validateCandidatesByGenerator({
|
|
@@ -3205,27 +3626,7 @@ function createGenerateBundleHook(context) {
|
|
|
3205
3626
|
debug,
|
|
3206
3627
|
skipGenerateFallback: true
|
|
3207
3628
|
});
|
|
3208
|
-
if (validatedSourceRuntime.size > 0)
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
if (runtimeState.twPatcher.majorVersion === 3 && useV3OxideSourceRuntime && generatorRuntime.size > 0 && (state.iteration === 0 || !hasRuntimeAffectingChanges) && cssEntries.length <= 1) {
|
|
3212
|
-
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3213
|
-
if (mainCssEntry) {
|
|
3214
|
-
const validatedRuntime = await validateCandidatesByGenerator({
|
|
3215
|
-
opts,
|
|
3216
|
-
runtimeState,
|
|
3217
|
-
candidates: generatorRuntime,
|
|
3218
|
-
rawSource: mainCssEntry.source,
|
|
3219
|
-
file: mainCssEntry.file,
|
|
3220
|
-
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3221
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3222
|
-
styleHandler,
|
|
3223
|
-
debug
|
|
3224
|
-
});
|
|
3225
|
-
if (validatedRuntime.size > 0) {
|
|
3226
|
-
generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, validatedRuntime);
|
|
3227
|
-
transformRuntime = generatorRuntime;
|
|
3228
|
-
}
|
|
3629
|
+
if (validatedSourceRuntime.size > 0) for (const candidate of validatedSourceRuntime) transformRuntime.add(candidate);
|
|
3229
3630
|
}
|
|
3230
3631
|
}
|
|
3231
3632
|
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
@@ -3239,7 +3640,7 @@ function createGenerateBundleHook(context) {
|
|
|
3239
3640
|
continue;
|
|
3240
3641
|
}
|
|
3241
3642
|
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3242
|
-
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0,
|
|
3643
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
3243
3644
|
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(path.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3244
3645
|
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3245
3646
|
rememberCssSource?.({
|
|
@@ -3254,12 +3655,12 @@ function createGenerateBundleHook(context) {
|
|
|
3254
3655
|
...generatorRuntime,
|
|
3255
3656
|
...transformRuntime
|
|
3256
3657
|
]);
|
|
3257
|
-
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
3258
3658
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
3259
3659
|
timingDetails["runtime"] = metrics.runtimeSet;
|
|
3260
3660
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
3261
3661
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
3262
|
-
const runtimeSignature = getRuntimeClassSetSignature(runtimeState.
|
|
3662
|
+
const runtimeSignature = getRuntimeClassSetSignature(runtimeState.tailwindRuntime) ?? "runtime:missing";
|
|
3663
|
+
const transformRuntimeSignature = createCandidateSignature(transformRuntime);
|
|
3263
3664
|
const shouldProcessTailwindGeneration = !useIncrementalMode || hasRuntimeAffectingChanges || generatorCandidatesChanged || snapshot.processFiles.css.size > 0;
|
|
3264
3665
|
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
3265
3666
|
jsEntries,
|
|
@@ -3267,7 +3668,7 @@ function createGenerateBundleHook(context) {
|
|
|
3267
3668
|
debug
|
|
3268
3669
|
});
|
|
3269
3670
|
const createHandlerOptions = createJsHandlerOptionsFactory({
|
|
3270
|
-
getMajorVersion: () => runtimeState.
|
|
3671
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
3271
3672
|
moduleGraph: moduleGraphOptions
|
|
3272
3673
|
});
|
|
3273
3674
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
@@ -3290,15 +3691,19 @@ function createGenerateBundleHook(context) {
|
|
|
3290
3691
|
continue;
|
|
3291
3692
|
}
|
|
3292
3693
|
if (!processFiles.html.has(file)) continue;
|
|
3293
|
-
const rawSource = originalEntrySource;
|
|
3294
|
-
const
|
|
3295
|
-
const
|
|
3694
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
3695
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3696
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3697
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
3698
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3699
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3700
|
+
const hashKey = cacheKey;
|
|
3296
3701
|
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3297
3702
|
tasks.push(timeTask("html", () => processCachedTask({
|
|
3298
3703
|
cache,
|
|
3299
3704
|
cacheKey,
|
|
3300
3705
|
hashKey,
|
|
3301
|
-
hash:
|
|
3706
|
+
hash: htmlProcessHash,
|
|
3302
3707
|
applyResult(source) {
|
|
3303
3708
|
originalSource.source = source;
|
|
3304
3709
|
},
|
|
@@ -3308,7 +3713,7 @@ function createGenerateBundleHook(context) {
|
|
|
3308
3713
|
},
|
|
3309
3714
|
async transform() {
|
|
3310
3715
|
const start = performance.now();
|
|
3311
|
-
let transformed = await templateHandler(rawSource,
|
|
3716
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
3312
3717
|
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3313
3718
|
let retryRuntimeSet;
|
|
3314
3719
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
@@ -3336,7 +3741,14 @@ function createGenerateBundleHook(context) {
|
|
|
3336
3741
|
metrics.css.total++;
|
|
3337
3742
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3338
3743
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3339
|
-
|
|
3744
|
+
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
3745
|
+
if (outputFile !== file && (originalSource.originalFileNames?.length ?? 0) > 0 && opts.cssMatcher(file)) outputFile = file;
|
|
3746
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
3747
|
+
const resolveMatchedOutputFileForCurrentAsset = (sourceFile) => {
|
|
3748
|
+
if (!sourceFile) return;
|
|
3749
|
+
if (normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalSource.originalFileNames?.some((originalFile) => normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
|
|
3750
|
+
return resolveOutputFileFromMatchedCssSource(sourceFile);
|
|
3751
|
+
};
|
|
3340
3752
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3341
3753
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
3342
3754
|
delete bundle[file];
|
|
@@ -3345,9 +3757,19 @@ function createGenerateBundleHook(context) {
|
|
|
3345
3757
|
}
|
|
3346
3758
|
const applyCssResult = (source) => {
|
|
3347
3759
|
if (outputFile !== file) {
|
|
3348
|
-
|
|
3760
|
+
const importShellSource = isRootMiniProgramStyleOutputFile(file) && isRootMiniProgramStyleOutputFile(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(opts.appType) ? createCssImportShell(file, outputFile) : void 0;
|
|
3761
|
+
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
3762
|
+
const existingOutput = bundle[outputFile];
|
|
3763
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
3764
|
+
else emitOrReplayCssAsset(outputFile, source);
|
|
3765
|
+
originalSource.source = importShellSource ?? source;
|
|
3766
|
+
return;
|
|
3767
|
+
}
|
|
3768
|
+
const existingOutput = bundle[outputFile];
|
|
3769
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
3770
|
+
else emitOrReplayCssAsset(outputFile, source);
|
|
3349
3771
|
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
3350
|
-
else originalSource.source = "";
|
|
3772
|
+
else originalSource.source = importShellSource ?? "";
|
|
3351
3773
|
return;
|
|
3352
3774
|
}
|
|
3353
3775
|
originalSource.source = source;
|
|
@@ -3365,18 +3787,59 @@ function createGenerateBundleHook(context) {
|
|
|
3365
3787
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
3366
3788
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
3367
3789
|
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => await refreshRememberedCssSource?.(remembered) ?? remembered));
|
|
3368
|
-
|
|
3790
|
+
let hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
3369
3791
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
3370
3792
|
if (inferredSfcStyleSource) {
|
|
3371
3793
|
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
3372
3794
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
3373
3795
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
3374
3796
|
}
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3797
|
+
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3798
|
+
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile))) {
|
|
3799
|
+
rememberedCssSources = [];
|
|
3800
|
+
hasUsableRememberedTailwindSource = false;
|
|
3801
|
+
}
|
|
3802
|
+
if (!hasUsableRememberedTailwindSource) {
|
|
3803
|
+
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
3804
|
+
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));
|
|
3805
|
+
if (inferredOriginalSourceStyle) {
|
|
3806
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
3807
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3808
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3809
|
+
rememberedCssSources = [{
|
|
3810
|
+
...inferredOriginalSourceStyle,
|
|
3811
|
+
outputFile
|
|
3812
|
+
}];
|
|
3813
|
+
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
3814
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
3815
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource);
|
|
3816
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file)) {
|
|
3817
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
3818
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3819
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3820
|
+
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(configuredGenerationSource.file));
|
|
3821
|
+
rememberedCssSources = [{
|
|
3822
|
+
outputFile,
|
|
3823
|
+
rawSource: configuredGenerationSource.source,
|
|
3824
|
+
sourceFile: configuredGenerationSource.file
|
|
3825
|
+
}];
|
|
3826
|
+
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3831
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")))) {
|
|
3832
|
+
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
3833
|
+
if (matchedOutputFile && normalizeOutputPathKey(matchedOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
3834
|
+
outputFile = matchedOutputFile;
|
|
3835
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3836
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3837
|
+
rememberedCssSource = {
|
|
3838
|
+
...rememberedCssSource,
|
|
3839
|
+
outputFile
|
|
3840
|
+
};
|
|
3841
|
+
}
|
|
3378
3842
|
}
|
|
3379
|
-
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3380
3843
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
3381
3844
|
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3382
3845
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
@@ -3394,28 +3857,37 @@ function createGenerateBundleHook(context) {
|
|
|
3394
3857
|
}
|
|
3395
3858
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
3396
3859
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
3860
|
+
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
3397
3861
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
3398
|
-
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective ||
|
|
3862
|
+
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
3399
3863
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
3400
|
-
|
|
3864
|
+
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(generatorSourceFile.replace(/[?#].*$/, "")))) usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
3401
3865
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
3402
3866
|
...getCssHandlerOptions(generatorSourceFile),
|
|
3403
3867
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
3404
3868
|
} : getCssHandlerOptions(file);
|
|
3405
|
-
const
|
|
3406
|
-
|
|
3869
|
+
const generatorCssHandlerOptions = {
|
|
3870
|
+
...cssHandlerOptions,
|
|
3871
|
+
sourceOptions: {
|
|
3872
|
+
...cssHandlerOptions.sourceOptions ?? {},
|
|
3873
|
+
sourceFile: generatorSourceFile,
|
|
3874
|
+
cssEntries: opts.cssEntries
|
|
3875
|
+
}
|
|
3876
|
+
};
|
|
3877
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
3878
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, generatorCssHandlerOptions);
|
|
3407
3879
|
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3408
3880
|
const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
3409
|
-
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile,
|
|
3881
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, generatorCssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
3410
3882
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3411
3883
|
opts,
|
|
3412
3884
|
tokenSources: sourceTraceTokenSources
|
|
3413
3885
|
});
|
|
3414
|
-
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile,
|
|
3886
|
+
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
3415
3887
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
3416
3888
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
3417
3889
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
3418
|
-
const cssShareScope = createCssTransformShareScopeKey(opts,
|
|
3890
|
+
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
3419
3891
|
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3420
3892
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
3421
3893
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
@@ -3436,14 +3908,14 @@ function createGenerateBundleHook(context) {
|
|
|
3436
3908
|
}
|
|
3437
3909
|
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
3438
3910
|
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3439
|
-
includeFallbackSignature:
|
|
3440
|
-
majorVersion: runtimeState.
|
|
3911
|
+
includeFallbackSignature: generatorCssHandlerOptions.isMainChunk,
|
|
3912
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
3441
3913
|
}) : trackedGeneratorCandidateSignature;
|
|
3442
3914
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
3443
3915
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3444
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.
|
|
3916
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
3445
3917
|
const cssCacheKey = file;
|
|
3446
|
-
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.
|
|
3918
|
+
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
3447
3919
|
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(":") : "";
|
|
3448
3920
|
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
3449
3921
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
@@ -3489,19 +3961,24 @@ function createGenerateBundleHook(context) {
|
|
|
3489
3961
|
const runTransform = async () => {
|
|
3490
3962
|
const start = performance.now();
|
|
3491
3963
|
await runtimeState.readyPromise;
|
|
3492
|
-
const
|
|
3964
|
+
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
3965
|
+
const generated = hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) ? await generateTailwindV4Css({
|
|
3493
3966
|
opts,
|
|
3494
3967
|
runtimeState,
|
|
3495
3968
|
runtime: scopedGeneratorRuntime,
|
|
3496
3969
|
rawSource: generatorRawSource,
|
|
3497
3970
|
file: generatorSourceFile,
|
|
3498
|
-
|
|
3971
|
+
outputFile,
|
|
3972
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3499
3973
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3500
3974
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3975
|
+
sourceCandidates: scopedGeneratorRuntime,
|
|
3501
3976
|
styleHandler,
|
|
3502
3977
|
debug,
|
|
3503
|
-
previousCss
|
|
3504
|
-
|
|
3978
|
+
previousCss,
|
|
3979
|
+
...vitePipelineCssAsset && !hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile) } : {},
|
|
3980
|
+
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
3981
|
+
}) : void 0;
|
|
3505
3982
|
if (generated) {
|
|
3506
3983
|
const tracedCss = annotateCss(generated.css);
|
|
3507
3984
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
@@ -3518,7 +3995,7 @@ function createGenerateBundleHook(context) {
|
|
|
3518
3995
|
});
|
|
3519
3996
|
metrics.css.elapsed += measureElapsed(start);
|
|
3520
3997
|
metrics.css.transformed++;
|
|
3521
|
-
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.
|
|
3998
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, outputFile);
|
|
3522
3999
|
return tracedCss;
|
|
3523
4000
|
}
|
|
3524
4001
|
if (isWebGeneratorTarget) {
|
|
@@ -3695,12 +4172,16 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
3695
4172
|
...majorVersion === void 0 ? {} : { majorVersion }
|
|
3696
4173
|
};
|
|
3697
4174
|
}
|
|
3698
|
-
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
3699
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4175
|
+
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
4176
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4177
|
+
appType: opts.appType,
|
|
4178
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4179
|
+
tailwindcssMajorVersion: majorVersion,
|
|
4180
|
+
uniAppX: opts.uniAppX
|
|
4181
|
+
});
|
|
3700
4182
|
if (hasLocalCssImport(rawSource)) return false;
|
|
3701
4183
|
if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
3702
4184
|
if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
3703
|
-
if (opts.twPatcher.majorVersion === 3) return false;
|
|
3704
4185
|
return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
|
|
3705
4186
|
}
|
|
3706
4187
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
@@ -3718,9 +4199,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3718
4199
|
async handler(_options, bundle) {
|
|
3719
4200
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
3720
4201
|
const resolvedConfig = getResolvedConfig();
|
|
3721
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3722
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3723
4202
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
4203
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4204
|
+
appType: opts.appType,
|
|
4205
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4206
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4207
|
+
uniAppX: opts.uniAppX,
|
|
4208
|
+
uniUtsPlatform
|
|
4209
|
+
}), {
|
|
4210
|
+
appType: opts.appType,
|
|
4211
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4212
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4213
|
+
uniAppX: opts.uniAppX,
|
|
4214
|
+
uniUtsPlatform
|
|
4215
|
+
});
|
|
4216
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3724
4217
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3725
4218
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3726
4219
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
@@ -3760,13 +4253,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3760
4253
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3761
4254
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
3762
4255
|
const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
|
|
3763
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
3764
|
-
const generated = await
|
|
4256
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
|
|
4257
|
+
const generated = await generateTailwindV4Css({
|
|
3765
4258
|
opts,
|
|
3766
4259
|
runtimeState,
|
|
3767
4260
|
runtime: harmonyRuntime,
|
|
3768
4261
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3769
4262
|
file: "uni-app-x-harmony-apply.css",
|
|
4263
|
+
outputFile: "uni-app-x-harmony-apply.css",
|
|
3770
4264
|
cssHandlerOptions: harmonyCssHandlerOptions,
|
|
3771
4265
|
cssUserHandlerOptions: {
|
|
3772
4266
|
...harmonyCssHandlerOptions,
|
|
@@ -3784,21 +4278,29 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3784
4278
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
|
|
3785
4279
|
};
|
|
3786
4280
|
const isCssOutputAssetEntry = (entry) => {
|
|
3787
|
-
const [, output] = entry;
|
|
3788
|
-
|
|
4281
|
+
const [bundleFile, output] = entry;
|
|
4282
|
+
const fileName = output.fileName || bundleFile;
|
|
4283
|
+
return output.type === "asset" && opts.cssMatcher(fileName) && !opts.htmlMatcher(fileName) && !isHTMLRequest(fileName) && !isCssAssetProcessed(output, fileName);
|
|
3789
4284
|
};
|
|
3790
4285
|
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
3791
4286
|
if (entries.length === 0) {
|
|
3792
4287
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
3793
4288
|
collectViteProcessedCssAssets();
|
|
3794
4289
|
injectViteProcessedCssIntoMainCss();
|
|
4290
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4291
|
+
appType: opts.appType,
|
|
4292
|
+
cssMatcher: opts.cssMatcher,
|
|
4293
|
+
debug,
|
|
4294
|
+
onUpdate: opts.onUpdate,
|
|
4295
|
+
recordCssAssetResult
|
|
4296
|
+
});
|
|
3795
4297
|
return;
|
|
3796
4298
|
}
|
|
3797
4299
|
await runtimeState.readyPromise;
|
|
3798
4300
|
await waitForSourceCandidateSyncs?.();
|
|
3799
4301
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
3800
4302
|
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
3801
|
-
const generatorRuntime =
|
|
4303
|
+
const generatorRuntime = shouldUseMiniProgramCssBranch(generatorBranch) ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3802
4304
|
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
3803
4305
|
const file = output.fileName || bundleFile;
|
|
3804
4306
|
const rawSource = output.source.toString();
|
|
@@ -3810,7 +4312,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3810
4312
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
3811
4313
|
return;
|
|
3812
4314
|
}
|
|
3813
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
4315
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file);
|
|
3814
4316
|
const cssUserHandlerOptions = {
|
|
3815
4317
|
...cssHandlerOptions,
|
|
3816
4318
|
isMainChunk: false
|
|
@@ -3819,24 +4321,25 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3819
4321
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
3820
4322
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
3821
4323
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
3822
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.
|
|
4324
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile) : cssHandlerOptions;
|
|
3823
4325
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
3824
4326
|
...generatorCssHandlerOptions,
|
|
3825
4327
|
isMainChunk: false
|
|
3826
4328
|
} : cssUserHandlerOptions;
|
|
3827
|
-
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await
|
|
4329
|
+
const generated = shouldGenerateCssByGenerator(opts, runtimeState.tailwindRuntime.majorVersion, file, generatorRawSource, processed) ? await generateTailwindV4Css({
|
|
3828
4330
|
opts,
|
|
3829
4331
|
runtimeState,
|
|
3830
4332
|
runtime: generatorRuntime,
|
|
3831
4333
|
rawSource: generatorRawSource,
|
|
3832
4334
|
file: generatorSourceFile,
|
|
4335
|
+
outputFile: file,
|
|
3833
4336
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3834
4337
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3835
4338
|
getSourceCandidatesForEntries,
|
|
3836
4339
|
styleHandler: opts.styleHandler,
|
|
3837
4340
|
debug
|
|
3838
4341
|
}) : void 0;
|
|
3839
|
-
const nextCss = annotateCss(generated?.css ?? (
|
|
4342
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
3840
4343
|
if (generated) {
|
|
3841
4344
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
3842
4345
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -3851,6 +4354,13 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3851
4354
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
3852
4355
|
collectViteProcessedCssAssets();
|
|
3853
4356
|
injectViteProcessedCssIntoMainCss();
|
|
4357
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4358
|
+
appType: opts.appType,
|
|
4359
|
+
cssMatcher: opts.cssMatcher,
|
|
4360
|
+
debug,
|
|
4361
|
+
onUpdate: opts.onUpdate,
|
|
4362
|
+
recordCssAssetResult
|
|
4363
|
+
});
|
|
3854
4364
|
}
|
|
3855
4365
|
}
|
|
3856
4366
|
};
|
|
@@ -3875,6 +4385,27 @@ const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
|
3875
4385
|
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3876
4386
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3877
4387
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
4388
|
+
function toMb$1(bytes) {
|
|
4389
|
+
return Math.round(bytes / 1024 / 1024);
|
|
4390
|
+
}
|
|
4391
|
+
function summarizeStringMapCache(map) {
|
|
4392
|
+
let bytes = 0;
|
|
4393
|
+
for (const value of map.values()) bytes += value.length;
|
|
4394
|
+
return {
|
|
4395
|
+
bytes,
|
|
4396
|
+
mb: toMb$1(bytes),
|
|
4397
|
+
size: map.size
|
|
4398
|
+
};
|
|
4399
|
+
}
|
|
4400
|
+
function summarizeRememberedCssSources(map) {
|
|
4401
|
+
let bytes = 0;
|
|
4402
|
+
for (const value of map.values()) bytes += value.rawSource.length;
|
|
4403
|
+
return {
|
|
4404
|
+
bytes,
|
|
4405
|
+
mb: toMb$1(bytes),
|
|
4406
|
+
size: map.size
|
|
4407
|
+
};
|
|
4408
|
+
}
|
|
3878
4409
|
function stripSourceHash(sourceFile) {
|
|
3879
4410
|
const hashIndex = sourceFile.indexOf("#");
|
|
3880
4411
|
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
@@ -3983,12 +4514,24 @@ function createViteCssMemory(options) {
|
|
|
3983
4514
|
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
3984
4515
|
if (isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
3985
4516
|
};
|
|
4517
|
+
const resolveCurrentStyleSource = async (sourceFile) => {
|
|
4518
|
+
const cached = resolveCachedStyleSource(sourceFile);
|
|
4519
|
+
if (cached != null) return cached;
|
|
4520
|
+
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
4521
|
+
if (!isSourceStyleRequest(file)) return;
|
|
4522
|
+
try {
|
|
4523
|
+
return await readFile(file, "utf8");
|
|
4524
|
+
} catch (error) {
|
|
4525
|
+
options.debug("refresh remembered css source read failed: %s %O", file, error);
|
|
4526
|
+
return;
|
|
4527
|
+
}
|
|
4528
|
+
};
|
|
3986
4529
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
3987
4530
|
const file = cleanUrl(sourceFile);
|
|
3988
4531
|
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
3989
4532
|
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
|
|
3990
4533
|
if (matchedRememberedSources.length === 0) return;
|
|
3991
|
-
const source =
|
|
4534
|
+
const source = await resolveCurrentStyleSource(file);
|
|
3992
4535
|
if (source == null) {
|
|
3993
4536
|
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
3994
4537
|
return;
|
|
@@ -4007,7 +4550,7 @@ function createViteCssMemory(options) {
|
|
|
4007
4550
|
const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
|
|
4008
4551
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4009
4552
|
if (!rememberedKey || !path.isAbsolute(file)) return;
|
|
4010
|
-
const source =
|
|
4553
|
+
const source = await resolveCurrentStyleSource(file);
|
|
4011
4554
|
if (source == null) {
|
|
4012
4555
|
options.debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4013
4556
|
return;
|
|
@@ -4045,8 +4588,10 @@ function createViteCssMemory(options) {
|
|
|
4045
4588
|
getRememberedCssSources: () => rememberedCssSources,
|
|
4046
4589
|
getStats: () => ({
|
|
4047
4590
|
rememberedCssSources: rememberedCssSources.size,
|
|
4591
|
+
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
4048
4592
|
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4049
|
-
knownSfcSources: knownSfcSources.size
|
|
4593
|
+
knownSfcSources: knownSfcSources.size,
|
|
4594
|
+
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
4050
4595
|
}),
|
|
4051
4596
|
rememberCssSource,
|
|
4052
4597
|
rememberKnownSfcSource,
|
|
@@ -4233,18 +4778,25 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4233
4778
|
async transform(code, id) {
|
|
4234
4779
|
if (!isCSSRequest(id)) return null;
|
|
4235
4780
|
const file = cleanUrl(id);
|
|
4236
|
-
const normalizedCode = hasTailwindRootDirectives(code) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
4781
|
+
const normalizedCode = hasTailwindRootDirectives(code) || code.includes("@config") ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
4237
4782
|
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
4238
4783
|
const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode);
|
|
4239
4784
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
4240
|
-
|
|
4785
|
+
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
4786
|
+
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
4241
4787
|
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
|
|
4242
4788
|
if (generatedCss !== void 0) return {
|
|
4243
4789
|
code: generatedCss,
|
|
4244
4790
|
map: null
|
|
4245
4791
|
};
|
|
4246
4792
|
}
|
|
4247
|
-
if (!options.shouldRewrite)
|
|
4793
|
+
if (!options.shouldRewrite) {
|
|
4794
|
+
if (normalizedCode !== code) return {
|
|
4795
|
+
code: normalizedCode,
|
|
4796
|
+
map: null
|
|
4797
|
+
};
|
|
4798
|
+
return null;
|
|
4799
|
+
}
|
|
4248
4800
|
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
4249
4801
|
join: joinPosixPath,
|
|
4250
4802
|
appType: resolveAppType(),
|
|
@@ -4265,11 +4817,11 @@ function hasVitePipelineTailwindGenerationDirective(code) {
|
|
|
4265
4817
|
//#endregion
|
|
4266
4818
|
//#region src/bundlers/vite/runtime-class-set.ts
|
|
4267
4819
|
function createViteRuntimeClassSet(options) {
|
|
4268
|
-
const { opts,
|
|
4820
|
+
const { opts, initialTailwindRuntime, refreshTailwindcssRuntime, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
4269
4821
|
const runtimeState = {
|
|
4270
|
-
|
|
4271
|
-
readyPromise: createTailwindRuntimeReadyPromise(
|
|
4272
|
-
|
|
4822
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
4823
|
+
readyPromise: createTailwindRuntimeReadyPromise(initialTailwindRuntime),
|
|
4824
|
+
refreshTailwindcssRuntime
|
|
4273
4825
|
};
|
|
4274
4826
|
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager({
|
|
4275
4827
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
@@ -4284,8 +4836,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
4284
4836
|
let runtimeRefreshSignature;
|
|
4285
4837
|
let runtimeRefreshOptionsKey;
|
|
4286
4838
|
function resolveRuntimeRefreshOptions() {
|
|
4287
|
-
const configPath = resolveTailwindcssOptions(runtimeState.
|
|
4288
|
-
const signature = getRuntimeClassSetSignature(runtimeState.
|
|
4839
|
+
const configPath = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.config;
|
|
4840
|
+
const signature = getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
4289
4841
|
const optionsKey = JSON.stringify({
|
|
4290
4842
|
appType: opts.appType,
|
|
4291
4843
|
uniAppX: uniAppXEnabled,
|
|
@@ -4321,7 +4873,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4321
4873
|
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
4322
4874
|
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
4323
4875
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4324
|
-
runtimeSetPromise = collectRuntimeClassSet(runtimeState.
|
|
4876
|
+
runtimeSetPromise = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4325
4877
|
force: forceRuntimeRefresh || invalidation.changed,
|
|
4326
4878
|
skipRefresh: forceRuntimeRefresh,
|
|
4327
4879
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4335,54 +4887,29 @@ function createViteRuntimeClassSet(options) {
|
|
|
4335
4887
|
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
4336
4888
|
}
|
|
4337
4889
|
}
|
|
4338
|
-
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false,
|
|
4890
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, _options = {}) {
|
|
4339
4891
|
const forceRuntimeRefresh = forceRefresh || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
4340
4892
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4341
|
-
const
|
|
4893
|
+
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
4342
4894
|
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
4343
|
-
await refreshRuntimeState(
|
|
4895
|
+
await refreshRuntimeState(shouldRefreshRuntime);
|
|
4344
4896
|
await runtimeState.readyPromise;
|
|
4345
|
-
if (
|
|
4897
|
+
if (shouldRefreshRuntime) {
|
|
4346
4898
|
runtimeSet = void 0;
|
|
4347
4899
|
runtimeSetPromise = void 0;
|
|
4348
4900
|
await bundleRuntimeClassSetManager.reset();
|
|
4349
4901
|
await transformRuntimeClassSetManager.reset();
|
|
4350
4902
|
}
|
|
4351
|
-
if (
|
|
4352
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.
|
|
4903
|
+
if (!forceRuntimeRefresh) try {
|
|
4904
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot);
|
|
4353
4905
|
runtimeSet = nextRuntimeSet;
|
|
4354
4906
|
return nextRuntimeSet;
|
|
4355
4907
|
} catch (error) {
|
|
4356
4908
|
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4357
4909
|
await bundleRuntimeClassSetManager.reset();
|
|
4358
4910
|
}
|
|
4359
|
-
if (runtimeState.twPatcher.majorVersion === 3 && !forceRuntimeRefresh) {
|
|
4360
|
-
if (options.transformOnly) try {
|
|
4361
|
-
return await transformRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
4362
|
-
} catch (error) {
|
|
4363
|
-
debug("incremental transform runtime set sync failed, fallback to full collect: %O", error);
|
|
4364
|
-
await transformRuntimeClassSetManager.reset();
|
|
4365
|
-
}
|
|
4366
|
-
try {
|
|
4367
|
-
let baseClassSet = options.baseClassSet;
|
|
4368
|
-
if (!baseClassSet && (!runtimeSet || shouldRefreshPatcher)) baseClassSet = await collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
4369
|
-
force: true,
|
|
4370
|
-
skipRefresh: shouldRefreshPatcher,
|
|
4371
|
-
clearCache: shouldRefreshPatcher
|
|
4372
|
-
});
|
|
4373
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot, {
|
|
4374
|
-
baseClassSet: baseClassSet ?? (options.allowBaselineOnlyInitialSync === true ? runtimeSet : void 0),
|
|
4375
|
-
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync === true && Boolean(runtimeSet)
|
|
4376
|
-
});
|
|
4377
|
-
runtimeSet = nextRuntimeSet;
|
|
4378
|
-
return nextRuntimeSet;
|
|
4379
|
-
} catch (error) {
|
|
4380
|
-
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4381
|
-
await bundleRuntimeClassSetManager.reset();
|
|
4382
|
-
}
|
|
4383
|
-
}
|
|
4384
4911
|
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
4385
|
-
const task = collectRuntimeClassSet(runtimeState.
|
|
4912
|
+
const task = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4386
4913
|
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
4387
4914
|
skipRefresh: forceRuntimeRefresh,
|
|
4388
4915
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4480,35 +5007,6 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4480
5007
|
}];
|
|
4481
5008
|
}
|
|
4482
5009
|
//#endregion
|
|
4483
|
-
//#region src/bundlers/vite/source-candidate-scan-signature.ts
|
|
4484
|
-
function normalizeSignaturePath(value) {
|
|
4485
|
-
return slash(path.resolve(value));
|
|
4486
|
-
}
|
|
4487
|
-
function serializeInlineCandidates(inlineCandidates) {
|
|
4488
|
-
return {
|
|
4489
|
-
excluded: [...inlineCandidates?.excluded ?? []].sort(),
|
|
4490
|
-
included: [...inlineCandidates?.included ?? []].sort()
|
|
4491
|
-
};
|
|
4492
|
-
}
|
|
4493
|
-
function serializeSourceEntries(entries) {
|
|
4494
|
-
return (entries ?? []).map((entry) => ({
|
|
4495
|
-
base: normalizeSignaturePath(entry.base),
|
|
4496
|
-
negated: entry.negated,
|
|
4497
|
-
pattern: entry.pattern
|
|
4498
|
-
})).sort((a, b) => `${a.base}\0${a.pattern}\0${a.negated}`.localeCompare(`${b.base}\0${b.pattern}\0${b.negated}`));
|
|
4499
|
-
}
|
|
4500
|
-
function createSourceCandidateScanSignature(input) {
|
|
4501
|
-
return JSON.stringify({
|
|
4502
|
-
inlineCandidates: serializeInlineCandidates(input.inlineCandidates),
|
|
4503
|
-
outDir: input.outDir ? normalizeSignaturePath(input.outDir) : void 0,
|
|
4504
|
-
roots: input.roots.map((root) => ({
|
|
4505
|
-
entries: serializeSourceEntries(root.entries),
|
|
4506
|
-
root: normalizeSignaturePath(root.root)
|
|
4507
|
-
})),
|
|
4508
|
-
scanAllSources: input.scanAllSources ?? false
|
|
4509
|
-
});
|
|
4510
|
-
}
|
|
4511
|
-
//#endregion
|
|
4512
5010
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
4513
5011
|
const PACKAGE_JSON_FILE = "package.json";
|
|
4514
5012
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -4535,9 +5033,33 @@ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
|
4535
5033
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
4536
5034
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
4537
5035
|
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
5036
|
+
function isMissingInternalCssSource(file) {
|
|
5037
|
+
return !existsSync(file) && path.resolve(file).startsWith(`${weappTailwindcssPackageDir}${path.sep}`);
|
|
5038
|
+
}
|
|
4538
5039
|
function normalizeVitePersistentCacheKey(file) {
|
|
4539
5040
|
return normalizeOutputPathKey(file);
|
|
4540
5041
|
}
|
|
5042
|
+
function toMb(bytes) {
|
|
5043
|
+
return Math.round(bytes / 1024 / 1024);
|
|
5044
|
+
}
|
|
5045
|
+
function summarizeStringCache(map) {
|
|
5046
|
+
let bytes = 0;
|
|
5047
|
+
for (const value of map.values()) bytes += value.length;
|
|
5048
|
+
return {
|
|
5049
|
+
bytes,
|
|
5050
|
+
mb: toMb(bytes),
|
|
5051
|
+
size: map.size
|
|
5052
|
+
};
|
|
5053
|
+
}
|
|
5054
|
+
function summarizeViteProcessedCssResults(map) {
|
|
5055
|
+
let bytes = 0;
|
|
5056
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
5057
|
+
return {
|
|
5058
|
+
bytes,
|
|
5059
|
+
mb: toMb(bytes),
|
|
5060
|
+
size: map.size
|
|
5061
|
+
};
|
|
5062
|
+
}
|
|
4541
5063
|
/**
|
|
4542
5064
|
* @name WeappTailwindcss
|
|
4543
5065
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -4558,14 +5080,28 @@ function WeappTailwindcss(options = {}) {
|
|
|
4558
5080
|
(_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
|
|
4559
5081
|
(_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
|
|
4560
5082
|
}
|
|
4561
|
-
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler,
|
|
5083
|
+
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
5084
|
+
const initialTailwindRuntime = tailwindRuntime;
|
|
5085
|
+
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
4562
5086
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
4563
5087
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
4564
|
-
const tailwindcssMajorVersion =
|
|
5088
|
+
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
5089
|
+
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
4565
5090
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
4566
|
-
const shouldRewriteCssImports =
|
|
4567
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4568
|
-
|
|
5091
|
+
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5092
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
5093
|
+
appType: opts.appType,
|
|
5094
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5095
|
+
tailwindcssMajorVersion,
|
|
5096
|
+
uniAppX
|
|
5097
|
+
});
|
|
5098
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5099
|
+
appType: opts.appType,
|
|
5100
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5101
|
+
tailwindcssMajorVersion,
|
|
5102
|
+
uniAppX
|
|
5103
|
+
});
|
|
5104
|
+
const shouldInferAppType = !hasExplicitAppType && !generatorBranch.isWeb;
|
|
4569
5105
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
4570
5106
|
...options,
|
|
4571
5107
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
@@ -4576,13 +5112,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
4576
5112
|
let autoCssSourcesRefresh;
|
|
4577
5113
|
let autoCssSourcesDiscovered = false;
|
|
4578
5114
|
const syncTailwindCssSourceCandidates = async (id, css) => {
|
|
5115
|
+
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource(cleanUrl(id))) return;
|
|
4579
5116
|
await sourceCandidateCollector.syncCss(id, css);
|
|
4580
5117
|
cacheCurrentSourceCandidateScan();
|
|
4581
5118
|
};
|
|
4582
5119
|
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
4583
|
-
if (
|
|
5120
|
+
if (!shouldOwnTailwindGeneration) return;
|
|
4584
5121
|
const file = cleanUrl(id);
|
|
4585
5122
|
if (!path.isAbsolute(file)) return;
|
|
5123
|
+
if (!isTailwindV4CssEntry(file)) return;
|
|
5124
|
+
if (isMissingInternalCssSource(file)) return;
|
|
4586
5125
|
const sourceFile = path.normalize(file);
|
|
4587
5126
|
const sourceBase = path.dirname(sourceFile);
|
|
4588
5127
|
const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
@@ -4618,7 +5157,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4618
5157
|
await autoCssSourcesRefresh;
|
|
4619
5158
|
};
|
|
4620
5159
|
const discoverAndRegisterAutoCssSources = async () => {
|
|
4621
|
-
if (
|
|
5160
|
+
if (!shouldOwnTailwindGeneration || hasInitialTailwindCssRoots || !resolvedConfig?.root) return;
|
|
4622
5161
|
const cssEntries = await discoverTailwindV4CssEntries(resolvedConfig.root, resolvedConfig.build?.outDir);
|
|
4623
5162
|
autoCssSourcesDiscovered = true;
|
|
4624
5163
|
let changed = false;
|
|
@@ -4643,11 +5182,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4643
5182
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
4644
5183
|
let resolvedConfig;
|
|
4645
5184
|
let recordedGeneratorCandidates;
|
|
4646
|
-
const
|
|
4647
|
-
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
4648
|
-
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
4649
|
-
extractor: sourceCandidateExtractor
|
|
4650
|
-
});
|
|
5185
|
+
const sourceCandidateCollector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
4651
5186
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4652
5187
|
let sourceScanEntries;
|
|
4653
5188
|
let sourceScanMatcher;
|
|
@@ -4668,8 +5203,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4668
5203
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
4669
5204
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
4670
5205
|
opts,
|
|
4671
|
-
|
|
4672
|
-
|
|
5206
|
+
initialTailwindRuntime,
|
|
5207
|
+
refreshTailwindcssRuntime: refreshTailwindRuntime,
|
|
4673
5208
|
uniAppXEnabled,
|
|
4674
5209
|
customAttributesEntities,
|
|
4675
5210
|
disabledDefaultTemplateHandler,
|
|
@@ -4726,6 +5261,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4726
5261
|
seenRoots.add(basedir);
|
|
4727
5262
|
}
|
|
4728
5263
|
for (const cssEntry of opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
5264
|
+
if (!isTailwindV4CssEntry(cssEntry)) continue;
|
|
4729
5265
|
const cssEntryRoot = path.dirname(path.resolve(cssEntry));
|
|
4730
5266
|
if (seenRoots.has(cssEntryRoot)) continue;
|
|
4731
5267
|
roots.push({ root: cssEntryRoot });
|
|
@@ -4760,7 +5296,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4760
5296
|
}
|
|
4761
5297
|
const root = resolvedConfig?.root ?? process$1.cwd();
|
|
4762
5298
|
const outDir = resolvedConfig?.build?.outDir;
|
|
4763
|
-
const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.
|
|
5299
|
+
const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.tailwindRuntime, {
|
|
4764
5300
|
outDir,
|
|
4765
5301
|
root
|
|
4766
5302
|
});
|
|
@@ -4811,6 +5347,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4811
5347
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
4812
5348
|
sourceCandidateCollector.remove(file);
|
|
4813
5349
|
cacheCurrentSourceCandidateScan();
|
|
5350
|
+
if (isSourceStyleRequest(file)) return readFile(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
5351
|
+
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);
|
|
5352
|
+
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4814
5353
|
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
4815
5354
|
}
|
|
4816
5355
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
@@ -4843,7 +5382,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4843
5382
|
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
4844
5383
|
const getViteCssCacheStats = () => ({
|
|
4845
5384
|
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
5385
|
+
viteGeneratedCssByFileRaw: summarizeStringCache(viteGeneratedCssByFile),
|
|
4846
5386
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
5387
|
+
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(viteProcessedCssAssetResults),
|
|
4847
5388
|
...cssMemory.getStats(),
|
|
4848
5389
|
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4849
5390
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
@@ -4889,7 +5430,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4889
5430
|
const transformCssHandlerOptions = createCssHandlerOptionsCache({
|
|
4890
5431
|
getAppType: () => opts.appType,
|
|
4891
5432
|
mainCssChunkMatcher,
|
|
4892
|
-
getMajorVersion: () => runtimeState.
|
|
5433
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4893
5434
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
4894
5435
|
getExtraOptions: (file) => ({
|
|
4895
5436
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -4901,11 +5442,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4901
5442
|
await runtimeState.readyPromise;
|
|
4902
5443
|
await waitForSourceCandidateSyncs();
|
|
4903
5444
|
const file = cleanUrl(id);
|
|
5445
|
+
const requestFile = isCSSRequest(id) ? id : file;
|
|
5446
|
+
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
4904
5447
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4905
5448
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4906
5449
|
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4907
5450
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
4908
|
-
const outputFile = resolveViteCssPipelineOutputFile(
|
|
5451
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, generatorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
4909
5452
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4910
5453
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4911
5454
|
const cssHandlerOptions = {
|
|
@@ -4914,12 +5457,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4914
5457
|
};
|
|
4915
5458
|
const transientCssSource = transientAutoCssSources.get(file);
|
|
4916
5459
|
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(code));
|
|
4917
|
-
const generated = await
|
|
5460
|
+
const generated = await generateTailwindV4Css({
|
|
4918
5461
|
opts,
|
|
4919
5462
|
runtimeState,
|
|
4920
5463
|
runtime,
|
|
4921
5464
|
rawSource: code,
|
|
4922
5465
|
file,
|
|
5466
|
+
outputFile,
|
|
4923
5467
|
cssHandlerOptions,
|
|
4924
5468
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
4925
5469
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
@@ -4968,6 +5512,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4968
5512
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
4969
5513
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
4970
5514
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
5515
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }),
|
|
4971
5516
|
shouldOwnTailwindGeneration,
|
|
4972
5517
|
shouldRewrite: shouldRewriteCssImports,
|
|
4973
5518
|
weappTailwindcssDirPosix
|
|
@@ -5167,11 +5712,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5167
5712
|
const removed = removeTailwindPostcssPlugins(postcssPlugins);
|
|
5168
5713
|
if (removed > 0) debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
5169
5714
|
}
|
|
5170
|
-
const idx = postcssPlugins.findIndex((x) => getPostcssPluginName(x) === "postcss-html-transform");
|
|
5171
|
-
if (idx > -1) {
|
|
5172
|
-
postcssPlugins.splice(idx, 1, postcssHtmlTransform());
|
|
5173
|
-
debug("remove postcss-html-transform plugin from vite config");
|
|
5174
|
-
}
|
|
5175
5715
|
}
|
|
5176
5716
|
}, { emit: false });
|
|
5177
5717
|
},
|