weapp-tailwindcss 5.0.12 → 5.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bundle-state-DU2ATDhw.js → bundle-state-CKWeTEhv.js} +2 -2
- package/dist/{bundle-state-BxMNKjBV.mjs → bundle-state-zQ2MrDdi.mjs} +1 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/vite/css-memory.d.ts +27 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +8 -7
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/map-cache.d.ts +2 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates.d.ts +3 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/vite/source-scan.d.ts +1 -1
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/cli.js +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
- package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/framework/index.d.ts +59 -0
- package/dist/framework.d.ts +1 -0
- package/dist/framework.js +198 -0
- package/dist/framework.mjs +180 -0
- package/dist/{generator-Cb1Zp3Al.js → generator-CzpArpCL.js} +1 -1
- package/dist/{generator-mvNFUvns.mjs → generator-ITLd7PTl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-BfZpaYSQ.mjs → gulp-DfOQERcV.mjs} +44 -16
- package/dist/{gulp-CxGZU0-v.js → gulp-XT8Jc7lH.js} +44 -16
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-BMftW7Us.js} +298 -221
- package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-DQIP_8qP.mjs} +297 -220
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/{precheck-30zNPRlI.js → precheck-B0Z8yW7E.js} +98 -27
- package/dist/{precheck-CsFr1q2l.mjs → precheck-CRI90iL1.mjs} +97 -26
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +3 -3
- package/dist/{tailwindcss-CK84uGBp.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
- package/dist/{tailwindcss-Clpkz1oR.js → tailwindcss-DZEwT3C_.js} +3 -3
- package/dist/{transform-Cju08-aJ.mjs → transform-DfcEjsZF.mjs} +29 -21
- package/dist/{transform-CaVEBOuR.js → transform-YmrmxuF3.js} +29 -21
- package/dist/types/user-defined-options/general.d.ts +3 -1
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/{v3-engine-CQE5JJNZ.js → v3-engine-2rrgylhn.js} +53 -6
- package/dist/{v3-engine-DKBaKWGL.mjs → v3-engine-C6eJ0YzK.mjs} +46 -5
- package/dist/{vite-BBGOjh9e.js → vite-CXHVsHmX.js} +1945 -1280
- package/dist/{vite-CS5DE-HD.mjs → vite-DjI09vVN.mjs} +1944 -1279
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +346 -186
- package/dist/weapp-tw-runtime-classset-loader.js +25 -0
- package/dist/{webpack-SPcri_D8.mjs → webpack-BcPpnT90.mjs} +165 -35
- package/dist/{webpack-DIWrcpRo.js → webpack-CfkUkMXG.js} +167 -37
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +9 -4
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
+
import { D as hasTailwindRootDirectives, E as hasTailwindApplyDirective, N as parseImportRequest, O as hasTailwindSourceDirectives, P as removeTailwindSourceDirectives, Q as filterUnsupportedMiniProgramTailwindV4Candidates, T as hasLocalCssImport, Y as getTailwindV4IncrementalGenerateCacheStats, _ as resolveTailwindConfigEntriesFromCssCached, a as getTailwindV3IncrementalGenerateCacheStats, b as resolveViteTailwindV4CssDependencies, g as discoverTailwindV4CssEntries, gt as omitUndefined, h as resolveViteSourceScanEntries, it as resolveTailwindV4CssSourceBase, j as normalizeTailwindSourceForGenerator, k as normalizeTailwindConfigDirectives, lt as findTailwindConfig, m as createViteSourceScanMatcher, ot as createDebug, pt as findNearestPackageRoot, u as getRuntimeClassSetSignature, ut as resolveTailwindcssOptions, y as resolveTailwindV4EntriesFromCssCached, z as hasTailwindGeneratedCssMarkers } from "./v3-engine-C6eJ0YzK.mjs";
|
|
3
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-ITLd7PTl.mjs";
|
|
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";
|
|
5
|
+
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
6
|
+
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-DTq3uYBK.mjs";
|
|
7
|
+
import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, c as validateCandidatesByGenerator, d as extractMarkedUserLayerComponentsCss, f as mergeMarkedUserLayerComponentsCss, g as annotateCssSourceTrace, i as isSourceCandidateRequest, l as pushConcurrentTaskFactories, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, t as createHmrTimingRecorder, u as runWithConcurrency, v as createCssTokenSourceMap } from "./hmr-timing-DQIP_8qP.mjs";
|
|
8
|
+
import { S as toAbsoluteOutputPath, _ as slash, a as applyLinkedResults, b as normalizeOutputPathKey, c as hasBundlerGeneratedCssMarker, d as resolvePackageDir, f as resolvePluginDisabledState, g as normalizePath, h as isCSSRequest, i as createRuntimeAffectingSourceSignature, l as parseBundlerGeneratedCssMarkerBlocks, m as formatPostcssSourceMap, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as cleanUrl, r as updateBundleBuildState, s as createBundlerGeneratedCssMarker, t as buildBundleSnapshot, u as stripBundlerGeneratedCssMarkers, v as isSourceStyleRequest, y as stripRequestQuery } from "./bundle-state-zQ2MrDdi.mjs";
|
|
8
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
|
+
import fs, { existsSync } from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import process$1 from "node:process";
|
|
9
13
|
import { containsCssAfterMinify, filterExistingCssRules, getPostcssPluginName, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
|
|
10
14
|
import { LRUCache } from "lru-cache";
|
|
11
15
|
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
12
|
-
import fs, { existsSync, readFileSync } from "node:fs";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
import process$1 from "node:process";
|
|
15
16
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
16
17
|
import { readFile } from "node:fs/promises";
|
|
17
18
|
import { Buffer } from "node:buffer";
|
|
@@ -475,7 +476,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
475
476
|
//#region src/uni-app-x/vite.ts
|
|
476
477
|
let transformUVuePromise;
|
|
477
478
|
function loadTransformUVue() {
|
|
478
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
479
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-DfcEjsZF.mjs").then((mod) => mod.transformUVue));
|
|
479
480
|
return transformUVuePromise;
|
|
480
481
|
}
|
|
481
482
|
const preprocessorLangs = new Set([
|
|
@@ -780,11 +781,118 @@ function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
|
780
781
|
return new Set([...candidates, "container"]);
|
|
781
782
|
}
|
|
782
783
|
//#endregion
|
|
784
|
+
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
785
|
+
function collectConfiguredTailwindV4CssSources(opts) {
|
|
786
|
+
const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
787
|
+
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...patcherCssSources];
|
|
788
|
+
}
|
|
789
|
+
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
790
|
+
const entries = [];
|
|
791
|
+
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
792
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
793
|
+
const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
794
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : path.join(base, "tailwind.css");
|
|
795
|
+
entries.push({
|
|
796
|
+
file: path.isAbsolute(file) ? path.resolve(file) : path.resolve(base, file),
|
|
797
|
+
source: cssSource.css
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
return entries;
|
|
801
|
+
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
804
|
+
function createReplayCssAsset(fileName, source) {
|
|
805
|
+
return {
|
|
806
|
+
type: "asset",
|
|
807
|
+
fileName,
|
|
808
|
+
name: void 0,
|
|
809
|
+
source,
|
|
810
|
+
needsCodeReference: false,
|
|
811
|
+
names: [],
|
|
812
|
+
originalFileName: null,
|
|
813
|
+
originalFileNames: []
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
817
|
+
const candidate = error;
|
|
818
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
819
|
+
}
|
|
820
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
821
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
822
|
+
for (const dependency of dependencies ?? []) try {
|
|
823
|
+
ctx.addWatchFile(dependency);
|
|
824
|
+
} catch (error) {
|
|
825
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
826
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
throw error;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
834
|
+
function createCssAssetEmitter(context) {
|
|
835
|
+
return (fileName, source) => {
|
|
836
|
+
const replayAsset = createReplayCssAsset(fileName, source);
|
|
837
|
+
if (context.emitFile) {
|
|
838
|
+
context.emitFile({
|
|
839
|
+
type: "asset",
|
|
840
|
+
fileName,
|
|
841
|
+
source
|
|
842
|
+
});
|
|
843
|
+
return replayAsset;
|
|
844
|
+
}
|
|
845
|
+
return replayAsset;
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
849
|
+
return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
|
|
850
|
+
}
|
|
851
|
+
//#endregion
|
|
783
852
|
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
784
853
|
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
785
854
|
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
786
|
-
const MINI_PROGRAM_STYLE_OUTPUT_EXT_RE = /\.(?:wx|ac|jx|tt|q|ty)ss$/i;
|
|
787
855
|
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
856
|
+
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
857
|
+
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
858
|
+
".wxss",
|
|
859
|
+
".acss",
|
|
860
|
+
".ttss",
|
|
861
|
+
".qss",
|
|
862
|
+
".jxss",
|
|
863
|
+
".tyss"
|
|
864
|
+
];
|
|
865
|
+
function normalizeStyleOutputExtension(value) {
|
|
866
|
+
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
867
|
+
const normalized = value.trim().toLowerCase();
|
|
868
|
+
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
869
|
+
}
|
|
870
|
+
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
871
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
872
|
+
if (!cssMatcher?.(cleanFile)) return;
|
|
873
|
+
const ext = path.extname(cleanFile);
|
|
874
|
+
if (!ext || ext === ".css") return;
|
|
875
|
+
return ext;
|
|
876
|
+
}
|
|
877
|
+
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
878
|
+
let extension;
|
|
879
|
+
for (const file of files ?? []) {
|
|
880
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
881
|
+
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
882
|
+
if (!matchedExtension) continue;
|
|
883
|
+
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
884
|
+
if (extension && extension !== matchedExtension) return;
|
|
885
|
+
extension = matchedExtension;
|
|
886
|
+
}
|
|
887
|
+
return extension;
|
|
888
|
+
}
|
|
889
|
+
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
890
|
+
if (!cssMatcher || !stem) return;
|
|
891
|
+
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
892
|
+
}
|
|
893
|
+
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
894
|
+
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
895
|
+
}
|
|
788
896
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
789
897
|
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
790
898
|
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
@@ -802,14 +910,26 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
802
910
|
if (outputFile.startsWith(`${normalizedSourceRoot}/`)) return outputFile.slice(normalizedSourceRoot.length + 1);
|
|
803
911
|
return outputFile;
|
|
804
912
|
}
|
|
805
|
-
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false) {
|
|
913
|
+
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
806
914
|
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
807
|
-
|
|
915
|
+
const stem = file.replace(/[?#].*$/, "").replace(SOURCE_STYLE_OUTPUT_EXT_RE, "");
|
|
916
|
+
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
917
|
+
cssMatcher: opts.cssMatcher,
|
|
918
|
+
fallback: styleOutputExtension,
|
|
919
|
+
files: styleOutputFiles,
|
|
920
|
+
stem
|
|
921
|
+
}));
|
|
808
922
|
}
|
|
809
|
-
function resolveViteCssPipelineOutputFile(file,
|
|
923
|
+
function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
810
924
|
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot);
|
|
811
|
-
|
|
812
|
-
|
|
925
|
+
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
926
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
927
|
+
const matchedStyleExtension = !isWebGeneratorTarget && !preserveCssExtension ? resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) : void 0;
|
|
928
|
+
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) && isCSSRequest(normalizedFile)) return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, matchedStyleExtension);
|
|
929
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
930
|
+
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
931
|
+
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(normalizedFile)) return normalizedFile;
|
|
932
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
813
933
|
}
|
|
814
934
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
815
935
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
@@ -828,19 +948,6 @@ function stripStyleFileExtension(file) {
|
|
|
828
948
|
const ext = path.extname(normalized);
|
|
829
949
|
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
830
950
|
}
|
|
831
|
-
function isAppOriginCssFile(file) {
|
|
832
|
-
return path.basename(stripStyleFileExtension(file)) === "app-origin";
|
|
833
|
-
}
|
|
834
|
-
function isMainAppCssFile(file) {
|
|
835
|
-
return path.basename(stripStyleFileExtension(file)) === "app";
|
|
836
|
-
}
|
|
837
|
-
function isMainStyleEntryCssFile(file) {
|
|
838
|
-
const basename = path.basename(stripStyleFileExtension(file));
|
|
839
|
-
return basename === "app" || basename === "main";
|
|
840
|
-
}
|
|
841
|
-
function isTailwindEntryCssFile(file) {
|
|
842
|
-
return path.basename(stripStyleFileExtension(file)) === "tailwind";
|
|
843
|
-
}
|
|
844
951
|
//#endregion
|
|
845
952
|
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
846
953
|
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
@@ -895,10 +1002,6 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
895
1002
|
if (!file || !path.isAbsolute(file)) return;
|
|
896
1003
|
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
897
1004
|
}
|
|
898
|
-
function collectConfiguredTailwindV4CssSources(opts) {
|
|
899
|
-
const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
900
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...patcherCssSources ?? []];
|
|
901
|
-
}
|
|
902
1005
|
function collectConfiguredCssEntries(opts) {
|
|
903
1006
|
const patcherCssEntries = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
904
1007
|
return [
|
|
@@ -950,6 +1053,9 @@ function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
|
950
1053
|
}
|
|
951
1054
|
//#endregion
|
|
952
1055
|
//#region src/bundlers/vite/generate-bundle/css-handler-options.ts
|
|
1056
|
+
function resolveViteCssHandlerExtraOptions(file) {
|
|
1057
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, "")).includes("/") ? { isMainChunk: false } : {};
|
|
1058
|
+
}
|
|
953
1059
|
function createCssHandlerOptionsCache(options) {
|
|
954
1060
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
955
1061
|
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -964,8 +1070,8 @@ function createCssHandlerOptionsCache(options) {
|
|
|
964
1070
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
965
1071
|
if (cached) return cached;
|
|
966
1072
|
const created = {
|
|
967
|
-
...extraOptions,
|
|
968
1073
|
isMainChunk,
|
|
1074
|
+
...extraOptions,
|
|
969
1075
|
postcssOptions: { options: { from } },
|
|
970
1076
|
majorVersion,
|
|
971
1077
|
sourceOptions: { outputRoot }
|
|
@@ -1030,414 +1136,16 @@ function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
|
1030
1136
|
return false;
|
|
1031
1137
|
}
|
|
1032
1138
|
//#endregion
|
|
1033
|
-
//#region src/bundlers/vite/generate-bundle/
|
|
1034
|
-
function
|
|
1035
|
-
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
1036
|
-
for (const [id, entry] of jsEntries) normalizedJsEntries.set(normalizeOutputPathKey(id), entry);
|
|
1037
|
-
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(normalizeOutputPathKey(id));
|
|
1038
|
-
}
|
|
1039
|
-
//#endregion
|
|
1040
|
-
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
1041
|
-
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
1042
|
-
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
1043
|
-
}
|
|
1044
|
-
function createJsHandlerOptionsFactory(options) {
|
|
1045
|
-
return (absoluteFilename, extra) => ({
|
|
1046
|
-
...extra,
|
|
1047
|
-
filename: absoluteFilename,
|
|
1048
|
-
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
1049
|
-
moduleGraph: options.moduleGraph,
|
|
1050
|
-
babelParserOptions: {
|
|
1051
|
-
...extra?.babelParserOptions ?? {},
|
|
1052
|
-
sourceFilename: absoluteFilename
|
|
1053
|
-
}
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
//#endregion
|
|
1057
|
-
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
1058
|
-
function createLinkedUpdateHelpers(options) {
|
|
1059
|
-
const pendingLinkedUpdates = [];
|
|
1060
|
-
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
1061
|
-
options.onUpdate(fileName, previous, next);
|
|
1062
|
-
options.debug("js linked handle: %s", fileName);
|
|
1063
|
-
};
|
|
1064
|
-
const scheduleLinkedApply = (entry, code) => {
|
|
1065
|
-
pendingLinkedUpdates.push(() => {
|
|
1066
|
-
if (entry.output.type === "chunk") entry.output.code = code;
|
|
1067
|
-
else entry.output.source = code;
|
|
1068
|
-
});
|
|
1069
|
-
};
|
|
1070
|
-
const applyLinkedUpdates = (linked) => {
|
|
1071
|
-
applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
1072
|
-
};
|
|
1073
|
-
return {
|
|
1074
|
-
applyLinkedUpdates,
|
|
1075
|
-
pendingLinkedUpdates
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
1079
|
-
if (!linked || !linkedSet) return;
|
|
1080
|
-
for (const id of Object.keys(linked)) {
|
|
1081
|
-
const linkedEntry = getJsEntry(id);
|
|
1082
|
-
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
//#endregion
|
|
1086
|
-
//#region src/bundlers/vite/generate-bundle/metrics.ts
|
|
1087
|
-
function formatDebugFileList(files, limit = 8) {
|
|
1088
|
-
if (files.size === 0) return "-";
|
|
1089
|
-
const sorted = [...files].sort();
|
|
1090
|
-
if (sorted.length <= limit) return sorted.join(",");
|
|
1091
|
-
return `${sorted.slice(0, limit).join(",")},...(+${sorted.length - limit})`;
|
|
1092
|
-
}
|
|
1093
|
-
function createEmptyMetric() {
|
|
1094
|
-
return {
|
|
1095
|
-
total: 0,
|
|
1096
|
-
transformed: 0,
|
|
1097
|
-
cacheHits: 0,
|
|
1098
|
-
elapsed: 0
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
function createEmptyMetrics() {
|
|
1139
|
+
//#region src/bundlers/vite/generate-bundle/env-flags.ts
|
|
1140
|
+
function resolveGenerateBundleEnvFlags() {
|
|
1102
1141
|
return {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1142
|
+
forceRuntimeRefreshByEnv: process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1143
|
+
disableDirtyOptimization: process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1144
|
+
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"
|
|
1107
1147
|
};
|
|
1108
1148
|
}
|
|
1109
|
-
function measureElapsed(start) {
|
|
1110
|
-
return performance.now() - start;
|
|
1111
|
-
}
|
|
1112
|
-
function formatCacheHitRate(metric) {
|
|
1113
|
-
if (metric.total === 0) return "0.00%";
|
|
1114
|
-
return `${(metric.cacheHits / metric.total * 100).toFixed(2)}%`;
|
|
1115
|
-
}
|
|
1116
|
-
function formatMs(value) {
|
|
1117
|
-
return value.toFixed(2);
|
|
1118
|
-
}
|
|
1119
|
-
//#endregion
|
|
1120
|
-
//#region src/bundlers/vite/generate-bundle/process-plan.ts
|
|
1121
|
-
function logBundleProcessPlan(options) {
|
|
1122
|
-
const { debug, snapshot, useIncrementalMode, iteration } = options;
|
|
1123
|
-
const { processFiles } = snapshot;
|
|
1124
|
-
if (useIncrementalMode) {
|
|
1125
|
-
debug("dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]", iteration, snapshot.changedByType.html.size, formatDebugFileList(snapshot.changedByType.html), snapshot.changedByType.js.size, formatDebugFileList(snapshot.changedByType.js), snapshot.changedByType.css.size, formatDebugFileList(snapshot.changedByType.css), snapshot.changedByType.other.size, formatDebugFileList(snapshot.changedByType.other));
|
|
1126
|
-
debug("process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]", iteration, processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
1130
|
-
}
|
|
1131
|
-
//#endregion
|
|
1132
|
-
//#region src/bundlers/vite/generate-bundle/sfc-style-source.ts
|
|
1133
|
-
const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
1134
|
-
".vue",
|
|
1135
|
-
".uvue",
|
|
1136
|
-
".nvue",
|
|
1137
|
-
".svelte",
|
|
1138
|
-
".mpx"
|
|
1139
|
-
];
|
|
1140
|
-
const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
1141
|
-
function extractSfcStyleSources(source) {
|
|
1142
|
-
const styleSources = [];
|
|
1143
|
-
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1144
|
-
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1145
|
-
while (match !== null) {
|
|
1146
|
-
styleSources.push(match[1] ?? "");
|
|
1147
|
-
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1148
|
-
}
|
|
1149
|
-
return styleSources;
|
|
1150
|
-
}
|
|
1151
|
-
function hasSfcStyleSources(source) {
|
|
1152
|
-
return extractSfcStyleSources(source).length > 0;
|
|
1153
|
-
}
|
|
1154
|
-
function hasTailwindGenerationSource(source) {
|
|
1155
|
-
return hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1156
|
-
}
|
|
1157
|
-
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSfcSource, debug) {
|
|
1158
|
-
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1159
|
-
if (!sourceFile) {
|
|
1160
|
-
debug("sfc style source infer skipped: no source file for %s", outputFile);
|
|
1161
|
-
return;
|
|
1162
|
-
}
|
|
1163
|
-
const source = getSfcSource?.(sourceFile);
|
|
1164
|
-
if (source == null) {
|
|
1165
|
-
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1169
|
-
if (!rawSource || !hasTailwindGenerationSource(rawSource)) {
|
|
1170
|
-
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1171
|
-
return;
|
|
1172
|
-
}
|
|
1173
|
-
debug("sfc style source inferred: %s -> %s", outputFile, sourceFile);
|
|
1174
|
-
return {
|
|
1175
|
-
outputFile,
|
|
1176
|
-
rawSource,
|
|
1177
|
-
sourceFile
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function normalizeSfcSourceFileForCompare(file) {
|
|
1181
|
-
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1182
|
-
}
|
|
1183
|
-
function collectChunkModuleIds(output) {
|
|
1184
|
-
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1185
|
-
return [
|
|
1186
|
-
output.facadeModuleId,
|
|
1187
|
-
...moduleIds,
|
|
1188
|
-
...Object.keys(output.modules ?? {})
|
|
1189
|
-
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
1190
|
-
}
|
|
1191
|
-
function resolveSiblingJsChunkFile(outputFile) {
|
|
1192
|
-
const normalizedOutputFile = outputFile.replace(/[?#].*$/, "");
|
|
1193
|
-
if (MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(MINI_PROGRAM_STYLE_OUTPUT_EXT_RE, ".js");
|
|
1194
|
-
if (CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".js");
|
|
1195
|
-
}
|
|
1196
|
-
function normalizeSfcModuleId(id) {
|
|
1197
|
-
const file = id.replace(/[?#].*$/, "");
|
|
1198
|
-
if (!SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => file.endsWith(extension))) return;
|
|
1199
|
-
if (!path.isAbsolute(file)) return;
|
|
1200
|
-
return path.resolve(file);
|
|
1201
|
-
}
|
|
1202
|
-
function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1203
|
-
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1204
|
-
if (!siblingJsFile) {
|
|
1205
|
-
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1209
|
-
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1210
|
-
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1211
|
-
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
const sourceFiles = collectChunkModuleIds(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1215
|
-
if (sourceFiles.length === 0) {
|
|
1216
|
-
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1220
|
-
sourceFile,
|
|
1221
|
-
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1222
|
-
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1223
|
-
debug("sfc style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1224
|
-
const bestScore = scoredSources[0]?.score;
|
|
1225
|
-
if (!bestScore) return;
|
|
1226
|
-
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1227
|
-
if (bestSources.length !== 1) {
|
|
1228
|
-
debug("sfc style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1229
|
-
return;
|
|
1230
|
-
}
|
|
1231
|
-
return bestSources[0]?.sourceFile;
|
|
1232
|
-
}
|
|
1233
|
-
//#endregion
|
|
1234
|
-
//#region src/bundlers/vite/generate-bundle/remembered-css.ts
|
|
1235
|
-
function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash) {
|
|
1236
|
-
return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
|
|
1237
|
-
}
|
|
1238
|
-
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
1239
|
-
if (!sources) return [];
|
|
1240
|
-
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
1241
|
-
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
1242
|
-
const markerFiles = new Set(parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => normalizeOutputPathKey(block.file)));
|
|
1243
|
-
if (markerFiles.size > 0) {
|
|
1244
|
-
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))));
|
|
1245
|
-
if (markerMatched.length > 0) return markerMatched;
|
|
1246
|
-
}
|
|
1247
|
-
const originalFiles = [
|
|
1248
|
-
file,
|
|
1249
|
-
originalSource.originalFileName,
|
|
1250
|
-
...originalSource.originalFileNames ?? []
|
|
1251
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1252
|
-
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile)));
|
|
1253
|
-
if (sourceMatched.length > 0) return sourceMatched;
|
|
1254
|
-
const outputMatched = rememberedSources.filter((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
|
|
1255
|
-
if (outputMatched.length > 0) return outputMatched;
|
|
1256
|
-
const shouldUseRememberedApplyFallback = !hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source);
|
|
1257
|
-
if (shouldUseRememberedApplyFallback && !rememberedSources.some((remembered) => hasTailwindApplyDirective(remembered.rawSource))) return [];
|
|
1258
|
-
const scoredMatches = rememberedSources.filter((remembered) => !shouldUseRememberedApplyFallback || hasTailwindApplyDirective(remembered.rawSource)).filter((remembered) => !(isMainAppCssFile(outputFile) && isAppOriginCssFile(remembered.outputFile))).map((remembered) => ({
|
|
1259
|
-
remembered,
|
|
1260
|
-
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
1261
|
-
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
1262
|
-
const bestScore = scoredMatches[0]?.score;
|
|
1263
|
-
return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : [];
|
|
1264
|
-
}
|
|
1265
|
-
function mergeRememberedCssSources(sources, outputFile) {
|
|
1266
|
-
if (sources.length <= 1) return sources[0];
|
|
1267
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1268
|
-
const rawSources = [];
|
|
1269
|
-
for (const source of sources) {
|
|
1270
|
-
const key = `${source.sourceFile}\0${source.rawSource}`;
|
|
1271
|
-
if (seen.has(key)) continue;
|
|
1272
|
-
seen.add(key);
|
|
1273
|
-
rawSources.push(source.rawSource);
|
|
1274
|
-
}
|
|
1275
|
-
return {
|
|
1276
|
-
outputFile,
|
|
1277
|
-
rawSource: rawSources.join("\n"),
|
|
1278
|
-
sourceFile: sources[0]?.sourceFile ?? outputFile
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot) {
|
|
1282
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1283
|
-
for (const [key, remembered] of sources ?? []) {
|
|
1284
|
-
const outputKey = normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot));
|
|
1285
|
-
const group = groups.get(outputKey) ?? [];
|
|
1286
|
-
group.push({
|
|
1287
|
-
key,
|
|
1288
|
-
remembered
|
|
1289
|
-
});
|
|
1290
|
-
groups.set(outputKey, group);
|
|
1291
|
-
}
|
|
1292
|
-
return groups;
|
|
1293
|
-
}
|
|
1294
|
-
//#endregion
|
|
1295
|
-
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
1296
|
-
function createReplayCssAsset(fileName, source) {
|
|
1297
|
-
return {
|
|
1298
|
-
type: "asset",
|
|
1299
|
-
fileName,
|
|
1300
|
-
name: void 0,
|
|
1301
|
-
source,
|
|
1302
|
-
needsCodeReference: false,
|
|
1303
|
-
names: [],
|
|
1304
|
-
originalFileName: null,
|
|
1305
|
-
originalFileNames: []
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
1309
|
-
const candidate = error;
|
|
1310
|
-
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
1311
|
-
}
|
|
1312
|
-
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
1313
|
-
if (typeof ctx.addWatchFile !== "function") return;
|
|
1314
|
-
for (const dependency of dependencies ?? []) try {
|
|
1315
|
-
ctx.addWatchFile(dependency);
|
|
1316
|
-
} catch (error) {
|
|
1317
|
-
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
1318
|
-
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
1319
|
-
continue;
|
|
1320
|
-
}
|
|
1321
|
-
throw error;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
//#endregion
|
|
1325
|
-
//#region src/bundlers/vite/generate-bundle/signatures.ts
|
|
1326
|
-
function summarizeStringDiff(previous, next) {
|
|
1327
|
-
if (previous === next) return "same";
|
|
1328
|
-
const previousLength = previous.length;
|
|
1329
|
-
const nextLength = next.length;
|
|
1330
|
-
const minLength = Math.min(previousLength, nextLength);
|
|
1331
|
-
let prefixLength = 0;
|
|
1332
|
-
while (prefixLength < minLength && previous.charCodeAt(prefixLength) === next.charCodeAt(prefixLength)) prefixLength += 1;
|
|
1333
|
-
let previousSuffixCursor = previousLength - 1;
|
|
1334
|
-
let nextSuffixCursor = nextLength - 1;
|
|
1335
|
-
while (previousSuffixCursor >= prefixLength && nextSuffixCursor >= prefixLength && previous.charCodeAt(previousSuffixCursor) === next.charCodeAt(nextSuffixCursor)) {
|
|
1336
|
-
previousSuffixCursor -= 1;
|
|
1337
|
-
nextSuffixCursor -= 1;
|
|
1338
|
-
}
|
|
1339
|
-
const previousChangedLength = previousSuffixCursor >= prefixLength ? previousSuffixCursor - prefixLength + 1 : 0;
|
|
1340
|
-
const nextChangedLength = nextSuffixCursor >= prefixLength ? nextSuffixCursor - prefixLength + 1 : 0;
|
|
1341
|
-
return `changed@${prefixLength} old=${previousChangedLength} new=${nextChangedLength} len=${previousLength}->${nextLength}`;
|
|
1342
|
-
}
|
|
1343
|
-
function createLinkedImpactSignature(entry, linkedImpactsByEntry, sourceHashByFile) {
|
|
1344
|
-
const changedLinkedFiles = linkedImpactsByEntry.get(entry);
|
|
1345
|
-
if (!changedLinkedFiles || changedLinkedFiles.size === 0) return;
|
|
1346
|
-
return [...changedLinkedFiles].sort().map((file) => {
|
|
1347
|
-
return `${file}:${sourceHashByFile.get(file) ?? "missing"}`;
|
|
1348
|
-
}).join(",");
|
|
1349
|
-
}
|
|
1350
|
-
function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
|
|
1351
|
-
if (!linkedImpactSignature) return runtimeSignature;
|
|
1352
|
-
return `${runtimeSignature}:linked:${linkedImpactSignature}`;
|
|
1353
|
-
}
|
|
1354
|
-
function createStableTextSignature(input) {
|
|
1355
|
-
let hash = 2166136261;
|
|
1356
|
-
for (let i = 0; i < input.length; i++) {
|
|
1357
|
-
hash ^= input.charCodeAt(i);
|
|
1358
|
-
hash = Math.imul(hash, 16777619);
|
|
1359
|
-
}
|
|
1360
|
-
return (hash >>> 0).toString(36);
|
|
1361
|
-
}
|
|
1362
|
-
function createCandidateSignature(candidates) {
|
|
1363
|
-
if (candidates.size === 0) return "empty";
|
|
1364
|
-
return createStableTextSignature([...candidates].sort().join("\n"));
|
|
1365
|
-
}
|
|
1366
|
-
function getSnapshotHash(snapshotMap, file, fallback) {
|
|
1367
|
-
return snapshotMap.get(file) ?? fallback;
|
|
1368
|
-
}
|
|
1369
|
-
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
1370
|
-
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
1371
|
-
}
|
|
1372
|
-
//#endregion
|
|
1373
|
-
//#region src/bundlers/vite/generate-bundle/subpackages.ts
|
|
1374
|
-
function readBundleAssetSource(output) {
|
|
1375
|
-
if (output.type !== "asset") return;
|
|
1376
|
-
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
1377
|
-
}
|
|
1378
|
-
function normalizePackageRoot(root) {
|
|
1379
|
-
return normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
1380
|
-
}
|
|
1381
|
-
function collectMiniProgramSubpackageRoots(bundle) {
|
|
1382
|
-
let hasAppJson = false;
|
|
1383
|
-
const roots = /* @__PURE__ */ new Set();
|
|
1384
|
-
for (const [file, output] of Object.entries(bundle)) {
|
|
1385
|
-
const outputFile = output.fileName || file;
|
|
1386
|
-
if (path.basename(outputFile) !== "app.json") continue;
|
|
1387
|
-
const source = readBundleAssetSource(output);
|
|
1388
|
-
if (!source) continue;
|
|
1389
|
-
hasAppJson = true;
|
|
1390
|
-
try {
|
|
1391
|
-
const appJson = JSON.parse(source);
|
|
1392
|
-
const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
1393
|
-
for (const subPackage of subPackages) {
|
|
1394
|
-
if (typeof subPackage.root !== "string" || subPackage.root.length === 0) continue;
|
|
1395
|
-
roots.add(normalizePackageRoot(subPackage.root));
|
|
1396
|
-
}
|
|
1397
|
-
} catch {}
|
|
1398
|
-
}
|
|
1399
|
-
return hasAppJson ? roots : void 0;
|
|
1400
|
-
}
|
|
1401
|
-
function isSubpackageOutputFile(file, subpackageRoots) {
|
|
1402
|
-
const normalizedFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1403
|
-
for (const root of subpackageRoots) if (root.length > 0 && (normalizedFile === root || normalizedFile.startsWith(`${root}/`) || normalizedFile.endsWith(`/${root}`) || normalizedFile.includes(`/${root}/`))) return true;
|
|
1404
|
-
return false;
|
|
1405
|
-
}
|
|
1406
|
-
function resolveSubpackageSourceRootFromModuleId(moduleId, subpackageRoot) {
|
|
1407
|
-
const file = slash(path.resolve(moduleId.replace(/[?#].*$/, "")));
|
|
1408
|
-
const normalizedRoot = normalizePackageRoot(subpackageRoot);
|
|
1409
|
-
const rootSegment = `/${normalizedRoot}/`;
|
|
1410
|
-
const rootIndex = file.lastIndexOf(rootSegment);
|
|
1411
|
-
if (rootIndex >= 0) return file.slice(0, rootIndex + rootSegment.length - 1);
|
|
1412
|
-
const rootSuffix = `/${normalizedRoot}`;
|
|
1413
|
-
if (file.endsWith(rootSuffix)) return file;
|
|
1414
|
-
}
|
|
1415
|
-
function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, sourceBaseRoots) {
|
|
1416
|
-
const sourceRoots = /* @__PURE__ */ new Set();
|
|
1417
|
-
const sourceEntries = [];
|
|
1418
|
-
for (const entry of snapshot.entries) {
|
|
1419
|
-
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1420
|
-
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1421
|
-
if (!matchedSubpackageRoot) continue;
|
|
1422
|
-
for (const moduleId of collectChunkModuleIds(entry.output)) {
|
|
1423
|
-
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1424
|
-
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1425
|
-
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
sourceEntries.push(...[...sourceRoots].map((sourceRoot) => ({
|
|
1429
|
-
base: sourceRoot,
|
|
1430
|
-
negated: false,
|
|
1431
|
-
pattern: "**/*"
|
|
1432
|
-
})));
|
|
1433
|
-
const resolvedBaseRoots = sourceBaseRoots.filter((baseRoot) => typeof baseRoot === "string" && baseRoot.length > 0).map((baseRoot) => path.resolve(baseRoot)).filter((baseRoot, index, roots) => roots.indexOf(baseRoot) === index);
|
|
1434
|
-
for (const baseRoot of resolvedBaseRoots) for (const subpackageRoot of subpackageRoots) sourceEntries.push({
|
|
1435
|
-
base: baseRoot,
|
|
1436
|
-
negated: false,
|
|
1437
|
-
pattern: `**/${normalizePackageRoot(subpackageRoot)}/**`
|
|
1438
|
-
});
|
|
1439
|
-
return sourceEntries;
|
|
1440
|
-
}
|
|
1441
1149
|
//#endregion
|
|
1442
1150
|
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
1443
1151
|
let _lazyMatch = () => {
|
|
@@ -1885,25 +1593,263 @@ const mix = (del = delimiter) => {
|
|
|
1885
1593
|
const posix = /* @__PURE__ */ mix(":");
|
|
1886
1594
|
const win32 = /* @__PURE__ */ mix(";");
|
|
1887
1595
|
//#endregion
|
|
1888
|
-
//#region src/bundlers/vite/
|
|
1889
|
-
const
|
|
1890
|
-
|
|
1891
|
-
|
|
1596
|
+
//#region src/bundlers/vite/generate-bundle/sfc-style-source.ts
|
|
1597
|
+
const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
1598
|
+
".vue",
|
|
1599
|
+
".uvue",
|
|
1600
|
+
".nvue",
|
|
1601
|
+
".svelte",
|
|
1602
|
+
".mpx"
|
|
1603
|
+
];
|
|
1604
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
1605
|
+
function extractSfcStyleSources(source) {
|
|
1606
|
+
const styleSources = [];
|
|
1607
|
+
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1608
|
+
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1609
|
+
while (match !== null) {
|
|
1610
|
+
styleSources.push(match[1] ?? "");
|
|
1611
|
+
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1612
|
+
}
|
|
1613
|
+
return styleSources;
|
|
1892
1614
|
}
|
|
1893
|
-
function
|
|
1894
|
-
|
|
1895
|
-
return basename === "app" || basename === "main";
|
|
1615
|
+
function hasSfcStyleSources(source) {
|
|
1616
|
+
return extractSfcStyleSources(source).length > 0;
|
|
1896
1617
|
}
|
|
1897
|
-
function
|
|
1898
|
-
return
|
|
1618
|
+
function hasTailwindGenerationSource(source) {
|
|
1619
|
+
return hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1899
1620
|
}
|
|
1900
|
-
function
|
|
1901
|
-
|
|
1621
|
+
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1622
|
+
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
1623
|
+
if (!sourceFile) {
|
|
1624
|
+
debug("sfc style source infer skipped: no source file for %s", outputFile);
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
const source = getSfcSource?.(sourceFile);
|
|
1628
|
+
if (source == null) {
|
|
1629
|
+
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1633
|
+
if (!rawSource || !hasTailwindGenerationSource(rawSource)) {
|
|
1634
|
+
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
debug("sfc style source inferred: %s -> %s", outputFile, sourceFile);
|
|
1638
|
+
return {
|
|
1639
|
+
outputFile,
|
|
1640
|
+
rawSource,
|
|
1641
|
+
sourceFile
|
|
1642
|
+
};
|
|
1902
1643
|
}
|
|
1903
|
-
function
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1644
|
+
function normalizeSfcSourceFileForCompare(file) {
|
|
1645
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1646
|
+
}
|
|
1647
|
+
function collectChunkModuleIds$1(output) {
|
|
1648
|
+
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1649
|
+
return [
|
|
1650
|
+
output.facadeModuleId,
|
|
1651
|
+
...moduleIds,
|
|
1652
|
+
...Object.keys(output.modules ?? {})
|
|
1653
|
+
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
1654
|
+
}
|
|
1655
|
+
function normalizeSourceStyleModuleId(id) {
|
|
1656
|
+
const file = id.replace(/[?#].*$/, "");
|
|
1657
|
+
if (!CSS_SOURCE_OUTPUT_EXT_RE.test(file)) return;
|
|
1658
|
+
if (!path.isAbsolute(file)) return;
|
|
1659
|
+
return path.resolve(file);
|
|
1660
|
+
}
|
|
1661
|
+
function resolveSiblingJsChunkFile(outputFile, cssMatcher) {
|
|
1662
|
+
const normalizedOutputFile = outputFile.replace(/[?#].*$/, "");
|
|
1663
|
+
if (cssMatcher?.(normalizedOutputFile)) {
|
|
1664
|
+
const extension = path.extname(normalizedOutputFile);
|
|
1665
|
+
return extension ? `${normalizedOutputFile.slice(0, -extension.length)}.js` : void 0;
|
|
1666
|
+
}
|
|
1667
|
+
if (CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".js");
|
|
1668
|
+
}
|
|
1669
|
+
function normalizeSfcModuleId(id) {
|
|
1670
|
+
const file = id.replace(/[?#].*$/, "");
|
|
1671
|
+
if (!SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => file.endsWith(extension))) return;
|
|
1672
|
+
if (!path.isAbsolute(file)) return;
|
|
1673
|
+
return path.resolve(file);
|
|
1674
|
+
}
|
|
1675
|
+
function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug) {
|
|
1676
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, cssMatcher);
|
|
1677
|
+
if (!siblingJsFile) {
|
|
1678
|
+
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1682
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1683
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1684
|
+
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1688
|
+
if (sourceFiles.length === 0) {
|
|
1689
|
+
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1693
|
+
sourceFile,
|
|
1694
|
+
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1695
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1696
|
+
debug("sfc style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1697
|
+
const bestScore = scoredSources[0]?.score;
|
|
1698
|
+
if (!bestScore) return;
|
|
1699
|
+
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1700
|
+
if (bestSources.length !== 1) {
|
|
1701
|
+
debug("sfc style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
return bestSources[0]?.sourceFile;
|
|
1705
|
+
}
|
|
1706
|
+
function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1707
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1708
|
+
if (!siblingJsFile) {
|
|
1709
|
+
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1713
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1714
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1715
|
+
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1719
|
+
if (sourceFiles.length === 0) {
|
|
1720
|
+
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1724
|
+
sourceFile,
|
|
1725
|
+
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1726
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1727
|
+
debug("source style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1728
|
+
const bestScore = scoredSources[0]?.score;
|
|
1729
|
+
if (!bestScore) return;
|
|
1730
|
+
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1731
|
+
if (bestSources.length !== 1) {
|
|
1732
|
+
debug("source style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
return bestSources[0]?.sourceFile;
|
|
1736
|
+
}
|
|
1737
|
+
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1738
|
+
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1739
|
+
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1740
|
+
if (!rawSource || !hasTailwindGenerationSource(rawSource)) {
|
|
1741
|
+
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSource(source)).map(([file, source]) => ({
|
|
1742
|
+
file,
|
|
1743
|
+
source,
|
|
1744
|
+
score: scoreMatchingStyleFileBase(outputFile, file, outputRoot, sourceRoot)
|
|
1745
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1746
|
+
const bestScore = scoredSources[0]?.score;
|
|
1747
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
1748
|
+
if (bestSources.length === 1) {
|
|
1749
|
+
sourceFile = bestSources[0].file;
|
|
1750
|
+
rawSource = bestSources[0].source;
|
|
1751
|
+
debug("source style source inferred from cache: %s -> %s", outputFile, sourceFile);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
if (!sourceFile || !rawSource) return;
|
|
1755
|
+
if (!hasTailwindGenerationSource(rawSource)) {
|
|
1756
|
+
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1757
|
+
return;
|
|
1758
|
+
}
|
|
1759
|
+
return {
|
|
1760
|
+
outputFile,
|
|
1761
|
+
rawSource,
|
|
1762
|
+
sourceFile
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
//#endregion
|
|
1766
|
+
//#region src/bundlers/vite/generate-bundle/subpackages.ts
|
|
1767
|
+
function readBundleAssetSource(output) {
|
|
1768
|
+
if (output.type !== "asset") return;
|
|
1769
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
1770
|
+
}
|
|
1771
|
+
function normalizePackageRoot(root) {
|
|
1772
|
+
return normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
1773
|
+
}
|
|
1774
|
+
function collectMiniProgramSubpackageRoots(bundle) {
|
|
1775
|
+
let hasAppJson = false;
|
|
1776
|
+
const roots = /* @__PURE__ */ new Set();
|
|
1777
|
+
for (const [file, output] of Object.entries(bundle)) {
|
|
1778
|
+
const outputFile = output.fileName || file;
|
|
1779
|
+
if (path.basename(outputFile) !== "app.json") continue;
|
|
1780
|
+
const source = readBundleAssetSource(output);
|
|
1781
|
+
if (!source) continue;
|
|
1782
|
+
hasAppJson = true;
|
|
1783
|
+
try {
|
|
1784
|
+
const appJson = JSON.parse(source);
|
|
1785
|
+
const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
1786
|
+
for (const subPackage of subPackages) {
|
|
1787
|
+
if (typeof subPackage.root !== "string" || subPackage.root.length === 0) continue;
|
|
1788
|
+
roots.add(normalizePackageRoot(subPackage.root));
|
|
1789
|
+
}
|
|
1790
|
+
} catch {}
|
|
1791
|
+
}
|
|
1792
|
+
return hasAppJson ? roots : void 0;
|
|
1793
|
+
}
|
|
1794
|
+
function isSubpackageOutputFile(file, subpackageRoots) {
|
|
1795
|
+
const normalizedFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1796
|
+
for (const root of subpackageRoots) if (root.length > 0 && (normalizedFile === root || normalizedFile.startsWith(`${root}/`) || normalizedFile.endsWith(`/${root}`) || normalizedFile.includes(`/${root}/`))) return true;
|
|
1797
|
+
return false;
|
|
1798
|
+
}
|
|
1799
|
+
function resolveSubpackageSourceRootFromModuleId(moduleId, subpackageRoot) {
|
|
1800
|
+
const file = slash(path.resolve(moduleId.replace(/[?#].*$/, "")));
|
|
1801
|
+
const normalizedRoot = normalizePackageRoot(subpackageRoot);
|
|
1802
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
1803
|
+
const rootIndex = file.lastIndexOf(rootSegment);
|
|
1804
|
+
if (rootIndex >= 0) return file.slice(0, rootIndex + rootSegment.length - 1);
|
|
1805
|
+
const rootSuffix = `/${normalizedRoot}`;
|
|
1806
|
+
if (file.endsWith(rootSuffix)) return file;
|
|
1807
|
+
}
|
|
1808
|
+
function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, sourceBaseRoots) {
|
|
1809
|
+
const sourceRoots = /* @__PURE__ */ new Set();
|
|
1810
|
+
const sourceEntries = [];
|
|
1811
|
+
for (const entry of snapshot.entries) {
|
|
1812
|
+
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1813
|
+
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1814
|
+
if (!matchedSubpackageRoot) continue;
|
|
1815
|
+
for (const moduleId of collectChunkModuleIds$1(entry.output)) {
|
|
1816
|
+
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1817
|
+
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1818
|
+
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
sourceEntries.push(...[...sourceRoots].map((sourceRoot) => ({
|
|
1822
|
+
base: sourceRoot,
|
|
1823
|
+
negated: false,
|
|
1824
|
+
pattern: "**/*"
|
|
1825
|
+
})));
|
|
1826
|
+
const resolvedBaseRoots = sourceBaseRoots.filter((baseRoot) => typeof baseRoot === "string" && baseRoot.length > 0).map((baseRoot) => path.resolve(baseRoot)).filter((baseRoot, index, roots) => roots.indexOf(baseRoot) === index);
|
|
1827
|
+
for (const baseRoot of resolvedBaseRoots) for (const subpackageRoot of subpackageRoots) sourceEntries.push({
|
|
1828
|
+
base: baseRoot,
|
|
1829
|
+
negated: false,
|
|
1830
|
+
pattern: `**/${normalizePackageRoot(subpackageRoot)}/**`
|
|
1831
|
+
});
|
|
1832
|
+
return sourceEntries;
|
|
1833
|
+
}
|
|
1834
|
+
//#endregion
|
|
1835
|
+
//#region src/bundlers/vite/processed-css-assets.ts
|
|
1836
|
+
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
1837
|
+
function isCssOutputFile(file) {
|
|
1838
|
+
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1839
|
+
}
|
|
1840
|
+
function getAssetFile(bundleFile, asset) {
|
|
1841
|
+
return asset.fileName || bundleFile;
|
|
1842
|
+
}
|
|
1843
|
+
function readAssetSource(asset) {
|
|
1844
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1845
|
+
}
|
|
1846
|
+
function clearAssetSource(asset) {
|
|
1847
|
+
asset.source = "";
|
|
1848
|
+
}
|
|
1849
|
+
function appendCss(baseCss, css) {
|
|
1850
|
+
if (baseCss.length === 0) return css;
|
|
1851
|
+
if (css.length === 0) return baseCss;
|
|
1852
|
+
return `${baseCss}\n${css}`;
|
|
1907
1853
|
}
|
|
1908
1854
|
function removeTailwindSourceMediaWrappers(css) {
|
|
1909
1855
|
if (!css.includes("@media source(")) return css;
|
|
@@ -1969,13 +1915,85 @@ function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcesse
|
|
|
1969
1915
|
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1970
1916
|
return parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
1971
1917
|
}
|
|
1918
|
+
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1919
|
+
const sources = [];
|
|
1920
|
+
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
1921
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1922
|
+
if (output.type !== "asset") continue;
|
|
1923
|
+
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
1924
|
+
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1925
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource(output)).trim();
|
|
1926
|
+
if (source.length > 0) sources.push(source);
|
|
1927
|
+
}
|
|
1928
|
+
return sources;
|
|
1929
|
+
}
|
|
1930
|
+
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
1931
|
+
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1932
|
+
if (blocks.length !== 1) return;
|
|
1933
|
+
const file = blocks[0]?.file;
|
|
1934
|
+
return typeof file === "string" && file.length > 0 ? file : void 0;
|
|
1935
|
+
}
|
|
1936
|
+
function shouldFilterRootGeneratedCssMarkerForScopedAsset(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
1937
|
+
const resolvedTargetFile = normalizeMarkerOutputFile(targetFile, resolveViteProcessedCssOutputFile);
|
|
1938
|
+
if (!isRootStyleOutputFile(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)) || isRootStyleOutputFile(resolvedTargetFile)) return false;
|
|
1939
|
+
return !isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile);
|
|
1940
|
+
}
|
|
1941
|
+
function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
|
|
1942
|
+
return removeDanglingCssSourceTraceComments(removeCssCoveredByImportedViteResults(css, collectRootStyleBundleCssSources(bundle, file)));
|
|
1943
|
+
}
|
|
1944
|
+
function removeDanglingCssSourceTraceComments(css) {
|
|
1945
|
+
if (!css.includes("/* tokens:")) return css;
|
|
1946
|
+
try {
|
|
1947
|
+
const root = postcss.parse(css);
|
|
1948
|
+
let changed = false;
|
|
1949
|
+
root.each((node) => {
|
|
1950
|
+
if (node.type !== "comment" || !node.text.trim().startsWith("tokens:")) return;
|
|
1951
|
+
const next = node.next();
|
|
1952
|
+
if (next?.type === "rule" || next?.type === "atrule") return;
|
|
1953
|
+
node.remove();
|
|
1954
|
+
changed = true;
|
|
1955
|
+
});
|
|
1956
|
+
return changed ? root.toString().trim() : css;
|
|
1957
|
+
} catch {
|
|
1958
|
+
return css;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
1962
|
+
let updated = 0;
|
|
1963
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1964
|
+
if (output.type !== "asset") continue;
|
|
1965
|
+
const file = getAssetFile(bundleFile, output);
|
|
1966
|
+
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
1967
|
+
const rawSource = readAssetSource(output);
|
|
1968
|
+
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
1969
|
+
if (nextCss === rawSource) continue;
|
|
1970
|
+
output.source = nextCss;
|
|
1971
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
1972
|
+
options.onUpdate?.(file, rawSource, nextCss);
|
|
1973
|
+
options.debug?.("remove root-covered css rules from scoped asset: %s bytes=%d", file, nextCss.length);
|
|
1974
|
+
updated++;
|
|
1975
|
+
}
|
|
1976
|
+
return updated;
|
|
1977
|
+
}
|
|
1972
1978
|
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
1973
|
-
if (options.injectIntoMain === true) return
|
|
1979
|
+
if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) === normalizeOutputPathKey(targetFile);
|
|
1974
1980
|
if (options.injectIntoMain === false) return false;
|
|
1975
1981
|
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1982
|
+
return normalizeOutputPathKey(sourceFile) !== targetFileKey && (opts.mainCssChunkMatcher(sourceFile, opts.appType) || typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) !== targetFileKey && opts.mainCssChunkMatcher(options.outputFile, opts.appType));
|
|
1983
|
+
}
|
|
1984
|
+
function isRootStyleOutputFile(file) {
|
|
1985
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1986
|
+
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1987
|
+
}
|
|
1988
|
+
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
1989
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
1990
|
+
if (records.some((record) => {
|
|
1991
|
+
if (record.injectIntoMain !== true) return false;
|
|
1992
|
+
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
1993
|
+
})) return true;
|
|
1994
|
+
if (records.some((record) => record.injectIntoMain === true)) return false;
|
|
1995
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) return true;
|
|
1996
|
+
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
1979
1997
|
}
|
|
1980
1998
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
1981
1999
|
const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
|
|
@@ -2007,6 +2025,21 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2007
2025
|
}
|
|
2008
2026
|
return files;
|
|
2009
2027
|
}
|
|
2028
|
+
function isCssImportOnlyBundleAsset(bundle, file, css) {
|
|
2029
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2030
|
+
if (importedStyleFiles.size === 0) return false;
|
|
2031
|
+
let hasNonImportNode = false;
|
|
2032
|
+
try {
|
|
2033
|
+
postcss.parse(css).each((node) => {
|
|
2034
|
+
if (node.type === "comment") return;
|
|
2035
|
+
if (node.type !== "atrule" || node.name !== "import") hasNonImportNode = true;
|
|
2036
|
+
});
|
|
2037
|
+
} catch {
|
|
2038
|
+
return false;
|
|
2039
|
+
}
|
|
2040
|
+
if (hasNonImportNode) return false;
|
|
2041
|
+
return collectImportedBundleCssSources(bundle, importedStyleFiles).length > 0;
|
|
2042
|
+
}
|
|
2010
2043
|
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2011
2044
|
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2012
2045
|
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
@@ -2019,27 +2052,38 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2019
2052
|
const file = getAssetFile(bundleFile, output);
|
|
2020
2053
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
2021
2054
|
const rawSource = readAssetSource(output);
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
continue;
|
|
2026
|
-
}
|
|
2027
|
-
const nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2055
|
+
let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2056
|
+
const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
|
|
2057
|
+
if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
|
|
2028
2058
|
if (nextCss !== rawSource) output.source = nextCss;
|
|
2029
2059
|
options.markCssAssetProcessed?.(output, file);
|
|
2030
2060
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2031
2061
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
2032
|
-
const shouldReplayIntoMainCss = options.opts != null &&
|
|
2062
|
+
const shouldReplayIntoMainCss = options.opts != null && (options.opts.mainCssChunkMatcher(file, options.opts.appType) || normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && (isRootStyleOutputFile(file) || posix.posix.basename(normalizeOutputPathKey(file.replace(/[?#].*$/, ""))) === posix.posix.basename(normalizeOutputPathKey(resolvedOutputFile.replace(/[?#].*$/, "")))) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType));
|
|
2033
2063
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2034
2064
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2035
2065
|
outputFile: resolvedOutputFile
|
|
2036
2066
|
});
|
|
2067
|
+
if (normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, nextCss, {
|
|
2068
|
+
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2069
|
+
outputFile: resolvedOutputFile
|
|
2070
|
+
});
|
|
2037
2071
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2038
2072
|
if (normalizeOutputPathKey(markerFile) === normalizeOutputPathKey(file)) continue;
|
|
2039
2073
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2040
2074
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2041
2075
|
outputFile: resolvedOutputFile
|
|
2042
2076
|
});
|
|
2077
|
+
if (normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(markerFile) && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, nextCss, {
|
|
2078
|
+
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2079
|
+
outputFile: resolvedOutputFile
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) {
|
|
2083
|
+
delete bundle[bundleFile];
|
|
2084
|
+
options.debug?.("skip covered vite-generated source css asset: %s", file);
|
|
2085
|
+
collected++;
|
|
2086
|
+
continue;
|
|
2043
2087
|
}
|
|
2044
2088
|
options.debug?.("collect vite-processed css asset: %s bytes=%d", file, nextCss.length);
|
|
2045
2089
|
collected++;
|
|
@@ -2063,7 +2107,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2063
2107
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2064
2108
|
if (output.type !== "asset") continue;
|
|
2065
2109
|
const file = getAssetFile(bundleFile, output);
|
|
2066
|
-
if (!options.opts.cssMatcher(file) || !options.opts
|
|
2110
|
+
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2067
2111
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2068
2112
|
const originalSource = readAssetSource(output);
|
|
2069
2113
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
@@ -2114,43 +2158,169 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2114
2158
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2115
2159
|
options.onUpdate?.(file, originalSource, nextCss);
|
|
2116
2160
|
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2161
|
+
for (const record of viteCssResults) {
|
|
2162
|
+
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2163
|
+
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2164
|
+
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2165
|
+
if (candidateOutput.type !== "asset") continue;
|
|
2166
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile(candidateFile, candidateOutput));
|
|
2167
|
+
const isRecordFile = candidateKey === recordFileKey;
|
|
2168
|
+
const isProcessedSource = readAssetSource(candidateOutput).trim() === record.css.trim();
|
|
2169
|
+
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2170
|
+
clearAssetSource(candidateOutput);
|
|
2171
|
+
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2117
2174
|
injected++;
|
|
2118
2175
|
}
|
|
2119
2176
|
return injected;
|
|
2120
2177
|
}
|
|
2121
2178
|
//#endregion
|
|
2122
|
-
//#region src/bundlers/vite/
|
|
2123
|
-
function
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
}
|
|
2131
|
-
//#endregion
|
|
2132
|
-
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
2133
|
-
function resolveWeappViteSourceRoot(config) {
|
|
2134
|
-
const srcRoot = config?.weapp?.srcRoot;
|
|
2135
|
-
return typeof srcRoot === "string" && srcRoot.trim().length > 0 ? srcRoot : void 0;
|
|
2179
|
+
//#region src/bundlers/vite/generate-bundle/bundle-file-names.ts
|
|
2180
|
+
function normalizeBundleFileNameKeysForTest(bundle) {
|
|
2181
|
+
for (const [file, output] of Object.entries(bundle)) {
|
|
2182
|
+
if (!output.fileName || output.fileName === file) continue;
|
|
2183
|
+
const existing = bundle[output.fileName];
|
|
2184
|
+
if (existing != null && existing !== output) continue;
|
|
2185
|
+
bundle[output.fileName] = output;
|
|
2186
|
+
delete bundle[file];
|
|
2187
|
+
}
|
|
2136
2188
|
}
|
|
2137
2189
|
//#endregion
|
|
2138
|
-
//#region src/bundlers/vite/generate-bundle.ts
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
const configured = Number.parseInt(process$1.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2142
|
-
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2143
|
-
return useIncrementalMode ? 1 : 2;
|
|
2144
|
-
}
|
|
2145
|
-
function addSiblingCssFile(files, file) {
|
|
2146
|
-
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
2147
|
-
else if (file.endsWith(".js")) files.add(file.replace(/\.js$/, ".wxss"));
|
|
2190
|
+
//#region src/bundlers/vite/generate-bundle/memory-debug.ts
|
|
2191
|
+
function toMb(bytes) {
|
|
2192
|
+
return Math.round(bytes / 1024 / 1024);
|
|
2148
2193
|
}
|
|
2149
|
-
function
|
|
2150
|
-
|
|
2151
|
-
for (const
|
|
2152
|
-
|
|
2153
|
-
|
|
2194
|
+
function summarizeStringMapCache(map) {
|
|
2195
|
+
let bytes = 0;
|
|
2196
|
+
for (const value of map.values()) bytes += value.length;
|
|
2197
|
+
return {
|
|
2198
|
+
bytes,
|
|
2199
|
+
mb: toMb(bytes),
|
|
2200
|
+
size: map.size
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
function resolveViteMemoryDebugStats(context) {
|
|
2204
|
+
if (process$1.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2205
|
+
const memory = process$1.memoryUsage();
|
|
2206
|
+
return {
|
|
2207
|
+
phase: context.phase,
|
|
2208
|
+
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2209
|
+
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)
|
|
2215
|
+
},
|
|
2216
|
+
runtime: {
|
|
2217
|
+
sourceCandidates: context.sourceCandidatesSize,
|
|
2218
|
+
runtime: context.runtimeSize,
|
|
2219
|
+
transformRuntime: context.transformRuntimeSize,
|
|
2220
|
+
generatorRuntime: context.generatorRuntimeSize
|
|
2221
|
+
},
|
|
2222
|
+
processCache: {
|
|
2223
|
+
instance: context.cache.instance.size,
|
|
2224
|
+
hashMap: context.cache.hashMap.size,
|
|
2225
|
+
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2226
|
+
activeHashKeys: context.activeProcessHashKeys.size
|
|
2227
|
+
},
|
|
2228
|
+
viteCss: {
|
|
2229
|
+
...context.getViteCssCacheStats?.(),
|
|
2230
|
+
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2231
|
+
},
|
|
2232
|
+
tailwind: {
|
|
2233
|
+
v3: getTailwindV3IncrementalGenerateCacheStats(),
|
|
2234
|
+
v4: getTailwindV4IncrementalGenerateCacheStats()
|
|
2235
|
+
}
|
|
2236
|
+
};
|
|
2237
|
+
}
|
|
2238
|
+
//#endregion
|
|
2239
|
+
//#region src/bundlers/vite/generate-bundle/metrics.ts
|
|
2240
|
+
function formatDebugFileList(files, limit = 8) {
|
|
2241
|
+
if (files.size === 0) return "-";
|
|
2242
|
+
const sorted = [...files].sort();
|
|
2243
|
+
if (sorted.length <= limit) return sorted.join(",");
|
|
2244
|
+
return `${sorted.slice(0, limit).join(",")},...(+${sorted.length - limit})`;
|
|
2245
|
+
}
|
|
2246
|
+
function createEmptyMetric() {
|
|
2247
|
+
return {
|
|
2248
|
+
total: 0,
|
|
2249
|
+
transformed: 0,
|
|
2250
|
+
cacheHits: 0,
|
|
2251
|
+
elapsed: 0
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
function createEmptyMetrics() {
|
|
2255
|
+
return {
|
|
2256
|
+
runtimeSet: 0,
|
|
2257
|
+
html: createEmptyMetric(),
|
|
2258
|
+
js: createEmptyMetric(),
|
|
2259
|
+
css: createEmptyMetric()
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
function measureElapsed(start) {
|
|
2263
|
+
return performance.now() - start;
|
|
2264
|
+
}
|
|
2265
|
+
function formatCacheHitRate(metric) {
|
|
2266
|
+
if (metric.total === 0) return "0.00%";
|
|
2267
|
+
return `${(metric.cacheHits / metric.total * 100).toFixed(2)}%`;
|
|
2268
|
+
}
|
|
2269
|
+
function formatMs(value) {
|
|
2270
|
+
return value.toFixed(2);
|
|
2271
|
+
}
|
|
2272
|
+
//#endregion
|
|
2273
|
+
//#region src/bundlers/vite/generate-bundle/uni-app-x-postprocess.ts
|
|
2274
|
+
async function handleUniAppXPostCssTasks(options) {
|
|
2275
|
+
const { bundle, debug, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler } = options;
|
|
2276
|
+
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
2277
|
+
if (opts.appType !== "uni-app-x" && !isNativeAppStyleTarget && !isHarmonyAppStyleTarget) return applyStyleSources;
|
|
2278
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
2279
|
+
const viteProcessedCssSources = [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
2280
|
+
const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
|
|
2281
|
+
if (isHarmonyAppStyleTarget && applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2282
|
+
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2283
|
+
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2284
|
+
const generated = await generateCssByGenerator({
|
|
2285
|
+
opts,
|
|
2286
|
+
runtimeState,
|
|
2287
|
+
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2288
|
+
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2289
|
+
file: outputFile,
|
|
2290
|
+
cssHandlerOptions,
|
|
2291
|
+
cssUserHandlerOptions: {
|
|
2292
|
+
...cssHandlerOptions,
|
|
2293
|
+
isMainChunk: false
|
|
2294
|
+
},
|
|
2295
|
+
getSourceCandidatesForEntries,
|
|
2296
|
+
styleHandler,
|
|
2297
|
+
debug
|
|
2298
|
+
});
|
|
2299
|
+
if (generated?.css) viteProcessedCssSources.push(annotateCssSourceTrace(generated.css, {
|
|
2300
|
+
opts,
|
|
2301
|
+
tokenSources: getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0
|
|
2302
|
+
}));
|
|
2303
|
+
}
|
|
2304
|
+
if (isHarmonyAppStyleTarget && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
2305
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
2306
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
2307
|
+
const currentSource = String(item.source);
|
|
2308
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
2309
|
+
if (nextSource !== currentSource) {
|
|
2310
|
+
item.source = nextSource;
|
|
2311
|
+
onUpdate(file, currentSource, nextSource);
|
|
2312
|
+
debug("uni-app-x style placeholder inject: %s", file);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
return applyStyleSources;
|
|
2316
|
+
}
|
|
2317
|
+
//#endregion
|
|
2318
|
+
//#region src/bundlers/vite/generate-bundle/vite-css-cache.ts
|
|
2319
|
+
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2320
|
+
function resolveViteCssTaskConcurrency(useIncrementalMode) {
|
|
2321
|
+
const configured = Number.parseInt(process$1.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2322
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2323
|
+
return useIncrementalMode ? 1 : 2;
|
|
2154
2324
|
}
|
|
2155
2325
|
function normalizeViteCssCacheKey(file) {
|
|
2156
2326
|
return normalizeOutputPathKey(file);
|
|
@@ -2189,60 +2359,702 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2189
2359
|
sourceHashByFile.delete(key);
|
|
2190
2360
|
}
|
|
2191
2361
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2362
|
+
//#endregion
|
|
2363
|
+
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
2364
|
+
async function finalizeGenerateBundle(options) {
|
|
2365
|
+
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
|
+
if (cssTaskFactories.length > 0) {
|
|
2367
|
+
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2368
|
+
tasks.push(runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2369
|
+
}
|
|
2370
|
+
const tasksStart = performance.now();
|
|
2371
|
+
await Promise.all(tasks);
|
|
2372
|
+
recordTimingDetail("tasks", tasksStart);
|
|
2373
|
+
for (const apply of pendingLinkedUpdates) apply();
|
|
2374
|
+
const applyStyleSources = await handleUniAppXPostCssTasks({
|
|
2375
|
+
bundle,
|
|
2376
|
+
debug,
|
|
2377
|
+
generatorRuntime,
|
|
2378
|
+
getCssHandlerOptions,
|
|
2379
|
+
getSourceCandidateSourcesForEntries,
|
|
2380
|
+
getSourceCandidatesForEntries,
|
|
2381
|
+
getViteProcessedCssAssetResults,
|
|
2382
|
+
isHarmonyAppStyleTarget,
|
|
2383
|
+
isNativeAppStyleTarget,
|
|
2384
|
+
onUpdate,
|
|
2385
|
+
opts,
|
|
2386
|
+
runtimeState,
|
|
2387
|
+
styleHandler
|
|
2388
|
+
});
|
|
2389
|
+
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
2390
|
+
collectViteProcessedCssAssetResults(bundle, {
|
|
2391
|
+
opts,
|
|
2392
|
+
isViteProcessedCssAsset,
|
|
2393
|
+
markCssAssetProcessed,
|
|
2394
|
+
recordCssAssetResult,
|
|
2395
|
+
recordViteProcessedCssAssetResult,
|
|
2396
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles),
|
|
2397
|
+
subpackageRoots: collectMiniProgramSubpackageRoots(bundle),
|
|
2398
|
+
debug
|
|
2399
|
+
});
|
|
2400
|
+
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
2401
|
+
opts,
|
|
2402
|
+
getViteProcessedCssAssetResults,
|
|
2403
|
+
markCssAssetProcessed,
|
|
2404
|
+
recordCssAssetResult,
|
|
2405
|
+
shouldRemoveInjectedSourceAsset: (_targetFile, record) => {
|
|
2406
|
+
if (record.injectIntoMain !== true || typeof record.outputFile !== "string") return false;
|
|
2407
|
+
return normalizeOutputPathKey(record.file) !== normalizeOutputPathKey(record.outputFile);
|
|
2408
|
+
},
|
|
2409
|
+
debug,
|
|
2410
|
+
onUpdate
|
|
2411
|
+
});
|
|
2412
|
+
};
|
|
2413
|
+
syncViteProcessedCssIntoMainCssAssets();
|
|
2414
|
+
if (isHarmonyAppStyleTarget && applyStyleSources.length > 0) {
|
|
2415
|
+
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
|
+
syncViteProcessedCssIntoMainCssAssets();
|
|
2417
|
+
}
|
|
2418
|
+
normalizeBundleFileNameKeysForTest(bundle);
|
|
2419
|
+
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2420
|
+
cssMatcher: opts.cssMatcher,
|
|
2421
|
+
debug,
|
|
2422
|
+
isViteProcessedCssAsset,
|
|
2423
|
+
onUpdate,
|
|
2424
|
+
recordCssAssetResult,
|
|
2425
|
+
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2426
|
+
});
|
|
2427
|
+
const stateUpdateStart = performance.now();
|
|
2428
|
+
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2429
|
+
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2430
|
+
if (useIncrementalMode && !snapshot.hasOmittedKnownFiles) cache.prune?.({
|
|
2431
|
+
cacheKeys: activeProcessCacheKeys,
|
|
2432
|
+
hashKeys: activeProcessHashKeys
|
|
2433
|
+
});
|
|
2434
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2435
|
+
pruneViteCssCaches?.({
|
|
2436
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2437
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2438
|
+
});
|
|
2439
|
+
recordTimingDetail("state.update", stateUpdateStart);
|
|
2440
|
+
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
|
+
if (hmrTimingRecorder) {
|
|
2442
|
+
hmrTimingRecorder.record("generateBundle", performance.now() - hmrTimingStartedAt, {
|
|
2443
|
+
...timingDetails,
|
|
2444
|
+
memoryDebug: resolveViteMemoryDebugStats({
|
|
2445
|
+
activeProcessCacheKeys,
|
|
2446
|
+
activeProcessHashKeys,
|
|
2447
|
+
cache,
|
|
2448
|
+
generatorRuntimeSize: generatorRuntime.size,
|
|
2449
|
+
getViteCssCacheStats,
|
|
2450
|
+
lastCssResultByFile,
|
|
2451
|
+
phase: "generateBundle",
|
|
2452
|
+
runtimeSize: runtime.size,
|
|
2453
|
+
sourceCandidatesSize: sourceCandidates.size,
|
|
2454
|
+
transformRuntimeSize: transformRuntime.size,
|
|
2455
|
+
useIncrementalMode
|
|
2456
|
+
})
|
|
2457
|
+
});
|
|
2458
|
+
hmrTimingRecorder.emitTotal();
|
|
2459
|
+
}
|
|
2460
|
+
onEnd();
|
|
2461
|
+
debug("end");
|
|
2194
2462
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2463
|
+
//#endregion
|
|
2464
|
+
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
2465
|
+
function createJsEntryResolver(jsEntries) {
|
|
2466
|
+
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
2467
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(normalizeOutputPathKey(id), entry);
|
|
2468
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(normalizeOutputPathKey(id));
|
|
2469
|
+
}
|
|
2470
|
+
//#endregion
|
|
2471
|
+
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
2472
|
+
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
2473
|
+
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
2474
|
+
}
|
|
2475
|
+
function createJsHandlerOptionsFactory(options) {
|
|
2476
|
+
return (absoluteFilename, extra) => ({
|
|
2477
|
+
...extra,
|
|
2478
|
+
filename: absoluteFilename,
|
|
2479
|
+
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
2480
|
+
moduleGraph: options.moduleGraph,
|
|
2481
|
+
babelParserOptions: {
|
|
2482
|
+
...extra?.babelParserOptions ?? {},
|
|
2483
|
+
sourceFilename: absoluteFilename
|
|
2484
|
+
}
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
//#endregion
|
|
2488
|
+
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
2489
|
+
function createLinkedUpdateHelpers(options) {
|
|
2490
|
+
const pendingLinkedUpdates = [];
|
|
2491
|
+
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
2492
|
+
options.onUpdate(fileName, previous, next);
|
|
2493
|
+
options.debug("js linked handle: %s", fileName);
|
|
2494
|
+
};
|
|
2495
|
+
const scheduleLinkedApply = (entry, code) => {
|
|
2496
|
+
pendingLinkedUpdates.push(() => {
|
|
2497
|
+
if (entry.output.type === "chunk") entry.output.code = code;
|
|
2498
|
+
else entry.output.source = code;
|
|
2499
|
+
});
|
|
2500
|
+
};
|
|
2501
|
+
const applyLinkedUpdates = (linked) => {
|
|
2502
|
+
applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
2503
|
+
};
|
|
2198
2504
|
return {
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
size: map.size
|
|
2505
|
+
applyLinkedUpdates,
|
|
2506
|
+
pendingLinkedUpdates
|
|
2202
2507
|
};
|
|
2203
2508
|
}
|
|
2204
|
-
function
|
|
2205
|
-
if (
|
|
2206
|
-
const
|
|
2509
|
+
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
2510
|
+
if (!linked || !linkedSet) return;
|
|
2511
|
+
for (const id of Object.keys(linked)) {
|
|
2512
|
+
const linkedEntry = getJsEntry(id);
|
|
2513
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
//#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
|
+
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2566
|
+
function processJsBundleEntry(options) {
|
|
2567
|
+
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
2568
|
+
const { file, output: originalSource, source: originalEntrySource } = entry;
|
|
2569
|
+
metrics.js.total++;
|
|
2570
|
+
const shouldTransformJs = !useIncrementalMode || processFiles.js.has(file);
|
|
2571
|
+
if (!shouldTransformJs) debug("js skip transform (clean), replay cache: %s", file);
|
|
2572
|
+
if (originalSource.type === "chunk") {
|
|
2573
|
+
const absoluteFile = path.resolve(outDir, file);
|
|
2574
|
+
const initialRawSource = originalEntrySource;
|
|
2575
|
+
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2576
|
+
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2577
|
+
jsTaskFactories.push(async () => {
|
|
2578
|
+
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
|
+
await processCachedTask({
|
|
2583
|
+
cache,
|
|
2584
|
+
cacheKey: file,
|
|
2585
|
+
hashKey,
|
|
2586
|
+
hash: `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`,
|
|
2587
|
+
applyResult(source) {
|
|
2588
|
+
originalSource.code = source;
|
|
2589
|
+
},
|
|
2590
|
+
onCacheHit() {
|
|
2591
|
+
metrics.js.cacheHits++;
|
|
2592
|
+
debug("js cache hit: %s", file);
|
|
2593
|
+
},
|
|
2594
|
+
async transform() {
|
|
2595
|
+
const start = performance.now();
|
|
2596
|
+
const rawSource = originalSource.code;
|
|
2597
|
+
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
2598
|
+
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2599
|
+
if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2600
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
2601
|
+
metrics.js.transformed++;
|
|
2602
|
+
return { result: rawSource };
|
|
2603
|
+
}
|
|
2604
|
+
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
2605
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
2606
|
+
metrics.js.transformed++;
|
|
2607
|
+
onUpdate(file, rawSource, code);
|
|
2608
|
+
debug("js handle: %s", file);
|
|
2609
|
+
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2610
|
+
applyLinkedUpdates(linked);
|
|
2611
|
+
return { result: code };
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
});
|
|
2616
|
+
} else if (uniAppX && originalSource.type === "asset") {
|
|
2617
|
+
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2618
|
+
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2619
|
+
const wrappedApplyLinkedUpdates = (linked) => {
|
|
2620
|
+
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2621
|
+
applyLinkedUpdates(linked);
|
|
2622
|
+
};
|
|
2623
|
+
const uniAppXJsHashKey = `${file}:js`;
|
|
2624
|
+
rememberProcessCacheKey(file, uniAppXJsHashKey);
|
|
2625
|
+
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2626
|
+
cache,
|
|
2627
|
+
hashKey: uniAppXJsHashKey,
|
|
2628
|
+
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2629
|
+
createHandlerOptions,
|
|
2630
|
+
debug,
|
|
2631
|
+
getAssetSource: createUniAppXBundleAssetSourceGetter(bundle),
|
|
2632
|
+
jsHandler,
|
|
2633
|
+
onUpdate,
|
|
2634
|
+
runtimeSet: transformRuntime,
|
|
2635
|
+
applyLinkedResults: wrappedApplyLinkedUpdates,
|
|
2636
|
+
uniAppX
|
|
2637
|
+
});
|
|
2638
|
+
jsTaskFactories.push(async () => {
|
|
2639
|
+
await timeTask("js", async () => {
|
|
2640
|
+
const start = performance.now();
|
|
2641
|
+
if (!shouldTransformJs) {
|
|
2642
|
+
debug("js skip transform (clean, uni-app-x), replay cache: %s", file);
|
|
2643
|
+
await factory();
|
|
2644
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
2645
|
+
metrics.js.transformed++;
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
const currentSource = originalEntrySource;
|
|
2649
|
+
const precheckOptions = createHandlerOptions(path.resolve(outDir, file), {
|
|
2650
|
+
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
2651
|
+
babelParserOptions: {
|
|
2652
|
+
plugins: ["typescript"],
|
|
2653
|
+
sourceType: "unambiguous"
|
|
2654
|
+
}
|
|
2655
|
+
});
|
|
2656
|
+
if (!disableJsPrecheck && shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
2657
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
2658
|
+
metrics.js.transformed++;
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
await factory();
|
|
2662
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
2663
|
+
metrics.js.transformed++;
|
|
2664
|
+
});
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
//#endregion
|
|
2669
|
+
//#region src/bundlers/vite/generate-bundle/process-plan.ts
|
|
2670
|
+
function logBundleProcessPlan(options) {
|
|
2671
|
+
const { debug, snapshot, useIncrementalMode, iteration } = options;
|
|
2672
|
+
const { processFiles } = snapshot;
|
|
2673
|
+
if (useIncrementalMode) {
|
|
2674
|
+
debug("dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]", iteration, snapshot.changedByType.html.size, formatDebugFileList(snapshot.changedByType.html), snapshot.changedByType.js.size, formatDebugFileList(snapshot.changedByType.js), snapshot.changedByType.css.size, formatDebugFileList(snapshot.changedByType.css), snapshot.changedByType.other.size, formatDebugFileList(snapshot.changedByType.other));
|
|
2675
|
+
debug("process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]", iteration, processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
2676
|
+
return;
|
|
2677
|
+
}
|
|
2678
|
+
debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
2679
|
+
}
|
|
2680
|
+
//#endregion
|
|
2681
|
+
//#region src/bundlers/vite/generate-bundle/remembered-css.ts
|
|
2682
|
+
function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash) {
|
|
2683
|
+
return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
|
|
2684
|
+
}
|
|
2685
|
+
function normalizeRememberedSourceIdentity(file) {
|
|
2686
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2687
|
+
}
|
|
2688
|
+
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
2689
|
+
if (!sources) return [];
|
|
2690
|
+
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
2691
|
+
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
2692
|
+
const markerFiles = new Set(parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => normalizeOutputPathKey(block.file)));
|
|
2693
|
+
if (markerFiles.size > 0) {
|
|
2694
|
+
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeRememberedSourceIdentity(remembered.sourceFile)));
|
|
2695
|
+
if (markerMatched.length > 0) return markerMatched;
|
|
2696
|
+
}
|
|
2697
|
+
const originalFiles = [
|
|
2698
|
+
file,
|
|
2699
|
+
originalSource.originalFileName,
|
|
2700
|
+
...originalSource.originalFileNames ?? []
|
|
2701
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
2702
|
+
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeRememberedSourceIdentity(remembered.sourceFile) === normalizeRememberedSourceIdentity(originalFile)));
|
|
2703
|
+
if (sourceMatched.length > 0) return sourceMatched;
|
|
2704
|
+
const outputMatched = rememberedSources.filter((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
|
|
2705
|
+
if (outputMatched.length > 0) return outputMatched;
|
|
2706
|
+
if (!hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
|
|
2707
|
+
const scoredMatches = rememberedSources.map((remembered) => ({
|
|
2708
|
+
remembered,
|
|
2709
|
+
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
2710
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
2711
|
+
const bestScore = scoredMatches[0]?.score;
|
|
2712
|
+
return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : [];
|
|
2713
|
+
}
|
|
2714
|
+
function mergeRememberedCssSources(sources, outputFile) {
|
|
2715
|
+
if (sources.length <= 1) return sources[0];
|
|
2716
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2717
|
+
const rawSources = [];
|
|
2718
|
+
for (const source of sources) {
|
|
2719
|
+
const key = `${source.sourceFile}\0${source.rawSource}`;
|
|
2720
|
+
if (seen.has(key)) continue;
|
|
2721
|
+
seen.add(key);
|
|
2722
|
+
rawSources.push(source.rawSource);
|
|
2723
|
+
}
|
|
2207
2724
|
return {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
rssMb: toMb(memory.rss),
|
|
2212
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
2213
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
2214
|
-
externalMb: toMb(memory.external),
|
|
2215
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
2216
|
-
},
|
|
2217
|
-
runtime: {
|
|
2218
|
-
sourceCandidates: context.sourceCandidatesSize,
|
|
2219
|
-
runtime: context.runtimeSize,
|
|
2220
|
-
transformRuntime: context.transformRuntimeSize,
|
|
2221
|
-
generatorRuntime: context.generatorRuntimeSize
|
|
2222
|
-
},
|
|
2223
|
-
processCache: {
|
|
2224
|
-
instance: context.cache.instance.size,
|
|
2225
|
-
hashMap: context.cache.hashMap.size,
|
|
2226
|
-
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2227
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
2228
|
-
},
|
|
2229
|
-
viteCss: {
|
|
2230
|
-
...context.getViteCssCacheStats?.(),
|
|
2231
|
-
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2232
|
-
},
|
|
2233
|
-
tailwind: {
|
|
2234
|
-
v3: getTailwindV3IncrementalGenerateCacheStats(),
|
|
2235
|
-
v4: getTailwindV4IncrementalGenerateCacheStats()
|
|
2236
|
-
}
|
|
2725
|
+
outputFile,
|
|
2726
|
+
rawSource: rawSources.join("\n"),
|
|
2727
|
+
sourceFile: sources[0]?.sourceFile ?? outputFile
|
|
2237
2728
|
};
|
|
2238
2729
|
}
|
|
2730
|
+
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
2731
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2732
|
+
for (const [key, remembered] of sources ?? []) {
|
|
2733
|
+
const outputKey = normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles));
|
|
2734
|
+
const group = groups.get(outputKey) ?? [];
|
|
2735
|
+
group.push({
|
|
2736
|
+
key,
|
|
2737
|
+
remembered
|
|
2738
|
+
});
|
|
2739
|
+
groups.set(outputKey, group);
|
|
2740
|
+
}
|
|
2741
|
+
return groups;
|
|
2742
|
+
}
|
|
2743
|
+
//#endregion
|
|
2744
|
+
//#region src/bundlers/vite/generate-bundle/scoped-generator.ts
|
|
2745
|
+
function hasOwnSourceDirectives(rawSource) {
|
|
2746
|
+
return rawSource.includes("@source") || rawSource.includes("@config");
|
|
2747
|
+
}
|
|
2239
2748
|
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
2240
|
-
if (!getSourceCandidatesForEntries || !rawSource
|
|
2241
|
-
const
|
|
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);
|
|
2242
2752
|
if (resolved?.entries === void 0) return fallbackSignature;
|
|
2243
2753
|
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
2244
2754
|
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
2245
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
|
+
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
2770
|
+
async function processRememberedCssReplay(options) {
|
|
2771
|
+
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
|
+
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
2773
|
+
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2774
|
+
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2775
|
+
key: item.key,
|
|
2776
|
+
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2777
|
+
})));
|
|
2778
|
+
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2779
|
+
if (!rememberedCssSource) continue;
|
|
2780
|
+
const { rawSource, sourceFile } = rememberedCssSource;
|
|
2781
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2782
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(sourceFile));
|
|
2783
|
+
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2784
|
+
const cssHandlerOptions = {
|
|
2785
|
+
...getCssHandlerOptions(sourceFile),
|
|
2786
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
2787
|
+
};
|
|
2788
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2789
|
+
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
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, rawSource, sourceFile);
|
|
2796
|
+
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
2797
|
+
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
2798
|
+
majorVersion: runtimeState.twPatcher.majorVersion
|
|
2799
|
+
}));
|
|
2800
|
+
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2801
|
+
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2802
|
+
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2803
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2804
|
+
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2805
|
+
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
2806
|
+
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
2807
|
+
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
2808
|
+
if (!shouldRecordRememberedReplayCss) continue;
|
|
2809
|
+
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2810
|
+
const start = performance.now();
|
|
2811
|
+
const generated = await generateCssByGenerator({
|
|
2812
|
+
opts,
|
|
2813
|
+
runtimeState,
|
|
2814
|
+
runtime: scopedGeneratorRuntime,
|
|
2815
|
+
rawSource,
|
|
2816
|
+
file: sourceFile,
|
|
2817
|
+
cssHandlerOptions,
|
|
2818
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2819
|
+
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2820
|
+
styleHandler,
|
|
2821
|
+
debug,
|
|
2822
|
+
previousCss
|
|
2823
|
+
});
|
|
2824
|
+
const css = annotateCss(generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css);
|
|
2825
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
2826
|
+
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
2827
|
+
if (generated) {
|
|
2828
|
+
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
2829
|
+
recordCssAssetResult?.(outputFile, css);
|
|
2830
|
+
const shouldInjectReplayCssIntoMain = shouldInjectCssIntoMainFromOutput(outputFile, sourceFile, outputCssHandlerOptions);
|
|
2831
|
+
recordViteProcessedCssAssetResult?.(sourceFile, css, {
|
|
2832
|
+
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectReplayCssIntoMain,
|
|
2833
|
+
outputFile
|
|
2834
|
+
});
|
|
2835
|
+
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
2836
|
+
}
|
|
2837
|
+
if (shouldEmitRememberedReplayCssAsset) {
|
|
2838
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
2839
|
+
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
2840
|
+
}
|
|
2841
|
+
metrics.css.elapsed += measureElapsed(start);
|
|
2842
|
+
metrics.css.transformed++;
|
|
2843
|
+
onUpdate(outputFile, rawSource, css);
|
|
2844
|
+
debug("css replay handle: %s", outputFile);
|
|
2845
|
+
}));
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
//#endregion
|
|
2849
|
+
//#region src/bundlers/vite/generate-bundle/runtime-linked-css.ts
|
|
2850
|
+
const MINI_PROGRAM_TEMPLATE_OUTPUT_EXT_RE = /\.(?:wxml|axml|jxml|ksml|ttml|qml|tyml|xhsml|swan)$/i;
|
|
2851
|
+
const JS_STYLE_IMPORT_RE = /\b(?:import|require)\s*(?:\(\s*)?["']([^"']+\.(?:css|less|sass|scss|styl|stylus|pcss|postcss))(?:[?#][^"']*)?["']/g;
|
|
2852
|
+
function addSiblingCssFile(files, file, extensionByStem, fallbackExtension) {
|
|
2853
|
+
const templateMatch = file.replace(/[?#].*$/, "").match(MINI_PROGRAM_TEMPLATE_OUTPUT_EXT_RE);
|
|
2854
|
+
if (templateMatch?.[0]) {
|
|
2855
|
+
const stem = file.slice(0, -templateMatch[0].length);
|
|
2856
|
+
files.add(`${stem}${extensionByStem.get(stem) ?? fallbackExtension}`);
|
|
2857
|
+
} else if (file.endsWith(".js")) {
|
|
2858
|
+
const stem = file.slice(0, -3);
|
|
2859
|
+
files.add(`${stem}${extensionByStem.get(stem) ?? fallbackExtension}`);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
function collectCssExtensionByStem(files, cssMatcher) {
|
|
2863
|
+
const extensionByStem = /* @__PURE__ */ new Map();
|
|
2864
|
+
for (const file of files) {
|
|
2865
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
2866
|
+
if (!cssMatcher(cleanFile)) continue;
|
|
2867
|
+
const extension = path.extname(cleanFile);
|
|
2868
|
+
if (!extension || extension === ".css") continue;
|
|
2869
|
+
extensionByStem.set(file.slice(0, -extension.length), extension);
|
|
2870
|
+
}
|
|
2871
|
+
return extensionByStem;
|
|
2872
|
+
}
|
|
2873
|
+
function collectRuntimeLinkedCssFiles(snapshot, extensionByStem, fallbackExtension) {
|
|
2874
|
+
const files = /* @__PURE__ */ new Set();
|
|
2875
|
+
for (const file of snapshot.runtimeAffectingChangedByType.html) addSiblingCssFile(files, file, extensionByStem, fallbackExtension);
|
|
2876
|
+
for (const file of snapshot.runtimeAffectingChangedByType.js) addSiblingCssFile(files, file, extensionByStem, fallbackExtension);
|
|
2877
|
+
return files;
|
|
2878
|
+
}
|
|
2879
|
+
function collectJsImportedCssFiles(snapshot) {
|
|
2880
|
+
const files = /* @__PURE__ */ new Set();
|
|
2881
|
+
for (const entry of snapshot.entries) {
|
|
2882
|
+
if (entry.type !== "js" || entry.output.type !== "chunk") continue;
|
|
2883
|
+
JS_STYLE_IMPORT_RE.lastIndex = 0;
|
|
2884
|
+
let match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2885
|
+
while (match !== null) {
|
|
2886
|
+
const request = match[1];
|
|
2887
|
+
if (request?.startsWith(".")) files.add(normalizeOutputPathKey(path.posix.join(path.posix.dirname(entry.file), request)));
|
|
2888
|
+
match = JS_STYLE_IMPORT_RE.exec(entry.source);
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
return files;
|
|
2892
|
+
}
|
|
2893
|
+
//#endregion
|
|
2894
|
+
//#region src/bundlers/vite/generate-bundle/source-candidate-scope.ts
|
|
2895
|
+
function intersectCandidateSets(left, right) {
|
|
2896
|
+
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
2897
|
+
const [small, large] = left.size <= right.size ? [left, right] : [right, left];
|
|
2898
|
+
const matched = /* @__PURE__ */ new Set();
|
|
2899
|
+
for (const candidate of small) if (large.has(candidate)) matched.add(candidate);
|
|
2900
|
+
return matched;
|
|
2901
|
+
}
|
|
2902
|
+
function intersectCandidateSourceMaps(left, right) {
|
|
2903
|
+
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Map();
|
|
2904
|
+
const matched = /* @__PURE__ */ new Map();
|
|
2905
|
+
for (const [candidate, sources] of left) if (right.has(candidate)) matched.set(candidate, sources);
|
|
2906
|
+
return matched;
|
|
2907
|
+
}
|
|
2908
|
+
function createSubpackageSourceCandidateScope(options) {
|
|
2909
|
+
const subpackageSourceExcludeEntries = options.subpackageRoots ? collectMiniProgramSubpackageSourceEntries(options.snapshot, options.subpackageRoots, [
|
|
2910
|
+
options.rootDir,
|
|
2911
|
+
options.tailwindcssBasedir,
|
|
2912
|
+
options.projectRoot
|
|
2913
|
+
]) : [];
|
|
2914
|
+
const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
|
|
2915
|
+
const resolveSubpackageOutputSourceEntries = (outputFile) => {
|
|
2916
|
+
if (!options.subpackageRoots) return;
|
|
2917
|
+
const matchedRoots = [...options.subpackageRoots].filter((root) => isSubpackageOutputFile(outputFile, new Set([root])));
|
|
2918
|
+
if (matchedRoots.length !== 1) return;
|
|
2919
|
+
const root = matchedRoots[0];
|
|
2920
|
+
if (!root) return;
|
|
2921
|
+
return options.sourceRoot ? [{
|
|
2922
|
+
base: options.sourceRoot,
|
|
2923
|
+
negated: false,
|
|
2924
|
+
pattern: `${root}/**/*`
|
|
2925
|
+
}] : [{
|
|
2926
|
+
base: options.rootDir,
|
|
2927
|
+
negated: false,
|
|
2928
|
+
pattern: `**/${root}/**/*`
|
|
2929
|
+
}];
|
|
2930
|
+
};
|
|
2931
|
+
const shouldExcludeSubpackageSourceCandidates = (outputFile, cssHandlerOptions) => cssHandlerOptions.isMainChunk === true && subpackageSourceExcludeEntries.length > 0 && isMainPackageStyleOutputFile(outputFile);
|
|
2932
|
+
const createScopedSourceCandidateGetter = (outputFile, cssHandlerOptions) => {
|
|
2933
|
+
if (!options.getSourceCandidatesForEntries) return;
|
|
2934
|
+
const subpackageEntries = resolveSubpackageOutputSourceEntries(outputFile);
|
|
2935
|
+
if (subpackageEntries) return (entries, filterOptions) => {
|
|
2936
|
+
if (entries !== void 0) {
|
|
2937
|
+
const scopedCandidates = options.getSourceCandidatesForEntries?.(entries, filterOptions) ?? /* @__PURE__ */ new Set();
|
|
2938
|
+
if (entries.length === 0) return scopedCandidates;
|
|
2939
|
+
const subpackageCandidates = options.getSourceCandidatesForEntries?.(subpackageEntries, filterOptions) ?? /* @__PURE__ */ new Set();
|
|
2940
|
+
const matchedCandidates = intersectCandidateSets(scopedCandidates, subpackageCandidates);
|
|
2941
|
+
if (matchedCandidates.size > 0 || subpackageCandidates.size > 0) return matchedCandidates;
|
|
2942
|
+
if (scopedCandidates.size > 0) return scopedCandidates;
|
|
2943
|
+
}
|
|
2944
|
+
return options.getSourceCandidatesForEntries?.(subpackageEntries, filterOptions) ?? /* @__PURE__ */ new Set();
|
|
2945
|
+
};
|
|
2946
|
+
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return options.getSourceCandidatesForEntries;
|
|
2947
|
+
return (entries, filterOptions) => options.getSourceCandidatesForEntries?.(entries, {
|
|
2948
|
+
...filterOptions,
|
|
2949
|
+
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2950
|
+
}) ?? /* @__PURE__ */ new Set();
|
|
2951
|
+
};
|
|
2952
|
+
const createScopedSourceCandidateSourceGetter = (outputFile, cssHandlerOptions) => {
|
|
2953
|
+
if (!options.getSourceCandidateSourcesForEntries) return;
|
|
2954
|
+
const subpackageEntries = resolveSubpackageOutputSourceEntries(outputFile);
|
|
2955
|
+
if (subpackageEntries) return (entries, filterOptions) => {
|
|
2956
|
+
if (entries !== void 0) {
|
|
2957
|
+
const scopedSources = options.getSourceCandidateSourcesForEntries?.(entries, filterOptions) ?? /* @__PURE__ */ new Map();
|
|
2958
|
+
if (entries.length === 0) return scopedSources;
|
|
2959
|
+
const subpackageSources = options.getSourceCandidateSourcesForEntries?.(subpackageEntries, filterOptions) ?? /* @__PURE__ */ new Map();
|
|
2960
|
+
const matchedSources = intersectCandidateSourceMaps(scopedSources, subpackageSources);
|
|
2961
|
+
if (matchedSources.size > 0 || subpackageSources.size > 0) return matchedSources;
|
|
2962
|
+
if (scopedSources.size > 0) return scopedSources;
|
|
2963
|
+
}
|
|
2964
|
+
return options.getSourceCandidateSourcesForEntries?.(subpackageEntries, filterOptions) ?? /* @__PURE__ */ new Map();
|
|
2965
|
+
};
|
|
2966
|
+
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return options.getSourceCandidateSourcesForEntries;
|
|
2967
|
+
return (entries, filterOptions) => options.getSourceCandidateSourcesForEntries?.(entries, {
|
|
2968
|
+
...filterOptions,
|
|
2969
|
+
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2970
|
+
}) ?? /* @__PURE__ */ new Map();
|
|
2971
|
+
};
|
|
2972
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
2973
|
+
return {
|
|
2974
|
+
createScopedSourceCandidateGetter,
|
|
2975
|
+
createScopedSourceCandidateSourceGetter,
|
|
2976
|
+
shouldExcludeSubpackageSourceCandidates,
|
|
2977
|
+
shouldInjectCssIntoMainFromOutput
|
|
2978
|
+
};
|
|
2979
|
+
}
|
|
2980
|
+
//#endregion
|
|
2981
|
+
//#region src/bundlers/vite/generate-bundle/timing.ts
|
|
2982
|
+
function createBundleTaskTimer(recordTimingDetail) {
|
|
2983
|
+
return async (name, task) => {
|
|
2984
|
+
const start = performance.now();
|
|
2985
|
+
try {
|
|
2986
|
+
await task();
|
|
2987
|
+
} finally {
|
|
2988
|
+
recordTimingDetail(`tasks.${name}`, start);
|
|
2989
|
+
}
|
|
2990
|
+
};
|
|
2991
|
+
}
|
|
2992
|
+
//#endregion
|
|
2993
|
+
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
2994
|
+
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
2995
|
+
if (opts.appType !== "uni-app-x" || !isUniAppXEnabled(opts.uniAppX) || !resolveUniUtsPlatform().isApp) return {};
|
|
2996
|
+
return {
|
|
2997
|
+
uniAppX: true,
|
|
2998
|
+
uniAppXCssTarget: "uvue",
|
|
2999
|
+
uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
//#endregion
|
|
3003
|
+
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
3004
|
+
function resolveSourceRootCandidate(root, value) {
|
|
3005
|
+
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
3006
|
+
const resolved = path.isAbsolute(value) ? value : path.resolve(root, value);
|
|
3007
|
+
return existsSync(resolved) ? resolved : void 0;
|
|
3008
|
+
}
|
|
3009
|
+
function resolveWeappViteSourceRoot(config, _appType) {
|
|
3010
|
+
const viteConfig = config;
|
|
3011
|
+
const root = typeof viteConfig?.root === "string" && viteConfig.root.length > 0 ? path.resolve(viteConfig.root) : process$1.cwd();
|
|
3012
|
+
const configuredSrcRoot = resolveSourceRootCandidate(root, viteConfig?.weapp?.srcRoot);
|
|
3013
|
+
if (configuredSrcRoot) return configuredSrcRoot;
|
|
3014
|
+
const envSrcRoot = resolveSourceRootCandidate(root, process$1.env.UNI_INPUT_DIR) ?? resolveSourceRootCandidate(root, process$1.env.UNI_INPUT_ROOT) ?? resolveSourceRootCandidate(root, process$1.env.UNI_APP_INPUT_DIR);
|
|
3015
|
+
if (envSrcRoot) return envSrcRoot;
|
|
3016
|
+
}
|
|
3017
|
+
function stripFileExtension(file) {
|
|
3018
|
+
return file.replace(/[?#].*$/, "").replace(/\.[^.\\/]+$/u, "");
|
|
3019
|
+
}
|
|
3020
|
+
function isUsefulModuleId(id) {
|
|
3021
|
+
return !id.includes("\0") && !id.includes("/node_modules/") && !id.includes("\\node_modules\\") && !/[?&]type=style\b/u.test(id);
|
|
3022
|
+
}
|
|
3023
|
+
function collectChunkModuleIds(chunk) {
|
|
3024
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3025
|
+
if (typeof chunk.facadeModuleId === "string" && chunk.facadeModuleId.length > 0) ids.add(chunk.facadeModuleId);
|
|
3026
|
+
for (const id of chunk.moduleIds ?? []) if (typeof id === "string" && id.length > 0) ids.add(id);
|
|
3027
|
+
return ids;
|
|
3028
|
+
}
|
|
3029
|
+
function resolveSourceRootFromChunk(root, fileName, chunk) {
|
|
3030
|
+
const outputBase = stripFileExtension(normalizeOutputPathKey(fileName));
|
|
3031
|
+
if (!outputBase.includes("/")) return;
|
|
3032
|
+
for (const id of collectChunkModuleIds(chunk)) {
|
|
3033
|
+
if (!isUsefulModuleId(id)) continue;
|
|
3034
|
+
const cleanId = id.replace(/[?#].*$/, "");
|
|
3035
|
+
const relativeModule = normalizeOutputPathKey(path.relative(root, cleanId));
|
|
3036
|
+
if (relativeModule.length === 0 || relativeModule === "." || relativeModule.startsWith("../") || path.isAbsolute(relativeModule)) continue;
|
|
3037
|
+
const moduleBase = stripFileExtension(relativeModule);
|
|
3038
|
+
if (!moduleBase.endsWith(outputBase)) continue;
|
|
3039
|
+
const sourceRoot = moduleBase.slice(0, moduleBase.length - outputBase.length).replace(/\/+$/u, "");
|
|
3040
|
+
if (sourceRoot.length === 0) continue;
|
|
3041
|
+
const resolved = path.resolve(root, sourceRoot);
|
|
3042
|
+
if (existsSync(resolved)) return resolved;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
3046
|
+
const viteConfig = config;
|
|
3047
|
+
const root = typeof viteConfig?.root === "string" && viteConfig.root.length > 0 ? path.resolve(viteConfig.root) : process$1.cwd();
|
|
3048
|
+
const sourceRoots = /* @__PURE__ */ new Set();
|
|
3049
|
+
for (const output of Object.values(bundle)) {
|
|
3050
|
+
if (output.type !== "chunk") continue;
|
|
3051
|
+
const sourceRoot = resolveSourceRootFromChunk(root, output.fileName, output);
|
|
3052
|
+
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
3053
|
+
}
|
|
3054
|
+
return sourceRoots.size === 1 ? [...sourceRoots][0] : void 0;
|
|
3055
|
+
}
|
|
3056
|
+
//#endregion
|
|
3057
|
+
//#region src/bundlers/vite/generate-bundle.ts
|
|
2246
3058
|
function createGenerateBundleHook(context) {
|
|
2247
3059
|
const state = createBundleBuildState();
|
|
2248
3060
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -2254,11 +3066,15 @@ function createGenerateBundleHook(context) {
|
|
|
2254
3066
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
2255
3067
|
getMajorVersion: () => context.runtimeState.twPatcher.majorVersion,
|
|
2256
3068
|
getOutputRoot: () => currentOutDir,
|
|
2257
|
-
getExtraOptions: () =>
|
|
3069
|
+
getExtraOptions: (file) => ({
|
|
3070
|
+
...resolveViteCssHandlerExtraOptions(file),
|
|
3071
|
+
...resolveUniAppXNativeCssHandlerOptions(context.opts),
|
|
3072
|
+
...currentSubpackageRoots && isSubpackageOutputFile(file, currentSubpackageRoots) ? { isMainChunk: false } : {}
|
|
3073
|
+
})
|
|
2258
3074
|
});
|
|
2259
3075
|
return async function generateBundle(_opt, bundle) {
|
|
2260
3076
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
2261
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
3077
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
2262
3078
|
const getBundlerSfcSource = (sourceFile) => {
|
|
2263
3079
|
const code = this.getModuleInfo?.(sourceFile)?.code;
|
|
2264
3080
|
return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
|
|
@@ -2276,19 +3092,23 @@ function createGenerateBundleHook(context) {
|
|
|
2276
3092
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget && runtimeState.twPatcher.majorVersion === 3;
|
|
2277
3093
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
2278
3094
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
2279
|
-
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
3095
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
2280
3096
|
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
3097
|
+
const defaultStyleOutputExtension = resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) });
|
|
2281
3098
|
await runtimeState.readyPromise;
|
|
2282
3099
|
debug("start");
|
|
2283
3100
|
onStart();
|
|
2284
3101
|
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" && hasBundlerGeneratedCssMarker(output.source)).map(([file]) => file));
|
|
3102
|
+
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
3103
|
+
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
2285
3104
|
collectViteProcessedCssAssetResults(bundle, {
|
|
2286
3105
|
opts,
|
|
2287
3106
|
isViteProcessedCssAsset,
|
|
2288
3107
|
markCssAssetProcessed,
|
|
2289
3108
|
recordCssAssetResult,
|
|
2290
3109
|
recordViteProcessedCssAssetResult,
|
|
2291
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot),
|
|
3110
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, Object.keys(bundle)),
|
|
3111
|
+
subpackageRoots: currentSubpackageRoots,
|
|
2292
3112
|
debug
|
|
2293
3113
|
});
|
|
2294
3114
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -2296,65 +3116,31 @@ function createGenerateBundleHook(context) {
|
|
|
2296
3116
|
const recordTimingDetail = (name, startedAt) => {
|
|
2297
3117
|
timingDetails[name] = (timingDetails[name] ?? 0) + Math.max(0, performance.now() - startedAt);
|
|
2298
3118
|
};
|
|
2299
|
-
const timeTask =
|
|
2300
|
-
|
|
2301
|
-
try {
|
|
2302
|
-
await task();
|
|
2303
|
-
} finally {
|
|
2304
|
-
recordTimingDetail(`tasks.${name}`, start);
|
|
2305
|
-
}
|
|
2306
|
-
};
|
|
2307
|
-
const emitOrReplayCssAsset = (fileName, source) => {
|
|
2308
|
-
const replayAsset = createReplayCssAsset(fileName, source);
|
|
2309
|
-
if (typeof this.emitFile === "function") this.emitFile({
|
|
2310
|
-
type: "asset",
|
|
2311
|
-
fileName,
|
|
2312
|
-
source
|
|
2313
|
-
});
|
|
2314
|
-
else bundle[fileName] = replayAsset;
|
|
2315
|
-
return replayAsset;
|
|
2316
|
-
};
|
|
3119
|
+
const timeTask = createBundleTaskTimer(recordTimingDetail);
|
|
3120
|
+
const emitOrReplayCssAsset = createCssAssetEmitter(this);
|
|
2317
3121
|
const metrics = createEmptyMetrics();
|
|
2318
|
-
const
|
|
2319
|
-
const disableDirtyOptimization = process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1";
|
|
2320
|
-
const disableJsPrecheck = process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1";
|
|
2321
|
-
const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
2322
|
-
const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
3122
|
+
const envFlags = resolveGenerateBundleEnvFlags();
|
|
2323
3123
|
const bundleFiles = Object.keys(bundle);
|
|
2324
3124
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
2325
|
-
const
|
|
2326
|
-
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
2327
|
-
const isMainPackageStyleOutputFile = (file) => currentSubpackageRoots != null && !isSubpackageOutputFile(file, currentSubpackageRoots);
|
|
3125
|
+
const configuredTailwindV4CssSourceEntries = collectConfiguredTailwindV4CssSourceEntries(opts, opts.tailwindcssBasedir ?? rootDir);
|
|
2328
3126
|
const buildCommand = resolvedConfig?.command === "build";
|
|
2329
3127
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
2330
3128
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
2331
3129
|
const useIncrementalMode = !buildCommand || hasPreviousBundleState || hasOmittedKnownFiles;
|
|
2332
3130
|
currentOutDir = outDir;
|
|
2333
3131
|
const snapshotStart = performance.now();
|
|
2334
|
-
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
2335
|
-
const
|
|
3132
|
+
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
3133
|
+
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
3134
|
+
getSourceCandidateSourcesForEntries,
|
|
3135
|
+
getSourceCandidatesForEntries,
|
|
3136
|
+
projectRoot: opts.tailwindcssPatcherOptions?.projectRoot,
|
|
2336
3137
|
rootDir,
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return getSourceCandidatesForEntries;
|
|
2344
|
-
return (entries, options) => getSourceCandidatesForEntries(entries, {
|
|
2345
|
-
...options,
|
|
2346
|
-
excludeEntries: [...options?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2347
|
-
});
|
|
2348
|
-
};
|
|
2349
|
-
const createScopedSourceCandidateSourceGetter = (outputFile, cssHandlerOptions) => {
|
|
2350
|
-
if (!getSourceCandidateSourcesForEntries) return;
|
|
2351
|
-
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return getSourceCandidateSourcesForEntries;
|
|
2352
|
-
return (entries, options) => getSourceCandidateSourcesForEntries(entries, {
|
|
2353
|
-
...options,
|
|
2354
|
-
excludeEntries: [...options?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2355
|
-
});
|
|
2356
|
-
};
|
|
2357
|
-
const shouldInjectCssIntoMainFromOutput = (outputFile, sourceFile, outputCssHandlerOptions) => isMainStyleEntryCssFile(sourceFile) || isTailwindEntryCssFile(outputFile) || useIncrementalMode && (outputCssHandlerOptions.isMainChunk || isMainPackageStyleOutputFile(outputFile));
|
|
3138
|
+
snapshot,
|
|
3139
|
+
sourceRoot,
|
|
3140
|
+
subpackageRoots: currentSubpackageRoots,
|
|
3141
|
+
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
3142
|
+
useIncrementalMode
|
|
3143
|
+
});
|
|
2358
3144
|
recordTimingDetail("snapshot", snapshotStart);
|
|
2359
3145
|
const useBundleRuntimeClassSet = !isWebGeneratorTarget && (useIncrementalMode || runtimeState.twPatcher.majorVersion === 4);
|
|
2360
3146
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -2369,32 +3155,59 @@ function createGenerateBundleHook(context) {
|
|
|
2369
3155
|
await waitForSourceCandidateSyncs?.();
|
|
2370
3156
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
2371
3157
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
2372
|
-
const createScopedGeneratorRuntime = (outputFile, cssHandlerOptions, runtime) => {
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
3158
|
+
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => createScopedGeneratorRuntime({
|
|
3159
|
+
cssHandlerOptions,
|
|
3160
|
+
fallbackRuntime: runtime,
|
|
3161
|
+
getSourceCandidatesForEntries,
|
|
3162
|
+
majorVersion: runtimeState.twPatcher.majorVersion,
|
|
3163
|
+
outputFile,
|
|
3164
|
+
rawSource,
|
|
3165
|
+
shouldExcludeSubpackageSourceCandidates,
|
|
3166
|
+
sourceFile,
|
|
3167
|
+
scopedSourceCandidateGetter: createScopedSourceCandidateGetter(outputFile, cssHandlerOptions)
|
|
3168
|
+
});
|
|
2378
3169
|
const jsEntries = snapshot.jsEntries;
|
|
2379
3170
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
2380
3171
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
2381
3172
|
const hasCssAssetEntry = snapshot.entries.some((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
2382
3173
|
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
2383
|
-
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !forceRuntimeRefreshByEnv && !disableV3OxideSourceRuntime;
|
|
3174
|
+
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !envFlags.forceRuntimeRefreshByEnv && !envFlags.disableV3OxideSourceRuntime;
|
|
2384
3175
|
const runtimeStart = performance.now();
|
|
2385
|
-
const transformBaseRuntime = useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, { transformOnly: true }) : void 0;
|
|
3176
|
+
const transformBaseRuntime = useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv, { transformOnly: true }) : void 0;
|
|
2386
3177
|
const forceV4RuntimeRefreshBySource = runtimeState.twPatcher.majorVersion === 4 && forceRuntimeRefreshBySource;
|
|
2387
|
-
const runtime = isWebGeneratorTarget && !shouldGenerateWebCssByGenerator ? /* @__PURE__ */ new Set() : useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, {
|
|
3178
|
+
const runtime = isWebGeneratorTarget && !shouldGenerateWebCssByGenerator ? /* @__PURE__ */ new Set() : useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv, {
|
|
2388
3179
|
allowBaselineOnlyInitialSync: true,
|
|
2389
3180
|
baseClassSet: sourceCandidates
|
|
2390
|
-
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
3181
|
+
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
2391
3182
|
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
2392
3183
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
2393
3184
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
2394
3185
|
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
2395
3186
|
let transformRuntime = transformBaseRuntime ?? runtime;
|
|
2396
3187
|
let generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, runtimeState.twPatcher.majorVersion === 3 && hasRuntimeAffectingChanges && transformBaseRuntime ? new Set([...filteredGeneratorCandidates, ...transformBaseRuntime]) : filteredGeneratorCandidates);
|
|
3188
|
+
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size === 0) {
|
|
3189
|
+
generatorRuntime = await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3190
|
+
transformRuntime = generatorRuntime;
|
|
3191
|
+
}
|
|
2397
3192
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3193
|
+
if (runtimeState.twPatcher.majorVersion === 4 && sourceCandidates.size > 0 && jsEntries.size > 0) {
|
|
3194
|
+
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3195
|
+
if (mainCssEntry) {
|
|
3196
|
+
const validatedSourceRuntime = await validateCandidatesByGenerator({
|
|
3197
|
+
opts,
|
|
3198
|
+
runtimeState,
|
|
3199
|
+
candidates: filteredGeneratorCandidates,
|
|
3200
|
+
rawSource: mainCssEntry.source,
|
|
3201
|
+
file: mainCssEntry.file,
|
|
3202
|
+
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3203
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3204
|
+
styleHandler,
|
|
3205
|
+
debug,
|
|
3206
|
+
skipGenerateFallback: true
|
|
3207
|
+
});
|
|
3208
|
+
if (validatedSourceRuntime.size > 0) transformRuntime = new Set([...transformRuntime, ...validatedSourceRuntime]);
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
2398
3211
|
if (runtimeState.twPatcher.majorVersion === 3 && useV3OxideSourceRuntime && generatorRuntime.size > 0 && (state.iteration === 0 || !hasRuntimeAffectingChanges) && cssEntries.length <= 1) {
|
|
2399
3212
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
2400
3213
|
if (mainCssEntry) {
|
|
@@ -2412,15 +3225,29 @@ function createGenerateBundleHook(context) {
|
|
|
2412
3225
|
if (validatedRuntime.size > 0) {
|
|
2413
3226
|
generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, validatedRuntime);
|
|
2414
3227
|
transformRuntime = generatorRuntime;
|
|
2415
|
-
} else {
|
|
2416
|
-
generatorRuntime = validatedRuntime;
|
|
2417
|
-
transformRuntime = validatedRuntime;
|
|
2418
3228
|
}
|
|
2419
3229
|
}
|
|
2420
3230
|
}
|
|
2421
3231
|
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
2422
3232
|
const generatorCandidatesChanged = state.generatorCandidateSignature !== generatorCandidateSignature;
|
|
2423
|
-
const
|
|
3233
|
+
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
3234
|
+
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
3235
|
+
const runtimeLinkedCssFiles = new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
|
|
3236
|
+
for (const file of runtimeLinkedCssFiles) {
|
|
3237
|
+
if (snapshot.sourceHashByFile.has(file)) {
|
|
3238
|
+
processFiles.css.add(file);
|
|
3239
|
+
continue;
|
|
3240
|
+
}
|
|
3241
|
+
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, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
3243
|
+
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(path.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3244
|
+
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3245
|
+
rememberCssSource?.({
|
|
3246
|
+
outputFile,
|
|
3247
|
+
rawSource,
|
|
3248
|
+
sourceFile: inferredSourceStyle?.sourceFile ?? path.resolve(outDir, file)
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
2424
3251
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
2425
3252
|
const dynamicRetryCandidates = new Set([
|
|
2426
3253
|
...sourceCandidates,
|
|
@@ -2507,8 +3334,9 @@ function createGenerateBundleHook(context) {
|
|
|
2507
3334
|
}
|
|
2508
3335
|
if (type === "css" && originalSource.type === "asset") {
|
|
2509
3336
|
metrics.css.total++;
|
|
2510
|
-
const
|
|
2511
|
-
const
|
|
3337
|
+
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3338
|
+
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3339
|
+
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
2512
3340
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2513
3341
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
2514
3342
|
delete bundle[file];
|
|
@@ -2517,9 +3345,10 @@ function createGenerateBundleHook(context) {
|
|
|
2517
3345
|
}
|
|
2518
3346
|
const applyCssResult = (source) => {
|
|
2519
3347
|
if (outputFile !== file) {
|
|
2520
|
-
delete bundle[file];
|
|
2521
3348
|
emitOrReplayCssAsset(outputFile, source);
|
|
2522
|
-
|
|
3349
|
+
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
3350
|
+
else originalSource.source = "";
|
|
3351
|
+
return;
|
|
2523
3352
|
}
|
|
2524
3353
|
originalSource.source = source;
|
|
2525
3354
|
};
|
|
@@ -2537,32 +3366,47 @@ function createGenerateBundleHook(context) {
|
|
|
2537
3366
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
2538
3367
|
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => await refreshRememberedCssSource?.(remembered) ?? remembered));
|
|
2539
3368
|
const hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
2540
|
-
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, getSfcSource, debug);
|
|
3369
|
+
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
2541
3370
|
if (inferredSfcStyleSource) {
|
|
2542
3371
|
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
2543
3372
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
2544
3373
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
2545
3374
|
}
|
|
3375
|
+
if (!rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource))) {
|
|
3376
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
3377
|
+
if (inferredSourceStyle) rememberedCssSources = [inferredSourceStyle];
|
|
3378
|
+
}
|
|
2546
3379
|
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
2547
|
-
const
|
|
3380
|
+
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
3381
|
+
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
2548
3382
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
2549
3383
|
const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
2550
3384
|
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && hasTailwindApplyDirective(generatorRawSource);
|
|
2551
3385
|
const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
|
|
2552
3386
|
const hasCurrentTailwindGenerationDirective = hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindApplyDirective(rawSource);
|
|
3387
|
+
if (shouldKeepImportedCssShell && !hasCurrentTailwindGenerationDirective) {
|
|
3388
|
+
applyCssResult(rawSource);
|
|
3389
|
+
markCssAssetProcessed?.(originalSource, outputFile);
|
|
3390
|
+
recordCssAssetResult?.(outputFile, rawSource);
|
|
3391
|
+
onUpdate(outputFile, rawSource, rawSource);
|
|
3392
|
+
debug("css preserve imported shell asset: %s", outputFile);
|
|
3393
|
+
continue;
|
|
3394
|
+
}
|
|
2553
3395
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
2554
|
-
const
|
|
2555
|
-
const
|
|
3396
|
+
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
3397
|
+
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
3398
|
+
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || runtimeState.twPatcher.majorVersion === 4 && hasRememberedTailwindGenerationSource);
|
|
3399
|
+
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
2556
3400
|
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2557
3401
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
2558
3402
|
...getCssHandlerOptions(generatorSourceFile),
|
|
2559
|
-
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
3403
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
2560
3404
|
} : getCssHandlerOptions(file);
|
|
2561
3405
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2562
3406
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2563
3407
|
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2564
3408
|
const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
2565
|
-
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
3409
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, cssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
2566
3410
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2567
3411
|
opts,
|
|
2568
3412
|
tokenSources: sourceTraceTokenSources
|
|
@@ -2572,17 +3416,18 @@ function createGenerateBundleHook(context) {
|
|
|
2572
3416
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
2573
3417
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
2574
3418
|
const cssShareScope = createCssTransformShareScopeKey(opts, generatorSourceFile, generatorRawSource);
|
|
2575
|
-
const
|
|
2576
|
-
const
|
|
2577
|
-
const
|
|
2578
|
-
|
|
3419
|
+
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3420
|
+
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
3421
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
3422
|
+
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
3423
|
+
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
3424
|
+
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && !hasStaleViteProcessedCssSource && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
2579
3425
|
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
2580
3426
|
applyCssResult(nextCss);
|
|
2581
3427
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
2582
3428
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
2583
|
-
const shouldInjectPreservedViteCssIntoMain = vitePipelineCssAsset && !isAppOriginCssFile(file) && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
2584
3429
|
recordViteProcessedCssAssetResult?.(outputFile, nextCss, {
|
|
2585
|
-
injectIntoMain:
|
|
3430
|
+
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
2586
3431
|
outputFile
|
|
2587
3432
|
});
|
|
2588
3433
|
onUpdate(outputFile, rawSource, nextCss);
|
|
@@ -2590,13 +3435,17 @@ function createGenerateBundleHook(context) {
|
|
|
2590
3435
|
continue;
|
|
2591
3436
|
}
|
|
2592
3437
|
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
2593
|
-
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3438
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3439
|
+
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
3440
|
+
majorVersion: runtimeState.twPatcher.majorVersion
|
|
3441
|
+
}) : trackedGeneratorCandidateSignature;
|
|
2594
3442
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
2595
3443
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2596
3444
|
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}:${sourceTraceSignature}`;
|
|
2597
3445
|
const cssCacheKey = file;
|
|
2598
3446
|
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`;
|
|
2599
|
-
|
|
3447
|
+
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
|
+
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
2600
3449
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
2601
3450
|
if (lastCss != null) {
|
|
2602
3451
|
applyCssResult(lastCss);
|
|
@@ -2611,7 +3460,7 @@ function createGenerateBundleHook(context) {
|
|
|
2611
3460
|
cache,
|
|
2612
3461
|
cacheKey: cssCacheKey,
|
|
2613
3462
|
hashKey: cssHashKey,
|
|
2614
|
-
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`,
|
|
3463
|
+
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}:${cssLinkedImpactSignature}`,
|
|
2615
3464
|
applyResult(source) {
|
|
2616
3465
|
applyCssResult(source);
|
|
2617
3466
|
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
@@ -2656,16 +3505,15 @@ function createGenerateBundleHook(context) {
|
|
|
2656
3505
|
if (generated) {
|
|
2657
3506
|
const tracedCss = annotateCss(generated.css);
|
|
2658
3507
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
2659
|
-
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3508
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
2660
3509
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
2661
3510
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
2662
|
-
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !isAppOriginCssFile(file) && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
2663
3511
|
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
2664
|
-
injectIntoMain:
|
|
3512
|
+
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
2665
3513
|
outputFile
|
|
2666
3514
|
});
|
|
2667
3515
|
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss, {
|
|
2668
|
-
injectIntoMain:
|
|
3516
|
+
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
2669
3517
|
outputFile
|
|
2670
3518
|
});
|
|
2671
3519
|
metrics.css.elapsed += measureElapsed(start);
|
|
@@ -2681,7 +3529,7 @@ function createGenerateBundleHook(context) {
|
|
|
2681
3529
|
}
|
|
2682
3530
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
2683
3531
|
const tracedCss = annotateCss(css);
|
|
2684
|
-
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3532
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
2685
3533
|
metrics.css.elapsed += measureElapsed(start);
|
|
2686
3534
|
metrics.css.transformed++;
|
|
2687
3535
|
return tracedCss;
|
|
@@ -2697,290 +3545,128 @@ function createGenerateBundleHook(context) {
|
|
|
2697
3545
|
continue;
|
|
2698
3546
|
}
|
|
2699
3547
|
if (type !== "js") continue;
|
|
2700
|
-
metrics.js.total++;
|
|
2701
3548
|
if (isWebGeneratorTarget) {
|
|
2702
3549
|
debug("js skip web target: %s", file);
|
|
2703
3550
|
continue;
|
|
2704
3551
|
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2711
|
-
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2712
|
-
jsTaskFactories.push(async () => {
|
|
2713
|
-
await timeTask("js", async () => {
|
|
2714
|
-
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2715
|
-
const hashKey = `${file}:js`;
|
|
2716
|
-
rememberProcessCacheKey(file, hashKey);
|
|
2717
|
-
await processCachedTask({
|
|
2718
|
-
cache,
|
|
2719
|
-
cacheKey: file,
|
|
2720
|
-
hashKey,
|
|
2721
|
-
hash: `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`,
|
|
2722
|
-
applyResult(source) {
|
|
2723
|
-
originalSource.code = source;
|
|
2724
|
-
},
|
|
2725
|
-
onCacheHit() {
|
|
2726
|
-
metrics.js.cacheHits++;
|
|
2727
|
-
debug("js cache hit: %s", file);
|
|
2728
|
-
},
|
|
2729
|
-
async transform() {
|
|
2730
|
-
const start = performance.now();
|
|
2731
|
-
const rawSource = originalSource.code;
|
|
2732
|
-
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
2733
|
-
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2734
|
-
if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2735
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
2736
|
-
metrics.js.transformed++;
|
|
2737
|
-
return { result: rawSource };
|
|
2738
|
-
}
|
|
2739
|
-
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
2740
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
2741
|
-
metrics.js.transformed++;
|
|
2742
|
-
onUpdate(file, rawSource, code);
|
|
2743
|
-
debug("js handle: %s", file);
|
|
2744
|
-
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2745
|
-
applyLinkedUpdates(linked);
|
|
2746
|
-
return { result: code };
|
|
2747
|
-
}
|
|
2748
|
-
});
|
|
2749
|
-
});
|
|
2750
|
-
});
|
|
2751
|
-
} else if (uniAppX && originalSource.type === "asset") {
|
|
2752
|
-
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2753
|
-
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2754
|
-
const baseApplyLinkedUpdates = applyLinkedUpdates;
|
|
2755
|
-
const wrappedApplyLinkedUpdates = (linked) => {
|
|
2756
|
-
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2757
|
-
baseApplyLinkedUpdates(linked);
|
|
2758
|
-
};
|
|
2759
|
-
const uniAppXJsHashKey = `${file}:js`;
|
|
2760
|
-
rememberProcessCacheKey(file, uniAppXJsHashKey);
|
|
2761
|
-
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2762
|
-
cache,
|
|
2763
|
-
hashKey: uniAppXJsHashKey,
|
|
2764
|
-
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2765
|
-
createHandlerOptions,
|
|
2766
|
-
debug,
|
|
2767
|
-
getAssetSource: createUniAppXBundleAssetSourceGetter(bundle),
|
|
2768
|
-
jsHandler,
|
|
2769
|
-
onUpdate,
|
|
2770
|
-
runtimeSet: transformRuntime,
|
|
2771
|
-
applyLinkedResults: wrappedApplyLinkedUpdates,
|
|
2772
|
-
uniAppX
|
|
2773
|
-
});
|
|
2774
|
-
jsTaskFactories.push(async () => {
|
|
2775
|
-
await timeTask("js", async () => {
|
|
2776
|
-
const start = performance.now();
|
|
2777
|
-
if (!shouldTransformJs) {
|
|
2778
|
-
debug("js skip transform (clean, uni-app-x), replay cache: %s", file);
|
|
2779
|
-
await factory();
|
|
2780
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
2781
|
-
metrics.js.transformed++;
|
|
2782
|
-
return;
|
|
2783
|
-
}
|
|
2784
|
-
const currentSource = originalEntrySource;
|
|
2785
|
-
const precheckOptions = createHandlerOptions(path.resolve(outDir, file), {
|
|
2786
|
-
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
2787
|
-
babelParserOptions: {
|
|
2788
|
-
plugins: ["typescript"],
|
|
2789
|
-
sourceType: "unambiguous"
|
|
2790
|
-
}
|
|
2791
|
-
});
|
|
2792
|
-
if (!disableJsPrecheck && shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
2793
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
2794
|
-
metrics.js.transformed++;
|
|
2795
|
-
return;
|
|
2796
|
-
}
|
|
2797
|
-
await factory();
|
|
2798
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
2799
|
-
metrics.js.transformed++;
|
|
2800
|
-
});
|
|
2801
|
-
});
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
if (useIncrementalMode || isNativeAppStyleTarget) {
|
|
2805
|
-
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot);
|
|
2806
|
-
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2807
|
-
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2808
|
-
key: item.key,
|
|
2809
|
-
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2810
|
-
})));
|
|
2811
|
-
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2812
|
-
if (!rememberedCssSource) continue;
|
|
2813
|
-
const { rawSource, sourceFile } = rememberedCssSource;
|
|
2814
|
-
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2815
|
-
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(sourceFile));
|
|
2816
|
-
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2817
|
-
const cssHandlerOptions = {
|
|
2818
|
-
...getCssHandlerOptions(sourceFile),
|
|
2819
|
-
isMainChunk: outputCssHandlerOptions.isMainChunk || isMainStyleEntryCssFile(sourceFile)
|
|
2820
|
-
};
|
|
2821
|
-
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2822
|
-
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2823
|
-
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2824
|
-
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2825
|
-
opts,
|
|
2826
|
-
tokenSources: sourceTraceTokenSources
|
|
2827
|
-
});
|
|
2828
|
-
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
2829
|
-
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, { includeFallbackSignature: cssHandlerOptions.isMainChunk }));
|
|
2830
|
-
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2831
|
-
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2832
|
-
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2833
|
-
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2834
|
-
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2835
|
-
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
2836
|
-
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2837
|
-
const start = performance.now();
|
|
2838
|
-
const generated = await generateCssByGenerator({
|
|
2839
|
-
opts,
|
|
2840
|
-
runtimeState,
|
|
2841
|
-
runtime: scopedGeneratorRuntime,
|
|
2842
|
-
rawSource,
|
|
2843
|
-
file: sourceFile,
|
|
2844
|
-
cssHandlerOptions,
|
|
2845
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2846
|
-
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2847
|
-
styleHandler,
|
|
2848
|
-
debug,
|
|
2849
|
-
previousCss
|
|
2850
|
-
});
|
|
2851
|
-
const css = annotateCss(generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css);
|
|
2852
|
-
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
2853
|
-
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
2854
|
-
if (generated) {
|
|
2855
|
-
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
2856
|
-
recordCssAssetResult?.(outputFile, css);
|
|
2857
|
-
const shouldInjectReplayCssIntoMain = shouldInjectCssIntoMainFromOutput(outputFile, sourceFile, outputCssHandlerOptions);
|
|
2858
|
-
recordViteProcessedCssAssetResult?.(sourceFile, css, {
|
|
2859
|
-
injectIntoMain: isAppOriginCssFile(outputFile) ? false : shouldInjectReplayCssIntoMain,
|
|
2860
|
-
outputFile
|
|
2861
|
-
});
|
|
2862
|
-
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
2863
|
-
}
|
|
2864
|
-
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
2865
|
-
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
2866
|
-
metrics.css.elapsed += measureElapsed(start);
|
|
2867
|
-
metrics.css.transformed++;
|
|
2868
|
-
onUpdate(outputFile, rawSource, css);
|
|
2869
|
-
debug("css replay handle: %s", outputFile);
|
|
2870
|
-
}));
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
2874
|
-
if (cssTaskFactories.length > 0) {
|
|
2875
|
-
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2876
|
-
tasks.push(runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2877
|
-
}
|
|
2878
|
-
const tasksStart = performance.now();
|
|
2879
|
-
await Promise.all(tasks);
|
|
2880
|
-
recordTimingDetail("tasks", tasksStart);
|
|
2881
|
-
for (const apply of pendingLinkedUpdates) apply();
|
|
2882
|
-
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
2883
|
-
if (opts.appType === "uni-app-x" || isNativeAppStyleTarget || isHarmonyAppStyleTarget) {
|
|
2884
|
-
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
2885
|
-
const viteProcessedCssSources = [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
2886
|
-
const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
|
|
2887
|
-
const shouldInjectHarmonyBundleStyles = isHarmonyAppStyleTarget;
|
|
2888
|
-
if (shouldInjectHarmonyBundleStyles) {
|
|
2889
|
-
if (applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2890
|
-
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2891
|
-
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2892
|
-
const generated = await generateCssByGenerator({
|
|
2893
|
-
opts,
|
|
2894
|
-
runtimeState,
|
|
2895
|
-
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2896
|
-
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2897
|
-
file: outputFile,
|
|
2898
|
-
cssHandlerOptions,
|
|
2899
|
-
cssUserHandlerOptions: {
|
|
2900
|
-
...cssHandlerOptions,
|
|
2901
|
-
isMainChunk: false
|
|
2902
|
-
},
|
|
2903
|
-
getSourceCandidatesForEntries,
|
|
2904
|
-
styleHandler,
|
|
2905
|
-
debug
|
|
2906
|
-
});
|
|
2907
|
-
if (generated?.css) viteProcessedCssSources.push(annotateCssSourceTrace(generated.css, {
|
|
2908
|
-
opts,
|
|
2909
|
-
tokenSources: getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0
|
|
2910
|
-
}));
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
if (shouldInjectHarmonyBundleStyles && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
2914
|
-
for (const [file, item] of Object.entries(bundle)) {
|
|
2915
|
-
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
2916
|
-
const currentSource = String(item.source);
|
|
2917
|
-
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
2918
|
-
if (nextSource !== currentSource) {
|
|
2919
|
-
item.source = nextSource;
|
|
2920
|
-
onUpdate(file, currentSource, nextSource);
|
|
2921
|
-
debug("uni-app-x style placeholder inject: %s", file);
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
-
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
2926
|
-
collectViteProcessedCssAssetResults(bundle, {
|
|
2927
|
-
opts,
|
|
2928
|
-
isViteProcessedCssAsset,
|
|
2929
|
-
markCssAssetProcessed,
|
|
2930
|
-
recordCssAssetResult,
|
|
2931
|
-
recordViteProcessedCssAssetResult,
|
|
2932
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot),
|
|
2933
|
-
debug
|
|
2934
|
-
});
|
|
2935
|
-
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
2936
|
-
opts,
|
|
2937
|
-
getViteProcessedCssAssetResults,
|
|
2938
|
-
markCssAssetProcessed,
|
|
2939
|
-
recordCssAssetResult,
|
|
3552
|
+
processJsBundleEntry({
|
|
3553
|
+
applyLinkedUpdates,
|
|
3554
|
+
bundle,
|
|
3555
|
+
cache,
|
|
3556
|
+
createHandlerOptions,
|
|
2940
3557
|
debug,
|
|
2941
|
-
|
|
3558
|
+
disableJsPrecheck: envFlags.disableJsPrecheck,
|
|
3559
|
+
entry,
|
|
3560
|
+
getJsEntry,
|
|
3561
|
+
jsHandler,
|
|
3562
|
+
jsTaskFactories,
|
|
3563
|
+
linkedByEntry,
|
|
3564
|
+
metrics,
|
|
3565
|
+
onUpdate,
|
|
3566
|
+
outDir,
|
|
3567
|
+
processFiles,
|
|
3568
|
+
rememberProcessCacheKey,
|
|
3569
|
+
runtimeSignature,
|
|
3570
|
+
snapshot,
|
|
3571
|
+
timeTask,
|
|
3572
|
+
transformRuntime,
|
|
3573
|
+
uniAppX,
|
|
3574
|
+
useIncrementalMode
|
|
2942
3575
|
});
|
|
2943
|
-
};
|
|
2944
|
-
syncViteProcessedCssIntoMainCssAssets();
|
|
2945
|
-
if (isHarmonyAppStyleTarget && applyStyleSources.length > 0) {
|
|
2946
|
-
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
2947
|
-
syncViteProcessedCssIntoMainCssAssets();
|
|
2948
3576
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
3577
|
+
if (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget) await processRememberedCssReplay({
|
|
3578
|
+
addWatchFile,
|
|
3579
|
+
activeViteCssCacheFiles,
|
|
3580
|
+
bundle,
|
|
3581
|
+
bundleFiles,
|
|
3582
|
+
cache,
|
|
3583
|
+
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
3584
|
+
createScopedSourceCandidateGetter,
|
|
3585
|
+
createScopedSourceCandidateSourceGetter,
|
|
3586
|
+
cssTaskFactories,
|
|
3587
|
+
debug,
|
|
3588
|
+
defaultStyleOutputExtension,
|
|
3589
|
+
emitOrReplayCssAsset,
|
|
3590
|
+
generatorRuntime,
|
|
3591
|
+
getCssHandlerOptions,
|
|
3592
|
+
getCssUserHandlerOptions,
|
|
3593
|
+
getRememberedCssSignature,
|
|
3594
|
+
getRememberedCssSources,
|
|
3595
|
+
isNativeAppStyleTarget,
|
|
3596
|
+
isWebGeneratorTarget,
|
|
3597
|
+
lastCssResultByFile,
|
|
3598
|
+
lastCssSourceHashByFile,
|
|
3599
|
+
markCssAssetProcessed,
|
|
3600
|
+
metrics,
|
|
3601
|
+
normalizeViteCssCacheKey,
|
|
3602
|
+
onUpdate,
|
|
3603
|
+
opts,
|
|
3604
|
+
recordCssAssetResult,
|
|
3605
|
+
recordViteProcessedCssAssetResult,
|
|
3606
|
+
refreshRememberedCssSource,
|
|
3607
|
+
rootDir,
|
|
3608
|
+
runtimeState,
|
|
3609
|
+
setRememberedCssSignature,
|
|
3610
|
+
shouldInjectCssIntoMainFromOutput,
|
|
3611
|
+
shouldPreserveAppCssExtension,
|
|
3612
|
+
sourceRoot,
|
|
3613
|
+
styleHandler,
|
|
3614
|
+
timeTask,
|
|
3615
|
+
useIncrementalMode
|
|
2955
3616
|
});
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
3617
|
+
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
3618
|
+
await finalizeGenerateBundle({
|
|
3619
|
+
activeProcessCacheKeys,
|
|
3620
|
+
activeProcessHashKeys,
|
|
3621
|
+
activeViteCssCacheFiles,
|
|
3622
|
+
bundle,
|
|
3623
|
+
bundleFiles,
|
|
3624
|
+
cache,
|
|
3625
|
+
cssTaskFactories,
|
|
3626
|
+
debug,
|
|
3627
|
+
defaultStyleOutputExtension,
|
|
3628
|
+
formatIteration: useIncrementalMode ? state.iteration : 0,
|
|
3629
|
+
generatorCandidateSignature,
|
|
3630
|
+
generatorRuntime,
|
|
3631
|
+
getCssHandlerOptions,
|
|
3632
|
+
getSourceCandidateSourcesForEntries,
|
|
3633
|
+
getSourceCandidatesForEntries,
|
|
3634
|
+
getViteCssCacheStats,
|
|
3635
|
+
getViteProcessedCssAssetResults,
|
|
3636
|
+
hmrTimingRecorder,
|
|
3637
|
+
hmrTimingStartedAt,
|
|
3638
|
+
isHarmonyAppStyleTarget,
|
|
3639
|
+
isNativeAppStyleTarget,
|
|
3640
|
+
isViteProcessedCssAsset,
|
|
3641
|
+
isWebGeneratorTarget,
|
|
3642
|
+
lastCssResultByFile,
|
|
3643
|
+
lastCssSourceHashByFile,
|
|
3644
|
+
linkedByEntry,
|
|
3645
|
+
markCssAssetProcessed,
|
|
3646
|
+
metrics,
|
|
3647
|
+
onEnd,
|
|
3648
|
+
onUpdate,
|
|
3649
|
+
opts,
|
|
3650
|
+
outDir,
|
|
3651
|
+
pendingLinkedUpdates,
|
|
3652
|
+
pruneViteCssCaches,
|
|
3653
|
+
recordCssAssetResult,
|
|
3654
|
+
recordTimingDetail,
|
|
3655
|
+
recordViteProcessedCssAssetResult,
|
|
3656
|
+
rootDir,
|
|
3657
|
+
runtime,
|
|
3658
|
+
runtimeState,
|
|
3659
|
+
shouldPreserveAppCssExtension,
|
|
3660
|
+
snapshot,
|
|
3661
|
+
sourceCandidates,
|
|
3662
|
+
sourceRoot,
|
|
3663
|
+
state,
|
|
3664
|
+
styleHandler,
|
|
3665
|
+
tasks,
|
|
3666
|
+
timingDetails,
|
|
3667
|
+
transformRuntime,
|
|
3668
|
+
useIncrementalMode
|
|
2960
3669
|
});
|
|
2961
|
-
recordTimingDetail("state.update", stateUpdateStart);
|
|
2962
|
-
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)", useIncrementalMode ? state.iteration : 0, 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));
|
|
2963
|
-
if (hmrTimingRecorder) {
|
|
2964
|
-
hmrTimingRecorder.record("generateBundle", performance.now() - hmrTimingStartedAt, {
|
|
2965
|
-
...timingDetails,
|
|
2966
|
-
memoryDebug: resolveViteMemoryDebugStats({
|
|
2967
|
-
activeProcessCacheKeys,
|
|
2968
|
-
activeProcessHashKeys,
|
|
2969
|
-
cache,
|
|
2970
|
-
generatorRuntimeSize: generatorRuntime.size,
|
|
2971
|
-
getViteCssCacheStats,
|
|
2972
|
-
lastCssResultByFile,
|
|
2973
|
-
phase: "generateBundle",
|
|
2974
|
-
runtimeSize: runtime.size,
|
|
2975
|
-
sourceCandidatesSize: sourceCandidates.size,
|
|
2976
|
-
transformRuntimeSize: transformRuntime.size,
|
|
2977
|
-
useIncrementalMode
|
|
2978
|
-
})
|
|
2979
|
-
});
|
|
2980
|
-
hmrTimingRecorder.emitTotal();
|
|
2981
|
-
}
|
|
2982
|
-
onEnd();
|
|
2983
|
-
debug("end");
|
|
2984
3670
|
};
|
|
2985
3671
|
}
|
|
2986
3672
|
//#endregion
|
|
@@ -3040,7 +3726,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3040
3726
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
3041
3727
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
3042
3728
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3043
|
-
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
3729
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
3044
3730
|
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
3045
3731
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3046
3732
|
opts,
|
|
@@ -3053,7 +3739,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3053
3739
|
markCssAssetProcessed,
|
|
3054
3740
|
recordCssAssetResult,
|
|
3055
3741
|
recordViteProcessedCssAssetResult,
|
|
3056
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot),
|
|
3742
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
3057
3743
|
debug
|
|
3058
3744
|
});
|
|
3059
3745
|
};
|
|
@@ -3170,6 +3856,278 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3170
3856
|
};
|
|
3171
3857
|
}
|
|
3172
3858
|
//#endregion
|
|
3859
|
+
//#region src/bundlers/vite/map-cache.ts
|
|
3860
|
+
function touchMapEntry(map, key, value) {
|
|
3861
|
+
map.delete(key);
|
|
3862
|
+
map.set(key, value);
|
|
3863
|
+
}
|
|
3864
|
+
function pruneMapToMaxSize(map, maxSize, onDelete) {
|
|
3865
|
+
while (map.size > maxSize) {
|
|
3866
|
+
const key = map.keys().next().value;
|
|
3867
|
+
if (key === void 0) break;
|
|
3868
|
+
map.delete(key);
|
|
3869
|
+
onDelete?.(key);
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
//#endregion
|
|
3873
|
+
//#region src/bundlers/vite/css-memory.ts
|
|
3874
|
+
const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
3875
|
+
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3876
|
+
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3877
|
+
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
3878
|
+
function stripSourceHash(sourceFile) {
|
|
3879
|
+
const hashIndex = sourceFile.indexOf("#");
|
|
3880
|
+
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
3881
|
+
}
|
|
3882
|
+
function normalizeCssSourceIdentity(sourceFile) {
|
|
3883
|
+
const cleanSourceFile = stripSourceHash(sourceFile);
|
|
3884
|
+
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
3885
|
+
const normalizedFile = normalizeOutputPathKey(filename);
|
|
3886
|
+
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
3887
|
+
return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
|
|
3888
|
+
}
|
|
3889
|
+
function hasSfcStyleBlocks(source) {
|
|
3890
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
3891
|
+
return SFC_STYLE_BLOCK_RE.test(source);
|
|
3892
|
+
}
|
|
3893
|
+
function extractSfcStyleBlock(source, index) {
|
|
3894
|
+
const targetIndex = index ?? 0;
|
|
3895
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
3896
|
+
let currentIndex = 0;
|
|
3897
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
3898
|
+
while (match !== null) {
|
|
3899
|
+
if (currentIndex === targetIndex) return match[1] ?? "";
|
|
3900
|
+
currentIndex++;
|
|
3901
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
function extractSfcStyleSource(source, index) {
|
|
3905
|
+
if (index !== void 0) return extractSfcStyleBlock(source, index);
|
|
3906
|
+
const styleSources = [];
|
|
3907
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
3908
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
3909
|
+
while (match !== null) {
|
|
3910
|
+
styleSources.push(match[1] ?? "");
|
|
3911
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
3912
|
+
}
|
|
3913
|
+
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
3914
|
+
}
|
|
3915
|
+
function normalizeKnownSfcSourceKey(file) {
|
|
3916
|
+
return normalizeOutputPathKey(path.resolve(cleanUrl(file)));
|
|
3917
|
+
}
|
|
3918
|
+
function shouldCollectTransformedSourceCandidates(id) {
|
|
3919
|
+
if (id.search(/[?#]/) < 0) return true;
|
|
3920
|
+
const file = cleanUrl(id);
|
|
3921
|
+
return !SFC_COMPONENT_FILE_RE.test(file);
|
|
3922
|
+
}
|
|
3923
|
+
function createViteCssMemory(options) {
|
|
3924
|
+
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
3925
|
+
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
3926
|
+
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
3927
|
+
const rememberKnownSfcSource = (id, code) => {
|
|
3928
|
+
if (id.search(/[?#]/) >= 0) return;
|
|
3929
|
+
const file = cleanUrl(id);
|
|
3930
|
+
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
3931
|
+
if (!hasSfcStyleBlocks(code)) return;
|
|
3932
|
+
touchMapEntry(knownSfcSources, normalizeKnownSfcSourceKey(file), code);
|
|
3933
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
3934
|
+
};
|
|
3935
|
+
const getKnownSfcSource = (file) => {
|
|
3936
|
+
const scanSource = options.getSourceCandidateSource(file);
|
|
3937
|
+
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
3938
|
+
const key = normalizeKnownSfcSourceKey(file);
|
|
3939
|
+
const source = knownSfcSources.get(key);
|
|
3940
|
+
if (source != null) touchMapEntry(knownSfcSources, key, source);
|
|
3941
|
+
return source;
|
|
3942
|
+
};
|
|
3943
|
+
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3944
|
+
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
3945
|
+
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
3946
|
+
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3947
|
+
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
3948
|
+
const previous = rememberedCssSources.get(key);
|
|
3949
|
+
touchMapEntry(rememberedCssSources, key, entry);
|
|
3950
|
+
const relatedRememberedEntries = [...rememberedCssSources].filter(([rememberedKey, remembered]) => rememberedKey !== key && normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
3951
|
+
for (const [rememberedKey, remembered] of relatedRememberedEntries) {
|
|
3952
|
+
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
3953
|
+
...remembered,
|
|
3954
|
+
rawSource: entry.rawSource,
|
|
3955
|
+
sourceFile: entry.sourceFile
|
|
3956
|
+
});
|
|
3957
|
+
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
3958
|
+
}
|
|
3959
|
+
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
3960
|
+
else if (previous?.rawSource !== entry.rawSource || previous?.sourceFile !== entry.sourceFile) rememberedCssSignatureByFile.delete(key);
|
|
3961
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
3962
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
3963
|
+
});
|
|
3964
|
+
};
|
|
3965
|
+
const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
|
|
3966
|
+
if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
|
|
3967
|
+
const nextRemembered = {
|
|
3968
|
+
...remembered,
|
|
3969
|
+
rawSource,
|
|
3970
|
+
sourceFile
|
|
3971
|
+
};
|
|
3972
|
+
touchMapEntry(rememberedCssSources, rememberedKey, nextRemembered);
|
|
3973
|
+
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
3974
|
+
return nextRemembered;
|
|
3975
|
+
};
|
|
3976
|
+
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
3977
|
+
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
3978
|
+
const relatedRememberedEntries = [...rememberedCssSources].filter(([, remembered]) => normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
3979
|
+
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
3980
|
+
};
|
|
3981
|
+
const resolveCachedStyleSource = (sourceFile) => {
|
|
3982
|
+
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
3983
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
3984
|
+
if (isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
3985
|
+
};
|
|
3986
|
+
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
3987
|
+
const file = cleanUrl(sourceFile);
|
|
3988
|
+
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
3989
|
+
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
|
|
3990
|
+
if (matchedRememberedSources.length === 0) return;
|
|
3991
|
+
const source = resolveCachedStyleSource(file);
|
|
3992
|
+
if (source == null) {
|
|
3993
|
+
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
3994
|
+
return;
|
|
3995
|
+
}
|
|
3996
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
3997
|
+
for (const remembered of matchedRememberedSources) {
|
|
3998
|
+
const { query } = parseVueRequest(remembered.sourceFile);
|
|
3999
|
+
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4000
|
+
if (styleSource !== void 0) refreshRememberedCssSourceBySourceFile(remembered.sourceFile, styleSource);
|
|
4001
|
+
}
|
|
4002
|
+
return;
|
|
4003
|
+
}
|
|
4004
|
+
if (isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
4005
|
+
};
|
|
4006
|
+
const refreshRememberedCssSource = async (remembered) => {
|
|
4007
|
+
const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
|
|
4008
|
+
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4009
|
+
if (!rememberedKey || !path.isAbsolute(file)) return;
|
|
4010
|
+
const source = resolveCachedStyleSource(file);
|
|
4011
|
+
if (source == null) {
|
|
4012
|
+
options.debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
4016
|
+
const { query } = parseVueRequest(remembered.sourceFile);
|
|
4017
|
+
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4018
|
+
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
4019
|
+
}
|
|
4020
|
+
if (isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
4021
|
+
};
|
|
4022
|
+
const prune = (pruneOptions) => {
|
|
4023
|
+
const activeFiles = new Set([...pruneOptions.activeFiles].map(normalizeOutputPathKey));
|
|
4024
|
+
for (const [key, remembered] of rememberedCssSources) {
|
|
4025
|
+
const outputKey = normalizeOutputPathKey(remembered.outputFile);
|
|
4026
|
+
const sourceKey = normalizeOutputPathKey(remembered.sourceFile);
|
|
4027
|
+
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
4028
|
+
rememberedCssSources.delete(key);
|
|
4029
|
+
rememberedCssSignatureByFile.delete(key);
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
if (pruneOptions.activeKnownSfcFiles) {
|
|
4033
|
+
const activeKnownSfcFiles = new Set([...pruneOptions.activeKnownSfcFiles].map((file) => normalizeKnownSfcSourceKey(file)).filter((file) => SFC_COMPONENT_FILE_RE.test(file)));
|
|
4034
|
+
for (const key of knownSfcSources.keys()) if (!activeKnownSfcFiles.has(key)) knownSfcSources.delete(key);
|
|
4035
|
+
}
|
|
4036
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4037
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4038
|
+
});
|
|
4039
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4040
|
+
};
|
|
4041
|
+
return {
|
|
4042
|
+
getKnownSfcSource,
|
|
4043
|
+
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(normalizeOutputPathKey(file)),
|
|
4044
|
+
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(normalizeOutputPathKey(file)),
|
|
4045
|
+
getRememberedCssSources: () => rememberedCssSources,
|
|
4046
|
+
getStats: () => ({
|
|
4047
|
+
rememberedCssSources: rememberedCssSources.size,
|
|
4048
|
+
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4049
|
+
knownSfcSources: knownSfcSources.size
|
|
4050
|
+
}),
|
|
4051
|
+
rememberCssSource,
|
|
4052
|
+
rememberKnownSfcSource,
|
|
4053
|
+
refreshRememberedCssSource,
|
|
4054
|
+
refreshRememberedCssSourceByCurrentFile,
|
|
4055
|
+
refreshRememberedCssSourceBySourceFile,
|
|
4056
|
+
setRememberedCssSignature: (file, cssRuntimeSignature) => {
|
|
4057
|
+
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
4058
|
+
},
|
|
4059
|
+
prune
|
|
4060
|
+
};
|
|
4061
|
+
}
|
|
4062
|
+
//#endregion
|
|
4063
|
+
//#region src/bundlers/vite/hot-css-modules.ts
|
|
4064
|
+
function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
4065
|
+
const modules = [];
|
|
4066
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
4067
|
+
const collectModule = (mod) => {
|
|
4068
|
+
if (mod == null || seenModules.has(mod)) return;
|
|
4069
|
+
if (!isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
4070
|
+
seenModules.add(mod);
|
|
4071
|
+
ctx.server.moduleGraph.invalidateModule(mod);
|
|
4072
|
+
modules.push(mod);
|
|
4073
|
+
};
|
|
4074
|
+
for (const id of tailwindRootCssModuleIds) {
|
|
4075
|
+
const candidates = [
|
|
4076
|
+
ctx.server.moduleGraph.getModuleById(id),
|
|
4077
|
+
ctx.server.moduleGraph.getModuleById(cleanUrl(id)),
|
|
4078
|
+
...ctx.server.moduleGraph.getModulesByFile(id) ?? [],
|
|
4079
|
+
...ctx.server.moduleGraph.getModulesByFile(cleanUrl(id)) ?? []
|
|
4080
|
+
];
|
|
4081
|
+
for (const mod of candidates) collectModule(mod);
|
|
4082
|
+
}
|
|
4083
|
+
return modules;
|
|
4084
|
+
}
|
|
4085
|
+
function resolveModuleHotUrl(mod) {
|
|
4086
|
+
if (typeof mod.url === "string" && mod.url.length > 0) return mod.url;
|
|
4087
|
+
if (typeof mod.id === "string" && mod.id.startsWith("/")) return mod.id;
|
|
4088
|
+
}
|
|
4089
|
+
function includesHotModule(modules, target) {
|
|
4090
|
+
const targetUrl = resolveModuleHotUrl(target);
|
|
4091
|
+
const targetId = target.id;
|
|
4092
|
+
return modules.some((mod) => {
|
|
4093
|
+
if (mod === target) return true;
|
|
4094
|
+
return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId;
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4097
|
+
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
4098
|
+
return modules.some((mod) => {
|
|
4099
|
+
return !isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
4102
|
+
function sendSupplementalCssHotUpdates(ctx, cssModules) {
|
|
4103
|
+
const updates = cssModules.filter((mod) => !includesHotModule(ctx.modules, mod)).map((mod) => {
|
|
4104
|
+
const hotUrl = resolveModuleHotUrl(mod);
|
|
4105
|
+
if (!hotUrl) return;
|
|
4106
|
+
return {
|
|
4107
|
+
type: "js-update",
|
|
4108
|
+
timestamp: ctx.timestamp,
|
|
4109
|
+
path: hotUrl,
|
|
4110
|
+
acceptedPath: hotUrl,
|
|
4111
|
+
explicitImportRequired: false,
|
|
4112
|
+
isWithinCircularImport: false
|
|
4113
|
+
};
|
|
4114
|
+
}).filter((update) => update !== void 0);
|
|
4115
|
+
if (updates.length === 0) return;
|
|
4116
|
+
queueMicrotask(() => {
|
|
4117
|
+
ctx.server.ws?.send?.({
|
|
4118
|
+
type: "update",
|
|
4119
|
+
updates
|
|
4120
|
+
});
|
|
4121
|
+
});
|
|
4122
|
+
}
|
|
4123
|
+
function sendFullReloadForUnresolvedHotUpdate(ctx) {
|
|
4124
|
+
ctx.server.ws?.send?.({
|
|
4125
|
+
type: "full-reload",
|
|
4126
|
+
path: "*",
|
|
4127
|
+
triggeredBy: ctx.file
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
//#endregion
|
|
3173
4131
|
//#region src/bundlers/vite/official-tailwind-plugins.ts
|
|
3174
4132
|
function isTailwindVitePlugin(plugin) {
|
|
3175
4133
|
if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
|
|
@@ -3213,67 +4171,6 @@ function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
|
3213
4171
|
return removed;
|
|
3214
4172
|
}
|
|
3215
4173
|
//#endregion
|
|
3216
|
-
//#region src/bundlers/vite/resolve-app-type.ts
|
|
3217
|
-
const PACKAGE_JSON_FILE$1 = "package.json";
|
|
3218
|
-
const MPX_SCRIPT_RE = /\bmpx(?:-cli-service)?\b/u;
|
|
3219
|
-
const TARO_SCRIPT_RE = /\btaro\b/u;
|
|
3220
|
-
const TAILWINDCSS_VITE_MARKERS = [["src/app.mpx", "mpx"], ["app.mpx", "mpx"]];
|
|
3221
|
-
function resolveDependencyNames(pkg) {
|
|
3222
|
-
return new Set([
|
|
3223
|
-
...Object.keys(pkg.dependencies ?? {}),
|
|
3224
|
-
...Object.keys(pkg.devDependencies ?? {}),
|
|
3225
|
-
...Object.keys(pkg.peerDependencies ?? {}),
|
|
3226
|
-
...Object.keys(pkg.optionalDependencies ?? {})
|
|
3227
|
-
]);
|
|
3228
|
-
}
|
|
3229
|
-
function hasScriptMatch(pkg, pattern) {
|
|
3230
|
-
return Object.values(pkg.scripts ?? {}).some((script) => pattern.test(script));
|
|
3231
|
-
}
|
|
3232
|
-
function resolveAppTypeFromPackageJson(pkg) {
|
|
3233
|
-
const dependencyNames = resolveDependencyNames(pkg);
|
|
3234
|
-
if (dependencyNames.has("weapp-vite") || [...dependencyNames].some((name) => name.startsWith("@weapp-vite/"))) return "weapp-vite";
|
|
3235
|
-
if ([...dependencyNames].some((name) => name.startsWith("@mpxjs/")) || hasScriptMatch(pkg, MPX_SCRIPT_RE)) return "mpx";
|
|
3236
|
-
if ([...dependencyNames].some((name) => name.startsWith("@tarojs/")) || hasScriptMatch(pkg, TARO_SCRIPT_RE)) return "taro";
|
|
3237
|
-
if (dependencyNames.has("@dcloudio/vite-plugin-uni")) return "uni-app-vite";
|
|
3238
|
-
if (dependencyNames.has("@dcloudio/vue-cli-plugin-uni") || dependencyNames.has("@dcloudio/uni-app") || Object.hasOwn(pkg, "uni-app")) return "uni-app";
|
|
3239
|
-
}
|
|
3240
|
-
function tryReadUniAppManifest(root) {
|
|
3241
|
-
const manifestPath = path.join(root, "manifest.json");
|
|
3242
|
-
if (!existsSync(manifestPath)) return;
|
|
3243
|
-
try {
|
|
3244
|
-
return JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
3245
|
-
} catch {}
|
|
3246
|
-
}
|
|
3247
|
-
function tryReadPackageJson(root) {
|
|
3248
|
-
const packageJsonPath = path.join(root, PACKAGE_JSON_FILE$1);
|
|
3249
|
-
if (!existsSync(packageJsonPath)) return;
|
|
3250
|
-
try {
|
|
3251
|
-
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
3252
|
-
} catch {}
|
|
3253
|
-
}
|
|
3254
|
-
function resolveAppTypeFromMarkers(root) {
|
|
3255
|
-
for (const [relativePath, appType] of TAILWINDCSS_VITE_MARKERS) if (existsSync(path.join(root, relativePath))) return appType;
|
|
3256
|
-
}
|
|
3257
|
-
function resolveImplicitAppTypeFromViteRoot(root) {
|
|
3258
|
-
const resolvedRoot = path.resolve(root);
|
|
3259
|
-
if (!existsSync(resolvedRoot)) return;
|
|
3260
|
-
const markerDetected = resolveAppTypeFromMarkers(resolvedRoot);
|
|
3261
|
-
if (markerDetected) return markerDetected;
|
|
3262
|
-
let current = resolvedRoot;
|
|
3263
|
-
while (true) {
|
|
3264
|
-
const manifest = tryReadUniAppManifest(current);
|
|
3265
|
-
if (manifest && Object.hasOwn(manifest, "uni-app-x")) return "uni-app-x";
|
|
3266
|
-
const pkg = tryReadPackageJson(current);
|
|
3267
|
-
if (pkg) {
|
|
3268
|
-
const detected = resolveAppTypeFromPackageJson(pkg);
|
|
3269
|
-
if (detected) return detected;
|
|
3270
|
-
}
|
|
3271
|
-
const parent = path.dirname(current);
|
|
3272
|
-
if (parent === current) break;
|
|
3273
|
-
current = parent;
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
//#endregion
|
|
3277
4174
|
//#region src/bundlers/shared/css-imports.ts
|
|
3278
4175
|
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
3279
4176
|
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
@@ -3541,7 +4438,7 @@ function isViteServeStyleRequest(id, command) {
|
|
|
3541
4438
|
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
3542
4439
|
}
|
|
3543
4440
|
function isViteServeCssRootRequest(id, command) {
|
|
3544
|
-
return command === "serve" &&
|
|
4441
|
+
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
3545
4442
|
}
|
|
3546
4443
|
function isViteCssHmrModule(code, id, command) {
|
|
3547
4444
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
|
|
@@ -3583,36 +4480,7 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
3583
4480
|
}];
|
|
3584
4481
|
}
|
|
3585
4482
|
//#endregion
|
|
3586
|
-
//#region src/bundlers/vite/
|
|
3587
|
-
const PACKAGE_JSON_FILE = "package.json";
|
|
3588
|
-
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
3589
|
-
const resolvedRoot = path.resolve(root);
|
|
3590
|
-
if (!existsSync(resolvedRoot)) return resolvedRoot;
|
|
3591
|
-
const searchRoots = [];
|
|
3592
|
-
let current = resolvedRoot;
|
|
3593
|
-
while (true) {
|
|
3594
|
-
searchRoots.push(current);
|
|
3595
|
-
const parent = path.dirname(current);
|
|
3596
|
-
if (parent === current) break;
|
|
3597
|
-
current = parent;
|
|
3598
|
-
}
|
|
3599
|
-
const tailwindConfigPath = findTailwindConfig(searchRoots);
|
|
3600
|
-
if (tailwindConfigPath) return path.dirname(tailwindConfigPath);
|
|
3601
|
-
const packageRoot = findNearestPackageRoot(resolvedRoot);
|
|
3602
|
-
if (packageRoot && existsSync(path.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
3603
|
-
return resolvedRoot;
|
|
3604
|
-
}
|
|
3605
|
-
//#endregion
|
|
3606
|
-
//#region src/bundlers/vite/index.ts
|
|
3607
|
-
const debug = createDebug();
|
|
3608
|
-
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
3609
|
-
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
3610
|
-
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
3611
|
-
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3612
|
-
const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
3613
|
-
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3614
|
-
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3615
|
-
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
4483
|
+
//#region src/bundlers/vite/source-candidate-scan-signature.ts
|
|
3616
4484
|
function normalizeSignaturePath(value) {
|
|
3617
4485
|
return slash(path.resolve(value));
|
|
3618
4486
|
}
|
|
@@ -3640,33 +4508,33 @@ function createSourceCandidateScanSignature(input) {
|
|
|
3640
4508
|
scanAllSources: input.scanAllSources ?? false
|
|
3641
4509
|
});
|
|
3642
4510
|
}
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
|
|
3657
|
-
}
|
|
3658
|
-
function touchMapEntry(map, key, value) {
|
|
3659
|
-
map.delete(key);
|
|
3660
|
-
map.set(key, value);
|
|
3661
|
-
}
|
|
3662
|
-
function pruneMapToMaxSize(map, maxSize, onDelete) {
|
|
3663
|
-
while (map.size > maxSize) {
|
|
3664
|
-
const key = map.keys().next().value;
|
|
3665
|
-
if (key === void 0) break;
|
|
3666
|
-
map.delete(key);
|
|
3667
|
-
onDelete?.(key);
|
|
4511
|
+
//#endregion
|
|
4512
|
+
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
4513
|
+
const PACKAGE_JSON_FILE = "package.json";
|
|
4514
|
+
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
4515
|
+
const resolvedRoot = path.resolve(root);
|
|
4516
|
+
if (!existsSync(resolvedRoot)) return resolvedRoot;
|
|
4517
|
+
const searchRoots = [];
|
|
4518
|
+
let current = resolvedRoot;
|
|
4519
|
+
while (true) {
|
|
4520
|
+
searchRoots.push(current);
|
|
4521
|
+
const parent = path.dirname(current);
|
|
4522
|
+
if (parent === current) break;
|
|
4523
|
+
current = parent;
|
|
3668
4524
|
}
|
|
4525
|
+
const tailwindConfigPath = findTailwindConfig(searchRoots);
|
|
4526
|
+
if (tailwindConfigPath) return path.dirname(tailwindConfigPath);
|
|
4527
|
+
const packageRoot = findNearestPackageRoot(resolvedRoot);
|
|
4528
|
+
if (packageRoot && existsSync(path.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
4529
|
+
return resolvedRoot;
|
|
3669
4530
|
}
|
|
4531
|
+
//#endregion
|
|
4532
|
+
//#region src/bundlers/vite/index.ts
|
|
4533
|
+
const debug = createDebug();
|
|
4534
|
+
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
4535
|
+
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
4536
|
+
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
4537
|
+
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3670
4538
|
function normalizeVitePersistentCacheKey(file) {
|
|
3671
4539
|
return normalizeOutputPathKey(file);
|
|
3672
4540
|
}
|
|
@@ -3703,6 +4571,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3703
4571
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
3704
4572
|
});
|
|
3705
4573
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
4574
|
+
const transientAutoCssSources = /* @__PURE__ */ new Map();
|
|
3706
4575
|
let refreshRuntimeStateForAutoCssSources;
|
|
3707
4576
|
let autoCssSourcesRefresh;
|
|
3708
4577
|
let autoCssSourcesDiscovered = false;
|
|
@@ -3711,7 +4580,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3711
4580
|
cacheCurrentSourceCandidateScan();
|
|
3712
4581
|
};
|
|
3713
4582
|
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
3714
|
-
if (tailwindcssMajorVersion < 4 || !shouldOwnTailwindGeneration
|
|
4583
|
+
if (tailwindcssMajorVersion < 4 || !shouldOwnTailwindGeneration) return;
|
|
3715
4584
|
const file = cleanUrl(id);
|
|
3716
4585
|
if (!path.isAbsolute(file)) return;
|
|
3717
4586
|
const sourceFile = path.normalize(file);
|
|
@@ -3720,11 +4589,24 @@ function WeappTailwindcss(options = {}) {
|
|
|
3720
4589
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
|
|
3721
4590
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
3722
4591
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
4592
|
+
const transientSource = {
|
|
4593
|
+
file: sourceFile,
|
|
4594
|
+
base: sourceBase,
|
|
4595
|
+
css: sourceCss,
|
|
4596
|
+
dependencies: []
|
|
4597
|
+
};
|
|
4598
|
+
if (hasInitialTailwindCssRoots) {
|
|
4599
|
+
transientAutoCssSources.set(sourceFile, transientSource);
|
|
4600
|
+
return;
|
|
4601
|
+
}
|
|
4602
|
+
const dependencies = await resolveViteTailwindV4CssDependencies(sourceCss, sourceBase);
|
|
4603
|
+
transientSource.dependencies = dependencies;
|
|
4604
|
+
transientAutoCssSources.set(sourceFile, transientSource);
|
|
3723
4605
|
if (!upsertTailwindV4CssSource(opts, {
|
|
3724
4606
|
file: sourceFile,
|
|
3725
4607
|
base: sourceBase,
|
|
3726
4608
|
css: sourceCss,
|
|
3727
|
-
dependencies
|
|
4609
|
+
dependencies
|
|
3728
4610
|
})) return;
|
|
3729
4611
|
invalidateSourceCandidateScan();
|
|
3730
4612
|
debug("detected tailwindcss v4 css source from vite css module: %s", sourceFile);
|
|
@@ -3779,9 +4661,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
3779
4661
|
const viteProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
3780
4662
|
const viteGeneratedCssByFile = /* @__PURE__ */ new Map();
|
|
3781
4663
|
const viteProcessedCssAssetResults = /* @__PURE__ */ new Map();
|
|
3782
|
-
const
|
|
3783
|
-
|
|
3784
|
-
|
|
4664
|
+
const cssMemory = createViteCssMemory({
|
|
4665
|
+
debug,
|
|
4666
|
+
getSourceCandidateSource: (file) => sourceCandidateCollector.source(file)
|
|
4667
|
+
});
|
|
3785
4668
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
3786
4669
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
3787
4670
|
opts,
|
|
@@ -3830,7 +4713,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3830
4713
|
explicit: sourceScanExplicit,
|
|
3831
4714
|
root
|
|
3832
4715
|
}];
|
|
3833
|
-
if (sourceScanExplicit) return [];
|
|
4716
|
+
if (sourceScanExplicit && entries !== void 0) return [];
|
|
3834
4717
|
const roots = [{
|
|
3835
4718
|
entries,
|
|
3836
4719
|
root
|
|
@@ -3907,7 +4790,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
3907
4790
|
sourceCandidateScanInvalidated = false;
|
|
3908
4791
|
return;
|
|
3909
4792
|
}
|
|
3910
|
-
sourceCandidateCollector.
|
|
4793
|
+
if (isWatchLikeBuild()) sourceCandidateCollector.resetScan();
|
|
4794
|
+
else sourceCandidateCollector.clearScan();
|
|
3911
4795
|
sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
3912
4796
|
await scanSourceCandidateRoots(roots, outDir);
|
|
3913
4797
|
sourceCandidateScanSignature = nextScanSignature;
|
|
@@ -3927,14 +4811,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
3927
4811
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
3928
4812
|
sourceCandidateCollector.remove(file);
|
|
3929
4813
|
cacheCurrentSourceCandidateScan();
|
|
3930
|
-
return refreshRememberedCssSourceByCurrentFile(file);
|
|
3931
|
-
}
|
|
3932
|
-
if (sourceScanExplicit && sourceScanEntries?.length === 0) {
|
|
3933
|
-
cacheCurrentSourceCandidateScan();
|
|
3934
|
-
return refreshRememberedCssSourceByCurrentFile(file);
|
|
4814
|
+
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
3935
4815
|
}
|
|
3936
4816
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
3937
|
-
if (existingTask) return existingTask.then(() => refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4817
|
+
if (existingTask) return existingTask.then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
3938
4818
|
const task = sourceCandidateCollector.syncCurrentFile(id).catch((error) => {
|
|
3939
4819
|
debug("source candidate watch sync failed: %s %O", id, error);
|
|
3940
4820
|
}).then(() => {
|
|
@@ -3945,142 +4825,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3945
4825
|
});
|
|
3946
4826
|
pendingSourceCandidateSyncs.add(task);
|
|
3947
4827
|
pendingSourceCandidateSyncByFile.set(file, task);
|
|
3948
|
-
return task.then(() => refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
3949
|
-
};
|
|
3950
|
-
const shouldCollectTransformedSourceCandidates = (id) => {
|
|
3951
|
-
if (id.search(/[?#]/) < 0) return true;
|
|
3952
|
-
const file = cleanUrl(id);
|
|
3953
|
-
return !SFC_COMPONENT_FILE_RE.test(file);
|
|
3954
|
-
};
|
|
3955
|
-
const hasSfcStyleBlocks = (source) => {
|
|
3956
|
-
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
3957
|
-
return SFC_STYLE_BLOCK_RE.test(source);
|
|
3958
|
-
};
|
|
3959
|
-
const normalizeKnownSfcSourceKey = (file) => normalizeOutputPathKey(path.resolve(cleanUrl(file)));
|
|
3960
|
-
const rememberKnownSfcSource = (id, code) => {
|
|
3961
|
-
if (id.search(/[?#]/) >= 0) return;
|
|
3962
|
-
const file = cleanUrl(id);
|
|
3963
|
-
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
3964
|
-
if (!hasSfcStyleBlocks(code)) return;
|
|
3965
|
-
touchMapEntry(knownSfcSources, normalizeKnownSfcSourceKey(file), code);
|
|
3966
|
-
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
3967
|
-
};
|
|
3968
|
-
const getKnownSfcSource = (file) => {
|
|
3969
|
-
const scanSource = sourceCandidateCollector.source(file);
|
|
3970
|
-
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
3971
|
-
const key = normalizeKnownSfcSourceKey(file);
|
|
3972
|
-
const source = knownSfcSources.get(key);
|
|
3973
|
-
if (source != null) touchMapEntry(knownSfcSources, key, source);
|
|
3974
|
-
return source;
|
|
3975
|
-
};
|
|
3976
|
-
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3977
|
-
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
3978
|
-
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
3979
|
-
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3980
|
-
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
3981
|
-
const previous = rememberedCssSources.get(key);
|
|
3982
|
-
touchMapEntry(rememberedCssSources, key, entry);
|
|
3983
|
-
for (const [rememberedKey, remembered] of rememberedCssSources) {
|
|
3984
|
-
if (rememberedKey === key || normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
|
|
3985
|
-
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
3986
|
-
...remembered,
|
|
3987
|
-
rawSource: entry.rawSource,
|
|
3988
|
-
sourceFile: entry.sourceFile
|
|
3989
|
-
});
|
|
3990
|
-
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
3991
|
-
}
|
|
3992
|
-
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
3993
|
-
else if (previous?.rawSource !== entry.rawSource || previous?.sourceFile !== entry.sourceFile) rememberedCssSignatureByFile.delete(key);
|
|
3994
|
-
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
3995
|
-
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
3996
|
-
});
|
|
3997
|
-
};
|
|
3998
|
-
const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
|
|
3999
|
-
if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
|
|
4000
|
-
const nextRemembered = {
|
|
4001
|
-
...remembered,
|
|
4002
|
-
rawSource,
|
|
4003
|
-
sourceFile
|
|
4004
|
-
};
|
|
4005
|
-
touchMapEntry(rememberedCssSources, rememberedKey, nextRemembered);
|
|
4006
|
-
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
4007
|
-
return nextRemembered;
|
|
4008
|
-
};
|
|
4009
|
-
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
4010
|
-
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
4011
|
-
for (const [rememberedKey, remembered] of rememberedCssSources) {
|
|
4012
|
-
if (normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
|
|
4013
|
-
refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
4014
|
-
}
|
|
4015
|
-
};
|
|
4016
|
-
const extractSfcStyleBlock = (source, index) => {
|
|
4017
|
-
const targetIndex = index ?? 0;
|
|
4018
|
-
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
4019
|
-
let currentIndex = 0;
|
|
4020
|
-
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4021
|
-
while (match !== null) {
|
|
4022
|
-
if (currentIndex === targetIndex) return match[1] ?? "";
|
|
4023
|
-
currentIndex++;
|
|
4024
|
-
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4025
|
-
}
|
|
4026
|
-
};
|
|
4027
|
-
const extractSfcStyleSource = (source, index) => {
|
|
4028
|
-
if (index !== void 0) return extractSfcStyleBlock(source, index);
|
|
4029
|
-
const styleSources = [];
|
|
4030
|
-
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
4031
|
-
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4032
|
-
while (match !== null) {
|
|
4033
|
-
styleSources.push(match[1] ?? "");
|
|
4034
|
-
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4035
|
-
}
|
|
4036
|
-
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
4037
|
-
};
|
|
4038
|
-
const resolveCachedStyleSource = (sourceFile) => {
|
|
4039
|
-
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
4040
|
-
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
4041
|
-
if (isSourceStyleRequest(file)) return sourceCandidateCollector.source(file);
|
|
4042
|
-
};
|
|
4043
|
-
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
4044
|
-
const file = cleanUrl(sourceFile);
|
|
4045
|
-
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
4046
|
-
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
|
|
4047
|
-
if (matchedRememberedSources.length === 0) return;
|
|
4048
|
-
const source = resolveCachedStyleSource(file);
|
|
4049
|
-
if (source == null) {
|
|
4050
|
-
debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
4051
|
-
return;
|
|
4052
|
-
}
|
|
4053
|
-
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
4054
|
-
for (const remembered of matchedRememberedSources) {
|
|
4055
|
-
const { query } = parseVueRequest(remembered.sourceFile);
|
|
4056
|
-
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4057
|
-
if (styleSource !== void 0) refreshRememberedCssSourceBySourceFile(remembered.sourceFile, styleSource);
|
|
4058
|
-
}
|
|
4059
|
-
return;
|
|
4060
|
-
}
|
|
4061
|
-
if (isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
4062
|
-
};
|
|
4063
|
-
const refreshRememberedCssSource = async (remembered) => {
|
|
4064
|
-
const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
|
|
4065
|
-
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4066
|
-
if (!rememberedKey || !path.isAbsolute(file)) return;
|
|
4067
|
-
const source = resolveCachedStyleSource(file);
|
|
4068
|
-
if (source == null) {
|
|
4069
|
-
debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4070
|
-
return;
|
|
4071
|
-
}
|
|
4072
|
-
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
4073
|
-
const { query } = parseVueRequest(remembered.sourceFile);
|
|
4074
|
-
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4075
|
-
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
4076
|
-
}
|
|
4077
|
-
if (isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
4078
|
-
};
|
|
4079
|
-
const getRememberedCssSources = () => rememberedCssSources;
|
|
4080
|
-
const getRememberedCssSourceEntry = (file) => rememberedCssSources.get(normalizeOutputPathKey(file));
|
|
4081
|
-
const getRememberedCssSignature = (file) => rememberedCssSignatureByFile.get(normalizeOutputPathKey(file));
|
|
4082
|
-
const setRememberedCssSignature = (file, cssRuntimeSignature) => {
|
|
4083
|
-
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
4828
|
+
return task.then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4084
4829
|
};
|
|
4085
4830
|
const recordCssAssetResult = (file, css) => {
|
|
4086
4831
|
touchMapEntry(viteGeneratedCssByFile, normalizeVitePersistentCacheKey(file), css);
|
|
@@ -4090,7 +4835,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4090
4835
|
const previous = viteProcessedCssAssetResults.get(key);
|
|
4091
4836
|
touchMapEntry(viteProcessedCssAssetResults, key, {
|
|
4092
4837
|
css,
|
|
4093
|
-
injectIntoMain: options.injectIntoMain ?? previous?.injectIntoMain,
|
|
4838
|
+
injectIntoMain: previous?.injectIntoMain === true ? true : options.injectIntoMain ?? previous?.injectIntoMain,
|
|
4094
4839
|
outputFile: options.outputFile ?? previous?.outputFile
|
|
4095
4840
|
});
|
|
4096
4841
|
};
|
|
@@ -4099,9 +4844,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4099
4844
|
const getViteCssCacheStats = () => ({
|
|
4100
4845
|
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
4101
4846
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
4102
|
-
|
|
4103
|
-
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4104
|
-
knownSfcSources: knownSfcSources.size,
|
|
4847
|
+
...cssMemory.getStats(),
|
|
4105
4848
|
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4106
4849
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
4107
4850
|
pendingSourceCandidateSyncByFile: pendingSourceCandidateSyncByFile.size
|
|
@@ -4113,22 +4856,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4113
4856
|
const outputKey = typeof record.outputFile === "string" ? normalizeVitePersistentCacheKey(record.outputFile) : void 0;
|
|
4114
4857
|
if (!activeFiles.has(key) && (outputKey == null || !activeFiles.has(outputKey))) viteProcessedCssAssetResults.delete(key);
|
|
4115
4858
|
}
|
|
4116
|
-
|
|
4117
|
-
const outputKey = normalizeVitePersistentCacheKey(remembered.outputFile);
|
|
4118
|
-
const sourceKey = normalizeVitePersistentCacheKey(remembered.sourceFile);
|
|
4119
|
-
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
4120
|
-
rememberedCssSources.delete(key);
|
|
4121
|
-
rememberedCssSignatureByFile.delete(key);
|
|
4122
|
-
}
|
|
4123
|
-
}
|
|
4124
|
-
if (options.activeKnownSfcFiles) {
|
|
4125
|
-
const activeKnownSfcFiles = new Set([...options.activeKnownSfcFiles].map((file) => normalizeKnownSfcSourceKey(file)).filter((file) => SFC_COMPONENT_FILE_RE.test(file)));
|
|
4126
|
-
for (const key of knownSfcSources.keys()) if (!activeKnownSfcFiles.has(key)) knownSfcSources.delete(key);
|
|
4127
|
-
}
|
|
4128
|
-
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4129
|
-
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4130
|
-
});
|
|
4131
|
-
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4859
|
+
cssMemory.prune(options);
|
|
4132
4860
|
};
|
|
4133
4861
|
const normalizeViteProcessedCssFile = (file) => path.resolve(cleanUrl(file));
|
|
4134
4862
|
const markViteProcessedCssSource = (file) => {
|
|
@@ -4139,44 +4867,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
4139
4867
|
tailwindRootCssModuleIds.add(id);
|
|
4140
4868
|
tailwindRootCssModuleIds.add(cleanUrl(id));
|
|
4141
4869
|
};
|
|
4142
|
-
const resolveHotTailwindCssModules = (ctx) => {
|
|
4143
|
-
const modules = [];
|
|
4144
|
-
const seenModules = /* @__PURE__ */ new Set();
|
|
4145
|
-
const collectModule = (mod) => {
|
|
4146
|
-
if (mod == null || seenModules.has(mod)) return;
|
|
4147
|
-
if (!isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
4148
|
-
seenModules.add(mod);
|
|
4149
|
-
ctx.server.moduleGraph.invalidateModule(mod);
|
|
4150
|
-
modules.push(mod);
|
|
4151
|
-
};
|
|
4152
|
-
for (const id of tailwindRootCssModuleIds) {
|
|
4153
|
-
const candidates = [
|
|
4154
|
-
ctx.server.moduleGraph.getModuleById(id),
|
|
4155
|
-
ctx.server.moduleGraph.getModuleById(cleanUrl(id)),
|
|
4156
|
-
...ctx.server.moduleGraph.getModulesByFile(id) ?? [],
|
|
4157
|
-
...ctx.server.moduleGraph.getModulesByFile(cleanUrl(id)) ?? []
|
|
4158
|
-
];
|
|
4159
|
-
for (const mod of candidates) collectModule(mod);
|
|
4160
|
-
}
|
|
4161
|
-
return modules;
|
|
4162
|
-
};
|
|
4163
|
-
const resolveModuleHotUrl = (mod) => {
|
|
4164
|
-
if (typeof mod.url === "string" && mod.url.length > 0) return mod.url;
|
|
4165
|
-
if (typeof mod.id === "string" && mod.id.startsWith("/")) return mod.id;
|
|
4166
|
-
};
|
|
4167
|
-
const includesHotModule = (modules, target) => {
|
|
4168
|
-
const targetUrl = resolveModuleHotUrl(target);
|
|
4169
|
-
const targetId = target.id;
|
|
4170
|
-
return modules.some((mod) => {
|
|
4171
|
-
if (mod === target) return true;
|
|
4172
|
-
return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId;
|
|
4173
|
-
});
|
|
4174
|
-
};
|
|
4175
|
-
const hasSelfAcceptingNonStyleHotModule = (modules) => {
|
|
4176
|
-
return modules.some((mod) => {
|
|
4177
|
-
return !isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
4178
|
-
});
|
|
4179
|
-
};
|
|
4180
4870
|
const isUniViteProject = () => {
|
|
4181
4871
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
4182
4872
|
};
|
|
@@ -4184,34 +4874,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
4184
4874
|
if (resolveUniUtsPlatform().isAppHarmony) return true;
|
|
4185
4875
|
return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
|
|
4186
4876
|
};
|
|
4187
|
-
const sendSupplementalCssHotUpdates = (ctx, cssModules) => {
|
|
4188
|
-
const updates = cssModules.filter((mod) => !includesHotModule(ctx.modules, mod)).map((mod) => {
|
|
4189
|
-
const hotUrl = resolveModuleHotUrl(mod);
|
|
4190
|
-
if (!hotUrl) return;
|
|
4191
|
-
return {
|
|
4192
|
-
type: "js-update",
|
|
4193
|
-
timestamp: ctx.timestamp,
|
|
4194
|
-
path: hotUrl,
|
|
4195
|
-
acceptedPath: hotUrl,
|
|
4196
|
-
explicitImportRequired: false,
|
|
4197
|
-
isWithinCircularImport: false
|
|
4198
|
-
};
|
|
4199
|
-
}).filter((update) => update !== void 0);
|
|
4200
|
-
if (updates.length === 0) return;
|
|
4201
|
-
queueMicrotask(() => {
|
|
4202
|
-
ctx.server.ws?.send?.({
|
|
4203
|
-
type: "update",
|
|
4204
|
-
updates
|
|
4205
|
-
});
|
|
4206
|
-
});
|
|
4207
|
-
};
|
|
4208
|
-
const sendFullReloadForUnresolvedHotUpdate = (ctx) => {
|
|
4209
|
-
ctx.server.ws?.send?.({
|
|
4210
|
-
type: "full-reload",
|
|
4211
|
-
path: "*",
|
|
4212
|
-
triggeredBy: ctx.file
|
|
4213
|
-
});
|
|
4214
|
-
};
|
|
4215
4877
|
const matchesViteProcessedCssSource = (candidate) => {
|
|
4216
4878
|
const normalized = normalizeViteProcessedCssFile(candidate);
|
|
4217
4879
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
@@ -4229,7 +4891,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
4229
4891
|
mainCssChunkMatcher,
|
|
4230
4892
|
getMajorVersion: () => runtimeState.twPatcher.majorVersion,
|
|
4231
4893
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
4232
|
-
getExtraOptions: () =>
|
|
4894
|
+
getExtraOptions: (file) => ({
|
|
4895
|
+
...resolveViteCssHandlerExtraOptions(file),
|
|
4896
|
+
...resolveUniAppXNativeCssHandlerOptions(opts)
|
|
4897
|
+
})
|
|
4233
4898
|
});
|
|
4234
4899
|
const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
|
|
4235
4900
|
if (!shouldOwnTailwindGeneration) return;
|
|
@@ -4239,15 +4904,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
4239
4904
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4240
4905
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4241
4906
|
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4242
|
-
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
4907
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
4243
4908
|
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, generatorOptions.target === "web", isNativeAppStyleTarget, sourceRoot);
|
|
4244
4909
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4245
4910
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4246
4911
|
const cssHandlerOptions = {
|
|
4247
4912
|
...transformCssHandlerOptions.getCssHandlerOptions(file),
|
|
4248
|
-
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
4913
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
4249
4914
|
};
|
|
4250
|
-
const
|
|
4915
|
+
const transientCssSource = transientAutoCssSources.get(file);
|
|
4916
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(code));
|
|
4251
4917
|
const generated = await generateCssByGenerator({
|
|
4252
4918
|
opts,
|
|
4253
4919
|
runtimeState,
|
|
@@ -4256,6 +4922,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4256
4922
|
file,
|
|
4257
4923
|
cssHandlerOptions,
|
|
4258
4924
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
4925
|
+
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
4259
4926
|
getSourceCandidatesForEntries,
|
|
4260
4927
|
styleHandler,
|
|
4261
4928
|
debug,
|
|
@@ -4269,7 +4936,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4269
4936
|
});
|
|
4270
4937
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
4271
4938
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
4272
|
-
const shouldInjectGeneratedCssIntoMain =
|
|
4939
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }) && !normalizeOutputPathKey(outputFile).includes("/");
|
|
4273
4940
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
4274
4941
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
4275
4942
|
outputFile
|
|
@@ -4286,7 +4953,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4286
4953
|
markViteProcessedCssSource(file);
|
|
4287
4954
|
rememberTailwindRootCssModule(id);
|
|
4288
4955
|
recordGeneratorCandidates(runtime);
|
|
4289
|
-
rememberCssSource({
|
|
4956
|
+
cssMemory.rememberCssSource({
|
|
4290
4957
|
outputFile,
|
|
4291
4958
|
rawSource: code,
|
|
4292
4959
|
sourceFile: id
|
|
@@ -4299,7 +4966,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4299
4966
|
generateTailwindCss: generateTailwindCssForVitePipeline,
|
|
4300
4967
|
rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
|
|
4301
4968
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
4302
|
-
onCssSourceTransform: (id, code) => refreshRememberedCssSourceBySourceFile(id, code),
|
|
4969
|
+
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
4303
4970
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
4304
4971
|
shouldOwnTailwindGeneration,
|
|
4305
4972
|
shouldRewrite: shouldRewriteCssImports,
|
|
@@ -4321,15 +4988,17 @@ function WeappTailwindcss(options = {}) {
|
|
|
4321
4988
|
getViteProcessedCssAssetResults,
|
|
4322
4989
|
getViteProcessedCssAssetResult,
|
|
4323
4990
|
getSourceCandidates,
|
|
4991
|
+
getSourceCandidateSource: (file) => sourceCandidateCollector.source(file),
|
|
4992
|
+
getSourceCandidateSources: () => sourceCandidateCollector.sources(),
|
|
4324
4993
|
getSourceCandidatesForEntries,
|
|
4325
4994
|
getSourceCandidateSourcesForEntries,
|
|
4326
4995
|
waitForSourceCandidateSyncs,
|
|
4327
|
-
rememberCssSource,
|
|
4328
|
-
refreshRememberedCssSource,
|
|
4329
|
-
getRememberedCssSources,
|
|
4330
|
-
getRememberedCssSignature,
|
|
4331
|
-
setRememberedCssSignature,
|
|
4332
|
-
getKnownSfcSource,
|
|
4996
|
+
rememberCssSource: cssMemory.rememberCssSource,
|
|
4997
|
+
refreshRememberedCssSource: cssMemory.refreshRememberedCssSource,
|
|
4998
|
+
getRememberedCssSources: cssMemory.getRememberedCssSources,
|
|
4999
|
+
getRememberedCssSignature: cssMemory.getRememberedCssSignature,
|
|
5000
|
+
setRememberedCssSignature: cssMemory.setRememberedCssSignature,
|
|
5001
|
+
getKnownSfcSource: cssMemory.getKnownSfcSource,
|
|
4333
5002
|
recordGeneratorCandidates,
|
|
4334
5003
|
pruneViteCssCaches,
|
|
4335
5004
|
getViteCssCacheStats,
|
|
@@ -4352,12 +5021,12 @@ function WeappTailwindcss(options = {}) {
|
|
|
4352
5021
|
getSourceCandidatesForEntries,
|
|
4353
5022
|
getSourceCandidateSourcesForEntries,
|
|
4354
5023
|
waitForSourceCandidateSyncs,
|
|
4355
|
-
rememberMainCssSource: (file, rawSource) => rememberCssSource({
|
|
5024
|
+
rememberMainCssSource: (file, rawSource) => cssMemory.rememberCssSource({
|
|
4356
5025
|
outputFile: file,
|
|
4357
5026
|
rawSource,
|
|
4358
5027
|
sourceFile: file
|
|
4359
5028
|
}),
|
|
4360
|
-
getRememberedMainCssSource: getRememberedCssSourceEntry
|
|
5029
|
+
getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
|
|
4361
5030
|
});
|
|
4362
5031
|
const isIosPlatform = resolveUniUtsPlatform().isAppIos;
|
|
4363
5032
|
const prepareTailwindGeneration = async () => {
|
|
@@ -4384,7 +5053,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4384
5053
|
name: `${vitePluginName}:source-candidates`,
|
|
4385
5054
|
enforce: "pre",
|
|
4386
5055
|
async transform(code, id) {
|
|
4387
|
-
if (shouldOwnTailwindGeneration) rememberKnownSfcSource(id, code);
|
|
5056
|
+
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, code);
|
|
4388
5057
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
|
|
4389
5058
|
return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
|
|
4390
5059
|
invalidateRecordedGeneratorCandidates();
|
|
@@ -4394,10 +5063,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
4394
5063
|
cacheCurrentSourceCandidateScan();
|
|
4395
5064
|
return;
|
|
4396
5065
|
}
|
|
4397
|
-
if (sourceScanExplicit && sourceScanEntries?.length === 0) {
|
|
4398
|
-
cacheCurrentSourceCandidateScan();
|
|
4399
|
-
return;
|
|
4400
|
-
}
|
|
4401
5066
|
await sourceCandidateCollector.merge(id, code);
|
|
4402
5067
|
cacheCurrentSourceCandidateScan();
|
|
4403
5068
|
}, { emit: false });
|
|
@@ -4419,7 +5084,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4419
5084
|
const isSourceCandidateHotUpdate = shouldOwnTailwindGeneration && isSourceCandidateRequest(ctx.file);
|
|
4420
5085
|
await syncChangedSourceCandidateFile(ctx.file);
|
|
4421
5086
|
if (isSourceCandidateHotUpdate) invalidateRecordedGeneratorCandidates();
|
|
4422
|
-
const cssModules = resolveHotTailwindCssModules(ctx);
|
|
5087
|
+
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
4423
5088
|
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && (!hasSelfAcceptingNonStyleHotModule(ctx.modules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
4424
5089
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
4425
5090
|
return [];
|