weapp-tailwindcss 5.0.0-next.5 → 5.0.0-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
- package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
- package/dist/bundlers/shared/generator-css.d.ts +10 -23
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
- package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -0
- package/dist/cache-BVAiJV3J.js +502 -0
- package/dist/cache-CHs4DXui.mjs +434 -0
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli.js +107 -603
- package/dist/cli.mjs +118 -613
- package/dist/constants.d.ts +0 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +28 -7
- package/dist/defaults.mjs +25 -8
- package/dist/{generator-9UEp8OoQ.js → generator-DKkhJbOg.js} +24 -7
- package/dist/{generator-Dpp-5s8z.mjs → generator-UBmfduYg.mjs} +20 -3
- package/dist/{generator-css-MyjZhF0z.mjs → generator-css-BIapP56i.mjs} +691 -606
- package/dist/{generator-css-CGueCYbX.js → generator-css-Mksw8PgB.js} +703 -606
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +33 -21
- package/dist/gulp.mjs +29 -17
- package/dist/index.js +5 -5
- package/dist/index.mjs +4 -4
- package/dist/logger-BRy6XPQ2.js +1 -0
- package/dist/logger-Bub1jggA.mjs +2 -0
- package/dist/postcss/config-directive.d.ts +1 -0
- package/dist/postcss/context.d.ts +9 -0
- package/dist/postcss/source-files.d.ts +8 -0
- package/dist/postcss/tailwind-version.d.ts +3 -0
- package/dist/postcss-QIXwT40c.js +298 -0
- package/dist/postcss-w48mGIhe.mjs +288 -0
- package/dist/postcss.js +3 -285
- package/dist/postcss.mjs +1 -278
- package/dist/{recorder-D4BKt75Q.js → precheck-B32p-gLI.js} +139 -274
- package/dist/{recorder-BIW3Kuke.mjs → precheck-B4RH6ZNN.mjs} +105 -239
- package/dist/presets.js +6 -4
- package/dist/presets.mjs +4 -2
- package/dist/runtime-patch-CwN5ya72.mjs +71 -0
- package/dist/runtime-patch-D6mBo_KB.js +85 -0
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +2 -3
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/patcher.d.ts +1 -1
- package/dist/{logger-D9clu_3f.js → tailwindcss-Bu-RWIHx.js} +70 -413
- package/dist/{logger-1gx9UllH.mjs → tailwindcss-C5IgPlQ0.mjs} +56 -382
- package/dist/types/index.d.ts +1 -6
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/{vite-fDM-UQpR.mjs → vite-BwgRVgxH.mjs} +677 -525
- package/dist/{vite-BkMGwDeH.js → vite-DyZuiyap.js} +704 -552
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +10 -1
- package/dist/{webpack-CICGEKT9.js → webpack-CNV2dx3Q.js} +72 -37
- package/dist/{webpack-D2Wdk28V.mjs → webpack-CT6EEENx.mjs} +58 -23
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -9
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/js/syntax.d.ts +0 -10
- package/dist/patcher-options-DnqazL9E.js +0 -34
- package/dist/patcher-options-GuOwX0-k.mjs +0 -17
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/version-CWBxRFPB.js +0 -56
- package/dist/version-WNz3MwRv.mjs +0 -49
- /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
- /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
- /package/dist/{run-tasks-Cq5A5nVD.js → run-tasks-B50A3pxt.js} +0 -0
- /package/dist/{run-tasks-DUVrDJGl.mjs → run-tasks-DdNi-hkk.mjs} +0 -0
- /package/dist/{utils-DmC9_In3.js → utils-BiShvil9.js} +0 -0
- /package/dist/{utils-7DUGTFED.mjs → utils-Btw1iOVV.mjs} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { n as getRuntimeClassSetSignature, r as invalidateRuntimeClassSet, t as getRuntimeClassSetCacheEntry } from "./cache-CHs4DXui.mjs";
|
|
2
|
+
import { n as createDebug, t as ensureTailwindcssRuntimePatch } from "./runtime-patch-CwN5ya72.mjs";
|
|
3
|
+
import { i as isMap, n as defuOverrideArray } from "./utils-Btw1iOVV.mjs";
|
|
4
|
+
import { getDefaultOptions, resolveDefaultCssPreflight } from "./defaults.mjs";
|
|
5
|
+
import { a as applyV4CssCalcDefaults, i as resolveUniAppXOptions, o as warnMissingCssEntries, r as isUniAppXEnabled, t as createTailwindcssPatcherFromContext } from "./tailwindcss-C5IgPlQ0.mjs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import process from "node:process";
|
|
7
|
-
import { Buffer } from "node:buffer";
|
|
8
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
-
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
10
8
|
import { logger, pc } from "@weapp-tailwindcss/logger";
|
|
9
|
+
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
10
|
+
import { Buffer } from "node:buffer";
|
|
11
|
+
import { rm } from "node:fs/promises";
|
|
11
12
|
import { LRUCache } from "lru-cache";
|
|
12
13
|
import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
|
|
13
14
|
import { MappingChars2String, escape } from "@weapp-core/escape";
|
|
14
|
-
import _createDebug from "debug";
|
|
15
15
|
import _babelTraverse from "@babel/traverse";
|
|
16
16
|
import { parse, parseExpression } from "@babel/parser";
|
|
17
17
|
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
@@ -102,33 +102,13 @@ function initializeCache(cacheConfig) {
|
|
|
102
102
|
return cacheConfig;
|
|
103
103
|
}
|
|
104
104
|
//#endregion
|
|
105
|
-
//#region src/debug/index.ts
|
|
106
|
-
const _debug = _createDebug("weapp-tw");
|
|
107
|
-
function createDebug(prefix) {
|
|
108
|
-
const debug = ((formatter, ...args) => {
|
|
109
|
-
return _debug((prefix ?? "") + formatter, ...args);
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(debug, "enabled", {
|
|
112
|
-
enumerable: false,
|
|
113
|
-
configurable: false,
|
|
114
|
-
get() {
|
|
115
|
-
return _debug.enabled;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return debug;
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
105
|
//#region src/tailwindcss/runtime.ts
|
|
122
106
|
const debug$1 = createDebug("[tailwindcss:runtime] ");
|
|
123
107
|
const refreshTailwindcssPatcherSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
|
|
124
|
-
function
|
|
125
|
-
return Promise.resolve(
|
|
108
|
+
function createTailwindRuntimeReadyPromise(twPatcher) {
|
|
109
|
+
return Promise.resolve().then(async () => {
|
|
110
|
+
await ensureTailwindcssRuntimePatch(twPatcher);
|
|
126
111
|
invalidateRuntimeClassSet(twPatcher);
|
|
127
|
-
if (onPatched) try {
|
|
128
|
-
await onPatched();
|
|
129
|
-
} catch (error) {
|
|
130
|
-
debug$1("failed to persist patch target after patch(): %O", error);
|
|
131
|
-
}
|
|
132
112
|
});
|
|
133
113
|
}
|
|
134
114
|
const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -146,14 +126,14 @@ async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
|
146
126
|
const clearCache = normalizedOptions.clearCache === true;
|
|
147
127
|
if (!force) return false;
|
|
148
128
|
debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, state.twPatcher.majorVersion ?? "unknown");
|
|
149
|
-
await state.
|
|
129
|
+
await state.readyPromise;
|
|
150
130
|
let refreshed = false;
|
|
151
131
|
if (typeof state.refreshTailwindcssPatcher === "function") {
|
|
152
132
|
const next = await state.refreshTailwindcssPatcher({ clearCache });
|
|
153
133
|
if (next !== state.twPatcher) state.twPatcher = next;
|
|
154
134
|
refreshed = true;
|
|
155
135
|
}
|
|
156
|
-
if (refreshed) state.
|
|
136
|
+
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(state.twPatcher);
|
|
157
137
|
debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, state.twPatcher.majorVersion ?? "unknown");
|
|
158
138
|
return refreshed;
|
|
159
139
|
}
|
|
@@ -166,7 +146,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
166
146
|
force: true,
|
|
167
147
|
clearCache
|
|
168
148
|
});
|
|
169
|
-
await state.
|
|
149
|
+
await state.readyPromise;
|
|
170
150
|
const entry = getRuntimeClassSetStateEntry(state);
|
|
171
151
|
const signature = getRuntimeClassSetSignature(state.twPatcher);
|
|
172
152
|
const signatureChanged = entry.signature !== signature;
|
|
@@ -186,7 +166,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
186
166
|
force: true,
|
|
187
167
|
clearCache: true
|
|
188
168
|
});
|
|
189
|
-
await state.
|
|
169
|
+
await state.readyPromise;
|
|
190
170
|
return collectRuntimeClassSet(state.twPatcher, {
|
|
191
171
|
force: true,
|
|
192
172
|
skipRefresh: true,
|
|
@@ -240,6 +220,7 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
|
240
220
|
if (entry.promise) return entry.promise;
|
|
241
221
|
} else entry.value = void 0;
|
|
242
222
|
const task = (async () => {
|
|
223
|
+
await ensureTailwindcssRuntimePatch(activePatcher);
|
|
243
224
|
const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
|
|
244
225
|
if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
|
|
245
226
|
const preferExtract = options.force === true;
|
|
@@ -319,197 +300,29 @@ function logRuntimeTailwindcssVersion(baseDir, rootPath, version) {
|
|
|
319
300
|
return;
|
|
320
301
|
}
|
|
321
302
|
if (!markRuntimeLog("missing", baseDir, rootPath, version)) return;
|
|
322
|
-
logger.warn(`${pc.cyanBright("Tailwind CSS")}
|
|
303
|
+
logger.warn(`${pc.cyanBright("Tailwind CSS")} 未安装,已跳过版本检测与运行时初始化。`);
|
|
323
304
|
}
|
|
324
305
|
//#endregion
|
|
325
|
-
//#region src/tailwindcss/targets
|
|
326
|
-
const PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
327
|
-
const PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
328
|
-
const PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
329
|
-
function toDisplayPath(value) {
|
|
330
|
-
return path.normalize(value).replace(/\\/g, "/");
|
|
331
|
-
}
|
|
306
|
+
//#region src/tailwindcss/targets.ts
|
|
332
307
|
function formatRelativeToBase(targetPath, baseDir) {
|
|
333
|
-
|
|
334
|
-
|
|
308
|
+
const normalized = path.normalize(targetPath);
|
|
309
|
+
if (!baseDir) return normalized.replace(/\\/g, "/");
|
|
310
|
+
const relative = path.relative(baseDir, normalized);
|
|
335
311
|
if (!relative || relative === ".") return ".";
|
|
336
|
-
if (relative.startsWith("..")) return
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
function resolveRecordLocation(baseDir) {
|
|
340
|
-
const normalizedBase = path.normalize(baseDir);
|
|
341
|
-
const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
|
|
342
|
-
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
343
|
-
const hasPackageJson = existsSync(packageJsonPath);
|
|
344
|
-
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
345
|
-
const recordKey = md5Hash(path.normalize(recordKeySource));
|
|
346
|
-
const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
347
|
-
return {
|
|
348
|
-
normalizedBase,
|
|
349
|
-
packageRoot,
|
|
350
|
-
recordDir,
|
|
351
|
-
recordKey,
|
|
352
|
-
recordPath: path.join(recordDir, PATCH_INFO_FILENAME),
|
|
353
|
-
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
354
|
-
};
|
|
312
|
+
if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
|
|
313
|
+
return path.join(".", relative).replace(/\\/g, "/");
|
|
355
314
|
}
|
|
356
|
-
function
|
|
357
|
-
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
358
|
-
return [...new Set([
|
|
359
|
-
recordPath,
|
|
360
|
-
path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
361
|
-
path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
362
|
-
path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
363
|
-
])];
|
|
364
|
-
}
|
|
365
|
-
//#endregion
|
|
366
|
-
//#region package.json
|
|
367
|
-
var version = "5.0.0-next.5";
|
|
368
|
-
//#endregion
|
|
369
|
-
//#region src/constants.ts
|
|
370
|
-
const pluginName = "weapp-tailwindcss";
|
|
371
|
-
const vitePluginName = "weapp-tailwindcss:adaptor";
|
|
372
|
-
const WEAPP_TW_VERSION = version;
|
|
373
|
-
const DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
374
|
-
"tailwind-merge": "@weapp-tailwindcss/merge",
|
|
375
|
-
"class-variance-authority": "@weapp-tailwindcss/cva",
|
|
376
|
-
"tailwind-variants": "@weapp-tailwindcss/variants"
|
|
377
|
-
};
|
|
378
|
-
//#endregion
|
|
379
|
-
//#region src/tailwindcss/targets/record-io.ts
|
|
380
|
-
const loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
381
|
-
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
382
|
-
const normalizedPath = path.normalize(recordPath);
|
|
383
|
-
if (loggedInvalidPatchRecords.has(normalizedPath)) return;
|
|
384
|
-
loggedInvalidPatchRecords.add(normalizedPath);
|
|
385
|
-
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
386
|
-
const baseDisplay = formatRelativeToBase(path.normalize(baseDir), process.cwd());
|
|
387
|
-
const reasonMessage = reason ? `:${reason}` : "";
|
|
388
|
-
logger.warn(`检测到损坏的 Tailwind CSS 目标记录 ${fileDisplay}${reasonMessage}。请在 ${baseDisplay} 重新执行 "weapp-tw patch --record-target" 或删除该文件后再运行。`);
|
|
389
|
-
}
|
|
390
|
-
function readPatchTargetRecord(baseDir) {
|
|
391
|
-
if (!baseDir) return;
|
|
392
|
-
const normalizedBase = path.normalize(baseDir);
|
|
393
|
-
for (const recordPath of getRecordFileCandidates(normalizedBase)) {
|
|
394
|
-
if (!existsSync(recordPath)) continue;
|
|
395
|
-
try {
|
|
396
|
-
const content = readFileSync(recordPath, "utf8");
|
|
397
|
-
const parsed = JSON.parse(content);
|
|
398
|
-
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
399
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, "缺少 tailwindPackagePath 字段");
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
return {
|
|
403
|
-
baseDir: normalizedBase,
|
|
404
|
-
path: recordPath,
|
|
405
|
-
record: parsed
|
|
406
|
-
};
|
|
407
|
-
} catch (error) {
|
|
408
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, error instanceof Error ? error.message : String(error));
|
|
409
|
-
continue;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
414
|
-
if (!baseDir || !patcher?.packageInfo?.rootPath) return;
|
|
415
|
-
const normalizedBase = path.normalize(baseDir);
|
|
416
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
417
|
-
const recordPath = options?.recordPath ? path.normalize(options.recordPath) : location.recordPath;
|
|
418
|
-
const record = {
|
|
419
|
-
tailwindPackagePath: path.normalize(patcher.packageInfo.rootPath),
|
|
420
|
-
packageVersion: patcher.packageInfo.version,
|
|
421
|
-
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
422
|
-
source: options?.source ?? "cli",
|
|
423
|
-
tailwindcssBasedir: normalizedBase,
|
|
424
|
-
cwd: options?.cwd ? path.normalize(options.cwd) : normalizedBase,
|
|
425
|
-
patchVersion: WEAPP_TW_VERSION,
|
|
426
|
-
packageJsonPath: options?.packageJsonPath ?? location.packageJsonPath,
|
|
427
|
-
recordKey: options?.recordKey ?? location.recordKey
|
|
428
|
-
};
|
|
429
|
-
try {
|
|
430
|
-
await mkdir(path.dirname(recordPath), { recursive: true });
|
|
431
|
-
await writeFile(recordPath, `${JSON.stringify(record, null, 2)}\n`, "utf8");
|
|
432
|
-
return recordPath;
|
|
433
|
-
} catch (error) {
|
|
434
|
-
const baseDisplay = formatRelativeToBase(normalizedBase, process.cwd());
|
|
435
|
-
logger.warn("自动更新 Tailwind CSS 补丁记录失败,请在 %s 运行 \"weapp-tw patch --cwd %s\"。", baseDisplay, normalizedBase);
|
|
436
|
-
logger.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/tailwindcss/targets/recorder.ts
|
|
442
|
-
function findPatchTargetRecord(baseDir) {
|
|
443
|
-
const visited = /* @__PURE__ */ new Set();
|
|
444
|
-
const fallback = baseDir ?? process.cwd();
|
|
445
|
-
let current = path.resolve(fallback);
|
|
446
|
-
while (!visited.has(current)) {
|
|
447
|
-
const record = readPatchTargetRecord(current);
|
|
448
|
-
if (record) return record;
|
|
449
|
-
const parent = path.dirname(current);
|
|
450
|
-
if (parent === current) break;
|
|
451
|
-
visited.add(current);
|
|
452
|
-
current = parent;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
456
|
-
if (!baseDir || !patcher?.packageInfo?.rootPath || options?.recordTarget === false) return;
|
|
457
|
-
const normalizedBase = path.normalize(baseDir);
|
|
458
|
-
const recorded = findPatchTargetRecord(normalizedBase);
|
|
459
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
460
|
-
const expectedPath = path.normalize(patcher.packageInfo.rootPath);
|
|
461
|
-
let reason;
|
|
462
|
-
if (!recorded) reason = "missing";
|
|
463
|
-
else if (path.normalize(recorded.record.tailwindPackagePath) !== expectedPath) reason = "mismatch";
|
|
464
|
-
else if (path.normalize(recorded.path) !== path.normalize(location.recordPath) || !recorded.record.recordKey || recorded.record.recordKey !== location.recordKey) reason = "migrate";
|
|
465
|
-
else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) reason = "stale";
|
|
466
|
-
else if (options?.cwd && recorded.record.cwd && path.normalize(recorded.record.cwd) !== path.normalize(options.cwd)) reason = "metadata";
|
|
467
|
-
else if (!recorded.record.cwd && options?.cwd) reason = "metadata";
|
|
468
|
-
if (!(options?.alwaysRecord || !recorded || Boolean(reason))) return;
|
|
469
|
-
let message;
|
|
470
|
-
switch (reason) {
|
|
471
|
-
case "mismatch":
|
|
472
|
-
message = "检测到 Tailwind CSS 目标记录与当前解析结果不一致,正在自动重新 patch 并刷新缓存。";
|
|
473
|
-
break;
|
|
474
|
-
case "migrate":
|
|
475
|
-
case "stale":
|
|
476
|
-
message = "正在刷新当前子包的 Tailwind CSS 补丁记录,确保缓存隔离。";
|
|
477
|
-
break;
|
|
478
|
-
case "missing":
|
|
479
|
-
message = "未找到当前子包的 Tailwind CSS 目标记录,正在生成。";
|
|
480
|
-
break;
|
|
481
|
-
default: break;
|
|
482
|
-
}
|
|
483
|
-
const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
|
|
484
|
-
cwd: options?.cwd ?? normalizedBase,
|
|
485
|
-
source: options?.source ?? "cli",
|
|
486
|
-
recordPath: location.recordPath,
|
|
487
|
-
recordKey: location.recordKey,
|
|
488
|
-
packageJsonPath: location.packageJsonPath
|
|
489
|
-
});
|
|
490
|
-
return {
|
|
491
|
-
recordPath: location.recordPath,
|
|
492
|
-
message,
|
|
493
|
-
reason,
|
|
494
|
-
onPatched
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region src/tailwindcss/targets.ts
|
|
499
|
-
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
315
|
+
function logTailwindcssTarget(patcher, baseDir) {
|
|
500
316
|
const packageInfo = patcher?.packageInfo;
|
|
501
|
-
const label =
|
|
317
|
+
const label = "Weapp-tailwindcss";
|
|
502
318
|
if (!packageInfo?.rootPath) {
|
|
503
319
|
logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
|
|
504
320
|
return;
|
|
505
321
|
}
|
|
506
322
|
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
507
323
|
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
logger.info("%s 绑定 Tailwind CSS -> %s%s", label, displayPath, version);
|
|
324
|
+
logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
|
|
325
|
+
logger.debug("%s 解析 Tailwind CSS -> %s%s", label, displayPath, version);
|
|
513
326
|
}
|
|
514
327
|
//#endregion
|
|
515
328
|
//#region src/context/compiler-context-cache.ts
|
|
@@ -714,6 +527,15 @@ function toCustomAttributesEntities(customAttributes) {
|
|
|
714
527
|
return Object.entries(customAttributes);
|
|
715
528
|
}
|
|
716
529
|
//#endregion
|
|
530
|
+
//#region src/constants.ts
|
|
531
|
+
const pluginName = "weapp-tailwindcss";
|
|
532
|
+
const vitePluginName = "weapp-tailwindcss:adaptor";
|
|
533
|
+
const DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
534
|
+
"tailwind-merge": "@weapp-tailwindcss/merge",
|
|
535
|
+
"class-variance-authority": "@weapp-tailwindcss/cva",
|
|
536
|
+
"tailwind-variants": "@weapp-tailwindcss/variants"
|
|
537
|
+
};
|
|
538
|
+
//#endregion
|
|
717
539
|
//#region src/babel/index.ts
|
|
718
540
|
function _interopDefaultCompat(e) {
|
|
719
541
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
@@ -1345,6 +1167,44 @@ function walkEvalExpression(path, options, updater, handler) {
|
|
|
1345
1167
|
}
|
|
1346
1168
|
}
|
|
1347
1169
|
//#endregion
|
|
1170
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
1171
|
+
function _typeof(o) {
|
|
1172
|
+
"@babel/helpers - typeof";
|
|
1173
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
1174
|
+
return typeof o;
|
|
1175
|
+
} : function(o) {
|
|
1176
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1177
|
+
}, _typeof(o);
|
|
1178
|
+
}
|
|
1179
|
+
//#endregion
|
|
1180
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
1181
|
+
function toPrimitive(t, r) {
|
|
1182
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1183
|
+
var e = t[Symbol.toPrimitive];
|
|
1184
|
+
if (void 0 !== e) {
|
|
1185
|
+
var i = e.call(t, r || "default");
|
|
1186
|
+
if ("object" != _typeof(i)) return i;
|
|
1187
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1188
|
+
}
|
|
1189
|
+
return ("string" === r ? String : Number)(t);
|
|
1190
|
+
}
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
1193
|
+
function toPropertyKey(t) {
|
|
1194
|
+
var i = toPrimitive(t, "string");
|
|
1195
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1196
|
+
}
|
|
1197
|
+
//#endregion
|
|
1198
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
1199
|
+
function _defineProperty(e, r, t) {
|
|
1200
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1201
|
+
value: t,
|
|
1202
|
+
enumerable: !0,
|
|
1203
|
+
configurable: !0,
|
|
1204
|
+
writable: !0
|
|
1205
|
+
}) : e[r] = t, e;
|
|
1206
|
+
}
|
|
1207
|
+
//#endregion
|
|
1348
1208
|
//#region src/js/JsTokenUpdater.ts
|
|
1349
1209
|
/**
|
|
1350
1210
|
* Lightweight helper that batches updates to {@link MagicString}.
|
|
@@ -1353,6 +1213,7 @@ function walkEvalExpression(path, options, updater, handler) {
|
|
|
1353
1213
|
*/
|
|
1354
1214
|
var JsTokenUpdater = class {
|
|
1355
1215
|
constructor({ value } = {}) {
|
|
1216
|
+
_defineProperty(this, "tokens", void 0);
|
|
1356
1217
|
this.tokens = value ? [...value] : [];
|
|
1357
1218
|
}
|
|
1358
1219
|
addToken(token) {
|
|
@@ -1386,7 +1247,7 @@ var JsTokenUpdater = class {
|
|
|
1386
1247
|
var IgnoredExportsTracker = class {
|
|
1387
1248
|
constructor(options) {
|
|
1388
1249
|
this.options = options;
|
|
1389
|
-
this
|
|
1250
|
+
_defineProperty(this, "ignoredExportNames", /* @__PURE__ */ new Map());
|
|
1390
1251
|
}
|
|
1391
1252
|
addIgnoredExport(filename, exportName) {
|
|
1392
1253
|
if (!exportName) return;
|
|
@@ -1505,8 +1366,16 @@ var IgnoredExportsTracker = class {
|
|
|
1505
1366
|
//#region src/js/ModuleGraph.ts
|
|
1506
1367
|
var JsModuleGraph = class {
|
|
1507
1368
|
constructor(entry, graphOptions) {
|
|
1508
|
-
this
|
|
1509
|
-
this
|
|
1369
|
+
_defineProperty(this, "modules", /* @__PURE__ */ new Map());
|
|
1370
|
+
_defineProperty(this, "queue", []);
|
|
1371
|
+
_defineProperty(this, "resolve", void 0);
|
|
1372
|
+
_defineProperty(this, "load", void 0);
|
|
1373
|
+
_defineProperty(this, "filter", void 0);
|
|
1374
|
+
_defineProperty(this, "maxDepth", void 0);
|
|
1375
|
+
_defineProperty(this, "baseOptions", void 0);
|
|
1376
|
+
_defineProperty(this, "parserOptions", void 0);
|
|
1377
|
+
_defineProperty(this, "rootFilename", void 0);
|
|
1378
|
+
_defineProperty(this, "ignoredExports", void 0);
|
|
1510
1379
|
this.resolve = graphOptions.resolve;
|
|
1511
1380
|
this.load = graphOptions.load;
|
|
1512
1381
|
this.filter = graphOptions.filter;
|
|
@@ -1678,6 +1547,12 @@ const NEVER_MATCH_NAME = () => false;
|
|
|
1678
1547
|
*/
|
|
1679
1548
|
var NodePathWalker = class {
|
|
1680
1549
|
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
1550
|
+
_defineProperty(this, "ignoreCallExpressionIdentifiers", void 0);
|
|
1551
|
+
_defineProperty(this, "callback", void 0);
|
|
1552
|
+
_defineProperty(this, "isIgnoredCallIdentifier", void 0);
|
|
1553
|
+
_defineProperty(this, "hasIgnoredCallIdentifiers", void 0);
|
|
1554
|
+
_defineProperty(this, "importsStore", void 0);
|
|
1555
|
+
_defineProperty(this, "visitedStore", void 0);
|
|
1681
1556
|
this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
|
|
1682
1557
|
this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
|
|
1683
1558
|
this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
|
|
@@ -2317,6 +2192,13 @@ function isAllWhitespace(value) {
|
|
|
2317
2192
|
//#region src/wxml/Tokenizer.ts
|
|
2318
2193
|
var Tokenizer = class {
|
|
2319
2194
|
constructor() {
|
|
2195
|
+
_defineProperty(this, "state", void 0);
|
|
2196
|
+
_defineProperty(this, "buffer", void 0);
|
|
2197
|
+
_defineProperty(this, "tokens", void 0);
|
|
2198
|
+
_defineProperty(this, "bufferStartIndex", void 0);
|
|
2199
|
+
_defineProperty(this, "expressionStartIndex", void 0);
|
|
2200
|
+
_defineProperty(this, "expressionBuffer", void 0);
|
|
2201
|
+
_defineProperty(this, "expressions", void 0);
|
|
2320
2202
|
this.reset();
|
|
2321
2203
|
}
|
|
2322
2204
|
processChar(char, index) {
|
|
@@ -2677,9 +2559,10 @@ function createInternalCompilerContext(opts) {
|
|
|
2677
2559
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
2678
2560
|
applyLoggerLevel(ctx.logLevel);
|
|
2679
2561
|
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
2680
|
-
logTailwindcssTarget(
|
|
2562
|
+
logTailwindcssTarget(twPatcher, ctx.tailwindcssBasedir);
|
|
2681
2563
|
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, twPatcher.packageInfo?.rootPath, twPatcher.packageInfo?.version);
|
|
2682
|
-
warnMissingCssEntries(ctx, twPatcher);
|
|
2564
|
+
if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, twPatcher);
|
|
2565
|
+
ctx.cssPreflight = resolveDefaultCssPreflight(opts?.cssPreflight, twPatcher.majorVersion);
|
|
2683
2566
|
const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, twPatcher);
|
|
2684
2567
|
ctx.cssCalc = cssCalcOptions;
|
|
2685
2568
|
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, twPatcher.majorVersion);
|
|
@@ -2705,9 +2588,9 @@ function createInternalCompilerContext(opts) {
|
|
|
2705
2588
|
return ctx;
|
|
2706
2589
|
}
|
|
2707
2590
|
/**
|
|
2708
|
-
*
|
|
2591
|
+
* 获取用户定义选项的内部表示,并初始化相关的处理程序和 Tailwind 运行时。
|
|
2709
2592
|
* @param opts - 用户定义的选项,可选。
|
|
2710
|
-
* @returns 返回一个包含内部用户定义选项的对象,包括样式、JS和模板处理程序,以及Tailwind CSS
|
|
2593
|
+
* @returns 返回一个包含内部用户定义选项的对象,包括样式、JS 和模板处理程序,以及 Tailwind CSS 运行时。
|
|
2711
2594
|
*/
|
|
2712
2595
|
function getCompilerContext(opts) {
|
|
2713
2596
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
@@ -2736,21 +2619,4 @@ function shouldSkipJsTransform(rawSource, options) {
|
|
|
2736
2619
|
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
2737
2620
|
}
|
|
2738
2621
|
//#endregion
|
|
2739
|
-
|
|
2740
|
-
function setupPatchRecorder(patcher, baseDir, options) {
|
|
2741
|
-
const recorder = createPatchTargetRecorder(baseDir, patcher, options);
|
|
2742
|
-
if (recorder?.message && options?.logMessage !== false) {
|
|
2743
|
-
const prefix = options?.messagePrefix ? `${options.messagePrefix} ` : "";
|
|
2744
|
-
logger$1.info("%s%s", prefix, recorder.message);
|
|
2745
|
-
}
|
|
2746
|
-
const onPatchCompleted = recorder?.onPatched ? async () => {
|
|
2747
|
-
await recorder.onPatched();
|
|
2748
|
-
} : void 0;
|
|
2749
|
-
return {
|
|
2750
|
-
recorder,
|
|
2751
|
-
patchPromise: patcher ? createTailwindPatchPromise(patcher, onPatchCompleted) : Promise.resolve(),
|
|
2752
|
-
onPatchCompleted
|
|
2753
|
-
};
|
|
2754
|
-
}
|
|
2755
|
-
//#endregion
|
|
2756
|
-
export { refreshTailwindRuntimeState as _, createAttributeMatcher as a, isClassContextLiteralPath as c, traverse as d, toCustomAttributesEntities as f, ensureRuntimeClassSet as g, collectRuntimeClassSet as h, generateCode as i, replaceWxml as l, vitePluginName as m, shouldSkipJsTransform as n, analyzeSource as o, pluginName as p, getCompilerContext as r, JsTokenUpdater as s, setupPatchRecorder as t, babelParse as u, createDebug as v };
|
|
2622
|
+
export { ensureRuntimeClassSet as _, analyzeSource as a, isClassContextLiteralPath as c, traverse as d, pluginName as f, createTailwindRuntimeReadyPromise as g, collectRuntimeClassSet as h, createAttributeMatcher as i, replaceWxml as l, toCustomAttributesEntities as m, getCompilerContext as n, JsTokenUpdater as o, vitePluginName as p, generateCode as r, _defineProperty as s, shouldSkipJsTransform as t, babelParse as u, refreshTailwindRuntimeState as v };
|
package/dist/presets.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
require("./cache-BVAiJV3J.js");
|
|
4
|
+
const require_utils = require("./utils-BiShvil9.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-Bu-RWIHx.js");
|
|
6
|
+
require("./logger-BRy6XPQ2.js");
|
|
5
7
|
let node_process = require("node:process");
|
|
6
8
|
node_process = require_chunk.__toESM(node_process);
|
|
7
9
|
let local_pkg = require("local-pkg");
|
|
@@ -15,7 +17,7 @@ function normalizeCssEntries(entries) {
|
|
|
15
17
|
}
|
|
16
18
|
function createBasePreset(options = {}) {
|
|
17
19
|
const { base, cssEntries, resolve, rawOptions, ...userOptions } = options;
|
|
18
|
-
const baseDir =
|
|
20
|
+
const baseDir = require_tailwindcss.resolveTailwindcssBasedir(base);
|
|
19
21
|
const normalizedCssEntries = normalizeCssEntries(cssEntries);
|
|
20
22
|
const tailwindConfig = {
|
|
21
23
|
v2: { cwd: baseDir },
|
|
@@ -87,7 +89,7 @@ function uniAppX(options) {
|
|
|
87
89
|
const cssEntries = normalizeCssEntries(options.cssEntries);
|
|
88
90
|
const resolvedResolve = resolveTailwindResolveOptions(options.base, options.resolve);
|
|
89
91
|
const installedTailwindDefaults = resolveInstalledTailwindDefaults(resolvedResolve);
|
|
90
|
-
const resolvedUniAppX =
|
|
92
|
+
const resolvedUniAppX = require_tailwindcss.resolveUniAppXOptions({
|
|
91
93
|
enabled: isApp,
|
|
92
94
|
componentLocalStyles: options.componentLocalStyles ?? true,
|
|
93
95
|
uvueUnsupported: options.uvueUnsupported,
|
package/dist/presets.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import "./cache-CHs4DXui.mjs";
|
|
2
|
+
import { n as defuOverrideArray, o as resolveUniUtsPlatform } from "./utils-Btw1iOVV.mjs";
|
|
3
|
+
import { i as resolveUniAppXOptions, n as resolveTailwindcssBasedir } from "./tailwindcss-C5IgPlQ0.mjs";
|
|
4
|
+
import { t as logger } from "./logger-Bub1jggA.mjs";
|
|
3
5
|
import process from "node:process";
|
|
4
6
|
import { getPackageInfoSync } from "local-pkg";
|
|
5
7
|
//#region src/presets/shared.ts
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { i as runtimeSignaturePatchersSymbol } from "./cache-CHs4DXui.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import _createDebug from "debug";
|
|
5
|
+
//#region src/debug/index.ts
|
|
6
|
+
const _debug = _createDebug("weapp-tw");
|
|
7
|
+
function createDebug(prefix) {
|
|
8
|
+
const debug = ((formatter, ...args) => {
|
|
9
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(debug, "enabled", {
|
|
12
|
+
enumerable: false,
|
|
13
|
+
configurable: false,
|
|
14
|
+
get() {
|
|
15
|
+
return _debug.enabled;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return debug;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/tailwindcss/runtime-patch.ts
|
|
22
|
+
const debug = createDebug("[tailwindcss:runtime-patch] ");
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
const runtimePatchPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
function getNestedPatchers(twPatcher) {
|
|
26
|
+
const nested = twPatcher[runtimeSignaturePatchersSymbol];
|
|
27
|
+
return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
|
|
28
|
+
}
|
|
29
|
+
function shouldApplyRuntimePatch(twPatcher) {
|
|
30
|
+
return twPatcher.majorVersion === 3 && typeof twPatcher.patch === "function";
|
|
31
|
+
}
|
|
32
|
+
function clearTailwindcssRequireCache(twPatcher) {
|
|
33
|
+
const rootPath = twPatcher.packageInfo?.rootPath;
|
|
34
|
+
if (!rootPath) return;
|
|
35
|
+
const normalizedRoot = path.resolve(rootPath);
|
|
36
|
+
let count = 0;
|
|
37
|
+
for (const id of Object.keys(require.cache)) {
|
|
38
|
+
const normalizedId = path.resolve(id);
|
|
39
|
+
if (normalizedId === normalizedRoot || normalizedId.startsWith(`${normalizedRoot}${path.sep}`)) {
|
|
40
|
+
delete require.cache[id];
|
|
41
|
+
count += 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (count > 0) debug("clear tailwindcss require cache after runtime patch, count=%d root=%s", count, normalizedRoot);
|
|
45
|
+
}
|
|
46
|
+
async function ensureTailwindcssRuntimePatch(twPatcher, options = {}) {
|
|
47
|
+
const nestedPatchers = getNestedPatchers(twPatcher);
|
|
48
|
+
if (nestedPatchers) {
|
|
49
|
+
await Promise.all(nestedPatchers.map((patcher) => ensureTailwindcssRuntimePatch(patcher)));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!shouldApplyRuntimePatch(twPatcher)) return;
|
|
53
|
+
const cached = runtimePatchPromiseCache.get(twPatcher);
|
|
54
|
+
if (cached) {
|
|
55
|
+
await cached;
|
|
56
|
+
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const task = Promise.resolve().then(async () => {
|
|
60
|
+
debug("apply tailwindcss runtime patch, package=%s version=%s root=%s", twPatcher.packageInfo?.name ?? "tailwindcss", twPatcher.packageInfo?.version ?? "unknown", twPatcher.packageInfo?.rootPath ?? "unknown");
|
|
61
|
+
await twPatcher.patch?.();
|
|
62
|
+
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
63
|
+
}).catch((error) => {
|
|
64
|
+
runtimePatchPromiseCache.delete(twPatcher);
|
|
65
|
+
throw error;
|
|
66
|
+
});
|
|
67
|
+
runtimePatchPromiseCache.set(twPatcher, task);
|
|
68
|
+
return task;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { createDebug as n, ensureTailwindcssRuntimePatch as t };
|