weapp-tailwindcss 5.0.12 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +27 -10
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +6 -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 +3 -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 +6 -23
- package/dist/bundlers/shared/generator-css/types.d.ts +15 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +37 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- 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 +9 -7
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +63 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +80 -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 +5 -2
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +30 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +3 -1
- 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 +4 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/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/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +12 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +3 -6
- package/dist/bundlers/vite/source-scan.d.ts +3 -3
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -10
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +5 -1
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +15 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +126 -439
- package/dist/cli.mjs +121 -434
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +4 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-30zNPRlI.js → context-BHxLe743.js} +484 -175
- package/dist/{precheck-CsFr1q2l.mjs → context-Mbzkek1q.mjs} +461 -159
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/{defaults-Boc26eel.js → defaults-CVcKbXBG.js} +6 -50
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-ZElj1zKc.mjs} +7 -45
- package/dist/defaults.d.ts +1 -7
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- 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/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-9rUz4Hcb.js +170 -0
- package/dist/generator-Dc4qaPmT.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-CxGZU0-v.js → gulp-B_sdP6dx.js} +80 -92
- package/dist/{gulp-BfZpaYSQ.mjs → gulp-uM36oIJs.mjs} +73 -85
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-BXMLsF4b.mjs} +1289 -909
- package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-CogqkFaF.js} +1397 -939
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +10 -20
- package/dist/presets.mjs +9 -19
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-DU2ATDhw.js → source-candidate-scan-signature-2ybpptAK.js} +262 -20
- package/dist/{bundle-state-BxMNKjBV.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +86 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
- package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-DHIYcqXT.js +1523 -0
- package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
- package/dist/{transform-CaVEBOuR.js → transform-CQVOgmzM.js} +45 -37
- package/dist/{transform-Cju08-aJ.mjs → transform-tExdt40m.mjs} +30 -22
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +8 -4
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
- package/dist/v4-engine-D4ubP7N5.js +2778 -0
- package/dist/{vite-BBGOjh9e.js → vite-CP0ylSxZ.js} +2887 -1683
- package/dist/{vite-CS5DE-HD.mjs → vite-CPO83EhA.mjs} +2753 -1548
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5741 -4396
- package/dist/weapp-tw-runtime-classset-loader.js +36 -0
- package/dist/webpack-Bsek8VhR.js +2094 -0
- package/dist/webpack-BzqhJ8yK.mjs +2082 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +11 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-Cb1Zp3Al.js +0 -92
- package/dist/generator-mvNFUvns.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-CK84uGBp.mjs +0 -556
- package/dist/tailwindcss-Clpkz1oR.js +0 -613
- package/dist/v3-engine-CQE5JJNZ.js +0 -4639
- package/dist/v3-engine-DKBaKWGL.mjs +0 -4231
- package/dist/webpack-DIWrcpRo.js +0 -1066
- package/dist/webpack-SPcri_D8.mjs +0 -1054
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -0,0 +1,2094 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
+
const require_v4_engine = require("./v4-engine-D4ubP7N5.js");
|
|
3
|
+
const require_generator = require("./generator-9rUz4Hcb.js");
|
|
4
|
+
const require_utils = require("./utils-BCa37Wqj.js");
|
|
5
|
+
const require_context = require("./context-BHxLe743.js");
|
|
6
|
+
const require_tailwindcss = require("./tailwindcss-DHIYcqXT.js");
|
|
7
|
+
const require_hmr_timing = require("./hmr-timing-CogqkFaF.js");
|
|
8
|
+
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-2ybpptAK.js");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
node_fs = require_chunk.__toESM(node_fs);
|
|
11
|
+
let node_path = require("node:path");
|
|
12
|
+
node_path = require_chunk.__toESM(node_path);
|
|
13
|
+
let node_process = require("node:process");
|
|
14
|
+
node_process = require_chunk.__toESM(node_process);
|
|
15
|
+
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
16
|
+
let node_fs_promises = require("node:fs/promises");
|
|
17
|
+
let micromatch = require("micromatch");
|
|
18
|
+
micromatch = require_chunk.__toESM(micromatch);
|
|
19
|
+
let node_module = require("node:module");
|
|
20
|
+
node_module = require_chunk.__toESM(node_module);
|
|
21
|
+
let _weapp_core_escape = require("@weapp-core/escape");
|
|
22
|
+
let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
|
|
23
|
+
//#region src/shared/tailwindcss-css-redirect.ts
|
|
24
|
+
const moduleWithMutableResolve = node_module.default;
|
|
25
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
26
|
+
function installTailwindcssCssRedirect(pkgDir) {
|
|
27
|
+
const target = node_path.default.join(pkgDir, "index.css");
|
|
28
|
+
const original = moduleWithMutableResolve._resolveFilename;
|
|
29
|
+
if (patched.has(original)) return;
|
|
30
|
+
const replacements = new Set(["tailwindcss", "tailwindcss$"]);
|
|
31
|
+
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
32
|
+
if (replacements.has(request)) return target;
|
|
33
|
+
if (request.startsWith("tailwindcss/")) return node_path.default.join(pkgDir, request.slice(12));
|
|
34
|
+
return original(request, parent, isMain, options);
|
|
35
|
+
};
|
|
36
|
+
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
37
|
+
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/shared/mpx.ts
|
|
41
|
+
const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
42
|
+
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
43
|
+
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
44
|
+
function isMpxStyleResourceQuery(query) {
|
|
45
|
+
if (typeof query !== "string") return false;
|
|
46
|
+
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
47
|
+
}
|
|
48
|
+
function isMpx(appType) {
|
|
49
|
+
return appType === "mpx";
|
|
50
|
+
}
|
|
51
|
+
function getTailwindcssCssEntry(pkgDir) {
|
|
52
|
+
return node_path.default.join(pkgDir, "index.css");
|
|
53
|
+
}
|
|
54
|
+
function resolveMpxWebpackPluginDir(compiler) {
|
|
55
|
+
const candidates = [
|
|
56
|
+
compiler?.context,
|
|
57
|
+
compiler?.options?.context,
|
|
58
|
+
node_process.default.cwd()
|
|
59
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
60
|
+
for (const candidate of candidates) try {
|
|
61
|
+
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
62
|
+
return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
63
|
+
} catch {}
|
|
64
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
65
|
+
if (cachedPackageJson) return node_path.default.dirname(cachedPackageJson);
|
|
66
|
+
try {
|
|
67
|
+
return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
68
|
+
} catch {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isMpxWebpackPluginRequest(request) {
|
|
73
|
+
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
74
|
+
}
|
|
75
|
+
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
76
|
+
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
77
|
+
return node_path.default.join(mpxWebpackPluginDir, request.slice(22));
|
|
78
|
+
}
|
|
79
|
+
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
80
|
+
const recordLoader = node_path.default.join(pkgDir, "lib/record-loader");
|
|
81
|
+
const styleCompiler = node_path.default.join(pkgDir, "lib/style-compiler/index");
|
|
82
|
+
const stripConditionalLoader = node_path.default.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
83
|
+
if (Array.isArray(alias)) alias.push({
|
|
84
|
+
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
85
|
+
alias: recordLoader
|
|
86
|
+
}, {
|
|
87
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
88
|
+
alias: styleCompiler
|
|
89
|
+
}, {
|
|
90
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
91
|
+
alias: stripConditionalLoader
|
|
92
|
+
}, {
|
|
93
|
+
name: /^@mpxjs\/webpack-plugin\//,
|
|
94
|
+
alias: pkgDir
|
|
95
|
+
});
|
|
96
|
+
else {
|
|
97
|
+
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
98
|
+
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
99
|
+
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
100
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
101
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
105
|
+
compiler.options.resolveLoader = compiler.options.resolveLoader || {};
|
|
106
|
+
const alias = compiler.options.resolveLoader.alias ?? {};
|
|
107
|
+
compiler.options.resolveLoader.alias = alias;
|
|
108
|
+
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
109
|
+
}
|
|
110
|
+
function resolveMpxWebpackPluginRequire(compiler) {
|
|
111
|
+
const candidates = [
|
|
112
|
+
compiler?.context,
|
|
113
|
+
compiler?.options?.context,
|
|
114
|
+
node_process.default.cwd()
|
|
115
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
116
|
+
for (const candidate of candidates) try {
|
|
117
|
+
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
118
|
+
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
119
|
+
return projectRequire;
|
|
120
|
+
} catch {}
|
|
121
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
122
|
+
if (cachedPackageJson) return (0, node_module.createRequire)(cachedPackageJson);
|
|
123
|
+
return localRequire;
|
|
124
|
+
}
|
|
125
|
+
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
126
|
+
if (!mpxWebpackPluginDir) return false;
|
|
127
|
+
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
128
|
+
let normalize;
|
|
129
|
+
try {
|
|
130
|
+
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
if (typeof normalize.lib !== "function") return false;
|
|
135
|
+
if (normalize.lib.__weappTwPatched) return true;
|
|
136
|
+
const wrappedLib = (file) => node_path.default.join(mpxWebpackPluginDir, "lib", file);
|
|
137
|
+
wrappedLib.__weappTwPatched = true;
|
|
138
|
+
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
139
|
+
normalize.lib = wrappedLib;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
143
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
144
|
+
compiler.options = compiler.options || {};
|
|
145
|
+
compiler.options.resolve = compiler.options.resolve || {};
|
|
146
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
147
|
+
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
148
|
+
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
149
|
+
const alias = compiler.options.resolve.alias ?? {};
|
|
150
|
+
compiler.options.resolve.alias = alias;
|
|
151
|
+
if (Array.isArray(alias)) alias.push({
|
|
152
|
+
name: "tailwindcss",
|
|
153
|
+
alias: tailwindcssCssEntry
|
|
154
|
+
}, {
|
|
155
|
+
name: "tailwindcss$",
|
|
156
|
+
alias: tailwindcssCssEntry
|
|
157
|
+
});
|
|
158
|
+
else {
|
|
159
|
+
alias.tailwindcss = tailwindcssCssEntry;
|
|
160
|
+
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
161
|
+
}
|
|
162
|
+
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
163
|
+
return tailwindcssCssEntry;
|
|
164
|
+
}
|
|
165
|
+
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
166
|
+
if (!enabled || typeof loaderContext.resolve !== "function") return;
|
|
167
|
+
const originalResolve = loaderContext.resolve;
|
|
168
|
+
if (originalResolve.__weappTwPatched) return;
|
|
169
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
170
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
171
|
+
const wrappedResolve = function(context, request, callback) {
|
|
172
|
+
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
173
|
+
if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
|
|
174
|
+
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
175
|
+
return originalResolve.call(this, context, request, callback);
|
|
176
|
+
};
|
|
177
|
+
wrappedResolve.__weappTwPatched = true;
|
|
178
|
+
loaderContext.resolve = wrappedResolve;
|
|
179
|
+
}
|
|
180
|
+
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
181
|
+
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
182
|
+
}
|
|
183
|
+
const CSS_EXT_RE = /\.css$/i;
|
|
184
|
+
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
185
|
+
var _compiler$options;
|
|
186
|
+
if (!loader) return;
|
|
187
|
+
const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
|
|
188
|
+
moduleOptions.rules = moduleOptions.rules || [];
|
|
189
|
+
const createRule = (match) => ({
|
|
190
|
+
...match,
|
|
191
|
+
enforce: "pre",
|
|
192
|
+
use: [{
|
|
193
|
+
loader,
|
|
194
|
+
options: loaderOptions
|
|
195
|
+
}]
|
|
196
|
+
});
|
|
197
|
+
moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
|
|
198
|
+
test: CSS_EXT_RE,
|
|
199
|
+
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
|
|
204
|
+
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
|
|
205
|
+
function getCacheKey(filename) {
|
|
206
|
+
return filename;
|
|
207
|
+
}
|
|
208
|
+
function stripResourceQuery(resource) {
|
|
209
|
+
if (typeof resource !== "string") return resource;
|
|
210
|
+
return require_source_candidate_scan_signature.stripRequestQuery(resource);
|
|
211
|
+
}
|
|
212
|
+
function isCssLikeModuleResource(resource, cssMatcher, appType) {
|
|
213
|
+
if (typeof resource !== "string") return false;
|
|
214
|
+
const normalizedResource = stripResourceQuery(resource);
|
|
215
|
+
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
216
|
+
if (require_source_candidate_scan_signature.isSourceStyleRequest(resource)) return true;
|
|
217
|
+
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
function hasLoaderEntry(entries, target) {
|
|
221
|
+
if (!target) return false;
|
|
222
|
+
return entries.some((entry) => entry.loader?.includes?.(target));
|
|
223
|
+
}
|
|
224
|
+
function normalizeWatchPath(file) {
|
|
225
|
+
return node_path.default.resolve(file);
|
|
226
|
+
}
|
|
227
|
+
function isFileInContext(file, context) {
|
|
228
|
+
const relative = node_path.default.relative(normalizeWatchPath(context), normalizeWatchPath(file));
|
|
229
|
+
return relative.length > 0 && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
230
|
+
}
|
|
231
|
+
function toChunkFiles(files) {
|
|
232
|
+
if (!files) return [];
|
|
233
|
+
if (Array.isArray(files)) return files;
|
|
234
|
+
return [...files];
|
|
235
|
+
}
|
|
236
|
+
function inferWebpackMainCssFiles(chunks, cssMatcher, options = {}) {
|
|
237
|
+
const mainCssFiles = /* @__PURE__ */ new Set();
|
|
238
|
+
const shouldCheckSourceResources = Boolean(options.mainSourceFiles?.size);
|
|
239
|
+
for (const chunk of chunks) {
|
|
240
|
+
const files = toChunkFiles(chunk.files);
|
|
241
|
+
if (!(chunk.hasRuntime?.() === true)) continue;
|
|
242
|
+
for (const file of files) {
|
|
243
|
+
if (!cssMatcher(file)) continue;
|
|
244
|
+
if (shouldCheckSourceResources) {
|
|
245
|
+
const resources = options.resourcesByAsset?.get(file);
|
|
246
|
+
if (!resources || ![...resources].some((resource) => options.mainSourceFiles?.has(resource))) continue;
|
|
247
|
+
}
|
|
248
|
+
mainCssFiles.add(file);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return mainCssFiles;
|
|
252
|
+
}
|
|
253
|
+
function resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAssetResourceFiles) {
|
|
254
|
+
const activeAssetResourceMatches = [...assetResources ?? []].map((sourceFile) => node_path.default.resolve(sourceFile)).filter((sourceFile) => activeWebpackAssetResourceFiles.has(sourceFile)).sort();
|
|
255
|
+
return activeAssetResourceMatches.length === 1 ? activeAssetResourceMatches[0] : void 0;
|
|
256
|
+
}
|
|
257
|
+
function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
|
|
258
|
+
const resourcesByAsset = /* @__PURE__ */ new Map();
|
|
259
|
+
if (!chunkGraph?.getChunkModulesIterable) return resourcesByAsset;
|
|
260
|
+
const collectModuleResources = (module, resources, seen = /* @__PURE__ */ new Set()) => {
|
|
261
|
+
if (!module || seen.has(module)) return;
|
|
262
|
+
seen.add(module);
|
|
263
|
+
for (const candidate of [
|
|
264
|
+
module.resource,
|
|
265
|
+
module.request,
|
|
266
|
+
module.userRequest
|
|
267
|
+
]) {
|
|
268
|
+
if (typeof candidate !== "string") continue;
|
|
269
|
+
const normalized = normalizeResource(candidate, module);
|
|
270
|
+
if (normalized) resources.add(normalized);
|
|
271
|
+
}
|
|
272
|
+
for (const nested of [module.rootModule, chunkGraph.getIssuer?.(module)]) if (nested) collectModuleResources(nested, resources, seen);
|
|
273
|
+
for (const nested of module.modules ?? []) collectModuleResources(nested, resources, seen);
|
|
274
|
+
for (const dependency of module.dependencies ?? []) {
|
|
275
|
+
const dependencyLike = dependency;
|
|
276
|
+
for (const candidate of [dependencyLike.request, dependencyLike.userRequest]) {
|
|
277
|
+
if (typeof candidate !== "string") continue;
|
|
278
|
+
const normalized = normalizeResource(candidate, module);
|
|
279
|
+
if (normalized) resources.add(normalized);
|
|
280
|
+
}
|
|
281
|
+
const dependencyModule = chunkGraph.getModule?.(dependency);
|
|
282
|
+
if (dependencyModule) collectModuleResources(dependencyModule, resources, seen);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
for (const chunk of chunks) {
|
|
286
|
+
const cssFiles = toChunkFiles(chunk.files).filter((file) => cssMatcher(file));
|
|
287
|
+
if (cssFiles.length === 0) continue;
|
|
288
|
+
const modules = chunkGraph.getChunkModulesIterable(chunk);
|
|
289
|
+
if (!modules) continue;
|
|
290
|
+
const cssResources = /* @__PURE__ */ new Set();
|
|
291
|
+
for (const module of modules) collectModuleResources(module, cssResources);
|
|
292
|
+
if (cssResources.size === 0) continue;
|
|
293
|
+
for (const cssFile of cssFiles) resourcesByAsset.set(cssFile, cssResources);
|
|
294
|
+
}
|
|
295
|
+
return resourcesByAsset;
|
|
296
|
+
}
|
|
297
|
+
function createAssetHashByChunkMap(chunks) {
|
|
298
|
+
const partsByFile = /* @__PURE__ */ new Map();
|
|
299
|
+
for (const chunk of chunks) {
|
|
300
|
+
const hash = typeof chunk.hash === "string" ? chunk.hash : void 0;
|
|
301
|
+
if (!hash) continue;
|
|
302
|
+
const chunkId = String(chunk.id ?? chunk.name ?? "");
|
|
303
|
+
for (const file of toChunkFiles(chunk.files)) {
|
|
304
|
+
if (!file) continue;
|
|
305
|
+
let parts = partsByFile.get(file);
|
|
306
|
+
if (!parts) {
|
|
307
|
+
parts = [];
|
|
308
|
+
partsByFile.set(file, parts);
|
|
309
|
+
}
|
|
310
|
+
parts.push(`${chunkId}:${hash}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const hashByFile = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const [file, parts] of partsByFile.entries()) hashByFile.set(file, parts.sort().join("|"));
|
|
315
|
+
return hashByFile;
|
|
316
|
+
}
|
|
317
|
+
function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
|
|
318
|
+
return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
|
|
319
|
+
}
|
|
320
|
+
function isWatchFileInRuntimeDependencies(file, dependencies) {
|
|
321
|
+
const normalizedFile = normalizeWatchPath(file);
|
|
322
|
+
for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
|
|
323
|
+
for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/bundlers/webpack/shared/css-loader-runtime.ts
|
|
328
|
+
function isWebpackCssLoaderRuntimeSource(source) {
|
|
329
|
+
return source.includes("___CSS_LOADER_EXPORT___") && source.includes("___CSS_LOADER_API_IMPORT___") && source.includes("module.exports = ___CSS_LOADER_EXPORT___");
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
|
|
333
|
+
function createChangedByType() {
|
|
334
|
+
return {
|
|
335
|
+
html: /* @__PURE__ */ new Set(),
|
|
336
|
+
js: /* @__PURE__ */ new Set(),
|
|
337
|
+
css: /* @__PURE__ */ new Set(),
|
|
338
|
+
other: /* @__PURE__ */ new Set()
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function createProcessFiles() {
|
|
342
|
+
return {
|
|
343
|
+
html: /* @__PURE__ */ new Set(),
|
|
344
|
+
js: /* @__PURE__ */ new Set(),
|
|
345
|
+
css: /* @__PURE__ */ new Set()
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function markProcessFile(type, file, processFiles) {
|
|
349
|
+
if (type === "html" || type === "js" || type === "css") processFiles[type].add(file);
|
|
350
|
+
}
|
|
351
|
+
function buildWebpackBundleSnapshot(assets, opts, state, compilation) {
|
|
352
|
+
const sourceHashByFile = /* @__PURE__ */ new Map();
|
|
353
|
+
const runtimeAffectingSignatureByFile = /* @__PURE__ */ new Map();
|
|
354
|
+
const runtimeAffectingHashByFile = /* @__PURE__ */ new Map();
|
|
355
|
+
const changedByType = createChangedByType();
|
|
356
|
+
const runtimeAffectingChangedByType = createChangedByType();
|
|
357
|
+
const processFiles = createProcessFiles();
|
|
358
|
+
const entries = [];
|
|
359
|
+
const firstRun = state.iteration === 0 && state.sourceHashByFile.size === 0;
|
|
360
|
+
for (const [file, asset] of Object.entries(assets)) {
|
|
361
|
+
const type = require_source_candidate_scan_signature.classifyBundleEntry(file, opts);
|
|
362
|
+
if (type !== "html" && type !== "js") continue;
|
|
363
|
+
const source = stringifyWebpackSource(compilation?.getAsset(file)?.source.source() ?? asset.source());
|
|
364
|
+
const hash = opts.cache.computeHash(source);
|
|
365
|
+
sourceHashByFile.set(file, hash);
|
|
366
|
+
const previousHash = state.sourceHashByFile.get(file);
|
|
367
|
+
const changed = previousHash == null || previousHash !== hash;
|
|
368
|
+
const previousRuntimeAffectingHash = state.runtimeAffectingHashByFile.get(file);
|
|
369
|
+
const runtimeAffectingHash = !changed && previousRuntimeAffectingHash != null ? previousRuntimeAffectingHash : (() => {
|
|
370
|
+
const runtimeAffectingSignature = require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(source, type);
|
|
371
|
+
runtimeAffectingSignatureByFile.set(file, runtimeAffectingSignature);
|
|
372
|
+
return opts.cache.computeHash(runtimeAffectingSignature);
|
|
373
|
+
})();
|
|
374
|
+
runtimeAffectingHashByFile.set(file, runtimeAffectingHash);
|
|
375
|
+
if (changed) changedByType[type].add(file);
|
|
376
|
+
if (previousRuntimeAffectingHash == null || previousRuntimeAffectingHash !== runtimeAffectingHash) runtimeAffectingChangedByType[type].add(file);
|
|
377
|
+
if (firstRun) markProcessFile(type, file, processFiles);
|
|
378
|
+
else if (type === "html") processFiles.html.add(file);
|
|
379
|
+
else if (changed) processFiles.js.add(file);
|
|
380
|
+
entries.push({
|
|
381
|
+
file,
|
|
382
|
+
output: {
|
|
383
|
+
fileName: file,
|
|
384
|
+
source,
|
|
385
|
+
type: "asset"
|
|
386
|
+
},
|
|
387
|
+
source,
|
|
388
|
+
type
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
entries,
|
|
393
|
+
jsEntries: /* @__PURE__ */ new Map(),
|
|
394
|
+
sourceHashByFile,
|
|
395
|
+
runtimeAffectingSignatureByFile,
|
|
396
|
+
runtimeAffectingHashByFile,
|
|
397
|
+
hasOmittedKnownFiles: false,
|
|
398
|
+
changedByType,
|
|
399
|
+
runtimeAffectingChangedByType,
|
|
400
|
+
processFiles,
|
|
401
|
+
linkedImpactsByEntry: /* @__PURE__ */ new Map()
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function releaseWebpackBundleSnapshotSources(snapshot) {
|
|
405
|
+
for (const entry of snapshot.entries) {
|
|
406
|
+
entry.source = "";
|
|
407
|
+
entry.output.source = "";
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function stringifyWebpackSource(source) {
|
|
411
|
+
if (typeof source === "string") return source;
|
|
412
|
+
return source?.toString() ?? "";
|
|
413
|
+
}
|
|
414
|
+
function createWebpackAssetUpdater(options) {
|
|
415
|
+
const getCurrentAssetSource = (file) => {
|
|
416
|
+
const asset = options.compilation.getAsset(file);
|
|
417
|
+
if (!asset) return;
|
|
418
|
+
return stringifyWebpackSource(asset.source.source());
|
|
419
|
+
};
|
|
420
|
+
const updateAssetIfChanged = (file, source, { compare = true, notifyUpdate = true } = {}) => {
|
|
421
|
+
if (!compare) {
|
|
422
|
+
options.compilation.updateAsset(file, typeof source === "string" ? new options.ConcatSource(source) : source);
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
const nextSource = typeof source === "string" ? source : stringifyWebpackSource(source.source());
|
|
426
|
+
const previousSource = getCurrentAssetSource(file);
|
|
427
|
+
if (previousSource === nextSource) {
|
|
428
|
+
options.debug("asset unchanged, skip update: %s", file);
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
options.compilation.updateAsset(file, typeof source === "string" ? new options.ConcatSource(source) : source);
|
|
432
|
+
if (notifyUpdate) options.onUpdate(file, previousSource ?? "", nextSource);
|
|
433
|
+
return true;
|
|
434
|
+
};
|
|
435
|
+
return {
|
|
436
|
+
getCurrentAssetSource,
|
|
437
|
+
updateAssetIfChanged
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.ts
|
|
442
|
+
const WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX = 2;
|
|
443
|
+
function trimScanCache(cache) {
|
|
444
|
+
while (cache.size > WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX) {
|
|
445
|
+
const oldestKey = cache.keys().next().value;
|
|
446
|
+
if (oldestKey === void 0) break;
|
|
447
|
+
cache.delete(oldestKey);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function collectWebpackSourceCandidateScanRoots(root, entries, explicit) {
|
|
451
|
+
const dedupedEntries = dedupeSourceEntries(entries);
|
|
452
|
+
if (dedupedEntries?.length) return [{
|
|
453
|
+
entries: dedupedEntries,
|
|
454
|
+
explicit,
|
|
455
|
+
root
|
|
456
|
+
}];
|
|
457
|
+
if (explicit && dedupedEntries !== void 0) return [];
|
|
458
|
+
return [{
|
|
459
|
+
entries: dedupedEntries,
|
|
460
|
+
root
|
|
461
|
+
}];
|
|
462
|
+
}
|
|
463
|
+
function dedupeSourceEntries(entries) {
|
|
464
|
+
if (!entries?.length) return entries;
|
|
465
|
+
const seen = /* @__PURE__ */ new Set();
|
|
466
|
+
const nextEntries = [];
|
|
467
|
+
for (const entry of entries) {
|
|
468
|
+
const key = JSON.stringify({
|
|
469
|
+
base: node_path.default.resolve(entry.base),
|
|
470
|
+
negated: entry.negated,
|
|
471
|
+
pattern: entry.pattern
|
|
472
|
+
});
|
|
473
|
+
if (seen.has(key)) continue;
|
|
474
|
+
seen.add(key);
|
|
475
|
+
nextEntries.push(entry);
|
|
476
|
+
}
|
|
477
|
+
return nextEntries;
|
|
478
|
+
}
|
|
479
|
+
function createWebpackSourceCandidateCacheRecord(collector, sourceScan, signatureHash) {
|
|
480
|
+
return {
|
|
481
|
+
getSourceCandidatesForEntries: (entries, options) => collector.valuesForEntries(entries, options),
|
|
482
|
+
signatureHash,
|
|
483
|
+
tokenSources: collector.sourcesForEntries(sourceScan?.entries)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function compactSnapshot(snapshot) {
|
|
487
|
+
return {
|
|
488
|
+
candidatesById: [],
|
|
489
|
+
cssCandidatesById: void 0,
|
|
490
|
+
inlineExcludedCandidates: snapshot.inlineExcludedCandidates,
|
|
491
|
+
inlineIncludedCandidates: snapshot.inlineIncludedCandidates,
|
|
492
|
+
scanCandidatesById: snapshot.scanCandidatesById,
|
|
493
|
+
sourceById: void 0,
|
|
494
|
+
transformCandidatesById: void 0
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function normalizeChangedFiles(changedFiles) {
|
|
498
|
+
return new Set([...changedFiles ?? []].map((file) => require_v4_engine.resolveSourceScanPath(file)));
|
|
499
|
+
}
|
|
500
|
+
async function resolveScanFileSnapshot(file) {
|
|
501
|
+
try {
|
|
502
|
+
const stats = await (0, node_fs_promises.stat)(file);
|
|
503
|
+
const source = await (0, node_fs_promises.readFile)(file, "utf8");
|
|
504
|
+
return {
|
|
505
|
+
meta: {
|
|
506
|
+
contentHash: (0, _weapp_tailwindcss_shared_node.md5)(source),
|
|
507
|
+
mtimeMs: stats.mtimeMs,
|
|
508
|
+
size: stats.size
|
|
509
|
+
},
|
|
510
|
+
source
|
|
511
|
+
};
|
|
512
|
+
} catch (error) {
|
|
513
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") return;
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function isSameFileMeta(left, right) {
|
|
518
|
+
return left?.contentHash === right?.contentHash && left?.mtimeMs === right?.mtimeMs && left?.size === right?.size;
|
|
519
|
+
}
|
|
520
|
+
async function resolveScanFiles(roots, outDir) {
|
|
521
|
+
const files = /* @__PURE__ */ new Set();
|
|
522
|
+
await Promise.all(roots.map(async (root) => {
|
|
523
|
+
const rootFiles = await require_hmr_timing.resolveSourceCandidateScanFiles({
|
|
524
|
+
entries: root.entries,
|
|
525
|
+
explicit: root.explicit,
|
|
526
|
+
filter: require_hmr_timing.isSourceCandidateRequest,
|
|
527
|
+
outDir,
|
|
528
|
+
root: root.root
|
|
529
|
+
});
|
|
530
|
+
for (const file of rootFiles) files.add(require_v4_engine.resolveSourceScanPath(file));
|
|
531
|
+
}));
|
|
532
|
+
return files;
|
|
533
|
+
}
|
|
534
|
+
async function syncChangedScanFiles(collector, cachedScan, scanFiles, changedFiles) {
|
|
535
|
+
for (const file of cachedScan.files.keys()) {
|
|
536
|
+
if (scanFiles.has(file)) continue;
|
|
537
|
+
collector.remove(file);
|
|
538
|
+
cachedScan.files.delete(file);
|
|
539
|
+
}
|
|
540
|
+
await Promise.all([...scanFiles].map(async (file) => {
|
|
541
|
+
const nextSnapshot = await resolveScanFileSnapshot(file);
|
|
542
|
+
if (!nextSnapshot) {
|
|
543
|
+
collector.remove(file);
|
|
544
|
+
cachedScan.files.delete(file);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const previousMeta = cachedScan.files.get(file);
|
|
548
|
+
if (previousMeta && isSameFileMeta(previousMeta, nextSnapshot.meta) && !changedFiles.has(file)) return;
|
|
549
|
+
await collector.sync(file, nextSnapshot.source);
|
|
550
|
+
cachedScan.files.set(file, nextSnapshot.meta);
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
function createWebpackSourceCandidateScanCache() {
|
|
554
|
+
const scans = /* @__PURE__ */ new Map();
|
|
555
|
+
let lastHit = false;
|
|
556
|
+
let lastSignatureHash;
|
|
557
|
+
async function resolve({ changedFiles, collector, outDir, root, sourceScan, watchMode }) {
|
|
558
|
+
const explicit = sourceScan?.explicit ?? false;
|
|
559
|
+
const roots = collectWebpackSourceCandidateScanRoots(root, sourceScan?.entries, explicit);
|
|
560
|
+
const nextSignatureHash = (0, _weapp_tailwindcss_shared_node.md5)(require_source_candidate_scan_signature.createSourceCandidateScanSignature({
|
|
561
|
+
inlineCandidates: sourceScan?.inlineCandidates,
|
|
562
|
+
outDir,
|
|
563
|
+
roots,
|
|
564
|
+
scanAllSources: !explicit
|
|
565
|
+
}));
|
|
566
|
+
const scanFiles = await resolveScanFiles(roots, outDir);
|
|
567
|
+
const cachedScan = watchMode ? scans.get(nextSignatureHash) : void 0;
|
|
568
|
+
if (cachedScan) {
|
|
569
|
+
collector.restore(cachedScan.snapshot);
|
|
570
|
+
collector.syncInline(sourceScan?.inlineCandidates);
|
|
571
|
+
await syncChangedScanFiles(collector, cachedScan, scanFiles, normalizeChangedFiles(changedFiles));
|
|
572
|
+
cachedScan.snapshot = compactSnapshot(collector.snapshot());
|
|
573
|
+
lastHit = true;
|
|
574
|
+
lastSignatureHash = nextSignatureHash;
|
|
575
|
+
return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
|
|
576
|
+
}
|
|
577
|
+
collector.clearScan();
|
|
578
|
+
collector.syncInline(sourceScan?.inlineCandidates);
|
|
579
|
+
const files = /* @__PURE__ */ new Map();
|
|
580
|
+
await Promise.all([...scanFiles].map(async (file) => {
|
|
581
|
+
const nextSnapshot = await resolveScanFileSnapshot(file);
|
|
582
|
+
if (!nextSnapshot) return;
|
|
583
|
+
await collector.sync(file, nextSnapshot.source);
|
|
584
|
+
files.set(file, nextSnapshot.meta);
|
|
585
|
+
}));
|
|
586
|
+
if (watchMode) {
|
|
587
|
+
scans.set(nextSignatureHash, {
|
|
588
|
+
files,
|
|
589
|
+
snapshot: compactSnapshot(collector.snapshot())
|
|
590
|
+
});
|
|
591
|
+
trimScanCache(scans);
|
|
592
|
+
} else scans.clear();
|
|
593
|
+
lastHit = false;
|
|
594
|
+
lastSignatureHash = nextSignatureHash;
|
|
595
|
+
return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
|
|
596
|
+
}
|
|
597
|
+
function getMemoryStats() {
|
|
598
|
+
const cachedScans = [...scans.values()];
|
|
599
|
+
return {
|
|
600
|
+
entries: cachedScans.reduce((count, scan) => count + (scan.snapshot.scanCandidatesById?.length ?? scan.snapshot.candidatesById.length), 0),
|
|
601
|
+
files: cachedScans.reduce((count, scan) => count + scan.files.size, 0),
|
|
602
|
+
lastHit,
|
|
603
|
+
signatureHash: lastSignatureHash,
|
|
604
|
+
snapshots: scans.size
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
return {
|
|
608
|
+
getMemoryStats,
|
|
609
|
+
resolve
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
|
|
614
|
+
const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
|
|
615
|
+
function removeTailwindV4StandaloneHostPreflightRule(source) {
|
|
616
|
+
if (!source.includes("--theme(")) return source;
|
|
617
|
+
try {
|
|
618
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
619
|
+
let changed = false;
|
|
620
|
+
root.walkRules((rule) => {
|
|
621
|
+
if (rule.selector.trim() !== ":host") return;
|
|
622
|
+
if (!rule.nodes?.some((node) => node.type === "decl" && node.value?.includes("--theme("))) return;
|
|
623
|
+
rule.remove();
|
|
624
|
+
changed = true;
|
|
625
|
+
});
|
|
626
|
+
return changed ? root.toString() : source;
|
|
627
|
+
} catch {
|
|
628
|
+
return source;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function isRuntimeTransformCandidate(candidate) {
|
|
632
|
+
return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
|
|
633
|
+
}
|
|
634
|
+
function collectRuntimeTokenSignatureParts(source) {
|
|
635
|
+
return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
|
|
636
|
+
}
|
|
637
|
+
function hasMissingRuntimeCandidates(classSet, candidates) {
|
|
638
|
+
if (!classSet || !candidates?.size) return false;
|
|
639
|
+
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate) && !classSet.has(candidate)) return true;
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
function resolveGeneratedCssRuntimeCandidates(source, fallbackClassSet) {
|
|
643
|
+
const classSet = collectGeneratedCssRuntimeCandidates(source);
|
|
644
|
+
if (classSet.size > 0 || fallbackClassSet === void 0) return classSet;
|
|
645
|
+
return fallbackClassSet;
|
|
646
|
+
}
|
|
647
|
+
function getRuntimeClassSetSync(tailwindRuntime) {
|
|
648
|
+
if (typeof tailwindRuntime.getClassSetSync !== "function") return /* @__PURE__ */ new Set();
|
|
649
|
+
try {
|
|
650
|
+
return new Set(tailwindRuntime.getClassSetSync() ?? []);
|
|
651
|
+
} catch {
|
|
652
|
+
return /* @__PURE__ */ new Set();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function toMb(bytes) {
|
|
656
|
+
return Math.round(bytes / 1024 / 1024);
|
|
657
|
+
}
|
|
658
|
+
function pruneMapToMaxSize(map, maxSize) {
|
|
659
|
+
while (map.size > maxSize) {
|
|
660
|
+
const oldestKey = map.keys().next().value;
|
|
661
|
+
if (oldestKey === void 0) break;
|
|
662
|
+
map.delete(oldestKey);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function stripTrailingLineWhitespace(source) {
|
|
666
|
+
return source.replace(/[ \t]+$/gm, "");
|
|
667
|
+
}
|
|
668
|
+
function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
|
|
669
|
+
const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
|
|
670
|
+
for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
|
|
671
|
+
for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
|
|
672
|
+
pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
673
|
+
pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
674
|
+
}
|
|
675
|
+
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
676
|
+
const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
|
|
677
|
+
if (sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
|
|
678
|
+
return rawSource;
|
|
679
|
+
}
|
|
680
|
+
function hasUsableWebpackGeneratorCssSources(cssSources) {
|
|
681
|
+
return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
|
|
682
|
+
}
|
|
683
|
+
function normalizeWebpackGeneratorCssSources(cssSources) {
|
|
684
|
+
if (!Array.isArray(cssSources)) return;
|
|
685
|
+
const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
|
|
686
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
687
|
+
}
|
|
688
|
+
function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource, options = {}) {
|
|
689
|
+
return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(rawSource) && /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(rawSource) && (!require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
|
|
690
|
+
}
|
|
691
|
+
function collectWebpackAssetUserCssMarkers(source) {
|
|
692
|
+
const markers = /* @__PURE__ */ new Set();
|
|
693
|
+
for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
694
|
+
for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
|
|
695
|
+
return markers;
|
|
696
|
+
}
|
|
697
|
+
function collectWebpackCssRuleIdentityMarkers(source) {
|
|
698
|
+
const markers = /* @__PURE__ */ new Set();
|
|
699
|
+
try {
|
|
700
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
701
|
+
root.walkRules((rule) => {
|
|
702
|
+
for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
703
|
+
});
|
|
704
|
+
root.walkAtRules("keyframes", (rule) => {
|
|
705
|
+
if (rule.params) markers.add(`keyframes:${rule.params}`);
|
|
706
|
+
});
|
|
707
|
+
} catch {}
|
|
708
|
+
return markers;
|
|
709
|
+
}
|
|
710
|
+
function unescapeCssIdentifier(value) {
|
|
711
|
+
return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
|
|
712
|
+
const hex = escaped.trim();
|
|
713
|
+
if (/^[0-9a-f]+$/i.test(hex)) {
|
|
714
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
715
|
+
if (Number.isFinite(codePoint)) return String.fromCodePoint(codePoint);
|
|
716
|
+
}
|
|
717
|
+
return escaped;
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
function collectGeneratedCssRuntimeCandidates(source) {
|
|
721
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
722
|
+
if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) || !require_v4_engine.hasTailwindGeneratedCss(source) && !require_v4_engine.hasTailwindGeneratedCssMarkers(source)) return candidates;
|
|
723
|
+
try {
|
|
724
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
725
|
+
for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
|
|
726
|
+
const candidate = unescapeCssIdentifier(match[1] ?? "");
|
|
727
|
+
if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
} catch {}
|
|
731
|
+
return candidates;
|
|
732
|
+
}
|
|
733
|
+
function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
|
|
734
|
+
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
|
|
735
|
+
if (rawMarkers.size === 0) return false;
|
|
736
|
+
const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
|
|
737
|
+
for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
function hasWebpackTailwindSourceDirectives(source) {
|
|
741
|
+
return Boolean(source) && (require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source) || require_v4_engine.hasTailwindGeneratedCss(source) || require_v4_engine.hasTailwindGeneratedCssMarkers(source));
|
|
742
|
+
}
|
|
743
|
+
function isWebpackTailwindImportRequest(request) {
|
|
744
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
745
|
+
}
|
|
746
|
+
function removeWebpackGeneratorNonTailwindImports(source) {
|
|
747
|
+
if (!source?.includes("@import")) return source;
|
|
748
|
+
try {
|
|
749
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
750
|
+
let changed = false;
|
|
751
|
+
root.walkAtRules("import", (rule) => {
|
|
752
|
+
if (isWebpackTailwindImportRequest(require_v4_engine.parseImportRequest(rule.params))) return;
|
|
753
|
+
rule.remove();
|
|
754
|
+
changed = true;
|
|
755
|
+
});
|
|
756
|
+
return changed ? root.toString() : source;
|
|
757
|
+
} catch {
|
|
758
|
+
return source;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function isWebpackCssSourceRepresentedInAsset(rawSource, sourceCss) {
|
|
762
|
+
if (!sourceCss || !hasWebpackTailwindSourceDirectives(sourceCss)) return false;
|
|
763
|
+
const sourceMarkers = collectWebpackCssRuleIdentityMarkers(sourceCss);
|
|
764
|
+
if (sourceMarkers.size === 0) return false;
|
|
765
|
+
const rawMarkers = collectWebpackCssRuleIdentityMarkers(rawSource);
|
|
766
|
+
for (const marker of sourceMarkers) if (!rawMarkers.has(marker)) return false;
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
function createWebpackGeneratorCssSource(file, css) {
|
|
770
|
+
if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
|
|
771
|
+
return {
|
|
772
|
+
file,
|
|
773
|
+
base: node_path.default.dirname(file),
|
|
774
|
+
css,
|
|
775
|
+
dependencies: [file]
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
|
|
779
|
+
const matchedSources = [];
|
|
780
|
+
const seen = /* @__PURE__ */ new Set();
|
|
781
|
+
for (const source of sources) {
|
|
782
|
+
const css = source.css;
|
|
783
|
+
if (!css || seen.has(css)) continue;
|
|
784
|
+
if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
|
|
785
|
+
seen.add(css);
|
|
786
|
+
if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
|
|
787
|
+
css,
|
|
788
|
+
file: source.file,
|
|
789
|
+
processed: source.processed === true
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
|
|
793
|
+
const parts = matchedSources.sort((a, b) => {
|
|
794
|
+
const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
|
|
795
|
+
if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
|
|
796
|
+
return a.file.localeCompare(b.file);
|
|
797
|
+
}).map((source) => source.css);
|
|
798
|
+
return parts.length > 0 ? {
|
|
799
|
+
css: parts.join("\n"),
|
|
800
|
+
processed: matchedSources.every((source) => source.processed)
|
|
801
|
+
} : void 0;
|
|
802
|
+
}
|
|
803
|
+
function createWebpackGeneratorUserCssSourceAppend(...sources) {
|
|
804
|
+
const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
|
|
805
|
+
if (parts.length === 0) return;
|
|
806
|
+
let css = "";
|
|
807
|
+
const usedParts = [];
|
|
808
|
+
for (const source of parts) {
|
|
809
|
+
const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, source.css) : source.css;
|
|
810
|
+
if (nextCss.trim().length === 0) continue;
|
|
811
|
+
css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
|
|
812
|
+
usedParts.push(source);
|
|
813
|
+
}
|
|
814
|
+
if (css.trim().length === 0) return;
|
|
815
|
+
return {
|
|
816
|
+
css,
|
|
817
|
+
processed: usedParts.every((source) => source.processed)
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function resolveWebpackMemoryDebugStats(context) {
|
|
821
|
+
if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
822
|
+
const memory = node_process.default.memoryUsage();
|
|
823
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
824
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
825
|
+
return {
|
|
826
|
+
phase: context.phase,
|
|
827
|
+
process: {
|
|
828
|
+
rssMb: toMb(memory.rss),
|
|
829
|
+
heapTotalMb: toMb(memory.heapTotal),
|
|
830
|
+
heapUsedMb: toMb(memory.heapUsed),
|
|
831
|
+
externalMb: toMb(memory.external),
|
|
832
|
+
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
833
|
+
},
|
|
834
|
+
assets: {
|
|
835
|
+
active: context.activeAssetFiles,
|
|
836
|
+
activeCss: context.activeCssFiles
|
|
837
|
+
},
|
|
838
|
+
processCache: {
|
|
839
|
+
instance: processCacheInstanceSize,
|
|
840
|
+
hashMap: processCacheHashMapSize,
|
|
841
|
+
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
842
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
843
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
844
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
845
|
+
pruned: true,
|
|
846
|
+
pruneSkipped: false
|
|
847
|
+
},
|
|
848
|
+
webpackCss: {
|
|
849
|
+
handlerOptions: context.cssHandlerOptionsCache.size,
|
|
850
|
+
userHandlerOptions: context.cssUserHandlerOptionsCache.size,
|
|
851
|
+
maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
|
|
852
|
+
},
|
|
853
|
+
sourceCandidateScan: context.sourceCandidateScan,
|
|
854
|
+
tailwind: { v4: require_v4_engine.getTailwindV4IncrementalGenerateCacheStats() }
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
function setupWebpackV5ProcessAssetsHook(options) {
|
|
858
|
+
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isKnownWebpackProcessedCssAsset, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, getWatchChangedFiles, runtimeClassSetManager, getWebpackCssSources, getWebpackGeneratedCssSources, pruneWebpackCssSources, prepareWebpackCssSources, debug } = options;
|
|
859
|
+
const { Compilation, sources } = compiler.webpack;
|
|
860
|
+
const { ConcatSource } = sources;
|
|
861
|
+
const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
|
|
862
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
863
|
+
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
864
|
+
const webpackSourceCandidateScanCache = createWebpackSourceCandidateScanCache();
|
|
865
|
+
const bundleBuildState = require_source_candidate_scan_signature.createBundleBuildState();
|
|
866
|
+
const bundleRuntimeClassSetManager = runtimeClassSetManager ?? require_hmr_timing.createBundleRuntimeClassSetManager();
|
|
867
|
+
const escapeFragments = require_hmr_timing.createEscapeFragments(_weapp_core_escape.MappingChars2String);
|
|
868
|
+
const processedCssAssetSkipDecisionCache = /* @__PURE__ */ new Map();
|
|
869
|
+
let webpackWatchRuntimeScanInitialized = false;
|
|
870
|
+
compiler.hooks.compilation.tap(require_context.pluginName, (compilation) => {
|
|
871
|
+
compilation.hooks.processAssets.tapPromise({
|
|
872
|
+
name: require_context.pluginName,
|
|
873
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
874
|
+
}, async (assets) => {
|
|
875
|
+
const entries = Object.entries(assets);
|
|
876
|
+
if (entries.length === 0) return;
|
|
877
|
+
const groupedEntries = require_utils.getGroupedEntries(entries, compilerOptions);
|
|
878
|
+
if (isWebGeneratorTarget && !groupedEntries.css?.length) return;
|
|
879
|
+
compilerOptions.onStart();
|
|
880
|
+
debug("start");
|
|
881
|
+
await runtimeState.readyPromise;
|
|
882
|
+
const hmrTimingStartedAt = performance.now();
|
|
883
|
+
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
884
|
+
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
885
|
+
const { updateAssetIfChanged } = createWebpackAssetUpdater({
|
|
886
|
+
compilation,
|
|
887
|
+
ConcatSource,
|
|
888
|
+
onUpdate: compilerOptions.onUpdate,
|
|
889
|
+
debug
|
|
890
|
+
});
|
|
891
|
+
const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
|
|
892
|
+
const outputDir = compilerOutputPath ? node_path.default.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? node_process.default.cwd();
|
|
893
|
+
const jsAssets = /* @__PURE__ */ new Map();
|
|
894
|
+
for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
|
|
895
|
+
const absolute = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
|
|
896
|
+
jsAssets.set(absolute, file);
|
|
897
|
+
}
|
|
898
|
+
const moduleGraphOptions = {
|
|
899
|
+
resolve(specifier, importer) {
|
|
900
|
+
return require_source_candidate_scan_signature.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
901
|
+
},
|
|
902
|
+
load: (id) => {
|
|
903
|
+
const assetName = jsAssets.get(id);
|
|
904
|
+
if (!assetName) return;
|
|
905
|
+
const asset = compilation.getAsset(assetName);
|
|
906
|
+
if (!asset) return;
|
|
907
|
+
const source = asset.source.source();
|
|
908
|
+
return typeof source === "string" ? source : source.toString();
|
|
909
|
+
},
|
|
910
|
+
filter(id) {
|
|
911
|
+
return jsAssets.has(id);
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
const applyLinkedResults = (linked) => {
|
|
915
|
+
if (!linked) return;
|
|
916
|
+
for (const [id, { code }] of Object.entries(linked)) {
|
|
917
|
+
const assetName = jsAssets.get(id);
|
|
918
|
+
if (!assetName) continue;
|
|
919
|
+
const asset = compilation.getAsset(assetName);
|
|
920
|
+
if (!asset) continue;
|
|
921
|
+
const previousSource = asset.source.source();
|
|
922
|
+
if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
|
|
923
|
+
if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
const watchMode = isWatchMode?.() === true;
|
|
927
|
+
const cssAssetResources = createWebpackCssAssetResourceMap(compilation.chunks, compilation.chunkGraph, compilerOptions.cssMatcher, (resource, issuer) => {
|
|
928
|
+
if (!isCssLikeModuleResource(resource, compilerOptions.cssMatcher, appType)) return;
|
|
929
|
+
const normalized = stripResourceQuery(resource);
|
|
930
|
+
if (!normalized) return;
|
|
931
|
+
if (node_path.default.isAbsolute(normalized)) return node_path.default.resolve(normalized);
|
|
932
|
+
const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
|
|
933
|
+
const issuerContext = issuerResource && node_path.default.isAbsolute(issuerResource) ? node_path.default.dirname(issuerResource) : issuer?.context;
|
|
934
|
+
return issuerContext ? node_path.default.resolve(issuerContext, normalized) : void 0;
|
|
935
|
+
});
|
|
936
|
+
const watchChangedFiles = new Set([...getWatchChangedFiles?.() ?? []].map((file) => node_path.default.resolve(file)));
|
|
937
|
+
const taskConcurrency = watchMode ? require_hmr_timing.resolveTaskConcurrency(1) : void 0;
|
|
938
|
+
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
939
|
+
const activeProcessHashKeys = /* @__PURE__ */ new Set();
|
|
940
|
+
const rememberProcessCacheKey = (cacheKey, hashKey = cacheKey) => {
|
|
941
|
+
activeProcessCacheKeys.add(cacheKey);
|
|
942
|
+
activeProcessHashKeys.add(hashKey);
|
|
943
|
+
};
|
|
944
|
+
const activeWebpackAssetResourceFiles = new Set([...cssAssetResources.values()].flatMap((resources) => [...resources].map((resource) => node_path.default.resolve(resource))));
|
|
945
|
+
const registeredWebpackCssSourceFiles = prepareWebpackCssSources?.(activeWebpackAssetResourceFiles) ?? /* @__PURE__ */ new Set();
|
|
946
|
+
for (const chunk of compilation.chunks) if (chunk.id) activeProcessHashKeys.add(chunk.id);
|
|
947
|
+
const cssSources = new Map([...getWebpackCssSources?.() ?? []].map(([file, source]) => [node_path.default.resolve(file), source]));
|
|
948
|
+
const generatedCssSources = new Map([...getWebpackGeneratedCssSources?.() ?? []].map(([file, source]) => [node_path.default.resolve(file), source]));
|
|
949
|
+
const hasConfiguredTailwindV4SourceRoots = () => {
|
|
950
|
+
const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
951
|
+
return (tailwindOptions?.v4?.cssEntries?.length ?? 0) > 0 || (tailwindOptions?.v4?.cssSources?.length ?? 0) > 0;
|
|
952
|
+
};
|
|
953
|
+
const configuredMainCssEntryFiles = (() => {
|
|
954
|
+
return [...require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.v4?.cssEntries ?? []].filter((file) => typeof file === "string" && file.length > 0).map((file) => node_path.default.resolve(file));
|
|
955
|
+
})();
|
|
956
|
+
const inferredMainCssFiles = inferWebpackMainCssFiles(compilation.chunks, compilerOptions.cssMatcher, {
|
|
957
|
+
mainSourceFiles: new Set(configuredMainCssEntryFiles),
|
|
958
|
+
resourcesByAsset: cssAssetResources
|
|
959
|
+
});
|
|
960
|
+
const singleConfiguredCssAsset = isWebGeneratorTarget && configuredMainCssEntryFiles.length > 0 && (groupedEntries.css?.length ?? 0) === 1 ? groupedEntries.css?.[0]?.[0] : void 0;
|
|
961
|
+
const isMainCssChunk = (file) => compilerOptions.mainCssChunkMatcher(file, appType) || inferredMainCssFiles.has(file) || file === singleConfiguredCssAsset;
|
|
962
|
+
const activeWebpackCssSourceFiles = /* @__PURE__ */ new Set();
|
|
963
|
+
const resolveConfiguredMainCssSourceFile = (file) => {
|
|
964
|
+
if (!isMainCssChunk(file)) return;
|
|
965
|
+
for (const sourceFile of configuredMainCssEntryFiles) if (cssSources.has(sourceFile)) {
|
|
966
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
967
|
+
return sourceFile;
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
const resolveWebpackCssSourceFile = (file, rawSource) => {
|
|
971
|
+
const assetResources = cssAssetResources.get(file);
|
|
972
|
+
const activeAssetResource = resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAssetResourceFiles);
|
|
973
|
+
if (cssSources.size === 0) {
|
|
974
|
+
if (activeAssetResource) {
|
|
975
|
+
activeWebpackCssSourceFiles.add(activeAssetResource);
|
|
976
|
+
return activeAssetResource;
|
|
977
|
+
}
|
|
978
|
+
if (assetResources && assetResources.size > 0) return;
|
|
979
|
+
return resolveConfiguredMainCssSourceFile(file);
|
|
980
|
+
}
|
|
981
|
+
const resourceMatches = [...assetResources ?? []].filter((sourceFile) => cssSources.has(sourceFile)).sort();
|
|
982
|
+
if (resourceMatches.length === 1) {
|
|
983
|
+
const sourceFile = resourceMatches[0];
|
|
984
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
985
|
+
return sourceFile;
|
|
986
|
+
}
|
|
987
|
+
const tailwindSourceMatches = resourceMatches.filter((sourceFile) => {
|
|
988
|
+
const sourceCss = cssSources.get(sourceFile)?.css;
|
|
989
|
+
return sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss));
|
|
990
|
+
});
|
|
991
|
+
if (tailwindSourceMatches.length === 1) {
|
|
992
|
+
const sourceFile = tailwindSourceMatches[0];
|
|
993
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
994
|
+
return sourceFile;
|
|
995
|
+
}
|
|
996
|
+
if (activeAssetResource) {
|
|
997
|
+
activeWebpackCssSourceFiles.add(activeAssetResource);
|
|
998
|
+
return activeAssetResource;
|
|
999
|
+
}
|
|
1000
|
+
if (rawSource) {
|
|
1001
|
+
const representedTailwindSourceMatches = [...cssSources.entries()].filter(([, source]) => isWebpackCssSourceRepresentedInAsset(rawSource, source.css)).map(([sourceFile]) => ({
|
|
1002
|
+
sourceFile,
|
|
1003
|
+
score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
|
|
1004
|
+
outputRoot: outputDir,
|
|
1005
|
+
projectRoot: compilerOptions.tailwindcssBasedir,
|
|
1006
|
+
cwd: compilerOptions.tailwindcssBasedir
|
|
1007
|
+
})
|
|
1008
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
|
|
1009
|
+
const bestScore = representedTailwindSourceMatches[0]?.score ?? 0;
|
|
1010
|
+
const bestMatches = representedTailwindSourceMatches.filter((match) => match.score === bestScore);
|
|
1011
|
+
if (bestMatches.length === 1) {
|
|
1012
|
+
const sourceFile = bestMatches[0]?.sourceFile;
|
|
1013
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
1014
|
+
return sourceFile;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
const pathMatches = [...cssSources.keys()].map((sourceFile) => ({
|
|
1018
|
+
sourceFile,
|
|
1019
|
+
score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
|
|
1020
|
+
outputRoot: outputDir,
|
|
1021
|
+
projectRoot: compilerOptions.tailwindcssBasedir,
|
|
1022
|
+
cwd: compilerOptions.tailwindcssBasedir
|
|
1023
|
+
})
|
|
1024
|
+
})).filter((match) => match.score >= 1e3).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
|
|
1025
|
+
const bestPathScore = pathMatches[0]?.score ?? 0;
|
|
1026
|
+
const bestPathMatches = pathMatches.filter((match) => match.score === bestPathScore);
|
|
1027
|
+
if (bestPathMatches.length === 1) {
|
|
1028
|
+
const sourceFile = bestPathMatches[0]?.sourceFile;
|
|
1029
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
1030
|
+
return sourceFile;
|
|
1031
|
+
}
|
|
1032
|
+
if (assetResources && assetResources.size > 0) return;
|
|
1033
|
+
return resolveConfiguredMainCssSourceFile(file);
|
|
1034
|
+
};
|
|
1035
|
+
const isSameWebpackSourceScope = (outputFile, candidateSourceFile, currentSourceFile) => {
|
|
1036
|
+
if (!currentSourceFile) return false;
|
|
1037
|
+
if (node_path.default.resolve(candidateSourceFile) === node_path.default.resolve(currentSourceFile)) return true;
|
|
1038
|
+
const candidateKey = node_path.default.resolve(candidateSourceFile);
|
|
1039
|
+
return cssAssetResources.get(outputFile)?.has(candidateKey) === true;
|
|
1040
|
+
};
|
|
1041
|
+
const getCssHandlerOptions = (file, rawSource) => {
|
|
1042
|
+
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
1043
|
+
const isMainChunk = isMainCssChunk(file);
|
|
1044
|
+
const sourceFile = resolveWebpackCssSourceFile(file, rawSource);
|
|
1045
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
|
|
1046
|
+
const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
|
|
1047
|
+
const generatorCssSource = createWebpackGeneratorCssSource(sourceFile, generatorSourceCss);
|
|
1048
|
+
const cacheKey = [
|
|
1049
|
+
majorVersion ?? "unknown",
|
|
1050
|
+
isMainChunk ? "1" : "0",
|
|
1051
|
+
sourceFile ?? "asset",
|
|
1052
|
+
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
1053
|
+
generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
|
|
1054
|
+
file
|
|
1055
|
+
].join(":");
|
|
1056
|
+
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
1057
|
+
if (cached) return cached;
|
|
1058
|
+
const created = {
|
|
1059
|
+
isMainChunk,
|
|
1060
|
+
postcssOptions: { options: { from: sourceFile ?? file } },
|
|
1061
|
+
sourceOptions: {
|
|
1062
|
+
outputRoot: outputDir,
|
|
1063
|
+
...generatorCssSource === void 0 ? {} : { cssSources: [generatorCssSource] },
|
|
1064
|
+
...generatorSourceCss === void 0 ? {} : { sourceCss: generatorSourceCss },
|
|
1065
|
+
...sourceFile === void 0 ? {} : { sourceFile }
|
|
1066
|
+
},
|
|
1067
|
+
...majorVersion === void 0 ? {} : { majorVersion }
|
|
1068
|
+
};
|
|
1069
|
+
cssHandlerOptionsCache.set(cacheKey, created);
|
|
1070
|
+
return created;
|
|
1071
|
+
};
|
|
1072
|
+
const getCssUserHandlerOptions = (file) => {
|
|
1073
|
+
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
1074
|
+
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
1075
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
|
|
1076
|
+
const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
|
|
1077
|
+
const cacheKey = [
|
|
1078
|
+
majorVersion ?? "unknown",
|
|
1079
|
+
sourceFile ?? "asset",
|
|
1080
|
+
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
1081
|
+
generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
|
|
1082
|
+
file
|
|
1083
|
+
].join(":");
|
|
1084
|
+
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
1085
|
+
if (cached) return cached;
|
|
1086
|
+
const created = {
|
|
1087
|
+
...getCssHandlerOptions(file),
|
|
1088
|
+
isMainChunk: false
|
|
1089
|
+
};
|
|
1090
|
+
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
1091
|
+
return created;
|
|
1092
|
+
};
|
|
1093
|
+
const refreshWebpackSourceCandidates = async () => {
|
|
1094
|
+
const root = compilerOptions.tailwindcssBasedir ?? node_process.default.cwd();
|
|
1095
|
+
let sourceScan;
|
|
1096
|
+
try {
|
|
1097
|
+
sourceScan = await require_tailwindcss.resolveViteSourceScanEntries(compilerOptions, runtimeState.tailwindRuntime, {
|
|
1098
|
+
root,
|
|
1099
|
+
outDir: outputDir
|
|
1100
|
+
});
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
debug("webpack source candidate scan skipped: %O", error);
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
return webpackSourceCandidateScanCache.resolve({
|
|
1106
|
+
changedFiles: watchChangedFiles,
|
|
1107
|
+
collector: require_hmr_timing.createSourceCandidateStore({ bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues }),
|
|
1108
|
+
outDir: outputDir,
|
|
1109
|
+
root,
|
|
1110
|
+
sourceScan,
|
|
1111
|
+
watchMode
|
|
1112
|
+
});
|
|
1113
|
+
};
|
|
1114
|
+
const finalizeCssAssetSource = (source, options = {}) => {
|
|
1115
|
+
const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
|
|
1116
|
+
if (isWebGeneratorTarget) {
|
|
1117
|
+
if (options.generatedCss === true) return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source))));
|
|
1118
|
+
return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_hmr_timing.removeTailwindV4GeneratorAtRules(require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
|
|
1119
|
+
}
|
|
1120
|
+
let finalized = require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
1121
|
+
if (isWebGeneratorTarget || options.generatedCss !== true) return isWebGeneratorTarget ? finalized : (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
1122
|
+
try {
|
|
1123
|
+
finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: true });
|
|
1124
|
+
} catch {
|
|
1125
|
+
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
|
|
1126
|
+
cssPreflight: !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? compilerOptions.cssPreflight : void 0,
|
|
1127
|
+
isTailwindcssV4: true,
|
|
1128
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
1132
|
+
};
|
|
1133
|
+
const finalizeMiniProgramUserCssAssetSource = (source, options = {}) => {
|
|
1134
|
+
const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
|
|
1135
|
+
if (isWebGeneratorTarget) return source;
|
|
1136
|
+
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_hmr_timing.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
|
|
1137
|
+
cssPreflight: options.cssPreflight !== false && !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? compilerOptions.cssPreflight : void 0,
|
|
1138
|
+
isTailwindcssV4: true,
|
|
1139
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
1140
|
+
})));
|
|
1141
|
+
};
|
|
1142
|
+
const webpackSourceCandidates = !isWebGeneratorTarget && (groupedEntries.css?.length ?? 0) > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates() : void 0;
|
|
1143
|
+
const webpackSourceCandidateValueSignature = webpackSourceCandidates ? require_source_candidate_scan_signature.createCandidateSignature(webpackSourceCandidates.getSourceCandidatesForEntries(void 0)) : "source-candidates:0";
|
|
1144
|
+
const cssSourceTraceTokenSources = require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) && webpackSourceCandidates ? require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions) : void 0;
|
|
1145
|
+
const cssSourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
|
|
1146
|
+
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
1147
|
+
opts: compilerOptions,
|
|
1148
|
+
tokenSources: cssSourceTraceTokenSources
|
|
1149
|
+
});
|
|
1150
|
+
const shouldInjectCssTracePreflight = (cssHandlerOptions) => {
|
|
1151
|
+
return compilerOptions.appType !== "mpx" || cssHandlerOptions.isMainChunk !== false;
|
|
1152
|
+
};
|
|
1153
|
+
const finalizeTracedCss = (css, cssHandlerOptions) => {
|
|
1154
|
+
const traced = annotateCss(css);
|
|
1155
|
+
if (isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(compilerOptions)) return traced;
|
|
1156
|
+
return finalizeMiniProgramUserCssAssetSource(traced, { cssPreflight: shouldInjectCssTracePreflight(cssHandlerOptions) });
|
|
1157
|
+
};
|
|
1158
|
+
const hasRuntimeTransformAssets = Boolean(!isWebGeneratorTarget && ((groupedEntries.html?.length ?? 0) > 0 || (groupedEntries.js?.length ?? 0) > 0));
|
|
1159
|
+
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
1160
|
+
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.tailwindRuntime.majorVersion ?? "unknown");
|
|
1161
|
+
let runtimeSet;
|
|
1162
|
+
let runtimeAffectingSourceHash = "runtime-affecting:0";
|
|
1163
|
+
if (isWebGeneratorTarget && !hasRuntimeTransformAssets && !forceRuntimeRefresh) runtimeSet = getRuntimeClassSetSync(runtimeState.tailwindRuntime);
|
|
1164
|
+
else if (watchMode && !forceRuntimeRefresh) {
|
|
1165
|
+
const shouldSkipInitialRuntimeBundleScan = isWebGeneratorTarget && !webpackWatchRuntimeScanInitialized;
|
|
1166
|
+
const baseRuntimeSet = getRuntimeClassSetSync(runtimeState.tailwindRuntime);
|
|
1167
|
+
const snapshot = buildWebpackBundleSnapshot(assets, compilerOptions, bundleBuildState, compilation);
|
|
1168
|
+
if (!webpackWatchRuntimeScanInitialized && !shouldSkipInitialRuntimeBundleScan) {
|
|
1169
|
+
for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
|
|
1170
|
+
}
|
|
1171
|
+
runtimeAffectingSourceHash = compilerOptions.cache.computeHash([...(groupedEntries.html ?? []).map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`), ...(groupedEntries.js ?? []).map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`)].sort().join("\n\n"));
|
|
1172
|
+
if (shouldSkipInitialRuntimeBundleScan) runtimeSet = baseRuntimeSet;
|
|
1173
|
+
else try {
|
|
1174
|
+
runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
|
|
1175
|
+
baseClassSet: baseRuntimeSet,
|
|
1176
|
+
skipInitialFullScanWithBase: false
|
|
1177
|
+
});
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1180
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1181
|
+
runtimeSet = getRuntimeClassSetSync(runtimeState.tailwindRuntime);
|
|
1182
|
+
}
|
|
1183
|
+
releaseWebpackBundleSnapshotSources(snapshot);
|
|
1184
|
+
require_source_candidate_scan_signature.updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
|
|
1185
|
+
webpackWatchRuntimeScanInitialized = true;
|
|
1186
|
+
} else {
|
|
1187
|
+
if (forceRuntimeRefresh) {
|
|
1188
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1189
|
+
webpackWatchRuntimeScanInitialized = false;
|
|
1190
|
+
}
|
|
1191
|
+
runtimeSet = await require_context.ensureRuntimeClassSet(runtimeState, {
|
|
1192
|
+
forceRefresh: forceRuntimeRefresh,
|
|
1193
|
+
forceCollect: !watchMode || forceRuntimeRefresh,
|
|
1194
|
+
clearCache: forceRuntimeRefresh,
|
|
1195
|
+
allowEmpty: false
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
1199
|
+
consumeRuntimeRefreshRequirement();
|
|
1200
|
+
const webpackSourceCandidateSet = webpackSourceCandidates?.getSourceCandidatesForEntries(void 0);
|
|
1201
|
+
const generatorRuntimeSet = new Set(runtimeSet);
|
|
1202
|
+
if (webpackSourceCandidateSet?.size) {
|
|
1203
|
+
for (const candidate of webpackSourceCandidateSet) if (isRuntimeTransformCandidate(candidate)) generatorRuntimeSet.add(candidate);
|
|
1204
|
+
}
|
|
1205
|
+
const transformRuntimeSet = new Set(runtimeSet);
|
|
1206
|
+
if (hasRuntimeTransformAssets && Array.isArray(groupedEntries.css)) for (const [, originalSource] of groupedEntries.css) for (const candidate of collectGeneratedCssRuntimeCandidates(originalSource.source().toString())) transformRuntimeSet.add(candidate);
|
|
1207
|
+
const transformedJsRuntimeCandidates = /* @__PURE__ */ new Set();
|
|
1208
|
+
let currentJsRuntimeCandidates;
|
|
1209
|
+
let currentJsRuntimeTokenSignature;
|
|
1210
|
+
const getCurrentJsRuntimeCandidates = () => {
|
|
1211
|
+
if (isWebGeneratorTarget) return;
|
|
1212
|
+
if (currentJsRuntimeCandidates) return currentJsRuntimeCandidates;
|
|
1213
|
+
currentJsRuntimeCandidates = /* @__PURE__ */ new Set();
|
|
1214
|
+
for (const file of jsAssets.values()) {
|
|
1215
|
+
const asset = compilation.getAsset(file);
|
|
1216
|
+
if (!asset) continue;
|
|
1217
|
+
const value = asset.source.source();
|
|
1218
|
+
const source = typeof value === "string" ? value : value.toString();
|
|
1219
|
+
for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, escapeFragments)) if (isRuntimeTransformCandidate(candidate)) currentJsRuntimeCandidates.add(candidate);
|
|
1220
|
+
}
|
|
1221
|
+
return currentJsRuntimeCandidates;
|
|
1222
|
+
};
|
|
1223
|
+
const getCurrentJsRuntimeTokenSignature = () => {
|
|
1224
|
+
if (currentJsRuntimeTokenSignature !== void 0) return currentJsRuntimeTokenSignature;
|
|
1225
|
+
if (isWebGeneratorTarget) {
|
|
1226
|
+
currentJsRuntimeTokenSignature = "";
|
|
1227
|
+
return currentJsRuntimeTokenSignature;
|
|
1228
|
+
}
|
|
1229
|
+
const tokens = [];
|
|
1230
|
+
for (const file of jsAssets.values()) {
|
|
1231
|
+
const asset = compilation.getAsset(file);
|
|
1232
|
+
if (!asset) continue;
|
|
1233
|
+
const value = asset.source.source();
|
|
1234
|
+
const source = typeof value === "string" ? value : value.toString();
|
|
1235
|
+
tokens.push(...collectRuntimeTokenSignatureParts(source));
|
|
1236
|
+
}
|
|
1237
|
+
currentJsRuntimeTokenSignature = tokens.sort().join("\n");
|
|
1238
|
+
return currentJsRuntimeTokenSignature;
|
|
1239
|
+
};
|
|
1240
|
+
const rememberTransformedRuntimeCandidates = (source) => {
|
|
1241
|
+
currentJsRuntimeCandidates = void 0;
|
|
1242
|
+
currentJsRuntimeTokenSignature = void 0;
|
|
1243
|
+
const value = typeof source === "string" ? source : source.source();
|
|
1244
|
+
const code = typeof value === "string" ? value : value.toString();
|
|
1245
|
+
for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(code, _weapp_core_escape.MappingChars2String, escapeFragments)) if (isRuntimeTransformCandidate(candidate)) transformedJsRuntimeCandidates.add(candidate);
|
|
1246
|
+
};
|
|
1247
|
+
const createRuntimeSetHash = (generatorRuntimeSet) => compilerOptions.cache.computeHash([
|
|
1248
|
+
require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime),
|
|
1249
|
+
[...runtimeSet].sort().join("\n"),
|
|
1250
|
+
[...transformRuntimeSet].sort().join("\n"),
|
|
1251
|
+
[...generatorRuntimeSet].sort().join("\n"),
|
|
1252
|
+
getCurrentJsRuntimeTokenSignature()
|
|
1253
|
+
].join("\n\n"));
|
|
1254
|
+
const getGeneratorRuntimeSet = () => {
|
|
1255
|
+
const currentJsCandidates = getCurrentJsRuntimeCandidates();
|
|
1256
|
+
if (transformedJsRuntimeCandidates.size === 0 && (!currentJsCandidates || currentJsCandidates.size === 0)) return generatorRuntimeSet;
|
|
1257
|
+
return new Set([
|
|
1258
|
+
...generatorRuntimeSet,
|
|
1259
|
+
...currentJsCandidates ?? [],
|
|
1260
|
+
...transformedJsRuntimeCandidates
|
|
1261
|
+
]);
|
|
1262
|
+
};
|
|
1263
|
+
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntimeSet };
|
|
1264
|
+
debug("get runtimeSet, class count: %d, transform class count: %d", runtimeSet.size, transformRuntimeSet.size);
|
|
1265
|
+
const tasks = [];
|
|
1266
|
+
const htmlTaskFactories = [];
|
|
1267
|
+
const cssTaskFactories = [];
|
|
1268
|
+
const enqueueTask = async (factory, target) => {
|
|
1269
|
+
if (watchMode) {
|
|
1270
|
+
await factory();
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
target.push(factory);
|
|
1274
|
+
};
|
|
1275
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
1276
|
+
const [file, originalSource] = element;
|
|
1277
|
+
let rawSource;
|
|
1278
|
+
const readRawSource = () => {
|
|
1279
|
+
rawSource ?? (rawSource = originalSource.source().toString());
|
|
1280
|
+
return rawSource;
|
|
1281
|
+
};
|
|
1282
|
+
const cacheKey = file;
|
|
1283
|
+
const hashKey = `${file}:asset`;
|
|
1284
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1285
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1286
|
+
await enqueueTask(async () => {
|
|
1287
|
+
await require_hmr_timing.processCachedTask({
|
|
1288
|
+
cache: compilerOptions.cache,
|
|
1289
|
+
cacheKey,
|
|
1290
|
+
hashKey,
|
|
1291
|
+
rawSource: chunkHash === void 0 ? readRawSource() : void 0,
|
|
1292
|
+
hash: chunkHash,
|
|
1293
|
+
applyResult(source, { cacheHit }) {
|
|
1294
|
+
updateAssetIfChanged(file, source, {
|
|
1295
|
+
compare: !cacheHit,
|
|
1296
|
+
notifyUpdate: !cacheHit
|
|
1297
|
+
});
|
|
1298
|
+
},
|
|
1299
|
+
onCacheHit() {
|
|
1300
|
+
debug("html cache hit: %s", file);
|
|
1301
|
+
},
|
|
1302
|
+
transform: async () => {
|
|
1303
|
+
const source = new ConcatSource(await compilerOptions.templateHandler(readRawSource(), defaultTemplateHandlerOptions));
|
|
1304
|
+
debug("html handle: %s", file);
|
|
1305
|
+
return { result: source };
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
}, htmlTaskFactories);
|
|
1309
|
+
}
|
|
1310
|
+
const jsTaskFactories = [];
|
|
1311
|
+
const enqueueJsTask = async (factory) => {
|
|
1312
|
+
await enqueueTask(factory, jsTaskFactories);
|
|
1313
|
+
};
|
|
1314
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
1315
|
+
const cacheKey = getCacheKey(file);
|
|
1316
|
+
const asset = compilation.getAsset(file);
|
|
1317
|
+
if (!asset) continue;
|
|
1318
|
+
const hashKey = `${file}:asset`;
|
|
1319
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1320
|
+
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
|
|
1321
|
+
let initialRawSource;
|
|
1322
|
+
const readInitialRawSource = () => {
|
|
1323
|
+
if (initialRawSource === void 0) {
|
|
1324
|
+
const initialSource = asset.source.source();
|
|
1325
|
+
initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
1326
|
+
}
|
|
1327
|
+
return initialRawSource;
|
|
1328
|
+
};
|
|
1329
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1330
|
+
await enqueueJsTask(async () => {
|
|
1331
|
+
await require_hmr_timing.processCachedTask({
|
|
1332
|
+
cache: compilerOptions.cache,
|
|
1333
|
+
cacheKey,
|
|
1334
|
+
hashKey,
|
|
1335
|
+
rawSource: chunkHash === void 0 ? readInitialRawSource() : void 0,
|
|
1336
|
+
hash: chunkHash,
|
|
1337
|
+
applyResult(source, { cacheHit }) {
|
|
1338
|
+
if (updateAssetIfChanged(file, source, {
|
|
1339
|
+
compare: !cacheHit,
|
|
1340
|
+
notifyUpdate: !cacheHit
|
|
1341
|
+
})) rememberTransformedRuntimeCandidates(source);
|
|
1342
|
+
},
|
|
1343
|
+
onCacheHit() {
|
|
1344
|
+
debug("js cache hit: %s", file);
|
|
1345
|
+
},
|
|
1346
|
+
transform: async () => {
|
|
1347
|
+
const currentSourceValue = compilation.getAsset(file)?.source.source();
|
|
1348
|
+
const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
|
|
1349
|
+
const handlerOptions = {
|
|
1350
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1351
|
+
generateMap: false,
|
|
1352
|
+
filename: absoluteFile,
|
|
1353
|
+
moduleGraph: moduleGraphOptions,
|
|
1354
|
+
babelParserOptions: { sourceFilename: absoluteFile }
|
|
1355
|
+
};
|
|
1356
|
+
if (require_context.shouldSkipJsTransform(currentSource, {
|
|
1357
|
+
...handlerOptions,
|
|
1358
|
+
classNameSet: transformRuntimeSet
|
|
1359
|
+
})) return { result: new ConcatSource(currentSource) };
|
|
1360
|
+
const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
|
|
1361
|
+
const source = new ConcatSource(code);
|
|
1362
|
+
debug("js handle: %s", file);
|
|
1363
|
+
applyLinkedResults(linked);
|
|
1364
|
+
return { result: source };
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
|
|
1370
|
+
const [file, originalSource] = element;
|
|
1371
|
+
let rawSource;
|
|
1372
|
+
const readRawSource = () => {
|
|
1373
|
+
rawSource ?? (rawSource = originalSource.source().toString());
|
|
1374
|
+
return rawSource;
|
|
1375
|
+
};
|
|
1376
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1377
|
+
const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file);
|
|
1378
|
+
const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
|
|
1379
|
+
const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
|
|
1380
|
+
const processedSourceCss = processedSourceFile ? cssSources.get(node_path.default.resolve(processedSourceFile))?.css : void 0;
|
|
1381
|
+
const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
|
|
1382
|
+
const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
|
|
1383
|
+
const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(node_path.default.resolve(processedSourceFile)) : void 0;
|
|
1384
|
+
const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, chunkHash === void 0 ? void 0 : "webpack-css-asset:chunk", `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`) ?? "hash:0"}`;
|
|
1385
|
+
let currentProcessedRawSource;
|
|
1386
|
+
let hasGeneratedCssMarker = false;
|
|
1387
|
+
let hasTailwindGeneratedAssetCss = false;
|
|
1388
|
+
const readCurrentProcessedRawSource = () => {
|
|
1389
|
+
currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
|
|
1390
|
+
return currentProcessedRawSource;
|
|
1391
|
+
};
|
|
1392
|
+
const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
|
|
1393
|
+
const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
|
|
1394
|
+
if (cachedSkipProcessedCssAsset !== void 0) {
|
|
1395
|
+
hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
|
|
1396
|
+
hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
|
|
1397
|
+
} else {
|
|
1398
|
+
const source = readCurrentProcessedRawSource();
|
|
1399
|
+
hasGeneratedCssMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source);
|
|
1400
|
+
hasTailwindGeneratedAssetCss = require_v4_engine.hasTailwindGeneratedCss(source) || require_v4_engine.hasTailwindGeneratedCssMarkers(source);
|
|
1401
|
+
}
|
|
1402
|
+
const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker;
|
|
1403
|
+
const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
|
|
1404
|
+
...source,
|
|
1405
|
+
file: sourceFile
|
|
1406
|
+
})), readCurrentProcessedRawSource()) !== void 0;
|
|
1407
|
+
const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && require_v4_engine.hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
|
|
1408
|
+
const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1409
|
+
const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1410
|
+
const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
|
|
1411
|
+
if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset);
|
|
1412
|
+
if (shouldSkipProcessedCssAsset) {
|
|
1413
|
+
const hashKey = `${file}:asset`;
|
|
1414
|
+
const sourceHash = chunkHash === void 0 ? compilerOptions.cache.computeHash(readCurrentProcessedRawSource()) : "webpack-css-asset:chunk";
|
|
1415
|
+
rememberProcessCacheKey(file, hashKey);
|
|
1416
|
+
await enqueueTask(async () => {
|
|
1417
|
+
await require_hmr_timing.processCachedTask({
|
|
1418
|
+
cache: compilerOptions.cache,
|
|
1419
|
+
cacheKey: file,
|
|
1420
|
+
hashKey,
|
|
1421
|
+
rawSource: chunkHash === void 0 ? readCurrentProcessedRawSource() : void 0,
|
|
1422
|
+
hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
|
|
1423
|
+
applyResult(source, { cacheHit }) {
|
|
1424
|
+
updateAssetIfChanged(file, source, {
|
|
1425
|
+
compare: !cacheHit,
|
|
1426
|
+
notifyUpdate: !cacheHit
|
|
1427
|
+
});
|
|
1428
|
+
},
|
|
1429
|
+
onCacheHit() {
|
|
1430
|
+
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
1431
|
+
},
|
|
1432
|
+
transform: async () => {
|
|
1433
|
+
const source = readCurrentProcessedRawSource();
|
|
1434
|
+
const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(hasTailwindGeneratedAssetCss && !hasGeneratedCssMarker ? isWebGeneratorTarget ? source : (await compilerOptions.styleHandler(source, cssHandlerOptionsForProcessedAsset)).css : source, { generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss }));
|
|
1435
|
+
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
1436
|
+
return { result: new ConcatSource(finalizeTracedCss(nextCss, cssHandlerOptionsForProcessedAsset)) };
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
}, cssTaskFactories);
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
const currentRawSource = readRawSource();
|
|
1443
|
+
if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
|
|
1444
|
+
const hashKey = `${file}:asset`;
|
|
1445
|
+
rememberProcessCacheKey(file, hashKey);
|
|
1446
|
+
await enqueueTask(async () => {
|
|
1447
|
+
await require_hmr_timing.processCachedTask({
|
|
1448
|
+
cache: compilerOptions.cache,
|
|
1449
|
+
cacheKey: file,
|
|
1450
|
+
hashKey,
|
|
1451
|
+
rawSource: currentRawSource,
|
|
1452
|
+
hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
|
|
1453
|
+
applyResult(source, { cacheHit }) {
|
|
1454
|
+
updateAssetIfChanged(file, source, {
|
|
1455
|
+
compare: !cacheHit,
|
|
1456
|
+
notifyUpdate: !cacheHit
|
|
1457
|
+
});
|
|
1458
|
+
},
|
|
1459
|
+
onCacheHit() {
|
|
1460
|
+
debug("css-loader runtime cache hit: %s", file);
|
|
1461
|
+
},
|
|
1462
|
+
transform: async () => ({ result: new ConcatSource(currentRawSource) })
|
|
1463
|
+
});
|
|
1464
|
+
}, cssTaskFactories);
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1467
|
+
const cacheKey = file;
|
|
1468
|
+
const hashKey = `${file}:asset`;
|
|
1469
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1470
|
+
const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
|
|
1471
|
+
const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
|
|
1472
|
+
const cssSourceHash = (() => {
|
|
1473
|
+
const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
|
|
1474
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
|
|
1475
|
+
const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
|
|
1476
|
+
if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
|
|
1477
|
+
return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
|
|
1478
|
+
})();
|
|
1479
|
+
const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
|
|
1480
|
+
await enqueueTask(async () => {
|
|
1481
|
+
await require_hmr_timing.processCachedTask({
|
|
1482
|
+
cache: compilerOptions.cache,
|
|
1483
|
+
cacheKey,
|
|
1484
|
+
hashKey,
|
|
1485
|
+
rawSource: currentRawSource,
|
|
1486
|
+
hash: runtimeAwareHash,
|
|
1487
|
+
applyResult(source, { cacheHit }) {
|
|
1488
|
+
updateAssetIfChanged(file, source, {
|
|
1489
|
+
compare: !cacheHit,
|
|
1490
|
+
notifyUpdate: !cacheHit
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
onCacheHit() {
|
|
1494
|
+
debug("css cache hit: %s", file);
|
|
1495
|
+
},
|
|
1496
|
+
transform: async () => {
|
|
1497
|
+
await runtimeState.readyPromise;
|
|
1498
|
+
const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
|
|
1499
|
+
const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
|
|
1500
|
+
if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
|
|
1501
|
+
const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
|
|
1502
|
+
const loaderGeneratedCss = sourceFile && !isWebGeneratorTarget ? generatedCssSources.get(node_path.default.resolve(sourceFile)) : void 0;
|
|
1503
|
+
const sourceCss = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css : void 0;
|
|
1504
|
+
const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
1505
|
+
if (loaderGeneratedCss && !shouldRegenerateExplicitTailwindV4CssSource) {
|
|
1506
|
+
for (const className of loaderGeneratedCss.classSet) {
|
|
1507
|
+
generatorRuntimeSet.add(className);
|
|
1508
|
+
transformRuntimeSet.add(className);
|
|
1509
|
+
}
|
|
1510
|
+
for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
|
|
1511
|
+
const css = finalizeTracedCss(finalizeCssAssetSource(loaderGeneratedCss.css, { generatedCss: true }), cssHandlerOptions);
|
|
1512
|
+
debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
|
|
1513
|
+
return { result: new ConcatSource(css) };
|
|
1514
|
+
}
|
|
1515
|
+
const sourceCssProcessed = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.processed === true : false;
|
|
1516
|
+
const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
|
|
1517
|
+
...source,
|
|
1518
|
+
file: registeredSourceFile
|
|
1519
|
+
})), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
|
|
1520
|
+
const currentAssetLooksGenerated = require_v4_engine.hasTailwindGeneratedCss(currentRawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(currentRawSource);
|
|
1521
|
+
const currentAssetHasBundlerGeneratedMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(currentRawSource);
|
|
1522
|
+
const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker;
|
|
1523
|
+
const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss));
|
|
1524
|
+
const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && hasAdditionalWebpackAssetUserCssMarkers(currentRawSource, generatorRawSource);
|
|
1525
|
+
const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
|
|
1526
|
+
const shouldAppendCurrentAssetUserCss = !currentAssetHasBundlerGeneratedMarker && !shouldPreserveGeneratedWebAssetUserCss && (!sourceCssProcessed || registeredUserRawSource === void 0 || currentAssetHasUserCss) && !(sourceCssProcessed && currentAssetLooksGenerated && !currentAssetHasUserCss);
|
|
1527
|
+
const userRawSource = createWebpackGeneratorUserCssSourceAppend(sourceCssProcessed && shouldAppendCurrentAssetUserCss ? {
|
|
1528
|
+
css: currentRawSource,
|
|
1529
|
+
processed: true
|
|
1530
|
+
} : shouldAppendCurrentAssetUserCss && currentAssetHasUserCss ? {
|
|
1531
|
+
css: currentRawSource,
|
|
1532
|
+
processed: currentAssetLooksGenerated
|
|
1533
|
+
} : void 0, registeredUserRawSource);
|
|
1534
|
+
if (require_hmr_timing.isPureLocalCssImportWrapper(currentRawSource)) return { result: new ConcatSource(require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
|
|
1535
|
+
const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
|
|
1536
|
+
const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
1537
|
+
const shouldForceTailwindV4Generation = cssHandlerOptions.isMainChunk && hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 || require_v4_engine.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(generatorRawSource) || hasExplicitTailwindV4SourceCss);
|
|
1538
|
+
const resolvedScopedGeneratorRuntimeSet = await require_source_candidate_scan_signature.createScopedGeneratorRuntime({
|
|
1539
|
+
cssHandlerOptions,
|
|
1540
|
+
fallbackRuntime: hasExplicitTailwindV4SourceCss ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet,
|
|
1541
|
+
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
1542
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1543
|
+
outputFile: file,
|
|
1544
|
+
rawSource: sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
|
|
1545
|
+
shouldExcludeSubpackageSourceCandidates: () => false,
|
|
1546
|
+
sourceFile: sourceFile ?? file,
|
|
1547
|
+
scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
|
|
1548
|
+
});
|
|
1549
|
+
const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== fallbackGeneratorRuntimeSet ? new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
|
|
1550
|
+
const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
|
|
1551
|
+
const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
|
|
1552
|
+
...cssHandlerOptions,
|
|
1553
|
+
sourceOptions: {
|
|
1554
|
+
...cssHandlerOptions.sourceOptions ?? {},
|
|
1555
|
+
cssSources: generatorCssSources
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
const generatorOptions = {
|
|
1559
|
+
opts: compilerOptions,
|
|
1560
|
+
runtimeState,
|
|
1561
|
+
runtime: scopedGeneratorRuntimeSet,
|
|
1562
|
+
rawSource: generatorRawSource,
|
|
1563
|
+
forceGenerator: shouldForceTailwindV4Generation,
|
|
1564
|
+
...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
|
|
1565
|
+
...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
|
|
1566
|
+
...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
|
|
1567
|
+
file,
|
|
1568
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
1569
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
1570
|
+
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
1571
|
+
sourceCandidates: scopedGeneratorRuntimeSet,
|
|
1572
|
+
restoreLocalCssImports: false,
|
|
1573
|
+
styleHandler: compilerOptions.styleHandler,
|
|
1574
|
+
debug
|
|
1575
|
+
};
|
|
1576
|
+
let generated;
|
|
1577
|
+
try {
|
|
1578
|
+
generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
1579
|
+
...generatorOptions,
|
|
1580
|
+
outputFile: file
|
|
1581
|
+
});
|
|
1582
|
+
} catch (error) {
|
|
1583
|
+
if (!(!require_v4_engine.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(generatorRawSource) && !hasExplicitTailwindV4SourceCss && configuredMainCssEntryFiles.length === 0)) throw error;
|
|
1584
|
+
debug("css generator skipped for plain webpack css asset: %s %O", file, error);
|
|
1585
|
+
generated = void 0;
|
|
1586
|
+
}
|
|
1587
|
+
const source = new ConcatSource(finalizeTracedCss(generated ? finalizeCssAssetSource(generated.css, { generatedCss: true }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false }), cssHandlerOptions));
|
|
1588
|
+
if (generated) {
|
|
1589
|
+
for (const className of generated.classSet) generatorRuntimeSet.add(className);
|
|
1590
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
|
|
1591
|
+
} else debug("css handle: %s", file);
|
|
1592
|
+
return { result: source };
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
}, cssTaskFactories);
|
|
1596
|
+
}
|
|
1597
|
+
if (!watchMode) {
|
|
1598
|
+
require_hmr_timing.pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
|
|
1599
|
+
await Promise.all(tasks);
|
|
1600
|
+
tasks.length = 0;
|
|
1601
|
+
require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
|
|
1602
|
+
await Promise.all(tasks);
|
|
1603
|
+
tasks.length = 0;
|
|
1604
|
+
require_hmr_timing.pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
|
|
1605
|
+
}
|
|
1606
|
+
await Promise.all(tasks);
|
|
1607
|
+
compilerOptions.cache.prune?.({
|
|
1608
|
+
cacheKeys: activeProcessCacheKeys,
|
|
1609
|
+
hashKeys: activeProcessHashKeys
|
|
1610
|
+
});
|
|
1611
|
+
const activeCssFiles = new Set(groupedEntries.css?.map(([file]) => file) ?? []);
|
|
1612
|
+
pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
|
|
1613
|
+
if (activeCssFiles.size > 0) pruneWebpackCssSources?.(new Set([
|
|
1614
|
+
...registeredWebpackCssSourceFiles,
|
|
1615
|
+
...activeWebpackCssSourceFiles,
|
|
1616
|
+
...[...cssAssetResources.values()].flatMap((resources) => [...resources])
|
|
1617
|
+
]), { watchMode });
|
|
1618
|
+
debug("end");
|
|
1619
|
+
require_hmr_timing.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
|
|
1620
|
+
activeAssetFiles: entries.length,
|
|
1621
|
+
activeCssFiles: activeCssFiles.size,
|
|
1622
|
+
activeProcessCacheKeys,
|
|
1623
|
+
activeProcessHashKeys,
|
|
1624
|
+
cache: compilerOptions.cache,
|
|
1625
|
+
cssHandlerOptionsCache,
|
|
1626
|
+
cssUserHandlerOptionsCache,
|
|
1627
|
+
phase: "processAssets",
|
|
1628
|
+
sourceCandidateScan: webpackSourceCandidateScanCache.getMemoryStats()
|
|
1629
|
+
}) });
|
|
1630
|
+
compilerOptions.onEnd();
|
|
1631
|
+
});
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
//#endregion
|
|
1635
|
+
//#region src/bundlers/webpack/loaders/runtime-registry.ts
|
|
1636
|
+
const runtimeRegistryHolder = globalThis;
|
|
1637
|
+
const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
|
|
1638
|
+
function setWebpackLoaderRuntime(key, entry) {
|
|
1639
|
+
runtimeRegistry.set(key, entry);
|
|
1640
|
+
}
|
|
1641
|
+
function deleteWebpackLoaderRuntime(key) {
|
|
1642
|
+
runtimeRegistry.delete(key);
|
|
1643
|
+
}
|
|
1644
|
+
//#endregion
|
|
1645
|
+
//#region src/bundlers/webpack/shared/loader-anchors.ts
|
|
1646
|
+
const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
1647
|
+
const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
|
|
1648
|
+
const MPX_REWRITE_PRECEDENCE_LOADERS = [MPX_STYLE_COMPILER_LOADER, MPX_STRIP_CONDITIONAL_LOADER];
|
|
1649
|
+
function createFinder(targets) {
|
|
1650
|
+
return (entries) => entries.findIndex((entry) => targets.some((target) => entry?.loader?.includes?.(target)));
|
|
1651
|
+
}
|
|
1652
|
+
function createPrioritizedFinder(targets) {
|
|
1653
|
+
return (entries) => {
|
|
1654
|
+
for (const target of targets) {
|
|
1655
|
+
const idx = entries.findIndex((entry) => entry?.loader?.includes?.(target));
|
|
1656
|
+
if (idx !== -1) return idx;
|
|
1657
|
+
}
|
|
1658
|
+
return -1;
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
function createLoaderAnchorFinders(appType) {
|
|
1662
|
+
if (isMpx(appType)) return {
|
|
1663
|
+
findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
|
|
1664
|
+
findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
|
|
1665
|
+
};
|
|
1666
|
+
const fallbackFinder = createFinder(["postcss-loader"]);
|
|
1667
|
+
return {
|
|
1668
|
+
findRewriteAnchor: fallbackFinder,
|
|
1669
|
+
findClassSetAnchor: fallbackFinder
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
//#endregion
|
|
1673
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
1674
|
+
function setupWebpackV5Loaders(options) {
|
|
1675
|
+
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
1676
|
+
const isMpxApp = isMpx(appType);
|
|
1677
|
+
const generatorTarget = compilerOptions.generator?.target ?? require_v4_engine.inferGeneratorTargetFromEnv();
|
|
1678
|
+
const generatorBranch = require_generator.resolveRuntimeBranch({
|
|
1679
|
+
appType: compilerOptions.appType,
|
|
1680
|
+
generatorTarget,
|
|
1681
|
+
platform: compilerOptions.cssOptions?.platform ?? compilerOptions.platform,
|
|
1682
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1683
|
+
uniAppX: compilerOptions.uniAppX
|
|
1684
|
+
});
|
|
1685
|
+
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
1686
|
+
const runtimeClassSetLoader = runtimeLoaderPath ?? node_path.default.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
1687
|
+
const shouldInjectRuntimeClassSetLoader = !generatorBranch.isWeb;
|
|
1688
|
+
const shouldInjectCssImportRewriteLoader = shouldRewriteCssImports || !generatorBranch.isWeb || runtimeState.tailwindRuntime.majorVersion === 4;
|
|
1689
|
+
const runtimeCssImportRewriteLoader = shouldInjectCssImportRewriteLoader ? node_path.default.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
1690
|
+
const runtimeClassSetLoaderExists = node_fs.default.existsSync(runtimeClassSetLoader);
|
|
1691
|
+
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? node_fs.default.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
1692
|
+
const runtimeLoaderRewriteOptions = shouldInjectCssImportRewriteLoader ? {
|
|
1693
|
+
pkgDir: weappTailwindcssPackageDir,
|
|
1694
|
+
compilerOptions,
|
|
1695
|
+
runtimeState,
|
|
1696
|
+
...appType === void 0 ? {} : { appType },
|
|
1697
|
+
...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
|
|
1698
|
+
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile },
|
|
1699
|
+
getRuntimeSet: getRuntimeSetInLoader,
|
|
1700
|
+
...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource },
|
|
1701
|
+
...registerWebpackGeneratedCss === void 0 ? {} : { registerGeneratedCss: registerWebpackGeneratedCss }
|
|
1702
|
+
} : void 0;
|
|
1703
|
+
setWebpackLoaderRuntime(runtimeRegistryKey, {
|
|
1704
|
+
classSet: {
|
|
1705
|
+
getClassSet: getClassSetInLoader,
|
|
1706
|
+
getWatchDependencies: getRuntimeWatchDependencies,
|
|
1707
|
+
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
|
|
1708
|
+
},
|
|
1709
|
+
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
1710
|
+
});
|
|
1711
|
+
const cleanupWebpackLoaderRuntime = () => {
|
|
1712
|
+
deleteWebpackLoaderRuntime(runtimeRegistryKey);
|
|
1713
|
+
};
|
|
1714
|
+
compiler.hooks.watchClose?.tap?.(require_context.pluginName, cleanupWebpackLoaderRuntime);
|
|
1715
|
+
compiler.hooks.shutdown?.tap?.(require_context.pluginName, cleanupWebpackLoaderRuntime);
|
|
1716
|
+
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
1717
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
1718
|
+
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
1719
|
+
const createRuntimeClassSetLoaderEntry = () => ({
|
|
1720
|
+
loader: runtimeClassSetLoader,
|
|
1721
|
+
options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
|
|
1722
|
+
ident: null,
|
|
1723
|
+
type: null
|
|
1724
|
+
});
|
|
1725
|
+
const createCssImportRewriteLoaderEntry = () => {
|
|
1726
|
+
if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
|
|
1727
|
+
return {
|
|
1728
|
+
loader: runtimeCssImportRewriteLoader,
|
|
1729
|
+
options: cssImportRewriteLoaderOptions,
|
|
1730
|
+
ident: null,
|
|
1731
|
+
type: null
|
|
1732
|
+
};
|
|
1733
|
+
};
|
|
1734
|
+
const { NormalModule } = compiler.webpack;
|
|
1735
|
+
compiler.hooks.compilation.tap(require_context.pluginName, (compilation) => {
|
|
1736
|
+
NormalModule.getCompilationHooks(compilation).loader.tap(require_context.pluginName, (_loaderContext, module) => {
|
|
1737
|
+
if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
|
|
1738
|
+
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
|
|
1739
|
+
const loaderEntries = module.loaders || [];
|
|
1740
|
+
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
1741
|
+
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
1742
|
+
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
1743
|
+
if (isCssModule && typeof module.resource === "string") markWebpackCssSourceModule?.(module.resource);
|
|
1744
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
1745
|
+
rewriteAnchorIdx,
|
|
1746
|
+
classSetAnchorIdx
|
|
1747
|
+
});
|
|
1748
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.endsWith(".css")) debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
1749
|
+
rewriteAnchorIdx,
|
|
1750
|
+
classSetAnchorIdx
|
|
1751
|
+
});
|
|
1752
|
+
if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
|
|
1753
|
+
const anchorlessInsert = (entry, position) => {
|
|
1754
|
+
if (position === "after") loaderEntries.push(entry);
|
|
1755
|
+
else loaderEntries.unshift(entry);
|
|
1756
|
+
};
|
|
1757
|
+
if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader && isCssModule) {
|
|
1758
|
+
const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
|
|
1759
|
+
const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
|
|
1760
|
+
if (rewriteLoaderEntry) {
|
|
1761
|
+
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
1762
|
+
if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
|
|
1763
|
+
else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
|
|
1764
|
+
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
if (shouldInjectRuntimeClassSetLoader && runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
1768
|
+
const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
|
|
1769
|
+
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
1770
|
+
if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
|
|
1771
|
+
else {
|
|
1772
|
+
const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
|
|
1773
|
+
loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
//#endregion
|
|
1780
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
1781
|
+
const debug = require_context.createDebug();
|
|
1782
|
+
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
1783
|
+
const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
|
|
1784
|
+
function normalizeIgnoredList(ignored) {
|
|
1785
|
+
return (Array.isArray(ignored) ? [...ignored] : [ignored]).filter((item) => typeof item === "string" || item instanceof RegExp || typeof item === "function");
|
|
1786
|
+
}
|
|
1787
|
+
function createOutputIgnoredPredicate(ignoredList, ignoredPath) {
|
|
1788
|
+
const predicate = (file) => {
|
|
1789
|
+
const resolvedFile = node_path.default.resolve(file);
|
|
1790
|
+
if (resolvedFile === ignoredPath || resolvedFile.startsWith(`${ignoredPath}${node_path.default.sep}`)) return true;
|
|
1791
|
+
const normalizedFile = file.replace(/\\/g, "/");
|
|
1792
|
+
return ignoredList.some((item) => {
|
|
1793
|
+
if (typeof item === "string") {
|
|
1794
|
+
const resolvedItem = node_path.default.resolve(item);
|
|
1795
|
+
if (resolvedFile === resolvedItem || resolvedFile.startsWith(`${resolvedItem}${node_path.default.sep}`)) return true;
|
|
1796
|
+
return micromatch.default.isMatch(normalizedFile, item);
|
|
1797
|
+
}
|
|
1798
|
+
if (item instanceof RegExp) return item.test(normalizedFile);
|
|
1799
|
+
return item(file);
|
|
1800
|
+
});
|
|
1801
|
+
};
|
|
1802
|
+
predicate[outputIgnoredPredicatePath] = ignoredPath;
|
|
1803
|
+
return predicate;
|
|
1804
|
+
}
|
|
1805
|
+
function appendIgnoredPath(ignored, ignoredPath) {
|
|
1806
|
+
if (typeof ignored === "function" && ignored[outputIgnoredPredicatePath] === ignoredPath) return ignored;
|
|
1807
|
+
const ignoredList = normalizeIgnoredList(ignored);
|
|
1808
|
+
if (ignoredList.some((item) => typeof item !== "string")) return createOutputIgnoredPredicate(ignoredList, ignoredPath);
|
|
1809
|
+
if (ignoredList.some((item) => typeof item === "string" && node_path.default.resolve(item) === ignoredPath)) return ignored;
|
|
1810
|
+
return [...ignoredList, ignoredPath];
|
|
1811
|
+
}
|
|
1812
|
+
function setupWebpackWatchOutputIgnore(compiler) {
|
|
1813
|
+
const appendOutputIgnoredPath = (watchOptions, outputPath) => {
|
|
1814
|
+
const resolvedOutputPath = outputPath || compiler.outputPath || compiler.options?.output?.path;
|
|
1815
|
+
const outputDir = resolvedOutputPath ? node_path.default.resolve(resolvedOutputPath) : void 0;
|
|
1816
|
+
if (!outputDir) return watchOptions;
|
|
1817
|
+
if (watchOptions && typeof watchOptions === "object") {
|
|
1818
|
+
const nextIgnored = appendIgnoredPath(watchOptions.ignored, outputDir);
|
|
1819
|
+
if (nextIgnored === void 0) delete watchOptions.ignored;
|
|
1820
|
+
else watchOptions.ignored = nextIgnored;
|
|
1821
|
+
return watchOptions;
|
|
1822
|
+
}
|
|
1823
|
+
return { ignored: appendIgnoredPath(void 0, outputDir) };
|
|
1824
|
+
};
|
|
1825
|
+
const compilerWatchOptions = appendOutputIgnoredPath(compiler.options.watchOptions);
|
|
1826
|
+
if (compilerWatchOptions) compiler.options.watchOptions = compilerWatchOptions;
|
|
1827
|
+
const syncOutputIgnoredPath = () => {
|
|
1828
|
+
const outputPath = compiler.outputPath || compiler.options?.output?.path;
|
|
1829
|
+
const watchOptions = compiler.watching?.watchOptions;
|
|
1830
|
+
if (watchOptions) appendOutputIgnoredPath(watchOptions, outputPath);
|
|
1831
|
+
};
|
|
1832
|
+
compiler.hooks.watchRun?.tap(require_context.pluginName, syncOutputIgnoredPath);
|
|
1833
|
+
compiler.hooks.thisCompilation?.tap(require_context.pluginName, (compilation) => {
|
|
1834
|
+
const outputPath = compilation.compiler?.outputPath || compilation.outputOptions?.path;
|
|
1835
|
+
const watchOptions = compiler.watching?.watchOptions;
|
|
1836
|
+
if (watchOptions) appendOutputIgnoredPath(watchOptions, outputPath);
|
|
1837
|
+
else {
|
|
1838
|
+
const compilerWatchOptions = appendOutputIgnoredPath(compiler.options.watchOptions, outputPath);
|
|
1839
|
+
if (compilerWatchOptions) compiler.options.watchOptions = compilerWatchOptions;
|
|
1840
|
+
}
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* @name WeappTailwindcss
|
|
1845
|
+
* @description webpack5 核心转义插件
|
|
1846
|
+
* @link https://tw.icebreaker.top/docs/intro
|
|
1847
|
+
*/
|
|
1848
|
+
var WeappTailwindcss = class {
|
|
1849
|
+
constructor(options = {}) {
|
|
1850
|
+
require_context._defineProperty(this, "options", void 0);
|
|
1851
|
+
require_context._defineProperty(this, "appType", void 0);
|
|
1852
|
+
require_context._defineProperty(this, "hasInitialTailwindCssRoots", void 0);
|
|
1853
|
+
this.hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots(options);
|
|
1854
|
+
this.options = require_context.getCompilerContext({
|
|
1855
|
+
...options,
|
|
1856
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
1857
|
+
});
|
|
1858
|
+
this.appType = this.options.appType;
|
|
1859
|
+
}
|
|
1860
|
+
apply(compiler) {
|
|
1861
|
+
compiler.options = compiler.options || {};
|
|
1862
|
+
const { disabled, onLoad, runtimeLoaderPath, tailwindRuntime, refreshTailwindcssRuntime } = this.options;
|
|
1863
|
+
const initialTailwindRuntime = tailwindRuntime;
|
|
1864
|
+
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
1865
|
+
const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
|
|
1866
|
+
const shouldRewriteCssImports = this.options.rewriteCssImports === true;
|
|
1867
|
+
const isMpxApp = isMpx(this.appType);
|
|
1868
|
+
if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
|
|
1869
|
+
if (disabledOptions.plugin) return;
|
|
1870
|
+
if (initialTailwindRuntime.majorVersion !== 4) throw new Error("weapp-tailwindcss/webpack 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
1871
|
+
setupWebpackWatchOutputIgnore(compiler);
|
|
1872
|
+
const runtimeState = {
|
|
1873
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
1874
|
+
readyPromise: require_context.createTailwindRuntimeReadyPromise(initialTailwindRuntime),
|
|
1875
|
+
refreshTailwindcssRuntime: refreshTailwindRuntime
|
|
1876
|
+
};
|
|
1877
|
+
let runtimeSetPrepared = false;
|
|
1878
|
+
let runtimeSetSignature;
|
|
1879
|
+
let runtimeRefreshRequiredForCompilation = false;
|
|
1880
|
+
let watchRunObserved = false;
|
|
1881
|
+
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
1882
|
+
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
1883
|
+
const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
1884
|
+
const webpackCssSources = /* @__PURE__ */ new Map();
|
|
1885
|
+
const webpackGeneratedCssSources = /* @__PURE__ */ new Map();
|
|
1886
|
+
const currentWebpackCssSourceFiles = /* @__PURE__ */ new Set();
|
|
1887
|
+
const currentWebpackCssSourceModules = /* @__PURE__ */ new Set();
|
|
1888
|
+
let runtimeMetadataPrepared = false;
|
|
1889
|
+
const updateRuntimeWatchDependencies = async () => {
|
|
1890
|
+
runtimeWatchDependencyFiles.clear();
|
|
1891
|
+
runtimeWatchDependencyContexts.clear();
|
|
1892
|
+
const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
1893
|
+
if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
|
|
1894
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
|
|
1895
|
+
for (const source of tailwindOptions?.v4?.cssSources ?? []) {
|
|
1896
|
+
if (source.file) runtimeWatchDependencyFiles.add(source.file);
|
|
1897
|
+
for (const dependency of source.dependencies ?? []) runtimeWatchDependencyFiles.add(dependency);
|
|
1898
|
+
}
|
|
1899
|
+
for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
1900
|
+
if (typeof runtimeState.tailwindRuntime.collectContentTokens !== "function") return;
|
|
1901
|
+
try {
|
|
1902
|
+
const report = await runtimeState.tailwindRuntime.collectContentTokens();
|
|
1903
|
+
for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
|
|
1904
|
+
for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
1905
|
+
} catch (error) {
|
|
1906
|
+
debug("collect runtime watch dependencies failed: %O", error);
|
|
1907
|
+
}
|
|
1908
|
+
};
|
|
1909
|
+
const ensureRuntimeMetadata = async (force = false) => {
|
|
1910
|
+
if (runtimeMetadataPrepared && !force) return;
|
|
1911
|
+
await updateRuntimeWatchDependencies();
|
|
1912
|
+
runtimeMetadataPrepared = true;
|
|
1913
|
+
};
|
|
1914
|
+
const collectWatchChangedFiles = () => {
|
|
1915
|
+
const compilerLike = compiler;
|
|
1916
|
+
return new Set([...compilerLike.modifiedFiles ?? [], ...compilerLike.removedFiles ?? []]);
|
|
1917
|
+
};
|
|
1918
|
+
const hasRuntimeDependencyChanges = (files) => {
|
|
1919
|
+
for (const file of files) if (isWatchFileInRuntimeDependencies(file, {
|
|
1920
|
+
contexts: runtimeWatchDependencyContexts,
|
|
1921
|
+
files: runtimeWatchDependencyFiles
|
|
1922
|
+
})) return true;
|
|
1923
|
+
return false;
|
|
1924
|
+
};
|
|
1925
|
+
const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
|
|
1926
|
+
if (markWatchRun) watchRunObserved = true;
|
|
1927
|
+
const changedFiles = collectWatchChangedFiles();
|
|
1928
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges(changedFiles);
|
|
1929
|
+
};
|
|
1930
|
+
const resetRuntimePreparation = () => {
|
|
1931
|
+
runtimeSetPrepared = false;
|
|
1932
|
+
syncRuntimeRefreshRequirement();
|
|
1933
|
+
};
|
|
1934
|
+
const registerAutoCssSource = async (source) => {
|
|
1935
|
+
if (!source.file) return;
|
|
1936
|
+
if (!require_v4_engine.upsertTailwindV4CssSource(this.options, source)) return;
|
|
1937
|
+
runtimeSetPrepared = false;
|
|
1938
|
+
runtimeMetadataPrepared = false;
|
|
1939
|
+
runtimeRefreshRequiredForCompilation = true;
|
|
1940
|
+
await require_context.refreshTailwindRuntimeState(runtimeState, {
|
|
1941
|
+
force: true,
|
|
1942
|
+
clearCache: true
|
|
1943
|
+
});
|
|
1944
|
+
debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
|
|
1945
|
+
};
|
|
1946
|
+
const markWebpackProcessedCssSource = (file) => {
|
|
1947
|
+
webpackProcessedCssSourceFiles.add(node_path.default.resolve(file));
|
|
1948
|
+
};
|
|
1949
|
+
const markWebpackCssSourceModule = (file) => {
|
|
1950
|
+
currentWebpackCssSourceModules.add(node_path.default.resolve(file));
|
|
1951
|
+
};
|
|
1952
|
+
const registerWebpackCssSourceFile = (source) => {
|
|
1953
|
+
const file = node_path.default.resolve(source.file);
|
|
1954
|
+
const previous = webpackCssSources.get(file);
|
|
1955
|
+
if (source.processed === true && previous?.processed === false) {
|
|
1956
|
+
currentWebpackCssSourceFiles.add(file);
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
webpackCssSources.set(file, {
|
|
1960
|
+
css: typeof source.css === "string" ? require_v4_engine.normalizeTailwindConfigDirectives(source.css, node_path.default.dirname(file)) : source.css,
|
|
1961
|
+
processed: source.processed
|
|
1962
|
+
});
|
|
1963
|
+
currentWebpackCssSourceFiles.add(file);
|
|
1964
|
+
};
|
|
1965
|
+
const registerWebpackGeneratedCss = (source) => {
|
|
1966
|
+
const file = node_path.default.resolve(source.file);
|
|
1967
|
+
webpackGeneratedCssSources.set(file, {
|
|
1968
|
+
...source,
|
|
1969
|
+
file
|
|
1970
|
+
});
|
|
1971
|
+
currentWebpackCssSourceFiles.add(file);
|
|
1972
|
+
};
|
|
1973
|
+
const pruneWebpackCssSources = (activeSourceFiles, _options = {}) => {
|
|
1974
|
+
const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
1975
|
+
const configuredSourceFiles = /* @__PURE__ */ new Set();
|
|
1976
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) configuredSourceFiles.add(node_path.default.resolve(entry));
|
|
1977
|
+
for (const source of tailwindOptions?.v4?.cssSources ?? []) if (source.file) configuredSourceFiles.add(node_path.default.resolve(source.file));
|
|
1978
|
+
for (const file of webpackCssSources.keys()) if (!activeSourceFiles.has(file) && !configuredSourceFiles.has(file)) webpackCssSources.delete(file);
|
|
1979
|
+
for (const file of webpackGeneratedCssSources.keys()) if (!activeSourceFiles.has(file) && !configuredSourceFiles.has(file)) webpackGeneratedCssSources.delete(file);
|
|
1980
|
+
};
|
|
1981
|
+
const prepareWebpackCssSources = (activeAssetResources = /* @__PURE__ */ new Set()) => {
|
|
1982
|
+
const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
1983
|
+
const configuredSourceFiles = /* @__PURE__ */ new Set();
|
|
1984
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) configuredSourceFiles.add(node_path.default.resolve(entry));
|
|
1985
|
+
for (const source of tailwindOptions?.v4?.cssSources ?? []) if (source.file) configuredSourceFiles.add(node_path.default.resolve(source.file));
|
|
1986
|
+
const activeSourceFiles = new Set([
|
|
1987
|
+
...configuredSourceFiles,
|
|
1988
|
+
...currentWebpackCssSourceModules,
|
|
1989
|
+
...activeAssetResources,
|
|
1990
|
+
...[...currentWebpackCssSourceFiles].filter((file) => currentWebpackCssSourceModules.has(file)),
|
|
1991
|
+
...[...currentWebpackCssSourceFiles].filter((file) => activeAssetResources.has(file))
|
|
1992
|
+
]);
|
|
1993
|
+
currentWebpackCssSourceFiles.clear();
|
|
1994
|
+
currentWebpackCssSourceModules.clear();
|
|
1995
|
+
return activeSourceFiles;
|
|
1996
|
+
};
|
|
1997
|
+
const isWebpackProcessedTailwindEntryAsset = (isMainCssChunk) => {
|
|
1998
|
+
if (isMainCssChunk !== true || webpackProcessedCssSourceFiles.size === 0) return false;
|
|
1999
|
+
const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
2000
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (webpackProcessedCssSourceFiles.has(node_path.default.resolve(entry))) return true;
|
|
2001
|
+
for (const source of tailwindOptions?.v4?.cssSources ?? []) if (source.file && webpackProcessedCssSourceFiles.has(node_path.default.resolve(source.file))) return true;
|
|
2002
|
+
return false;
|
|
2003
|
+
};
|
|
2004
|
+
compiler.hooks.invalid?.tap?.(require_context.pluginName, (fileName) => {
|
|
2005
|
+
if (!fileName) return;
|
|
2006
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([node_path.default.resolve(fileName)]);
|
|
2007
|
+
});
|
|
2008
|
+
compiler.hooks.watchRun?.tap?.(require_context.pluginName, () => syncRuntimeRefreshRequirement(true));
|
|
2009
|
+
if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(require_context.pluginName, resetRuntimePreparation);
|
|
2010
|
+
else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(require_context.pluginName, resetRuntimePreparation);
|
|
2011
|
+
async function getClassSetInLoader() {
|
|
2012
|
+
if (runtimeSetPrepared) return;
|
|
2013
|
+
const signature = require_tailwindcss.getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
2014
|
+
const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
|
|
2015
|
+
debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
|
|
2016
|
+
runtimeSetPrepared = true;
|
|
2017
|
+
await require_context.ensureRuntimeClassSet(runtimeState, {
|
|
2018
|
+
forceRefresh,
|
|
2019
|
+
forceCollect: forceRefresh || !watchRunObserved,
|
|
2020
|
+
clearCache: forceRefresh,
|
|
2021
|
+
allowEmpty: true
|
|
2022
|
+
});
|
|
2023
|
+
await ensureRuntimeMetadata(forceRefresh);
|
|
2024
|
+
runtimeSetSignature = signature;
|
|
2025
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
2026
|
+
}
|
|
2027
|
+
async function getRuntimeSetInLoader() {
|
|
2028
|
+
await getClassSetInLoader();
|
|
2029
|
+
return require_context.ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
|
|
2030
|
+
}
|
|
2031
|
+
onLoad();
|
|
2032
|
+
setupWebpackV5Loaders({
|
|
2033
|
+
compiler,
|
|
2034
|
+
options: this.options,
|
|
2035
|
+
appType: this.appType,
|
|
2036
|
+
weappTailwindcssPackageDir,
|
|
2037
|
+
shouldRewriteCssImports,
|
|
2038
|
+
runtimeLoaderPath,
|
|
2039
|
+
registerAutoCssSource,
|
|
2040
|
+
runtimeState,
|
|
2041
|
+
getClassSetInLoader,
|
|
2042
|
+
getRuntimeSetInLoader,
|
|
2043
|
+
markWebpackProcessedCssSource,
|
|
2044
|
+
markWebpackCssSourceModule,
|
|
2045
|
+
registerWebpackCssSourceFile,
|
|
2046
|
+
registerWebpackGeneratedCss,
|
|
2047
|
+
getRuntimeWatchDependencies() {
|
|
2048
|
+
return {
|
|
2049
|
+
files: runtimeWatchDependencyFiles,
|
|
2050
|
+
contexts: runtimeWatchDependencyContexts
|
|
2051
|
+
};
|
|
2052
|
+
},
|
|
2053
|
+
debug
|
|
2054
|
+
});
|
|
2055
|
+
setupWebpackV5ProcessAssetsHook({
|
|
2056
|
+
compiler,
|
|
2057
|
+
options: this.options,
|
|
2058
|
+
appType: this.appType,
|
|
2059
|
+
runtimeState,
|
|
2060
|
+
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
2061
|
+
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
2062
|
+
isKnownWebpackProcessedCssAsset(file, metadata) {
|
|
2063
|
+
return webpackProcessedCssSourceFiles.has(node_path.default.resolve(file)) || isWebpackProcessedTailwindEntryAsset(metadata?.isMainCssChunk);
|
|
2064
|
+
},
|
|
2065
|
+
isWebpackProcessedCssAsset(file, rawSource, metadata) {
|
|
2066
|
+
return webpackProcessedCssSourceFiles.has(node_path.default.resolve(file)) || isWebpackProcessedTailwindEntryAsset(metadata?.isMainCssChunk) || require_v4_engine.hasTailwindGeneratedCss(rawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
|
|
2067
|
+
},
|
|
2068
|
+
consumeRuntimeRefreshRequirement() {
|
|
2069
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
2070
|
+
},
|
|
2071
|
+
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
2072
|
+
getWatchChangedFiles: collectWatchChangedFiles,
|
|
2073
|
+
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
2074
|
+
getWebpackCssSources: () => webpackCssSources,
|
|
2075
|
+
getWebpackGeneratedCssSources: () => webpackGeneratedCssSources,
|
|
2076
|
+
pruneWebpackCssSources,
|
|
2077
|
+
prepareWebpackCssSources,
|
|
2078
|
+
debug
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
//#endregion
|
|
2083
|
+
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
2084
|
+
enumerable: true,
|
|
2085
|
+
get: function() {
|
|
2086
|
+
return WeappTailwindcss;
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
Object.defineProperty(exports, "weappTailwindcssPackageDir", {
|
|
2090
|
+
enumerable: true,
|
|
2091
|
+
get: function() {
|
|
2092
|
+
return weappTailwindcssPackageDir;
|
|
2093
|
+
}
|
|
2094
|
+
});
|