weapp-tailwindcss 5.0.13 → 5.1.1
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/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/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 +16 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +138 -444
- package/dist/cli.mjs +134 -440
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +5 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
- package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
- package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
- package/dist/defaults.d.ts +2 -8
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-6oMJtTDO.js +170 -0
- package/dist/generator-CjzBK7h-.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
- 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 +87 -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 +15 -7
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
- package/dist/tailwindcss-dbrbY4cd.js +1528 -0
- package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
- package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
- package/dist/v4-engine-ON_oSLfO.js +2752 -0
- package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
- package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-8PaV1gG3.mjs +2334 -0
- package/dist/webpack-CGgBOx9l.js +2346 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -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-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_v4_engine = require("./v4-engine-ON_oSLfO.js");
|
|
3
|
+
const require_generator = require("./generator-6oMJtTDO.js");
|
|
4
4
|
require("./utils-BCa37Wqj.js");
|
|
5
|
-
const
|
|
5
|
+
const require_defaults = require("./defaults-CmFBmxsr.js");
|
|
6
|
+
const require_tailwindcss = require("./tailwindcss-dbrbY4cd.js");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_chunk.__toESM(node_path);
|
|
8
9
|
let node_process = require("node:process");
|
|
9
10
|
node_process = require_chunk.__toESM(node_process);
|
|
11
|
+
let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
|
|
10
12
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
11
13
|
let lru_cache = require("lru-cache");
|
|
12
|
-
let tailwindcss_patch = require("tailwindcss-patch");
|
|
13
|
-
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
14
14
|
let node_fs_promises = require("node:fs/promises");
|
|
15
|
+
let node_module = require("node:module");
|
|
15
16
|
let node_buffer = require("node:buffer");
|
|
17
|
+
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
16
18
|
let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
|
|
17
19
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
20
|
+
let debug = require("debug");
|
|
21
|
+
debug = require_chunk.__toESM(debug);
|
|
18
22
|
let _babel_traverse = require("@babel/traverse");
|
|
19
23
|
_babel_traverse = require_chunk.__toESM(_babel_traverse);
|
|
20
24
|
let _babel_parser = require("@babel/parser");
|
|
@@ -69,15 +73,16 @@ function createCache(options) {
|
|
|
69
73
|
});
|
|
70
74
|
return cache;
|
|
71
75
|
},
|
|
76
|
+
pruneHashKeys(hashKeys) {
|
|
77
|
+
const activeHashKeys = new Set(hashKeys);
|
|
78
|
+
for (const key of hashMap.keys()) if (!activeHashKeys.has(key)) hashMap.delete(key);
|
|
79
|
+
},
|
|
72
80
|
prune(options) {
|
|
73
81
|
if (options.cacheKeys) {
|
|
74
82
|
const cacheKeys = new Set(options.cacheKeys);
|
|
75
83
|
for (const key of instance.keys()) if (!cacheKeys.has(key)) instance.delete(key);
|
|
76
84
|
}
|
|
77
|
-
if (options.hashKeys)
|
|
78
|
-
const hashKeys = new Set(options.hashKeys);
|
|
79
|
-
for (const key of hashMap.keys()) if (!hashKeys.has(key)) hashMap.delete(key);
|
|
80
|
-
}
|
|
85
|
+
if (options.hashKeys) cache.pruneHashKeys?.(options.hashKeys);
|
|
81
86
|
},
|
|
82
87
|
has(key) {
|
|
83
88
|
return instance.has(key);
|
|
@@ -116,13 +121,28 @@ function initializeCache(cacheConfig) {
|
|
|
116
121
|
return cacheConfig;
|
|
117
122
|
}
|
|
118
123
|
//#endregion
|
|
124
|
+
//#region src/debug/index.ts
|
|
125
|
+
const _debug = (0, debug.default)("weapp-tw");
|
|
126
|
+
function createDebug(prefix) {
|
|
127
|
+
const debug$3 = ((formatter, ...args) => {
|
|
128
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(debug$3, "enabled", {
|
|
131
|
+
enumerable: false,
|
|
132
|
+
configurable: false,
|
|
133
|
+
get() {
|
|
134
|
+
return _debug.enabled;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return debug$3;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
119
140
|
//#region src/tailwindcss/runtime.ts
|
|
120
|
-
const debug$
|
|
121
|
-
const
|
|
122
|
-
function createTailwindRuntimeReadyPromise(
|
|
141
|
+
const debug$2 = createDebug("[tailwindcss:runtime] ");
|
|
142
|
+
const refreshTailwindcssRuntimeSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssRuntime");
|
|
143
|
+
function createTailwindRuntimeReadyPromise(tailwindRuntime) {
|
|
123
144
|
return Promise.resolve().then(async () => {
|
|
124
|
-
|
|
125
|
-
require_v3_engine.invalidateRuntimeClassSet(twPatcher);
|
|
145
|
+
require_tailwindcss.invalidateRuntimeClassSet(tailwindRuntime);
|
|
126
146
|
});
|
|
127
147
|
}
|
|
128
148
|
const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -134,21 +154,31 @@ function getRuntimeClassSetStateEntry(state) {
|
|
|
134
154
|
}
|
|
135
155
|
return entry;
|
|
136
156
|
}
|
|
157
|
+
function getTailwindRuntime(state) {
|
|
158
|
+
return state.tailwindRuntime;
|
|
159
|
+
}
|
|
160
|
+
function setTailwindRuntime(state, runtime) {
|
|
161
|
+
state.tailwindRuntime = runtime;
|
|
162
|
+
}
|
|
163
|
+
function getRefreshTailwindRuntime(state) {
|
|
164
|
+
return state.refreshTailwindcssRuntime;
|
|
165
|
+
}
|
|
137
166
|
async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
138
167
|
const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
|
|
139
168
|
const force = normalizedOptions.force;
|
|
140
169
|
const clearCache = normalizedOptions.clearCache === true;
|
|
141
170
|
if (!force) return false;
|
|
142
|
-
debug$
|
|
171
|
+
debug$2("refresh runtime state start, clearCache=%s major=%s", clearCache, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
143
172
|
await state.readyPromise;
|
|
144
173
|
let refreshed = false;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
174
|
+
const refreshTailwindRuntime = getRefreshTailwindRuntime(state);
|
|
175
|
+
if (typeof refreshTailwindRuntime === "function") {
|
|
176
|
+
const next = await refreshTailwindRuntime({ clearCache });
|
|
177
|
+
if (next !== getTailwindRuntime(state)) setTailwindRuntime(state, next);
|
|
148
178
|
refreshed = true;
|
|
149
179
|
}
|
|
150
|
-
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(state
|
|
151
|
-
debug$
|
|
180
|
+
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(getTailwindRuntime(state));
|
|
181
|
+
debug$2("refresh runtime state end, refreshed=%s major=%s", refreshed, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
152
182
|
return refreshed;
|
|
153
183
|
}
|
|
154
184
|
async function ensureRuntimeClassSet(state, options = {}) {
|
|
@@ -162,7 +192,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
162
192
|
});
|
|
163
193
|
await state.readyPromise;
|
|
164
194
|
const entry = getRuntimeClassSetStateEntry(state);
|
|
165
|
-
const signature = await
|
|
195
|
+
const signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
166
196
|
const signatureChanged = entry.signature !== signature;
|
|
167
197
|
const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
|
|
168
198
|
if (!shouldForceCollect) {
|
|
@@ -170,7 +200,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
170
200
|
if (entry.promise) return entry.promise;
|
|
171
201
|
}
|
|
172
202
|
const task = (async () => {
|
|
173
|
-
const collected = await collectRuntimeClassSet(state
|
|
203
|
+
const collected = await collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
174
204
|
force: shouldForceCollect,
|
|
175
205
|
skipRefresh: true,
|
|
176
206
|
clearCache
|
|
@@ -181,7 +211,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
181
211
|
clearCache: true
|
|
182
212
|
});
|
|
183
213
|
await state.readyPromise;
|
|
184
|
-
return collectRuntimeClassSet(state
|
|
214
|
+
return collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
185
215
|
force: true,
|
|
186
216
|
skipRefresh: true,
|
|
187
217
|
clearCache: true
|
|
@@ -191,118 +221,92 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
191
221
|
try {
|
|
192
222
|
const runtimeSet = await task;
|
|
193
223
|
entry.value = runtimeSet;
|
|
194
|
-
entry.signature = await
|
|
224
|
+
entry.signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
195
225
|
return runtimeSet;
|
|
196
226
|
} finally {
|
|
197
227
|
if (entry.promise === task) entry.promise = void 0;
|
|
198
228
|
}
|
|
199
229
|
}
|
|
200
|
-
function
|
|
201
|
-
if (
|
|
202
|
-
if (majorVersion === 3) return true;
|
|
203
|
-
if (majorVersion === 4) return true;
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
207
|
-
if (typeof twPatcher.getClassSetSync !== "function") return;
|
|
208
|
-
if (!shouldPreferSync(twPatcher.majorVersion)) return;
|
|
230
|
+
function tryGetRuntimeClassSetSync(tailwindRuntime) {
|
|
231
|
+
if (typeof tailwindRuntime.getClassSetSync !== "function") return;
|
|
209
232
|
try {
|
|
210
|
-
const set =
|
|
233
|
+
const set = tailwindRuntime.getClassSetSync();
|
|
211
234
|
if (set && set.size === 0) return;
|
|
212
235
|
return set;
|
|
213
236
|
} catch (error) {
|
|
214
|
-
|
|
215
|
-
else debug$1("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
237
|
+
debug$2("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
216
238
|
return;
|
|
217
239
|
}
|
|
218
240
|
}
|
|
219
|
-
async function collectTailwindV4GeneratorClassSet(
|
|
241
|
+
async function collectTailwindV4GeneratorClassSet(tailwindRuntime) {
|
|
242
|
+
if (typeof tailwindRuntime.collectContentTokens !== "function") return;
|
|
220
243
|
try {
|
|
221
|
-
const
|
|
244
|
+
const source = await require_v4_engine.resolveTailwindV4SourceFromRuntime(tailwindRuntime);
|
|
245
|
+
const generated = await require_v4_engine.createTailwindV4Engine(source).generate({
|
|
222
246
|
scanSources: true,
|
|
223
|
-
target: "
|
|
247
|
+
target: "web"
|
|
224
248
|
});
|
|
225
|
-
|
|
226
|
-
|
|
249
|
+
const classSet = (0, _tailwindcss_mangle_engine.resolveValidTailwindV4Candidates)(await (0, _tailwindcss_mangle_engine.loadTailwindV4DesignSystem)(source), generated.classSet, { ...source.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: source.bareArbitraryValues } });
|
|
250
|
+
debug$2("runtime class set resolved via tailwindcss v4 generator source scan, raw=%d valid=%d", generated.classSet.size, classSet.size);
|
|
251
|
+
return classSet;
|
|
227
252
|
} catch (error) {
|
|
228
|
-
debug$
|
|
253
|
+
debug$2("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
|
|
229
254
|
return;
|
|
230
255
|
}
|
|
231
256
|
}
|
|
232
|
-
async function mergeTailwindV4GeneratorClassSet(
|
|
233
|
-
|
|
234
|
-
const generatorClassSet = await collectTailwindV4GeneratorClassSet(twPatcher);
|
|
257
|
+
async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
|
|
258
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
|
|
235
259
|
if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
|
|
236
260
|
return new Set([...classSet, ...generatorClassSet]);
|
|
237
261
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
242
|
-
let activePatcher = twPatcher;
|
|
262
|
+
async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
|
|
263
|
+
let activeRuntime = tailwindRuntime;
|
|
243
264
|
if (options.force && !options.skipRefresh) {
|
|
244
|
-
const refresh =
|
|
265
|
+
const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
|
|
245
266
|
if (typeof refresh === "function") try {
|
|
246
267
|
const refreshed = await refresh({ clearCache: options.clearCache === true });
|
|
247
|
-
if (refreshed)
|
|
268
|
+
if (refreshed) activeRuntime = refreshed;
|
|
248
269
|
} catch (error) {
|
|
249
|
-
debug$
|
|
270
|
+
debug$2("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
|
|
250
271
|
}
|
|
251
272
|
}
|
|
252
|
-
const entry =
|
|
253
|
-
const signature = await
|
|
273
|
+
const entry = require_tailwindcss.getRuntimeClassSetCacheEntry(activeRuntime);
|
|
274
|
+
const signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(activeRuntime);
|
|
254
275
|
if (!options.force) {
|
|
255
276
|
if (entry.value && entry.signature === signature) return entry.value;
|
|
256
277
|
if (entry.promise) return entry.promise;
|
|
257
278
|
} else entry.value = void 0;
|
|
258
279
|
const task = (async () => {
|
|
259
|
-
await require_v3_engine.ensureTailwindcssRuntimePatch(activePatcher);
|
|
260
|
-
const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
|
|
261
|
-
if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
|
|
262
280
|
const preferExtract = options.force === true;
|
|
263
281
|
try {
|
|
264
|
-
const result = await
|
|
282
|
+
const result = await activeRuntime.extract({ write: false });
|
|
265
283
|
if (result?.classSet) {
|
|
266
284
|
if (result.classSet.size > 0) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return result.classSet;
|
|
270
|
-
}
|
|
271
|
-
const merged = await mergeTailwindV4GeneratorClassSet(activePatcher, result.classSet);
|
|
272
|
-
debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
|
|
285
|
+
const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
|
|
286
|
+
debug$2("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
|
|
273
287
|
return merged;
|
|
274
288
|
}
|
|
275
|
-
if (preferExtract
|
|
276
|
-
|
|
277
|
-
return result.classSet;
|
|
278
|
-
}
|
|
279
|
-
if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
|
|
280
|
-
else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
289
|
+
if (preferExtract) debug$2("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
|
|
290
|
+
else debug$2("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
281
291
|
}
|
|
282
292
|
} catch (error) {
|
|
283
|
-
debug$
|
|
284
|
-
}
|
|
285
|
-
if (activePatcher.majorVersion === 4) {
|
|
286
|
-
const generatorClassSet = await collectTailwindV4GeneratorClassSet(activePatcher);
|
|
287
|
-
if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
|
|
288
|
-
}
|
|
289
|
-
if (preExtractSyncSet) {
|
|
290
|
-
debug$1("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
|
|
291
|
-
return preExtractSyncSet;
|
|
293
|
+
debug$2("extract() failed, fallback to getClassSet(): %O", error);
|
|
292
294
|
}
|
|
293
|
-
const
|
|
295
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
|
|
296
|
+
if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
|
|
297
|
+
const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
|
|
294
298
|
if (syncSet) {
|
|
295
|
-
debug$
|
|
299
|
+
debug$2("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
|
|
296
300
|
return syncSet;
|
|
297
301
|
}
|
|
298
302
|
try {
|
|
299
|
-
const fallbackSet = await Promise.resolve(
|
|
303
|
+
const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
|
|
300
304
|
if (fallbackSet) {
|
|
301
|
-
debug$
|
|
305
|
+
debug$2("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
|
|
302
306
|
return fallbackSet;
|
|
303
307
|
}
|
|
304
308
|
} catch (error) {
|
|
305
|
-
debug$
|
|
309
|
+
debug$2("getClassSet() failed, returning empty set: %O", error);
|
|
306
310
|
}
|
|
307
311
|
return /* @__PURE__ */ new Set();
|
|
308
312
|
})();
|
|
@@ -361,8 +365,8 @@ function formatRelativeToBase(targetPath, baseDir) {
|
|
|
361
365
|
if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
|
|
362
366
|
return node_path.default.join(".", relative).replace(/\\/g, "/");
|
|
363
367
|
}
|
|
364
|
-
function logTailwindcssTarget(
|
|
365
|
-
const packageInfo =
|
|
368
|
+
function logTailwindcssTarget(tailwindRuntime, baseDir) {
|
|
369
|
+
const packageInfo = tailwindRuntime?.packageInfo;
|
|
366
370
|
const label = "Weapp-tailwindcss";
|
|
367
371
|
if (!packageInfo?.rootPath) {
|
|
368
372
|
_weapp_tailwindcss_logger.logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? node_process.default.cwd());
|
|
@@ -376,7 +380,7 @@ function logTailwindcssTarget(patcher, baseDir) {
|
|
|
376
380
|
//#endregion
|
|
377
381
|
//#region src/unocss/index.ts
|
|
378
382
|
function normalizeUnocssOptions(unocss) {
|
|
379
|
-
return
|
|
383
|
+
return require_v4_engine.resolveBooleanObjectOption(unocss, {});
|
|
380
384
|
}
|
|
381
385
|
function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
|
|
382
386
|
const baseArbitraryValues = arbitraryValues ?? {};
|
|
@@ -395,10 +399,28 @@ function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
|
|
|
395
399
|
const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
396
400
|
const AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
397
401
|
const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
|
|
402
|
+
const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
|
|
403
|
+
const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
|
|
398
404
|
const globalCacheHolder = globalThis;
|
|
399
405
|
const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
400
406
|
const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
|
|
401
407
|
const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
|
|
408
|
+
function resolveCompilerContextCacheMax(defaultValue) {
|
|
409
|
+
const raw = Number.parseInt(node_process.default.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
|
|
410
|
+
if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
|
|
411
|
+
return Math.floor(raw);
|
|
412
|
+
}
|
|
413
|
+
function touchMapValue(map, key, value) {
|
|
414
|
+
map.delete(key);
|
|
415
|
+
map.set(key, value);
|
|
416
|
+
}
|
|
417
|
+
function pruneMapToMaxSize(map, maxSize) {
|
|
418
|
+
while (map.size > maxSize) {
|
|
419
|
+
const firstKey = map.keys().next().value;
|
|
420
|
+
if (firstKey === void 0) break;
|
|
421
|
+
map.delete(firstKey);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
402
424
|
function withCircularGuard(value, stack, factory) {
|
|
403
425
|
if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
|
|
404
426
|
stack.add(value);
|
|
@@ -568,7 +590,8 @@ function createCompilerContextCacheKey(opts) {
|
|
|
568
590
|
const cached = keyStore.get(runtimeCacheScopeKey);
|
|
569
591
|
if (cached !== void 0) return cached;
|
|
570
592
|
const cacheKey = (0, _weapp_tailwindcss_shared_node.md5)(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
|
|
571
|
-
keyStore
|
|
593
|
+
touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
|
|
594
|
+
pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
|
|
572
595
|
return cacheKey;
|
|
573
596
|
} catch (error) {
|
|
574
597
|
_weapp_tailwindcss_logger.logger.debug("skip compiler context cache: %O", error);
|
|
@@ -579,10 +602,16 @@ function withCompilerContextCache(opts, factory) {
|
|
|
579
602
|
const cacheKey = createCompilerContextCacheKey(opts);
|
|
580
603
|
if (cacheKey) {
|
|
581
604
|
const cached = compilerContextCache.get(cacheKey);
|
|
582
|
-
if (cached)
|
|
605
|
+
if (cached) {
|
|
606
|
+
touchMapValue(compilerContextCache, cacheKey, cached);
|
|
607
|
+
return cached;
|
|
608
|
+
}
|
|
583
609
|
}
|
|
584
610
|
const ctx = factory();
|
|
585
|
-
if (cacheKey)
|
|
611
|
+
if (cacheKey) {
|
|
612
|
+
touchMapValue(compilerContextCache, cacheKey, ctx);
|
|
613
|
+
pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
|
|
614
|
+
}
|
|
586
615
|
return ctx;
|
|
587
616
|
}
|
|
588
617
|
//#endregion
|
|
@@ -713,7 +742,7 @@ function replaceWxml(original, options = {
|
|
|
713
742
|
const { keepEOL, escapeMap, ignoreHead } = options;
|
|
714
743
|
let res = original;
|
|
715
744
|
if (!keepEOL) res = res.replaceAll(NEWLINE_RE, "");
|
|
716
|
-
res = (0, _weapp_core_escape.escape)(res,
|
|
745
|
+
res = (0, _weapp_core_escape.escape)(res, require_v4_engine.omitUndefined({
|
|
717
746
|
map: escapeMap,
|
|
718
747
|
ignoreHead
|
|
719
748
|
}));
|
|
@@ -934,7 +963,7 @@ function getReplacement(candidate, escapeMap, store = getReplacementCacheStore(e
|
|
|
934
963
|
}
|
|
935
964
|
//#endregion
|
|
936
965
|
//#region src/js/handlers.ts
|
|
937
|
-
const debug =
|
|
966
|
+
const debug$1 = createDebug("[js:handlers] ");
|
|
938
967
|
const WEAPP_TW_IGNORE_MARKER = "weapp-tw";
|
|
939
968
|
const IGNORE_MARKER = "ignore";
|
|
940
969
|
function hasIgnoreComment(node) {
|
|
@@ -946,6 +975,19 @@ function hasIgnoreComment(node) {
|
|
|
946
975
|
}
|
|
947
976
|
return false;
|
|
948
977
|
}
|
|
978
|
+
function isConditionTestLiteral(path) {
|
|
979
|
+
let current = path;
|
|
980
|
+
while (current?.parentPath) {
|
|
981
|
+
const parent = current.parentPath;
|
|
982
|
+
if (parent.isConditionalExpression()) return parent.node.test === current.node;
|
|
983
|
+
if (parent.isBinaryExpression() || parent.isCallExpression() || parent.isLogicalExpression() || parent.isMemberExpression() || parent.isUnaryExpression()) {
|
|
984
|
+
current = parent;
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
return false;
|
|
990
|
+
}
|
|
949
991
|
function extractLiteralValue(path, { unescapeUnicode }) {
|
|
950
992
|
const { node } = path;
|
|
951
993
|
let offset = 0;
|
|
@@ -1011,10 +1053,11 @@ function replaceHandleValue(path, options) {
|
|
|
1011
1053
|
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
1012
1054
|
if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) return;
|
|
1013
1055
|
if (hasIgnoreComment(path.node)) return;
|
|
1056
|
+
if (isConditionTestLiteral(path)) return;
|
|
1014
1057
|
const { literal, original, offset } = extractLiteralValue(path, options);
|
|
1015
|
-
const candidates = (0,
|
|
1058
|
+
const candidates = (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal);
|
|
1016
1059
|
if (candidates.length === 0) return;
|
|
1017
|
-
const debugEnabled = debug.enabled;
|
|
1060
|
+
const debugEnabled = debug$1.enabled;
|
|
1018
1061
|
const classContext = options.wrapExpression || isClassContextLiteralPath(path);
|
|
1019
1062
|
let transformed = literal;
|
|
1020
1063
|
let mutated = false;
|
|
@@ -1050,7 +1093,7 @@ function replaceHandleValue(path, options) {
|
|
|
1050
1093
|
}
|
|
1051
1094
|
const node = path.node;
|
|
1052
1095
|
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") return;
|
|
1053
|
-
if (debugEnabled) debug("runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s", classNameSet?.size ?? 0, fallbackDecisionCount > 0, candidates.length, matchedCandidateCount, escapedDecisionCount, skippedSamples?.length ?? 0, options.filename ?? "unknown", escapedSamples?.join(",") || "-", skippedSamples?.join(",") || "-");
|
|
1096
|
+
if (debugEnabled) debug$1("runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s", classNameSet?.size ?? 0, fallbackDecisionCount > 0, candidates.length, matchedCandidateCount, escapedDecisionCount, skippedSamples?.length ?? 0, options.filename ?? "unknown", escapedSamples?.join(",") || "-", skippedSamples?.join(",") || "-");
|
|
1054
1097
|
const start = node.start + offset;
|
|
1055
1098
|
const end = node.end - offset;
|
|
1056
1099
|
if (start >= end || transformed === original) return;
|
|
@@ -2026,6 +2069,198 @@ function jsHandler(rawSource, options) {
|
|
|
2026
2069
|
}
|
|
2027
2070
|
defaultEvalHandler = jsHandler;
|
|
2028
2071
|
//#endregion
|
|
2072
|
+
//#region src/js/literal-transform.ts
|
|
2073
|
+
function transformLiteralText(literal, options) {
|
|
2074
|
+
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
2075
|
+
if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
|
|
2076
|
+
const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
|
|
2077
|
+
const candidates = (0, _tailwindcss_mangle_engine.splitCandidateTokens)(source);
|
|
2078
|
+
if (candidates.length === 0) return;
|
|
2079
|
+
const transformOptions = {
|
|
2080
|
+
...options,
|
|
2081
|
+
classContext: true
|
|
2082
|
+
};
|
|
2083
|
+
const replacementCache = getReplacementCacheStore(options.escapeMap);
|
|
2084
|
+
let transformed = source;
|
|
2085
|
+
let mutated = false;
|
|
2086
|
+
for (const candidate of candidates) {
|
|
2087
|
+
const result = resolveClassNameTransformWithResult(candidate, transformOptions);
|
|
2088
|
+
if (result.decision === "skip" || !transformed.includes(candidate)) continue;
|
|
2089
|
+
const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
|
|
2090
|
+
const replaced = transformed.replace(candidate, replacement);
|
|
2091
|
+
if (replaced !== transformed) {
|
|
2092
|
+
transformed = replaced;
|
|
2093
|
+
mutated = true;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
return mutated ? transformed : void 0;
|
|
2097
|
+
}
|
|
2098
|
+
//#endregion
|
|
2099
|
+
//#region src/js/fast-path/oxc.ts
|
|
2100
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2101
|
+
let oxcParser;
|
|
2102
|
+
let oxcWalker;
|
|
2103
|
+
function isOxcParserRuntimeSupported(version = node_process.default.versions.node) {
|
|
2104
|
+
const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
|
|
2105
|
+
if (!match) return false;
|
|
2106
|
+
const major = Number(match[1]);
|
|
2107
|
+
const minor = Number(match[2]);
|
|
2108
|
+
if (major === 20) return minor >= 19;
|
|
2109
|
+
if (major === 21) return false;
|
|
2110
|
+
if (major === 22) return minor >= 12;
|
|
2111
|
+
return major > 22;
|
|
2112
|
+
}
|
|
2113
|
+
function loadOxcParser() {
|
|
2114
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2115
|
+
if (oxcParser === false) return;
|
|
2116
|
+
if (oxcParser) return oxcParser;
|
|
2117
|
+
try {
|
|
2118
|
+
oxcParser = require$1("oxc-parser");
|
|
2119
|
+
} catch {
|
|
2120
|
+
oxcParser = false;
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
return oxcParser;
|
|
2124
|
+
}
|
|
2125
|
+
function loadOxcWalker() {
|
|
2126
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2127
|
+
if (oxcWalker === false) return;
|
|
2128
|
+
if (oxcWalker) return oxcWalker;
|
|
2129
|
+
try {
|
|
2130
|
+
oxcWalker = require$1("oxc-walker");
|
|
2131
|
+
} catch {
|
|
2132
|
+
oxcWalker = false;
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
return oxcWalker;
|
|
2136
|
+
}
|
|
2137
|
+
function hasValues(values) {
|
|
2138
|
+
return Array.isArray(values) && values.length > 0;
|
|
2139
|
+
}
|
|
2140
|
+
function hasUnsupportedSourceMarker(rawSource) {
|
|
2141
|
+
return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
|
|
2142
|
+
}
|
|
2143
|
+
function hasSupportedClassMatchSource(options) {
|
|
2144
|
+
return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
|
|
2145
|
+
}
|
|
2146
|
+
function canUseOxcJsFastPath(options) {
|
|
2147
|
+
if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
|
|
2148
|
+
return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
|
|
2149
|
+
}
|
|
2150
|
+
function getParserLang(filename) {
|
|
2151
|
+
if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
|
|
2152
|
+
if (filename?.endsWith(".tsx")) return "tsx";
|
|
2153
|
+
if (filename?.endsWith(".jsx")) return "jsx";
|
|
2154
|
+
return "js";
|
|
2155
|
+
}
|
|
2156
|
+
function getParserSourceType(sourceType) {
|
|
2157
|
+
return sourceType === "script" || sourceType === "module" ? sourceType : "module";
|
|
2158
|
+
}
|
|
2159
|
+
function isRangeValid(start, end) {
|
|
2160
|
+
return typeof start === "number" && typeof end === "number" && start < end;
|
|
2161
|
+
}
|
|
2162
|
+
function getMagicString(rawSource, context) {
|
|
2163
|
+
if (!context.ms) context.ms = new magic_string.default(rawSource);
|
|
2164
|
+
return context.ms;
|
|
2165
|
+
}
|
|
2166
|
+
function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
|
|
2167
|
+
if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2168
|
+
const transformed = transformLiteralText(node.value, transformOptions);
|
|
2169
|
+
if (!transformed) return false;
|
|
2170
|
+
const start = node.start + 1;
|
|
2171
|
+
const end = node.end - 1;
|
|
2172
|
+
if (start >= end || transformed === rawSource.slice(start, end)) return false;
|
|
2173
|
+
getMagicString(rawSource, context).update(start, end, (0, _ast_core_escape.jsStringEscape)(transformed));
|
|
2174
|
+
return true;
|
|
2175
|
+
}
|
|
2176
|
+
function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
|
|
2177
|
+
const raw = node.value?.raw;
|
|
2178
|
+
if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2179
|
+
const transformed = transformLiteralText(raw, transformOptions);
|
|
2180
|
+
if (!transformed || transformed === raw) return false;
|
|
2181
|
+
const first = rawSource[node.start];
|
|
2182
|
+
const last = rawSource[node.end - 1];
|
|
2183
|
+
const start = node.start + (first === "`" || first === "}" ? 1 : 0);
|
|
2184
|
+
const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
|
|
2185
|
+
if (start >= end) return false;
|
|
2186
|
+
getMagicString(rawSource, context).update(start, end, transformed);
|
|
2187
|
+
return true;
|
|
2188
|
+
}
|
|
2189
|
+
function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
|
|
2190
|
+
let changed = false;
|
|
2191
|
+
walker.walk(program, { enter(node) {
|
|
2192
|
+
if (node.type === "Literal") {
|
|
2193
|
+
changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
if (node.type === "TemplateElement") {
|
|
2197
|
+
changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
|
|
2198
|
+
this.skip();
|
|
2199
|
+
}
|
|
2200
|
+
} });
|
|
2201
|
+
return changed;
|
|
2202
|
+
}
|
|
2203
|
+
function oxcJsHandler(rawSource, options) {
|
|
2204
|
+
if (!canUseOxcJsFastPath(options)) return;
|
|
2205
|
+
if (hasUnsupportedSourceMarker(rawSource)) return;
|
|
2206
|
+
const parser = loadOxcParser();
|
|
2207
|
+
const walker = loadOxcWalker();
|
|
2208
|
+
if (!parser || !walker) return;
|
|
2209
|
+
let result;
|
|
2210
|
+
try {
|
|
2211
|
+
result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
|
|
2212
|
+
sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
|
|
2213
|
+
lang: getParserLang(options.filename)
|
|
2214
|
+
});
|
|
2215
|
+
} catch {
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
|
|
2219
|
+
const stringLiteralOptions = options.needEscaped === true ? options : {
|
|
2220
|
+
...options,
|
|
2221
|
+
needEscaped: true
|
|
2222
|
+
};
|
|
2223
|
+
const templateLiteralOptions = options.needEscaped === false ? options : {
|
|
2224
|
+
...options,
|
|
2225
|
+
needEscaped: false
|
|
2226
|
+
};
|
|
2227
|
+
const replacementContext = {};
|
|
2228
|
+
if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
|
|
2229
|
+
return { code: replacementContext.ms.toString() };
|
|
2230
|
+
}
|
|
2231
|
+
//#endregion
|
|
2232
|
+
//#region src/js/precheck.ts
|
|
2233
|
+
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
2234
|
+
const FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
|
|
2235
|
+
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
2236
|
+
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
2237
|
+
/**
|
|
2238
|
+
* 判断源码是否可能声明跨模块依赖。
|
|
2239
|
+
*
|
|
2240
|
+
* 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
|
|
2241
|
+
* 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
|
|
2242
|
+
*/
|
|
2243
|
+
function hasDependencyHint(rawSource) {
|
|
2244
|
+
return DEPENDENCY_HINT_RE.test(rawSource);
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* 判断是否可以跳过 JS 转换。
|
|
2248
|
+
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
2249
|
+
*
|
|
2250
|
+
* @param rawSource - 原始 JS 源码字符串
|
|
2251
|
+
* @param options - 可选的 JS 处理器配置选项
|
|
2252
|
+
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
2253
|
+
*/
|
|
2254
|
+
function shouldSkipJsTransform(rawSource, options) {
|
|
2255
|
+
if (node_process.default.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
2256
|
+
if (!rawSource) return true;
|
|
2257
|
+
if (options?.alwaysEscape) return false;
|
|
2258
|
+
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
2259
|
+
if (options?.wrapExpression) return false;
|
|
2260
|
+
if (hasDependencyHint(rawSource)) return false;
|
|
2261
|
+
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
2262
|
+
}
|
|
2263
|
+
//#endregion
|
|
2029
2264
|
//#region src/js/index.ts
|
|
2030
2265
|
/** 默认 LRU 缓存最大条目数 */
|
|
2031
2266
|
const RESULT_CACHE_MAX = 512;
|
|
@@ -2070,6 +2305,7 @@ function getOptionsFingerprint(options) {
|
|
|
2070
2305
|
JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
|
|
2071
2306
|
JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
|
|
2072
2307
|
JSON.stringify(options.moduleSpecifierReplacements ?? null),
|
|
2308
|
+
String(options.experimentalJsFastPath ?? ""),
|
|
2073
2309
|
JSON.stringify(options.babelParserOptions ?? null)
|
|
2074
2310
|
].join("|");
|
|
2075
2311
|
fingerprintCache.set(options, fingerprint);
|
|
@@ -2085,6 +2321,13 @@ function shouldCacheJsResult(rawSource, options) {
|
|
|
2085
2321
|
if (options.moduleGraph || options.filename) return false;
|
|
2086
2322
|
return true;
|
|
2087
2323
|
}
|
|
2324
|
+
function resolveFastPathOptions(rawSource, options) {
|
|
2325
|
+
if (!options.moduleGraph) return options;
|
|
2326
|
+
if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
|
|
2327
|
+
if (hasDependencyHint(rawSource)) return options;
|
|
2328
|
+
const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
|
|
2329
|
+
return fastPathOptions;
|
|
2330
|
+
}
|
|
2088
2331
|
function createJsHandler(options) {
|
|
2089
2332
|
const defaults = {
|
|
2090
2333
|
escapeMap: options.escapeMap,
|
|
@@ -2097,6 +2340,7 @@ function createJsHandler(options) {
|
|
|
2097
2340
|
alwaysEscape: options.alwaysEscape,
|
|
2098
2341
|
unescapeUnicode: options.unescapeUnicode,
|
|
2099
2342
|
babelParserOptions: options.babelParserOptions,
|
|
2343
|
+
experimentalJsFastPath: options.experimentalJsFastPath,
|
|
2100
2344
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
2101
2345
|
ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
|
|
2102
2346
|
uniAppX: options.uniAppX,
|
|
@@ -2165,7 +2409,7 @@ function createJsHandler(options) {
|
|
|
2165
2409
|
const resolvedOptions = resolveOptions(classNameSet, options);
|
|
2166
2410
|
const cached = getCachedJsResult(rawSource, resolvedOptions);
|
|
2167
2411
|
if (cached) return cached;
|
|
2168
|
-
return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
|
|
2412
|
+
return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
|
|
2169
2413
|
}
|
|
2170
2414
|
return handler;
|
|
2171
2415
|
}
|
|
@@ -4539,7 +4783,7 @@ const DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
|
4539
4783
|
//#endregion
|
|
4540
4784
|
//#region src/context/runtime-package-replacements.ts
|
|
4541
4785
|
function resolveRuntimePackageReplacements(option) {
|
|
4542
|
-
const mapping =
|
|
4786
|
+
const mapping = require_v4_engine.resolveBooleanObjectOption(option, DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS);
|
|
4543
4787
|
if (!mapping) return;
|
|
4544
4788
|
const normalized = {};
|
|
4545
4789
|
for (const [from, to] of Object.entries(mapping)) {
|
|
@@ -4550,8 +4794,22 @@ function resolveRuntimePackageReplacements(option) {
|
|
|
4550
4794
|
}
|
|
4551
4795
|
//#endregion
|
|
4552
4796
|
//#region src/context/style-options.ts
|
|
4553
|
-
function
|
|
4797
|
+
function normalizeStyleHandlerMajorVersion(majorVersion) {
|
|
4798
|
+
return majorVersion === 4 ? 4 : void 0;
|
|
4799
|
+
}
|
|
4800
|
+
function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
|
|
4554
4801
|
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX);
|
|
4802
|
+
const branch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
|
|
4803
|
+
appType: ctx.appType,
|
|
4804
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4805
|
+
tailwindcssMajorVersion,
|
|
4806
|
+
uniAppX: resolvedUniAppXOptions
|
|
4807
|
+
}), {
|
|
4808
|
+
appType: ctx.appType,
|
|
4809
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4810
|
+
tailwindcssMajorVersion,
|
|
4811
|
+
uniAppX: resolvedUniAppXOptions
|
|
4812
|
+
});
|
|
4555
4813
|
const hasCssOptions = ctx.cssOptions !== void 0;
|
|
4556
4814
|
const cssOptions = {
|
|
4557
4815
|
cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
|
|
@@ -4566,13 +4824,14 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4566
4824
|
atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
|
|
4567
4825
|
autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
|
|
4568
4826
|
cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
|
|
4569
|
-
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4827
|
+
platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
|
|
4570
4828
|
px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
|
|
4571
4829
|
unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
|
|
4572
4830
|
unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
|
|
4573
4831
|
injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
|
|
4574
4832
|
};
|
|
4575
4833
|
return {
|
|
4834
|
+
appType: ctx.appType,
|
|
4576
4835
|
cssPreflight: cssOptions.cssPreflight,
|
|
4577
4836
|
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
4578
4837
|
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
@@ -4586,7 +4845,7 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4586
4845
|
atRules: cssOptions.atRules,
|
|
4587
4846
|
autoprefixer: cssOptions.autoprefixer,
|
|
4588
4847
|
cssCalc: cssOptions.cssCalc,
|
|
4589
|
-
uniAppX:
|
|
4848
|
+
uniAppX: branch.isNativeApp,
|
|
4590
4849
|
platform: cssOptions.platform,
|
|
4591
4850
|
px2rpx: cssOptions.px2rpx,
|
|
4592
4851
|
unitsToPx: cssOptions.unitsToPx,
|
|
@@ -4596,9 +4855,9 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4596
4855
|
//#endregion
|
|
4597
4856
|
//#region src/context/handlers.ts
|
|
4598
4857
|
function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
|
|
4599
|
-
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4858
|
+
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4600
4859
|
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
|
|
4601
|
-
const styleOptions = resolveStyleOptionsFromContext(ctx);
|
|
4860
|
+
const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
|
|
4602
4861
|
const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
|
|
4603
4862
|
const uniAppXEnabled = styleOptions.uniAppX === true;
|
|
4604
4863
|
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
@@ -4609,7 +4868,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
4609
4868
|
postcssOptions,
|
|
4610
4869
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
4611
4870
|
cssCalc: cssCalcOptions,
|
|
4612
|
-
majorVersion: tailwindcssMajorVersion
|
|
4871
|
+
majorVersion: normalizeStyleHandlerMajorVersion(tailwindcssMajorVersion)
|
|
4613
4872
|
});
|
|
4614
4873
|
const jsHandler = createJsHandler({
|
|
4615
4874
|
escapeMap,
|
|
@@ -4619,6 +4878,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
4619
4878
|
tailwindcssMajorVersion,
|
|
4620
4879
|
generateMap: true,
|
|
4621
4880
|
babelParserOptions,
|
|
4881
|
+
experimentalJsFastPath,
|
|
4622
4882
|
ignoreCallExpressionIdentifiers,
|
|
4623
4883
|
ignoreTaggedTemplateExpressionIdentifiers,
|
|
4624
4884
|
uniAppX: uniAppXEnabled,
|
|
@@ -4652,7 +4912,7 @@ function applyLoggerLevel(logLevel) {
|
|
|
4652
4912
|
function resolveContextCssPreflight(opts, ctx, majorVersion) {
|
|
4653
4913
|
const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
|
|
4654
4914
|
const cssPreflight = require_defaults.resolveDefaultCssPreflight(userCssPreflight, majorVersion);
|
|
4655
|
-
if (
|
|
4915
|
+
if (cssPreflight === false || !require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
|
|
4656
4916
|
const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
|
|
4657
4917
|
return {
|
|
4658
4918
|
...cssPreflight,
|
|
@@ -4705,21 +4965,21 @@ function syncLegacyFieldsToCssOptions(ctx) {
|
|
|
4705
4965
|
injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
|
|
4706
4966
|
};
|
|
4707
4967
|
}
|
|
4708
|
-
async function
|
|
4709
|
-
if (!
|
|
4710
|
-
const cacheOptions =
|
|
4968
|
+
async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
|
|
4969
|
+
if (!tailwindRuntime) return;
|
|
4970
|
+
const cacheOptions = tailwindRuntime.options?.cache;
|
|
4711
4971
|
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
|
|
4712
|
-
if (typeof
|
|
4713
|
-
await
|
|
4972
|
+
if (typeof tailwindRuntime.clearCache === "function") try {
|
|
4973
|
+
await tailwindRuntime.clearCache({ scope: "all" });
|
|
4714
4974
|
} catch (error) {
|
|
4715
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss
|
|
4975
|
+
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
|
|
4716
4976
|
}
|
|
4717
4977
|
if (!options?.removeDirectory) return;
|
|
4718
4978
|
const cachePaths = /* @__PURE__ */ new Map();
|
|
4719
4979
|
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
4720
|
-
|
|
4721
|
-
const privateCachePath = patcher?.cacheStore?.options?.path;
|
|
4980
|
+
const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
|
|
4722
4981
|
if (privateCachePath) cachePaths.set(privateCachePath, false);
|
|
4982
|
+
if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
|
|
4723
4983
|
if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
|
|
4724
4984
|
if (!cachePaths.size) return;
|
|
4725
4985
|
for (const [cachePath, recursive] of cachePaths.entries()) try {
|
|
@@ -4730,7 +4990,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
4730
4990
|
} catch (error) {
|
|
4731
4991
|
const err = error;
|
|
4732
4992
|
if (err?.code === "ENOENT") continue;
|
|
4733
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss
|
|
4993
|
+
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
|
|
4734
4994
|
}
|
|
4735
4995
|
}
|
|
4736
4996
|
function createInternalCompilerContext(opts) {
|
|
@@ -4739,32 +4999,32 @@ function createInternalCompilerContext(opts) {
|
|
|
4739
4999
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
4740
5000
|
syncCssOptionsToLegacyFields(ctx);
|
|
4741
5001
|
applyLoggerLevel(ctx.logLevel);
|
|
4742
|
-
const
|
|
4743
|
-
logTailwindcssTarget(
|
|
4744
|
-
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir,
|
|
4745
|
-
if (opts?.__internalDeferMissingCssEntriesWarning !== true) require_tailwindcss.warnMissingCssEntries(ctx,
|
|
4746
|
-
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx,
|
|
4747
|
-
const cssCalcOptions = require_tailwindcss.applyV4CssCalcDefaults(ctx.cssCalc,
|
|
5002
|
+
const tailwindRuntime = require_tailwindcss.createTailwindcssRuntimeFromContext(ctx);
|
|
5003
|
+
logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
|
|
5004
|
+
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
|
|
5005
|
+
if (opts?.__internalDeferMissingCssEntriesWarning !== true) require_tailwindcss.warnMissingCssEntries(ctx, tailwindRuntime);
|
|
5006
|
+
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
|
|
5007
|
+
const cssCalcOptions = require_tailwindcss.applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
|
|
4748
5008
|
ctx.cssCalc = cssCalcOptions;
|
|
4749
5009
|
syncLegacyFieldsToCssOptions(ctx);
|
|
4750
|
-
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions,
|
|
5010
|
+
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
|
|
4751
5011
|
ctx.styleHandler = styleHandler;
|
|
4752
5012
|
ctx.jsHandler = jsHandler;
|
|
4753
5013
|
ctx.templateHandler = templateHandler;
|
|
4754
5014
|
ctx.cache = initializeCache(ctx.cache);
|
|
4755
|
-
ctx.
|
|
4756
|
-
const
|
|
4757
|
-
const
|
|
4758
|
-
if (options?.clearCache !== false) await
|
|
4759
|
-
|
|
4760
|
-
const
|
|
4761
|
-
Object.assign(
|
|
4762
|
-
ctx.
|
|
4763
|
-
return
|
|
5015
|
+
ctx.tailwindRuntime = tailwindRuntime;
|
|
5016
|
+
const refreshTailwindcssRuntime = async (options) => {
|
|
5017
|
+
const previousRuntime = ctx.tailwindRuntime;
|
|
5018
|
+
if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
|
|
5019
|
+
require_tailwindcss.invalidateRuntimeClassSet(previousRuntime);
|
|
5020
|
+
const nextRuntime = require_tailwindcss.createTailwindcssRuntimeFromContext(ctx);
|
|
5021
|
+
Object.assign(previousRuntime, nextRuntime);
|
|
5022
|
+
ctx.tailwindRuntime = previousRuntime;
|
|
5023
|
+
return previousRuntime;
|
|
4764
5024
|
};
|
|
4765
|
-
ctx.
|
|
4766
|
-
Object.defineProperty(ctx.
|
|
4767
|
-
value:
|
|
5025
|
+
ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
|
|
5026
|
+
Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
|
|
5027
|
+
value: refreshTailwindcssRuntime,
|
|
4768
5028
|
configurable: true
|
|
4769
5029
|
});
|
|
4770
5030
|
return ctx;
|
|
@@ -4778,29 +5038,6 @@ function getCompilerContext(opts) {
|
|
|
4778
5038
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
4779
5039
|
}
|
|
4780
5040
|
//#endregion
|
|
4781
|
-
//#region src/js/precheck.ts
|
|
4782
|
-
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
4783
|
-
const FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
|
|
4784
|
-
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
4785
|
-
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
4786
|
-
/**
|
|
4787
|
-
* 判断是否可以跳过 JS 转换。
|
|
4788
|
-
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
4789
|
-
*
|
|
4790
|
-
* @param rawSource - 原始 JS 源码字符串
|
|
4791
|
-
* @param options - 可选的 JS 处理器配置选项
|
|
4792
|
-
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
4793
|
-
*/
|
|
4794
|
-
function shouldSkipJsTransform(rawSource, options) {
|
|
4795
|
-
if (node_process.default.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
4796
|
-
if (!rawSource) return true;
|
|
4797
|
-
if (options?.alwaysEscape) return false;
|
|
4798
|
-
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
4799
|
-
if (options?.wrapExpression) return false;
|
|
4800
|
-
if (DEPENDENCY_HINT_RE.test(rawSource)) return false;
|
|
4801
|
-
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
4802
|
-
}
|
|
4803
|
-
//#endregion
|
|
4804
5041
|
Object.defineProperty(exports, "JsTokenUpdater", {
|
|
4805
5042
|
enumerable: true,
|
|
4806
5043
|
get: function() {
|
|
@@ -4843,6 +5080,12 @@ Object.defineProperty(exports, "createAttributeMatcher", {
|
|
|
4843
5080
|
return createAttributeMatcher;
|
|
4844
5081
|
}
|
|
4845
5082
|
});
|
|
5083
|
+
Object.defineProperty(exports, "createDebug", {
|
|
5084
|
+
enumerable: true,
|
|
5085
|
+
get: function() {
|
|
5086
|
+
return createDebug;
|
|
5087
|
+
}
|
|
5088
|
+
});
|
|
4846
5089
|
Object.defineProperty(exports, "createTailwindRuntimeReadyPromise", {
|
|
4847
5090
|
enumerable: true,
|
|
4848
5091
|
get: function() {
|
|
@@ -4873,6 +5116,12 @@ Object.defineProperty(exports, "isClassContextLiteralPath", {
|
|
|
4873
5116
|
return isClassContextLiteralPath;
|
|
4874
5117
|
}
|
|
4875
5118
|
});
|
|
5119
|
+
Object.defineProperty(exports, "normalizeStyleHandlerMajorVersion", {
|
|
5120
|
+
enumerable: true,
|
|
5121
|
+
get: function() {
|
|
5122
|
+
return normalizeStyleHandlerMajorVersion;
|
|
5123
|
+
}
|
|
5124
|
+
});
|
|
4876
5125
|
Object.defineProperty(exports, "pluginName", {
|
|
4877
5126
|
enumerable: true,
|
|
4878
5127
|
get: function() {
|