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
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { i as isMap, n as defuOverrideArray } from "./utils-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
1
|
+
import { G as createTailwindV4Engine$1, ct as omitUndefined, n as resolveTailwindV4SourceFromRuntime, y as resolveBooleanObjectOption } from "./v4-engine-CF9zt4Cw.mjs";
|
|
2
|
+
import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Dc4qaPmT.mjs";
|
|
3
|
+
import { i as isMap, n as defuOverrideArray } from "./utils-DodxWHGz.mjs";
|
|
4
|
+
import { a as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, i as resolveDefaultCssPreflight, o as HARD_PARSE_CACHE_MAX_ENTRIES, r as getDefaultOptions } from "./defaults-ZElj1zKc.mjs";
|
|
5
|
+
import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-wyUHrfil.mjs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
8
7
|
import path from "node:path";
|
|
9
8
|
import process from "node:process";
|
|
10
|
-
import {
|
|
9
|
+
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
10
|
+
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
11
|
+
import { LRUCache } from "lru-cache";
|
|
11
12
|
import { rm } from "node:fs/promises";
|
|
12
13
|
import { Buffer } from "node:buffer";
|
|
14
|
+
import { logger, pc } from "@weapp-tailwindcss/logger";
|
|
13
15
|
import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
|
|
14
16
|
import { MappingChars2String, escape } from "@weapp-core/escape";
|
|
17
|
+
import _createDebug from "debug";
|
|
15
18
|
import _babelTraverse from "@babel/traverse";
|
|
16
19
|
import { parse, parseExpression } from "@babel/parser";
|
|
17
20
|
import MagicString from "magic-string";
|
|
@@ -62,15 +65,16 @@ function createCache(options) {
|
|
|
62
65
|
});
|
|
63
66
|
return cache;
|
|
64
67
|
},
|
|
68
|
+
pruneHashKeys(hashKeys) {
|
|
69
|
+
const activeHashKeys = new Set(hashKeys);
|
|
70
|
+
for (const key of hashMap.keys()) if (!activeHashKeys.has(key)) hashMap.delete(key);
|
|
71
|
+
},
|
|
65
72
|
prune(options) {
|
|
66
73
|
if (options.cacheKeys) {
|
|
67
74
|
const cacheKeys = new Set(options.cacheKeys);
|
|
68
75
|
for (const key of instance.keys()) if (!cacheKeys.has(key)) instance.delete(key);
|
|
69
76
|
}
|
|
70
|
-
if (options.hashKeys)
|
|
71
|
-
const hashKeys = new Set(options.hashKeys);
|
|
72
|
-
for (const key of hashMap.keys()) if (!hashKeys.has(key)) hashMap.delete(key);
|
|
73
|
-
}
|
|
77
|
+
if (options.hashKeys) cache.pruneHashKeys?.(options.hashKeys);
|
|
74
78
|
},
|
|
75
79
|
has(key) {
|
|
76
80
|
return instance.has(key);
|
|
@@ -109,13 +113,28 @@ function initializeCache(cacheConfig) {
|
|
|
109
113
|
return cacheConfig;
|
|
110
114
|
}
|
|
111
115
|
//#endregion
|
|
116
|
+
//#region src/debug/index.ts
|
|
117
|
+
const _debug = _createDebug("weapp-tw");
|
|
118
|
+
function createDebug(prefix) {
|
|
119
|
+
const debug = ((formatter, ...args) => {
|
|
120
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(debug, "enabled", {
|
|
123
|
+
enumerable: false,
|
|
124
|
+
configurable: false,
|
|
125
|
+
get() {
|
|
126
|
+
return _debug.enabled;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return debug;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
112
132
|
//#region src/tailwindcss/runtime.ts
|
|
113
133
|
const debug$1 = createDebug("[tailwindcss:runtime] ");
|
|
114
|
-
const
|
|
115
|
-
function createTailwindRuntimeReadyPromise(
|
|
134
|
+
const refreshTailwindcssRuntimeSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssRuntime");
|
|
135
|
+
function createTailwindRuntimeReadyPromise(tailwindRuntime) {
|
|
116
136
|
return Promise.resolve().then(async () => {
|
|
117
|
-
|
|
118
|
-
invalidateRuntimeClassSet(twPatcher);
|
|
137
|
+
invalidateRuntimeClassSet(tailwindRuntime);
|
|
119
138
|
});
|
|
120
139
|
}
|
|
121
140
|
const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -127,21 +146,31 @@ function getRuntimeClassSetStateEntry(state) {
|
|
|
127
146
|
}
|
|
128
147
|
return entry;
|
|
129
148
|
}
|
|
149
|
+
function getTailwindRuntime(state) {
|
|
150
|
+
return state.tailwindRuntime;
|
|
151
|
+
}
|
|
152
|
+
function setTailwindRuntime(state, runtime) {
|
|
153
|
+
state.tailwindRuntime = runtime;
|
|
154
|
+
}
|
|
155
|
+
function getRefreshTailwindRuntime(state) {
|
|
156
|
+
return state.refreshTailwindcssRuntime;
|
|
157
|
+
}
|
|
130
158
|
async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
131
159
|
const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
|
|
132
160
|
const force = normalizedOptions.force;
|
|
133
161
|
const clearCache = normalizedOptions.clearCache === true;
|
|
134
162
|
if (!force) return false;
|
|
135
|
-
debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, state.
|
|
163
|
+
debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
136
164
|
await state.readyPromise;
|
|
137
165
|
let refreshed = false;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
166
|
+
const refreshTailwindRuntime = getRefreshTailwindRuntime(state);
|
|
167
|
+
if (typeof refreshTailwindRuntime === "function") {
|
|
168
|
+
const next = await refreshTailwindRuntime({ clearCache });
|
|
169
|
+
if (next !== getTailwindRuntime(state)) setTailwindRuntime(state, next);
|
|
141
170
|
refreshed = true;
|
|
142
171
|
}
|
|
143
|
-
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(state
|
|
144
|
-
debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, state.
|
|
172
|
+
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(getTailwindRuntime(state));
|
|
173
|
+
debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
145
174
|
return refreshed;
|
|
146
175
|
}
|
|
147
176
|
async function ensureRuntimeClassSet(state, options = {}) {
|
|
@@ -155,7 +184,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
155
184
|
});
|
|
156
185
|
await state.readyPromise;
|
|
157
186
|
const entry = getRuntimeClassSetStateEntry(state);
|
|
158
|
-
const signature = await getRuntimeClassSetSignatureWithSources(state
|
|
187
|
+
const signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
159
188
|
const signatureChanged = entry.signature !== signature;
|
|
160
189
|
const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
|
|
161
190
|
if (!shouldForceCollect) {
|
|
@@ -163,7 +192,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
163
192
|
if (entry.promise) return entry.promise;
|
|
164
193
|
}
|
|
165
194
|
const task = (async () => {
|
|
166
|
-
const collected = await collectRuntimeClassSet(state
|
|
195
|
+
const collected = await collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
167
196
|
force: shouldForceCollect,
|
|
168
197
|
skipRefresh: true,
|
|
169
198
|
clearCache
|
|
@@ -174,7 +203,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
174
203
|
clearCache: true
|
|
175
204
|
});
|
|
176
205
|
await state.readyPromise;
|
|
177
|
-
return collectRuntimeClassSet(state
|
|
206
|
+
return collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
178
207
|
force: true,
|
|
179
208
|
skipRefresh: true,
|
|
180
209
|
clearCache: true
|
|
@@ -184,36 +213,29 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
184
213
|
try {
|
|
185
214
|
const runtimeSet = await task;
|
|
186
215
|
entry.value = runtimeSet;
|
|
187
|
-
entry.signature = await getRuntimeClassSetSignatureWithSources(state
|
|
216
|
+
entry.signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
188
217
|
return runtimeSet;
|
|
189
218
|
} finally {
|
|
190
219
|
if (entry.promise === task) entry.promise = void 0;
|
|
191
220
|
}
|
|
192
221
|
}
|
|
193
|
-
function
|
|
194
|
-
if (
|
|
195
|
-
if (majorVersion === 3) return true;
|
|
196
|
-
if (majorVersion === 4) return true;
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
200
|
-
if (typeof twPatcher.getClassSetSync !== "function") return;
|
|
201
|
-
if (!shouldPreferSync(twPatcher.majorVersion)) return;
|
|
222
|
+
function tryGetRuntimeClassSetSync(tailwindRuntime) {
|
|
223
|
+
if (typeof tailwindRuntime.getClassSetSync !== "function") return;
|
|
202
224
|
try {
|
|
203
|
-
const set =
|
|
225
|
+
const set = tailwindRuntime.getClassSetSync();
|
|
204
226
|
if (set && set.size === 0) return;
|
|
205
227
|
return set;
|
|
206
228
|
} catch (error) {
|
|
207
|
-
|
|
208
|
-
else debug$1("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
229
|
+
debug$1("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
209
230
|
return;
|
|
210
231
|
}
|
|
211
232
|
}
|
|
212
|
-
async function collectTailwindV4GeneratorClassSet(
|
|
233
|
+
async function collectTailwindV4GeneratorClassSet(tailwindRuntime) {
|
|
234
|
+
if (typeof tailwindRuntime.collectContentTokens !== "function") return;
|
|
213
235
|
try {
|
|
214
|
-
const generated = await createTailwindV4Engine$1(await
|
|
236
|
+
const generated = await createTailwindV4Engine$1(await resolveTailwindV4SourceFromRuntime(tailwindRuntime)).generate({
|
|
215
237
|
scanSources: true,
|
|
216
|
-
target: "
|
|
238
|
+
target: "web"
|
|
217
239
|
});
|
|
218
240
|
debug$1("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
|
|
219
241
|
return generated.classSet;
|
|
@@ -222,74 +244,53 @@ async function collectTailwindV4GeneratorClassSet(twPatcher) {
|
|
|
222
244
|
return;
|
|
223
245
|
}
|
|
224
246
|
}
|
|
225
|
-
async function mergeTailwindV4GeneratorClassSet(
|
|
226
|
-
|
|
227
|
-
const generatorClassSet = await collectTailwindV4GeneratorClassSet(twPatcher);
|
|
247
|
+
async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
|
|
248
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
|
|
228
249
|
if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
|
|
229
250
|
return new Set([...classSet, ...generatorClassSet]);
|
|
230
251
|
}
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
235
|
-
let activePatcher = twPatcher;
|
|
252
|
+
async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
|
|
253
|
+
let activeRuntime = tailwindRuntime;
|
|
236
254
|
if (options.force && !options.skipRefresh) {
|
|
237
|
-
const refresh =
|
|
255
|
+
const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
|
|
238
256
|
if (typeof refresh === "function") try {
|
|
239
257
|
const refreshed = await refresh({ clearCache: options.clearCache === true });
|
|
240
|
-
if (refreshed)
|
|
258
|
+
if (refreshed) activeRuntime = refreshed;
|
|
241
259
|
} catch (error) {
|
|
242
|
-
debug$1("
|
|
260
|
+
debug$1("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
|
|
243
261
|
}
|
|
244
262
|
}
|
|
245
|
-
const entry = getRuntimeClassSetCacheEntry(
|
|
246
|
-
const signature = await getRuntimeClassSetSignatureWithSources(
|
|
263
|
+
const entry = getRuntimeClassSetCacheEntry(activeRuntime);
|
|
264
|
+
const signature = await getRuntimeClassSetSignatureWithSources(activeRuntime);
|
|
247
265
|
if (!options.force) {
|
|
248
266
|
if (entry.value && entry.signature === signature) return entry.value;
|
|
249
267
|
if (entry.promise) return entry.promise;
|
|
250
268
|
} else entry.value = void 0;
|
|
251
269
|
const task = (async () => {
|
|
252
|
-
await ensureTailwindcssRuntimePatch(activePatcher);
|
|
253
|
-
const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
|
|
254
|
-
if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
|
|
255
270
|
const preferExtract = options.force === true;
|
|
256
271
|
try {
|
|
257
|
-
const result = await
|
|
272
|
+
const result = await activeRuntime.extract({ write: false });
|
|
258
273
|
if (result?.classSet) {
|
|
259
274
|
if (result.classSet.size > 0) {
|
|
260
|
-
|
|
261
|
-
debug$1("runtime class set resolved via extract(), size=%d", result.classSet.size);
|
|
262
|
-
return result.classSet;
|
|
263
|
-
}
|
|
264
|
-
const merged = await mergeTailwindV4GeneratorClassSet(activePatcher, result.classSet);
|
|
275
|
+
const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
|
|
265
276
|
debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
|
|
266
277
|
return merged;
|
|
267
278
|
}
|
|
268
|
-
if (preferExtract && activePatcher.majorVersion !== 4) {
|
|
269
|
-
debug$1("runtime class set resolved via empty extract() on force collect, size=0");
|
|
270
|
-
return result.classSet;
|
|
271
|
-
}
|
|
272
279
|
if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
|
|
273
280
|
else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
274
281
|
}
|
|
275
282
|
} catch (error) {
|
|
276
283
|
debug$1("extract() failed, fallback to getClassSet(): %O", error);
|
|
277
284
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
if (preExtractSyncSet) {
|
|
283
|
-
debug$1("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
|
|
284
|
-
return preExtractSyncSet;
|
|
285
|
-
}
|
|
286
|
-
const syncSet = tryGetRuntimeClassSetSync(activePatcher);
|
|
285
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
|
|
286
|
+
if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
|
|
287
|
+
const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
|
|
287
288
|
if (syncSet) {
|
|
288
289
|
debug$1("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
|
|
289
290
|
return syncSet;
|
|
290
291
|
}
|
|
291
292
|
try {
|
|
292
|
-
const fallbackSet = await Promise.resolve(
|
|
293
|
+
const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
|
|
293
294
|
if (fallbackSet) {
|
|
294
295
|
debug$1("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
|
|
295
296
|
return fallbackSet;
|
|
@@ -354,8 +355,8 @@ function formatRelativeToBase(targetPath, baseDir) {
|
|
|
354
355
|
if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
|
|
355
356
|
return path.join(".", relative).replace(/\\/g, "/");
|
|
356
357
|
}
|
|
357
|
-
function logTailwindcssTarget(
|
|
358
|
-
const packageInfo =
|
|
358
|
+
function logTailwindcssTarget(tailwindRuntime, baseDir) {
|
|
359
|
+
const packageInfo = tailwindRuntime?.packageInfo;
|
|
359
360
|
const label = "Weapp-tailwindcss";
|
|
360
361
|
if (!packageInfo?.rootPath) {
|
|
361
362
|
logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
|
|
@@ -388,10 +389,28 @@ function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
|
|
|
388
389
|
const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
389
390
|
const AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
390
391
|
const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
|
|
392
|
+
const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
|
|
393
|
+
const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
|
|
391
394
|
const globalCacheHolder = globalThis;
|
|
392
395
|
const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
393
396
|
const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
|
|
394
397
|
const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
|
|
398
|
+
function resolveCompilerContextCacheMax(defaultValue) {
|
|
399
|
+
const raw = Number.parseInt(process.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
|
|
400
|
+
if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
|
|
401
|
+
return Math.floor(raw);
|
|
402
|
+
}
|
|
403
|
+
function touchMapValue(map, key, value) {
|
|
404
|
+
map.delete(key);
|
|
405
|
+
map.set(key, value);
|
|
406
|
+
}
|
|
407
|
+
function pruneMapToMaxSize(map, maxSize) {
|
|
408
|
+
while (map.size > maxSize) {
|
|
409
|
+
const firstKey = map.keys().next().value;
|
|
410
|
+
if (firstKey === void 0) break;
|
|
411
|
+
map.delete(firstKey);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
395
414
|
function withCircularGuard(value, stack, factory) {
|
|
396
415
|
if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
|
|
397
416
|
stack.add(value);
|
|
@@ -561,7 +580,8 @@ function createCompilerContextCacheKey(opts) {
|
|
|
561
580
|
const cached = keyStore.get(runtimeCacheScopeKey);
|
|
562
581
|
if (cached !== void 0) return cached;
|
|
563
582
|
const cacheKey = md5Hash(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
|
|
564
|
-
keyStore
|
|
583
|
+
touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
|
|
584
|
+
pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
|
|
565
585
|
return cacheKey;
|
|
566
586
|
} catch (error) {
|
|
567
587
|
logger.debug("skip compiler context cache: %O", error);
|
|
@@ -572,10 +592,16 @@ function withCompilerContextCache(opts, factory) {
|
|
|
572
592
|
const cacheKey = createCompilerContextCacheKey(opts);
|
|
573
593
|
if (cacheKey) {
|
|
574
594
|
const cached = compilerContextCache.get(cacheKey);
|
|
575
|
-
if (cached)
|
|
595
|
+
if (cached) {
|
|
596
|
+
touchMapValue(compilerContextCache, cacheKey, cached);
|
|
597
|
+
return cached;
|
|
598
|
+
}
|
|
576
599
|
}
|
|
577
600
|
const ctx = factory();
|
|
578
|
-
if (cacheKey)
|
|
601
|
+
if (cacheKey) {
|
|
602
|
+
touchMapValue(compilerContextCache, cacheKey, ctx);
|
|
603
|
+
pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
|
|
604
|
+
}
|
|
579
605
|
return ctx;
|
|
580
606
|
}
|
|
581
607
|
//#endregion
|
|
@@ -939,6 +965,19 @@ function hasIgnoreComment(node) {
|
|
|
939
965
|
}
|
|
940
966
|
return false;
|
|
941
967
|
}
|
|
968
|
+
function isConditionTestLiteral(path) {
|
|
969
|
+
let current = path;
|
|
970
|
+
while (current?.parentPath) {
|
|
971
|
+
const parent = current.parentPath;
|
|
972
|
+
if (parent.isConditionalExpression()) return parent.node.test === current.node;
|
|
973
|
+
if (parent.isBinaryExpression() || parent.isCallExpression() || parent.isLogicalExpression() || parent.isMemberExpression() || parent.isUnaryExpression()) {
|
|
974
|
+
current = parent;
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
942
981
|
function extractLiteralValue(path, { unescapeUnicode }) {
|
|
943
982
|
const { node } = path;
|
|
944
983
|
let offset = 0;
|
|
@@ -1004,6 +1043,7 @@ function replaceHandleValue(path, options) {
|
|
|
1004
1043
|
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
1005
1044
|
if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) return;
|
|
1006
1045
|
if (hasIgnoreComment(path.node)) return;
|
|
1046
|
+
if (isConditionTestLiteral(path)) return;
|
|
1007
1047
|
const { literal, original, offset } = extractLiteralValue(path, options);
|
|
1008
1048
|
const candidates = splitCandidateTokens(literal);
|
|
1009
1049
|
if (candidates.length === 0) return;
|
|
@@ -2019,6 +2059,198 @@ function jsHandler(rawSource, options) {
|
|
|
2019
2059
|
}
|
|
2020
2060
|
defaultEvalHandler = jsHandler;
|
|
2021
2061
|
//#endregion
|
|
2062
|
+
//#region src/js/literal-transform.ts
|
|
2063
|
+
function transformLiteralText(literal, options) {
|
|
2064
|
+
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
2065
|
+
if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
|
|
2066
|
+
const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
|
|
2067
|
+
const candidates = splitCandidateTokens(source);
|
|
2068
|
+
if (candidates.length === 0) return;
|
|
2069
|
+
const transformOptions = {
|
|
2070
|
+
...options,
|
|
2071
|
+
classContext: true
|
|
2072
|
+
};
|
|
2073
|
+
const replacementCache = getReplacementCacheStore(options.escapeMap);
|
|
2074
|
+
let transformed = source;
|
|
2075
|
+
let mutated = false;
|
|
2076
|
+
for (const candidate of candidates) {
|
|
2077
|
+
const result = resolveClassNameTransformWithResult(candidate, transformOptions);
|
|
2078
|
+
if (result.decision === "skip" || !transformed.includes(candidate)) continue;
|
|
2079
|
+
const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
|
|
2080
|
+
const replaced = transformed.replace(candidate, replacement);
|
|
2081
|
+
if (replaced !== transformed) {
|
|
2082
|
+
transformed = replaced;
|
|
2083
|
+
mutated = true;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
return mutated ? transformed : void 0;
|
|
2087
|
+
}
|
|
2088
|
+
//#endregion
|
|
2089
|
+
//#region src/js/fast-path/oxc.ts
|
|
2090
|
+
const require = createRequire(import.meta.url);
|
|
2091
|
+
let oxcParser;
|
|
2092
|
+
let oxcWalker;
|
|
2093
|
+
function isOxcParserRuntimeSupported(version = process.versions.node) {
|
|
2094
|
+
const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
|
|
2095
|
+
if (!match) return false;
|
|
2096
|
+
const major = Number(match[1]);
|
|
2097
|
+
const minor = Number(match[2]);
|
|
2098
|
+
if (major === 20) return minor >= 19;
|
|
2099
|
+
if (major === 21) return false;
|
|
2100
|
+
if (major === 22) return minor >= 12;
|
|
2101
|
+
return major > 22;
|
|
2102
|
+
}
|
|
2103
|
+
function loadOxcParser() {
|
|
2104
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2105
|
+
if (oxcParser === false) return;
|
|
2106
|
+
if (oxcParser) return oxcParser;
|
|
2107
|
+
try {
|
|
2108
|
+
oxcParser = require("oxc-parser");
|
|
2109
|
+
} catch {
|
|
2110
|
+
oxcParser = false;
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
return oxcParser;
|
|
2114
|
+
}
|
|
2115
|
+
function loadOxcWalker() {
|
|
2116
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2117
|
+
if (oxcWalker === false) return;
|
|
2118
|
+
if (oxcWalker) return oxcWalker;
|
|
2119
|
+
try {
|
|
2120
|
+
oxcWalker = require("oxc-walker");
|
|
2121
|
+
} catch {
|
|
2122
|
+
oxcWalker = false;
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
return oxcWalker;
|
|
2126
|
+
}
|
|
2127
|
+
function hasValues(values) {
|
|
2128
|
+
return Array.isArray(values) && values.length > 0;
|
|
2129
|
+
}
|
|
2130
|
+
function hasUnsupportedSourceMarker(rawSource) {
|
|
2131
|
+
return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
|
|
2132
|
+
}
|
|
2133
|
+
function hasSupportedClassMatchSource(options) {
|
|
2134
|
+
return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
|
|
2135
|
+
}
|
|
2136
|
+
function canUseOxcJsFastPath(options) {
|
|
2137
|
+
if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
|
|
2138
|
+
return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
|
|
2139
|
+
}
|
|
2140
|
+
function getParserLang(filename) {
|
|
2141
|
+
if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
|
|
2142
|
+
if (filename?.endsWith(".tsx")) return "tsx";
|
|
2143
|
+
if (filename?.endsWith(".jsx")) return "jsx";
|
|
2144
|
+
return "js";
|
|
2145
|
+
}
|
|
2146
|
+
function getParserSourceType(sourceType) {
|
|
2147
|
+
return sourceType === "script" || sourceType === "module" ? sourceType : "module";
|
|
2148
|
+
}
|
|
2149
|
+
function isRangeValid(start, end) {
|
|
2150
|
+
return typeof start === "number" && typeof end === "number" && start < end;
|
|
2151
|
+
}
|
|
2152
|
+
function getMagicString(rawSource, context) {
|
|
2153
|
+
if (!context.ms) context.ms = new MagicString(rawSource);
|
|
2154
|
+
return context.ms;
|
|
2155
|
+
}
|
|
2156
|
+
function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
|
|
2157
|
+
if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2158
|
+
const transformed = transformLiteralText(node.value, transformOptions);
|
|
2159
|
+
if (!transformed) return false;
|
|
2160
|
+
const start = node.start + 1;
|
|
2161
|
+
const end = node.end - 1;
|
|
2162
|
+
if (start >= end || transformed === rawSource.slice(start, end)) return false;
|
|
2163
|
+
getMagicString(rawSource, context).update(start, end, jsStringEscape(transformed));
|
|
2164
|
+
return true;
|
|
2165
|
+
}
|
|
2166
|
+
function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
|
|
2167
|
+
const raw = node.value?.raw;
|
|
2168
|
+
if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2169
|
+
const transformed = transformLiteralText(raw, transformOptions);
|
|
2170
|
+
if (!transformed || transformed === raw) return false;
|
|
2171
|
+
const first = rawSource[node.start];
|
|
2172
|
+
const last = rawSource[node.end - 1];
|
|
2173
|
+
const start = node.start + (first === "`" || first === "}" ? 1 : 0);
|
|
2174
|
+
const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
|
|
2175
|
+
if (start >= end) return false;
|
|
2176
|
+
getMagicString(rawSource, context).update(start, end, transformed);
|
|
2177
|
+
return true;
|
|
2178
|
+
}
|
|
2179
|
+
function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
|
|
2180
|
+
let changed = false;
|
|
2181
|
+
walker.walk(program, { enter(node) {
|
|
2182
|
+
if (node.type === "Literal") {
|
|
2183
|
+
changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
if (node.type === "TemplateElement") {
|
|
2187
|
+
changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
|
|
2188
|
+
this.skip();
|
|
2189
|
+
}
|
|
2190
|
+
} });
|
|
2191
|
+
return changed;
|
|
2192
|
+
}
|
|
2193
|
+
function oxcJsHandler(rawSource, options) {
|
|
2194
|
+
if (!canUseOxcJsFastPath(options)) return;
|
|
2195
|
+
if (hasUnsupportedSourceMarker(rawSource)) return;
|
|
2196
|
+
const parser = loadOxcParser();
|
|
2197
|
+
const walker = loadOxcWalker();
|
|
2198
|
+
if (!parser || !walker) return;
|
|
2199
|
+
let result;
|
|
2200
|
+
try {
|
|
2201
|
+
result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
|
|
2202
|
+
sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
|
|
2203
|
+
lang: getParserLang(options.filename)
|
|
2204
|
+
});
|
|
2205
|
+
} catch {
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
|
|
2209
|
+
const stringLiteralOptions = options.needEscaped === true ? options : {
|
|
2210
|
+
...options,
|
|
2211
|
+
needEscaped: true
|
|
2212
|
+
};
|
|
2213
|
+
const templateLiteralOptions = options.needEscaped === false ? options : {
|
|
2214
|
+
...options,
|
|
2215
|
+
needEscaped: false
|
|
2216
|
+
};
|
|
2217
|
+
const replacementContext = {};
|
|
2218
|
+
if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
|
|
2219
|
+
return { code: replacementContext.ms.toString() };
|
|
2220
|
+
}
|
|
2221
|
+
//#endregion
|
|
2222
|
+
//#region src/js/precheck.ts
|
|
2223
|
+
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
2224
|
+
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)-/;
|
|
2225
|
+
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
2226
|
+
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
2227
|
+
/**
|
|
2228
|
+
* 判断源码是否可能声明跨模块依赖。
|
|
2229
|
+
*
|
|
2230
|
+
* 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
|
|
2231
|
+
* 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
|
|
2232
|
+
*/
|
|
2233
|
+
function hasDependencyHint(rawSource) {
|
|
2234
|
+
return DEPENDENCY_HINT_RE.test(rawSource);
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* 判断是否可以跳过 JS 转换。
|
|
2238
|
+
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
2239
|
+
*
|
|
2240
|
+
* @param rawSource - 原始 JS 源码字符串
|
|
2241
|
+
* @param options - 可选的 JS 处理器配置选项
|
|
2242
|
+
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
2243
|
+
*/
|
|
2244
|
+
function shouldSkipJsTransform(rawSource, options) {
|
|
2245
|
+
if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
2246
|
+
if (!rawSource) return true;
|
|
2247
|
+
if (options?.alwaysEscape) return false;
|
|
2248
|
+
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
2249
|
+
if (options?.wrapExpression) return false;
|
|
2250
|
+
if (hasDependencyHint(rawSource)) return false;
|
|
2251
|
+
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
2252
|
+
}
|
|
2253
|
+
//#endregion
|
|
2022
2254
|
//#region src/js/index.ts
|
|
2023
2255
|
/** 默认 LRU 缓存最大条目数 */
|
|
2024
2256
|
const RESULT_CACHE_MAX = 512;
|
|
@@ -2063,6 +2295,7 @@ function getOptionsFingerprint(options) {
|
|
|
2063
2295
|
JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
|
|
2064
2296
|
JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
|
|
2065
2297
|
JSON.stringify(options.moduleSpecifierReplacements ?? null),
|
|
2298
|
+
String(options.experimentalJsFastPath ?? ""),
|
|
2066
2299
|
JSON.stringify(options.babelParserOptions ?? null)
|
|
2067
2300
|
].join("|");
|
|
2068
2301
|
fingerprintCache.set(options, fingerprint);
|
|
@@ -2078,6 +2311,13 @@ function shouldCacheJsResult(rawSource, options) {
|
|
|
2078
2311
|
if (options.moduleGraph || options.filename) return false;
|
|
2079
2312
|
return true;
|
|
2080
2313
|
}
|
|
2314
|
+
function resolveFastPathOptions(rawSource, options) {
|
|
2315
|
+
if (!options.moduleGraph) return options;
|
|
2316
|
+
if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
|
|
2317
|
+
if (hasDependencyHint(rawSource)) return options;
|
|
2318
|
+
const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
|
|
2319
|
+
return fastPathOptions;
|
|
2320
|
+
}
|
|
2081
2321
|
function createJsHandler(options) {
|
|
2082
2322
|
const defaults = {
|
|
2083
2323
|
escapeMap: options.escapeMap,
|
|
@@ -2090,6 +2330,7 @@ function createJsHandler(options) {
|
|
|
2090
2330
|
alwaysEscape: options.alwaysEscape,
|
|
2091
2331
|
unescapeUnicode: options.unescapeUnicode,
|
|
2092
2332
|
babelParserOptions: options.babelParserOptions,
|
|
2333
|
+
experimentalJsFastPath: options.experimentalJsFastPath,
|
|
2093
2334
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
2094
2335
|
ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
|
|
2095
2336
|
uniAppX: options.uniAppX,
|
|
@@ -2158,7 +2399,7 @@ function createJsHandler(options) {
|
|
|
2158
2399
|
const resolvedOptions = resolveOptions(classNameSet, options);
|
|
2159
2400
|
const cached = getCachedJsResult(rawSource, resolvedOptions);
|
|
2160
2401
|
if (cached) return cached;
|
|
2161
|
-
return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
|
|
2402
|
+
return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
|
|
2162
2403
|
}
|
|
2163
2404
|
return handler;
|
|
2164
2405
|
}
|
|
@@ -4543,38 +4784,74 @@ function resolveRuntimePackageReplacements(option) {
|
|
|
4543
4784
|
}
|
|
4544
4785
|
//#endregion
|
|
4545
4786
|
//#region src/context/style-options.ts
|
|
4546
|
-
function resolveStyleOptionsFromContext(ctx) {
|
|
4787
|
+
function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
|
|
4547
4788
|
const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
|
|
4789
|
+
const branch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
|
|
4790
|
+
appType: ctx.appType,
|
|
4791
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4792
|
+
tailwindcssMajorVersion,
|
|
4793
|
+
uniAppX: resolvedUniAppXOptions
|
|
4794
|
+
}), {
|
|
4795
|
+
appType: ctx.appType,
|
|
4796
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4797
|
+
tailwindcssMajorVersion,
|
|
4798
|
+
uniAppX: resolvedUniAppXOptions
|
|
4799
|
+
});
|
|
4800
|
+
const hasCssOptions = ctx.cssOptions !== void 0;
|
|
4801
|
+
const cssOptions = {
|
|
4802
|
+
cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
|
|
4803
|
+
cssPreflightRange: ctx.cssOptions?.cssPreflightRange ?? ctx.cssPreflightRange,
|
|
4804
|
+
cssChildCombinatorReplaceValue: ctx.cssOptions?.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue,
|
|
4805
|
+
cssSelectorReplacement: ctx.cssOptions?.cssSelectorReplacement ?? ctx.cssSelectorReplacement,
|
|
4806
|
+
rem2rpx: ctx.cssOptions?.rem2rpx ?? ctx.rem2rpx,
|
|
4807
|
+
cssRemoveProperty: ctx.cssOptions?.cssRemoveProperty ?? ctx.cssRemoveProperty,
|
|
4808
|
+
cssRemoveHoverPseudoClass: ctx.cssOptions?.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass,
|
|
4809
|
+
tailwindcssV4GradientFallback: ctx.cssOptions?.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback,
|
|
4810
|
+
cssPresetEnv: ctx.cssOptions?.cssPresetEnv ?? ctx.cssPresetEnv,
|
|
4811
|
+
atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
|
|
4812
|
+
autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
|
|
4813
|
+
cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
|
|
4814
|
+
platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
|
|
4815
|
+
px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
|
|
4816
|
+
unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
|
|
4817
|
+
unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
|
|
4818
|
+
injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
|
|
4819
|
+
};
|
|
4548
4820
|
return {
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4821
|
+
appType: ctx.appType,
|
|
4822
|
+
cssPreflight: cssOptions.cssPreflight,
|
|
4823
|
+
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
4824
|
+
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
4825
|
+
cssSelectorReplacement: cssOptions.cssSelectorReplacement,
|
|
4826
|
+
rem2rpx: cssOptions.rem2rpx,
|
|
4827
|
+
...hasCssOptions ? { cssOptions } : {},
|
|
4828
|
+
cssRemoveProperty: cssOptions.cssRemoveProperty,
|
|
4829
|
+
cssRemoveHoverPseudoClass: cssOptions.cssRemoveHoverPseudoClass,
|
|
4830
|
+
tailwindcssV4GradientFallback: cssOptions.tailwindcssV4GradientFallback,
|
|
4831
|
+
cssPresetEnv: cssOptions.cssPresetEnv,
|
|
4832
|
+
atRules: cssOptions.atRules,
|
|
4833
|
+
autoprefixer: cssOptions.autoprefixer,
|
|
4834
|
+
cssCalc: cssOptions.cssCalc,
|
|
4835
|
+
uniAppX: branch.isNativeApp,
|
|
4836
|
+
platform: cssOptions.platform,
|
|
4837
|
+
px2rpx: cssOptions.px2rpx,
|
|
4838
|
+
unitsToPx: cssOptions.unitsToPx,
|
|
4839
|
+
unitConversion: cssOptions.unitConversion
|
|
4564
4840
|
};
|
|
4565
4841
|
}
|
|
4566
4842
|
//#endregion
|
|
4567
4843
|
//#region src/context/handlers.ts
|
|
4568
4844
|
function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
|
|
4569
|
-
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4845
|
+
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4570
4846
|
const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
|
|
4571
|
-
const styleOptions = resolveStyleOptionsFromContext(ctx);
|
|
4847
|
+
const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
|
|
4848
|
+
const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
|
|
4572
4849
|
const uniAppXEnabled = styleOptions.uniAppX === true;
|
|
4573
4850
|
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
4574
4851
|
const styleHandler = createStyleHandler({
|
|
4575
4852
|
...styleOptions,
|
|
4576
4853
|
escapeMap,
|
|
4577
|
-
injectAdditionalCssVarScope,
|
|
4854
|
+
injectAdditionalCssVarScope: resolvedInjectAdditionalCssVarScope,
|
|
4578
4855
|
postcssOptions,
|
|
4579
4856
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
4580
4857
|
cssCalc: cssCalcOptions,
|
|
@@ -4588,6 +4865,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
4588
4865
|
tailwindcssMajorVersion,
|
|
4589
4866
|
generateMap: true,
|
|
4590
4867
|
babelParserOptions,
|
|
4868
|
+
experimentalJsFastPath,
|
|
4591
4869
|
ignoreCallExpressionIdentifiers,
|
|
4592
4870
|
ignoreTaggedTemplateExpressionIdentifiers,
|
|
4593
4871
|
uniAppX: uniAppXEnabled,
|
|
@@ -4619,30 +4897,75 @@ function applyLoggerLevel(logLevel) {
|
|
|
4619
4897
|
//#endregion
|
|
4620
4898
|
//#region src/context/index.ts
|
|
4621
4899
|
function resolveContextCssPreflight(opts, ctx, majorVersion) {
|
|
4622
|
-
const
|
|
4623
|
-
|
|
4624
|
-
|
|
4900
|
+
const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
|
|
4901
|
+
const cssPreflight = resolveDefaultCssPreflight(userCssPreflight, majorVersion);
|
|
4902
|
+
if (cssPreflight === false || !resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
|
|
4903
|
+
const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
|
|
4625
4904
|
return {
|
|
4626
4905
|
...cssPreflight,
|
|
4627
|
-
"border-width":
|
|
4628
|
-
"border-style":
|
|
4629
|
-
"border":
|
|
4906
|
+
"border-width": userCssPreflightObject && "border-width" in userCssPreflightObject ? cssPreflight["border-width"] ?? false : "0",
|
|
4907
|
+
"border-style": userCssPreflightObject && "border-style" in userCssPreflightObject ? cssPreflight["border-style"] ?? false : false,
|
|
4908
|
+
"border": userCssPreflightObject && "border" in userCssPreflightObject ? cssPreflight["border"] ?? false : false
|
|
4909
|
+
};
|
|
4910
|
+
}
|
|
4911
|
+
function syncCssOptionsToLegacyFields(ctx) {
|
|
4912
|
+
if (!ctx.cssOptions) return;
|
|
4913
|
+
const cssOptions = ctx.cssOptions;
|
|
4914
|
+
ctx.cssPreflight = cssOptions.cssPreflight ?? ctx.cssPreflight;
|
|
4915
|
+
ctx.cssPreflightRange = cssOptions.cssPreflightRange ?? ctx.cssPreflightRange;
|
|
4916
|
+
ctx.cssChildCombinatorReplaceValue = cssOptions.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue;
|
|
4917
|
+
ctx.cssSelectorReplacement = cssOptions.cssSelectorReplacement ?? ctx.cssSelectorReplacement;
|
|
4918
|
+
ctx.rem2rpx = cssOptions.rem2rpx ?? ctx.rem2rpx;
|
|
4919
|
+
ctx.cssRemoveProperty = cssOptions.cssRemoveProperty ?? ctx.cssRemoveProperty;
|
|
4920
|
+
ctx.cssRemoveHoverPseudoClass = cssOptions.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass;
|
|
4921
|
+
ctx.tailwindcssV4GradientFallback = cssOptions.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback;
|
|
4922
|
+
ctx.cssPresetEnv = cssOptions.cssPresetEnv ?? ctx.cssPresetEnv;
|
|
4923
|
+
ctx.atRules = cssOptions.atRules ?? ctx.atRules;
|
|
4924
|
+
ctx.autoprefixer = cssOptions.autoprefixer ?? ctx.autoprefixer;
|
|
4925
|
+
ctx.cssCalc = cssOptions.cssCalc ?? ctx.cssCalc;
|
|
4926
|
+
ctx.platform = cssOptions.platform ?? ctx.platform;
|
|
4927
|
+
ctx.px2rpx = cssOptions.px2rpx ?? ctx.px2rpx;
|
|
4928
|
+
ctx.unitsToPx = cssOptions.unitsToPx ?? ctx.unitsToPx;
|
|
4929
|
+
ctx.unitConversion = cssOptions.unitConversion ?? ctx.unitConversion;
|
|
4930
|
+
ctx.injectAdditionalCssVarScope = cssOptions.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope;
|
|
4931
|
+
}
|
|
4932
|
+
function syncLegacyFieldsToCssOptions(ctx) {
|
|
4933
|
+
if (!ctx.cssOptions) return;
|
|
4934
|
+
ctx.cssOptions = {
|
|
4935
|
+
...ctx.cssOptions ?? {},
|
|
4936
|
+
cssPreflight: ctx.cssPreflight,
|
|
4937
|
+
cssPreflightRange: ctx.cssPreflightRange,
|
|
4938
|
+
cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
|
|
4939
|
+
cssSelectorReplacement: ctx.cssSelectorReplacement,
|
|
4940
|
+
rem2rpx: ctx.rem2rpx,
|
|
4941
|
+
cssRemoveProperty: ctx.cssRemoveProperty,
|
|
4942
|
+
cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
|
|
4943
|
+
tailwindcssV4GradientFallback: ctx.tailwindcssV4GradientFallback,
|
|
4944
|
+
cssPresetEnv: ctx.cssPresetEnv,
|
|
4945
|
+
atRules: ctx.atRules,
|
|
4946
|
+
autoprefixer: ctx.autoprefixer,
|
|
4947
|
+
cssCalc: ctx.cssCalc,
|
|
4948
|
+
platform: ctx.platform,
|
|
4949
|
+
px2rpx: ctx.px2rpx,
|
|
4950
|
+
unitsToPx: ctx.unitsToPx,
|
|
4951
|
+
unitConversion: ctx.unitConversion,
|
|
4952
|
+
injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
|
|
4630
4953
|
};
|
|
4631
4954
|
}
|
|
4632
|
-
async function
|
|
4633
|
-
if (!
|
|
4634
|
-
const cacheOptions =
|
|
4955
|
+
async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
|
|
4956
|
+
if (!tailwindRuntime) return;
|
|
4957
|
+
const cacheOptions = tailwindRuntime.options?.cache;
|
|
4635
4958
|
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
|
|
4636
|
-
if (typeof
|
|
4637
|
-
await
|
|
4959
|
+
if (typeof tailwindRuntime.clearCache === "function") try {
|
|
4960
|
+
await tailwindRuntime.clearCache({ scope: "all" });
|
|
4638
4961
|
} catch (error) {
|
|
4639
|
-
logger.debug("failed to clear tailwindcss
|
|
4962
|
+
logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
|
|
4640
4963
|
}
|
|
4641
4964
|
if (!options?.removeDirectory) return;
|
|
4642
4965
|
const cachePaths = /* @__PURE__ */ new Map();
|
|
4643
4966
|
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
4644
4967
|
if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
|
|
4645
|
-
const privateCachePath =
|
|
4968
|
+
const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
|
|
4646
4969
|
if (privateCachePath) cachePaths.set(privateCachePath, false);
|
|
4647
4970
|
if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
|
|
4648
4971
|
if (!cachePaths.size) return;
|
|
@@ -4654,39 +4977,41 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
4654
4977
|
} catch (error) {
|
|
4655
4978
|
const err = error;
|
|
4656
4979
|
if (err?.code === "ENOENT") continue;
|
|
4657
|
-
logger.debug("failed to clear tailwindcss
|
|
4980
|
+
logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
|
|
4658
4981
|
}
|
|
4659
4982
|
}
|
|
4660
4983
|
function createInternalCompilerContext(opts) {
|
|
4661
4984
|
const ctx = defuOverrideArray(opts, getDefaultOptions(), {});
|
|
4662
4985
|
ctx.arbitraryValues = resolveUnocssBareArbitraryValues(ctx.arbitraryValues, ctx.unocss);
|
|
4663
4986
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
4987
|
+
syncCssOptionsToLegacyFields(ctx);
|
|
4664
4988
|
applyLoggerLevel(ctx.logLevel);
|
|
4665
|
-
const
|
|
4666
|
-
logTailwindcssTarget(
|
|
4667
|
-
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir,
|
|
4668
|
-
if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx,
|
|
4669
|
-
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx,
|
|
4670
|
-
const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc,
|
|
4989
|
+
const tailwindRuntime = createTailwindcssRuntimeFromContext(ctx);
|
|
4990
|
+
logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
|
|
4991
|
+
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
|
|
4992
|
+
if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, tailwindRuntime);
|
|
4993
|
+
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
|
|
4994
|
+
const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
|
|
4671
4995
|
ctx.cssCalc = cssCalcOptions;
|
|
4672
|
-
|
|
4996
|
+
syncLegacyFieldsToCssOptions(ctx);
|
|
4997
|
+
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
|
|
4673
4998
|
ctx.styleHandler = styleHandler;
|
|
4674
4999
|
ctx.jsHandler = jsHandler;
|
|
4675
5000
|
ctx.templateHandler = templateHandler;
|
|
4676
5001
|
ctx.cache = initializeCache(ctx.cache);
|
|
4677
|
-
ctx.
|
|
4678
|
-
const
|
|
4679
|
-
const
|
|
4680
|
-
if (options?.clearCache !== false) await
|
|
4681
|
-
invalidateRuntimeClassSet(
|
|
4682
|
-
const
|
|
4683
|
-
Object.assign(
|
|
4684
|
-
ctx.
|
|
4685
|
-
return
|
|
5002
|
+
ctx.tailwindRuntime = tailwindRuntime;
|
|
5003
|
+
const refreshTailwindcssRuntime = async (options) => {
|
|
5004
|
+
const previousRuntime = ctx.tailwindRuntime;
|
|
5005
|
+
if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
|
|
5006
|
+
invalidateRuntimeClassSet(previousRuntime);
|
|
5007
|
+
const nextRuntime = createTailwindcssRuntimeFromContext(ctx);
|
|
5008
|
+
Object.assign(previousRuntime, nextRuntime);
|
|
5009
|
+
ctx.tailwindRuntime = previousRuntime;
|
|
5010
|
+
return previousRuntime;
|
|
4686
5011
|
};
|
|
4687
|
-
ctx.
|
|
4688
|
-
Object.defineProperty(ctx.
|
|
4689
|
-
value:
|
|
5012
|
+
ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
|
|
5013
|
+
Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
|
|
5014
|
+
value: refreshTailwindcssRuntime,
|
|
4690
5015
|
configurable: true
|
|
4691
5016
|
});
|
|
4692
5017
|
return ctx;
|
|
@@ -4700,27 +5025,4 @@ function getCompilerContext(opts) {
|
|
|
4700
5025
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
4701
5026
|
}
|
|
4702
5027
|
//#endregion
|
|
4703
|
-
|
|
4704
|
-
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
4705
|
-
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)-/;
|
|
4706
|
-
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
4707
|
-
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
4708
|
-
/**
|
|
4709
|
-
* 判断是否可以跳过 JS 转换。
|
|
4710
|
-
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
4711
|
-
*
|
|
4712
|
-
* @param rawSource - 原始 JS 源码字符串
|
|
4713
|
-
* @param options - 可选的 JS 处理器配置选项
|
|
4714
|
-
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
4715
|
-
*/
|
|
4716
|
-
function shouldSkipJsTransform(rawSource, options) {
|
|
4717
|
-
if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
4718
|
-
if (!rawSource) return true;
|
|
4719
|
-
if (options?.alwaysEscape) return false;
|
|
4720
|
-
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
4721
|
-
if (options?.wrapExpression) return false;
|
|
4722
|
-
if (DEPENDENCY_HINT_RE.test(rawSource)) return false;
|
|
4723
|
-
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
4724
|
-
}
|
|
4725
|
-
//#endregion
|
|
4726
|
-
export { collectRuntimeClassSet as _, vitePluginName as a, refreshTailwindRuntimeState as b, createAttributeMatcher as c, _defineProperty as d, isClassContextLiteralPath as f, toCustomAttributesEntities as g, traverse as h, pluginName as i, analyzeSource as l, babelParse as m, getCompilerContext as n, Parser as o, replaceWxml as p, resolveStyleOptionsFromContext as r, generateCode as s, shouldSkipJsTransform as t, JsTokenUpdater as u, createTailwindRuntimeReadyPromise as v, md5Hash as x, ensureRuntimeClassSet as y };
|
|
5028
|
+
export { md5Hash as S, collectRuntimeClassSet as _, Parser as a, refreshTailwindRuntimeState as b, shouldSkipJsTransform as c, _defineProperty as d, isClassContextLiteralPath as f, toCustomAttributesEntities as g, traverse as h, vitePluginName as i, analyzeSource as l, babelParse as m, resolveStyleOptionsFromContext as n, generateCode as o, replaceWxml as p, pluginName as r, createAttributeMatcher as s, getCompilerContext as t, JsTokenUpdater as u, createTailwindRuntimeReadyPromise as v, createDebug as x, ensureRuntimeClassSet as y };
|