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