weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.7
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.md +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- 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 +11 -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 +12 -22
- 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 +2 -1
- package/dist/bundlers/vite/index.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 +0 -1
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
- package/dist/cache-DPN5yKSX.js +497 -0
- package/dist/cache-nq0_XJoS.mjs +429 -0
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli.js +108 -598
- package/dist/cli.mjs +119 -608
- package/dist/constants.d.ts +1 -2
- 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.d.ts +1 -0
- 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 +33 -14
- package/dist/defaults.mjs +30 -15
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
- package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
- package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +29 -28
- package/dist/gulp.mjs +25 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- 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-BtAP6sQO.mjs +288 -0
- package/dist/postcss-WsXlC7A-.js +298 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -276
- package/dist/postcss.mjs +1 -269
- package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
- package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
- package/dist/presets.js +6 -4
- package/dist/presets.mjs +4 -2
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
- package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
- package/dist/runtime-patch-qwuisukL.js +85 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- 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/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +2 -1
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
- package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +2 -9
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +0 -2
- package/dist/types/user-defined-options/important.d.ts +3 -3
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
- package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
- package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +23 -35
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- 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/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/js/syntax.d.ts +0 -10
- package/dist/loader-anchors-1MumTAtA.mjs +0 -205
- package/dist/loader-anchors-TrFvT6g1.js +0 -273
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- 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/types/disabled-options.d.ts +0 -4
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
- /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/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
- /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -30,13 +30,13 @@ node_path = __toESM(node_path);
|
|
|
30
30
|
let node_fs_promises = require("node:fs/promises");
|
|
31
31
|
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
32
32
|
let lru_cache = require("lru-cache");
|
|
33
|
-
|
|
33
|
+
require("@weapp-tailwindcss/shared/node");
|
|
34
34
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
35
35
|
require("@weapp-tailwindcss/shared");
|
|
36
36
|
let debug = require("debug");
|
|
37
37
|
debug = __toESM(debug);
|
|
38
|
-
let node_fs = require("node:fs");
|
|
39
38
|
let node_module = require("node:module");
|
|
39
|
+
let node_fs = require("node:fs");
|
|
40
40
|
require("@weapp-tailwindcss/postcss");
|
|
41
41
|
let _babel_traverse = require("@babel/traverse");
|
|
42
42
|
_babel_traverse = __toESM(_babel_traverse);
|
|
@@ -48,260 +48,36 @@ let _ast_core_escape = require("@ast-core/escape");
|
|
|
48
48
|
let _weapp_tailwindcss_shared_extractors = require("@weapp-tailwindcss/shared/extractors");
|
|
49
49
|
require("@babel/types");
|
|
50
50
|
require("htmlparser2");
|
|
51
|
-
let local_pkg = require("local-pkg");
|
|
52
|
-
let fast_glob = require("fast-glob");
|
|
53
|
-
fast_glob = __toESM(fast_glob);
|
|
54
|
-
let yaml = require("yaml");
|
|
55
51
|
//#region src/debug/index.ts
|
|
56
52
|
const _debug = (0, debug.default)("weapp-tw");
|
|
57
53
|
function createDebug(prefix) {
|
|
58
|
-
const debug$
|
|
54
|
+
const debug$4 = ((formatter, ...args) => {
|
|
59
55
|
return _debug((prefix ?? "") + formatter, ...args);
|
|
60
56
|
});
|
|
61
|
-
Object.defineProperty(debug$
|
|
57
|
+
Object.defineProperty(debug$4, "enabled", {
|
|
62
58
|
enumerable: false,
|
|
63
59
|
configurable: false,
|
|
64
60
|
get() {
|
|
65
61
|
return _debug.enabled;
|
|
66
62
|
}
|
|
67
63
|
});
|
|
68
|
-
return debug$
|
|
64
|
+
return debug$4;
|
|
69
65
|
}
|
|
66
|
+
createDebug("[tailwindcss:runtime-patch] ");
|
|
67
|
+
(0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
70
68
|
createDebug("[tailwindcss:runtime] ");
|
|
71
69
|
//#endregion
|
|
72
70
|
//#region src/tailwindcss/runtime-logs.ts
|
|
73
71
|
const runtimeLogDedupeHolder = globalThis;
|
|
74
|
-
|
|
75
|
-
function createRuntimeLogKey(category, baseDir, rootPath, version) {
|
|
76
|
-
return JSON.stringify([
|
|
77
|
-
category,
|
|
78
|
-
baseDir ?? node_process.default.cwd(),
|
|
79
|
-
rootPath ?? "",
|
|
80
|
-
version ?? ""
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
function markRuntimeLog(category, baseDir, rootPath, version) {
|
|
84
|
-
const key = createRuntimeLogKey(category, baseDir, rootPath, version);
|
|
85
|
-
if (runtimeLogDedupe.has(key)) return false;
|
|
86
|
-
runtimeLogDedupe.add(key);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
function logRuntimeTailwindcssTarget(baseDir, rootPath, version) {
|
|
90
|
-
if (!markRuntimeLog("target", baseDir, rootPath, version)) return;
|
|
91
|
-
const versionText = version ? ` (v${version})` : "";
|
|
92
|
-
_weapp_tailwindcss_logger.logger.info("%s 使用 Tailwind CSS%s", "Weapp-tailwindcss", versionText);
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/context/workspace.ts
|
|
96
|
-
function findWorkspaceRoot(startDir) {
|
|
97
|
-
if (!startDir) return;
|
|
98
|
-
let current = node_path.default.resolve(startDir);
|
|
99
|
-
while (true) {
|
|
100
|
-
if ((0, node_fs.existsSync)(node_path.default.join(current, "pnpm-workspace.yaml"))) return current;
|
|
101
|
-
const parent = node_path.default.dirname(current);
|
|
102
|
-
if (parent === current) return;
|
|
103
|
-
current = parent;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function findNearestPackageRoot(startDir) {
|
|
107
|
-
if (!startDir) return;
|
|
108
|
-
let current = node_path.default.resolve(startDir);
|
|
109
|
-
while (true) {
|
|
110
|
-
if ((0, node_fs.existsSync)(node_path.default.join(current, "package.json"))) return current;
|
|
111
|
-
const parent = node_path.default.dirname(current);
|
|
112
|
-
if (parent === current) return;
|
|
113
|
-
current = parent;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/tailwindcss/targets/paths.ts
|
|
118
|
-
const PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
119
|
-
const PATCH_INFO_CACHE_RELATIVE_PATH = node_path.default.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
120
|
-
const PATCH_INFO_LEGACY_RELATIVE_PATH = node_path.default.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
121
|
-
function toDisplayPath(value) {
|
|
122
|
-
return node_path.default.normalize(value).replace(/\\/g, "/");
|
|
123
|
-
}
|
|
124
|
-
function formatRelativeToBase(targetPath, baseDir) {
|
|
125
|
-
if (!baseDir) return toDisplayPath(targetPath);
|
|
126
|
-
const relative = node_path.default.relative(baseDir, targetPath);
|
|
127
|
-
if (!relative || relative === ".") return ".";
|
|
128
|
-
if (relative.startsWith("..")) return toDisplayPath(targetPath);
|
|
129
|
-
return toDisplayPath(node_path.default.join(".", relative));
|
|
130
|
-
}
|
|
131
|
-
function resolveRecordLocation(baseDir) {
|
|
132
|
-
const normalizedBase = node_path.default.normalize(baseDir);
|
|
133
|
-
const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
|
|
134
|
-
const packageJsonPath = node_path.default.join(packageRoot, "package.json");
|
|
135
|
-
const hasPackageJson = (0, node_fs.existsSync)(packageJsonPath);
|
|
136
|
-
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
137
|
-
const recordKey = (0, _weapp_tailwindcss_shared_node.md5)(node_path.default.normalize(recordKeySource));
|
|
138
|
-
const recordDir = node_path.default.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
139
|
-
return {
|
|
140
|
-
normalizedBase,
|
|
141
|
-
packageRoot,
|
|
142
|
-
recordDir,
|
|
143
|
-
recordKey,
|
|
144
|
-
recordPath: node_path.default.join(recordDir, PATCH_INFO_FILENAME),
|
|
145
|
-
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function getRecordFileCandidates(baseDir) {
|
|
149
|
-
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
150
|
-
return [...new Set([
|
|
151
|
-
recordPath,
|
|
152
|
-
node_path.default.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
153
|
-
node_path.default.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
154
|
-
node_path.default.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
155
|
-
])];
|
|
156
|
-
}
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region package.json
|
|
159
|
-
var version = "5.0.0-next.3";
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/constants.ts
|
|
162
|
-
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
163
|
-
const WEAPP_TW_VERSION = version;
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/tailwindcss/targets/record-io.ts
|
|
166
|
-
const loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
167
|
-
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
168
|
-
const normalizedPath = node_path.default.normalize(recordPath);
|
|
169
|
-
if (loggedInvalidPatchRecords.has(normalizedPath)) return;
|
|
170
|
-
loggedInvalidPatchRecords.add(normalizedPath);
|
|
171
|
-
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
172
|
-
const baseDisplay = formatRelativeToBase(node_path.default.normalize(baseDir), node_process.default.cwd());
|
|
173
|
-
const reasonMessage = reason ? `:${reason}` : "";
|
|
174
|
-
_weapp_tailwindcss_logger.logger.warn(`检测到损坏的 Tailwind CSS 目标记录 ${fileDisplay}${reasonMessage}。请在 ${baseDisplay} 重新执行 "weapp-tw patch --record-target" 或删除该文件后再运行。`);
|
|
175
|
-
}
|
|
176
|
-
function readPatchTargetRecord(baseDir) {
|
|
177
|
-
if (!baseDir) return;
|
|
178
|
-
const normalizedBase = node_path.default.normalize(baseDir);
|
|
179
|
-
for (const recordPath of getRecordFileCandidates(normalizedBase)) {
|
|
180
|
-
if (!(0, node_fs.existsSync)(recordPath)) continue;
|
|
181
|
-
try {
|
|
182
|
-
const content = (0, node_fs.readFileSync)(recordPath, "utf8");
|
|
183
|
-
const parsed = JSON.parse(content);
|
|
184
|
-
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
185
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, "缺少 tailwindPackagePath 字段");
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
baseDir: normalizedBase,
|
|
190
|
-
path: recordPath,
|
|
191
|
-
record: parsed
|
|
192
|
-
};
|
|
193
|
-
} catch (error) {
|
|
194
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, error instanceof Error ? error.message : String(error));
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
200
|
-
if (!baseDir || !patcher?.packageInfo?.rootPath) return;
|
|
201
|
-
const normalizedBase = node_path.default.normalize(baseDir);
|
|
202
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
203
|
-
const recordPath = options?.recordPath ? node_path.default.normalize(options.recordPath) : location.recordPath;
|
|
204
|
-
const record = {
|
|
205
|
-
tailwindPackagePath: node_path.default.normalize(patcher.packageInfo.rootPath),
|
|
206
|
-
packageVersion: patcher.packageInfo.version,
|
|
207
|
-
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
208
|
-
source: options?.source ?? "cli",
|
|
209
|
-
tailwindcssBasedir: normalizedBase,
|
|
210
|
-
cwd: options?.cwd ? node_path.default.normalize(options.cwd) : normalizedBase,
|
|
211
|
-
patchVersion: WEAPP_TW_VERSION,
|
|
212
|
-
packageJsonPath: options?.packageJsonPath ?? location.packageJsonPath,
|
|
213
|
-
recordKey: options?.recordKey ?? location.recordKey
|
|
214
|
-
};
|
|
215
|
-
try {
|
|
216
|
-
await (0, node_fs_promises.mkdir)(node_path.default.dirname(recordPath), { recursive: true });
|
|
217
|
-
await (0, node_fs_promises.writeFile)(recordPath, `${JSON.stringify(record, null, 2)}\n`, "utf8");
|
|
218
|
-
return recordPath;
|
|
219
|
-
} catch (error) {
|
|
220
|
-
const baseDisplay = formatRelativeToBase(normalizedBase, node_process.default.cwd());
|
|
221
|
-
_weapp_tailwindcss_logger.logger.warn("自动更新 Tailwind CSS 补丁记录失败,请在 %s 运行 \"weapp-tw patch --cwd %s\"。", baseDisplay, normalizedBase);
|
|
222
|
-
_weapp_tailwindcss_logger.logger.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/tailwindcss/targets/recorder.ts
|
|
228
|
-
function findPatchTargetRecord(baseDir) {
|
|
229
|
-
const visited = /* @__PURE__ */ new Set();
|
|
230
|
-
const fallback = baseDir ?? node_process.default.cwd();
|
|
231
|
-
let current = node_path.default.resolve(fallback);
|
|
232
|
-
while (!visited.has(current)) {
|
|
233
|
-
const record = readPatchTargetRecord(current);
|
|
234
|
-
if (record) return record;
|
|
235
|
-
const parent = node_path.default.dirname(current);
|
|
236
|
-
if (parent === current) break;
|
|
237
|
-
visited.add(current);
|
|
238
|
-
current = parent;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
242
|
-
if (!baseDir || !patcher?.packageInfo?.rootPath || options?.recordTarget === false) return;
|
|
243
|
-
const normalizedBase = node_path.default.normalize(baseDir);
|
|
244
|
-
const recorded = findPatchTargetRecord(normalizedBase);
|
|
245
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
246
|
-
const expectedPath = node_path.default.normalize(patcher.packageInfo.rootPath);
|
|
247
|
-
let reason;
|
|
248
|
-
if (!recorded) reason = "missing";
|
|
249
|
-
else if (node_path.default.normalize(recorded.record.tailwindPackagePath) !== expectedPath) reason = "mismatch";
|
|
250
|
-
else if (node_path.default.normalize(recorded.path) !== node_path.default.normalize(location.recordPath) || !recorded.record.recordKey || recorded.record.recordKey !== location.recordKey) reason = "migrate";
|
|
251
|
-
else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) reason = "stale";
|
|
252
|
-
else if (options?.cwd && recorded.record.cwd && node_path.default.normalize(recorded.record.cwd) !== node_path.default.normalize(options.cwd)) reason = "metadata";
|
|
253
|
-
else if (!recorded.record.cwd && options?.cwd) reason = "metadata";
|
|
254
|
-
if (!(options?.alwaysRecord || !recorded || Boolean(reason))) return;
|
|
255
|
-
let message;
|
|
256
|
-
switch (reason) {
|
|
257
|
-
case "mismatch":
|
|
258
|
-
message = "检测到 Tailwind CSS 目标记录与当前解析结果不一致,正在自动重新 patch 并刷新缓存。";
|
|
259
|
-
break;
|
|
260
|
-
case "migrate":
|
|
261
|
-
case "stale":
|
|
262
|
-
message = "正在刷新当前子包的 Tailwind CSS 补丁记录,确保缓存隔离。";
|
|
263
|
-
break;
|
|
264
|
-
case "missing":
|
|
265
|
-
message = "未找到当前子包的 Tailwind CSS 目标记录,正在生成。";
|
|
266
|
-
break;
|
|
267
|
-
default: break;
|
|
268
|
-
}
|
|
269
|
-
const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
|
|
270
|
-
cwd: options?.cwd ?? normalizedBase,
|
|
271
|
-
source: options?.source ?? "cli",
|
|
272
|
-
recordPath: location.recordPath,
|
|
273
|
-
recordKey: location.recordKey,
|
|
274
|
-
packageJsonPath: location.packageJsonPath
|
|
275
|
-
});
|
|
276
|
-
return {
|
|
277
|
-
recordPath: location.recordPath,
|
|
278
|
-
message,
|
|
279
|
-
reason,
|
|
280
|
-
onPatched
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/tailwindcss/targets.ts
|
|
285
|
-
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
286
|
-
const packageInfo = patcher?.packageInfo;
|
|
287
|
-
const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
|
|
288
|
-
if (!packageInfo?.rootPath) {
|
|
289
|
-
_weapp_tailwindcss_logger.logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? node_process.default.cwd());
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
293
|
-
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
294
|
-
if (kind === "runtime") {
|
|
295
|
-
logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
_weapp_tailwindcss_logger.logger.info("%s 绑定 Tailwind CSS -> %s%s", label, displayPath, version);
|
|
299
|
-
}
|
|
72
|
+
runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
|
|
300
73
|
//#endregion
|
|
301
74
|
//#region src/context/compiler-context-cache.ts
|
|
302
75
|
const globalCacheHolder = globalThis;
|
|
303
76
|
globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
304
77
|
//#endregion
|
|
78
|
+
//#region src/constants.ts
|
|
79
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
80
|
+
//#endregion
|
|
305
81
|
//#region src/babel/index.ts
|
|
306
82
|
function _interopDefaultCompat(e) {
|
|
307
83
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
@@ -933,6 +709,44 @@ function walkEvalExpression(path, options, updater, handler) {
|
|
|
933
709
|
}
|
|
934
710
|
}
|
|
935
711
|
//#endregion
|
|
712
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
713
|
+
function _typeof(o) {
|
|
714
|
+
"@babel/helpers - typeof";
|
|
715
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
716
|
+
return typeof o;
|
|
717
|
+
} : function(o) {
|
|
718
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
719
|
+
}, _typeof(o);
|
|
720
|
+
}
|
|
721
|
+
//#endregion
|
|
722
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
723
|
+
function toPrimitive(t, r) {
|
|
724
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
725
|
+
var e = t[Symbol.toPrimitive];
|
|
726
|
+
if (void 0 !== e) {
|
|
727
|
+
var i = e.call(t, r || "default");
|
|
728
|
+
if ("object" != _typeof(i)) return i;
|
|
729
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
730
|
+
}
|
|
731
|
+
return ("string" === r ? String : Number)(t);
|
|
732
|
+
}
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
735
|
+
function toPropertyKey(t) {
|
|
736
|
+
var i = toPrimitive(t, "string");
|
|
737
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
738
|
+
}
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
741
|
+
function _defineProperty(e, r, t) {
|
|
742
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
743
|
+
value: t,
|
|
744
|
+
enumerable: !0,
|
|
745
|
+
configurable: !0,
|
|
746
|
+
writable: !0
|
|
747
|
+
}) : e[r] = t, e;
|
|
748
|
+
}
|
|
749
|
+
//#endregion
|
|
936
750
|
//#region src/js/JsTokenUpdater.ts
|
|
937
751
|
/**
|
|
938
752
|
* Lightweight helper that batches updates to {@link MagicString}.
|
|
@@ -941,6 +755,7 @@ function walkEvalExpression(path, options, updater, handler) {
|
|
|
941
755
|
*/
|
|
942
756
|
var JsTokenUpdater = class {
|
|
943
757
|
constructor({ value } = {}) {
|
|
758
|
+
_defineProperty(this, "tokens", void 0);
|
|
944
759
|
this.tokens = value ? [...value] : [];
|
|
945
760
|
}
|
|
946
761
|
addToken(token) {
|
|
@@ -974,7 +789,7 @@ var JsTokenUpdater = class {
|
|
|
974
789
|
var IgnoredExportsTracker = class {
|
|
975
790
|
constructor(options) {
|
|
976
791
|
this.options = options;
|
|
977
|
-
this
|
|
792
|
+
_defineProperty(this, "ignoredExportNames", /* @__PURE__ */ new Map());
|
|
978
793
|
}
|
|
979
794
|
addIgnoredExport(filename, exportName) {
|
|
980
795
|
if (!exportName) return;
|
|
@@ -1093,8 +908,16 @@ var IgnoredExportsTracker = class {
|
|
|
1093
908
|
//#region src/js/ModuleGraph.ts
|
|
1094
909
|
var JsModuleGraph = class {
|
|
1095
910
|
constructor(entry, graphOptions) {
|
|
1096
|
-
this
|
|
1097
|
-
this
|
|
911
|
+
_defineProperty(this, "modules", /* @__PURE__ */ new Map());
|
|
912
|
+
_defineProperty(this, "queue", []);
|
|
913
|
+
_defineProperty(this, "resolve", void 0);
|
|
914
|
+
_defineProperty(this, "load", void 0);
|
|
915
|
+
_defineProperty(this, "filter", void 0);
|
|
916
|
+
_defineProperty(this, "maxDepth", void 0);
|
|
917
|
+
_defineProperty(this, "baseOptions", void 0);
|
|
918
|
+
_defineProperty(this, "parserOptions", void 0);
|
|
919
|
+
_defineProperty(this, "rootFilename", void 0);
|
|
920
|
+
_defineProperty(this, "ignoredExports", void 0);
|
|
1098
921
|
this.resolve = graphOptions.resolve;
|
|
1099
922
|
this.load = graphOptions.load;
|
|
1100
923
|
this.filter = graphOptions.filter;
|
|
@@ -1266,6 +1089,12 @@ const NEVER_MATCH_NAME = () => false;
|
|
|
1266
1089
|
*/
|
|
1267
1090
|
var NodePathWalker = class {
|
|
1268
1091
|
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
1092
|
+
_defineProperty(this, "ignoreCallExpressionIdentifiers", void 0);
|
|
1093
|
+
_defineProperty(this, "callback", void 0);
|
|
1094
|
+
_defineProperty(this, "isIgnoredCallIdentifier", void 0);
|
|
1095
|
+
_defineProperty(this, "hasIgnoredCallIdentifiers", void 0);
|
|
1096
|
+
_defineProperty(this, "importsStore", void 0);
|
|
1097
|
+
_defineProperty(this, "visitedStore", void 0);
|
|
1269
1098
|
this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
|
|
1270
1099
|
this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
|
|
1271
1100
|
this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
|
|
@@ -1673,6 +1502,13 @@ function isWhitespace(char) {
|
|
|
1673
1502
|
//#region src/wxml/Tokenizer.ts
|
|
1674
1503
|
var Tokenizer = class {
|
|
1675
1504
|
constructor() {
|
|
1505
|
+
_defineProperty(this, "state", void 0);
|
|
1506
|
+
_defineProperty(this, "buffer", void 0);
|
|
1507
|
+
_defineProperty(this, "tokens", void 0);
|
|
1508
|
+
_defineProperty(this, "bufferStartIndex", void 0);
|
|
1509
|
+
_defineProperty(this, "expressionStartIndex", void 0);
|
|
1510
|
+
_defineProperty(this, "expressionBuffer", void 0);
|
|
1511
|
+
_defineProperty(this, "expressions", void 0);
|
|
1676
1512
|
this.reset();
|
|
1677
1513
|
}
|
|
1678
1514
|
processChar(char, index) {
|
|
@@ -1787,36 +1623,6 @@ var Tokenizer = class {
|
|
|
1787
1623
|
};
|
|
1788
1624
|
new Tokenizer();
|
|
1789
1625
|
//#endregion
|
|
1790
|
-
//#region src/context/index.ts
|
|
1791
|
-
async function clearTailwindcssPatcherCache(patcher, options) {
|
|
1792
|
-
if (!patcher) return;
|
|
1793
|
-
const cacheOptions = patcher.options?.cache;
|
|
1794
|
-
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
|
|
1795
|
-
if (typeof patcher.clearCache === "function") try {
|
|
1796
|
-
await patcher.clearCache({ scope: "all" });
|
|
1797
|
-
} catch (error) {
|
|
1798
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
|
|
1799
|
-
}
|
|
1800
|
-
if (!options?.removeDirectory) return;
|
|
1801
|
-
const cachePaths = /* @__PURE__ */ new Map();
|
|
1802
|
-
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
1803
|
-
if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
|
|
1804
|
-
const privateCachePath = patcher?.cacheStore?.options?.path;
|
|
1805
|
-
if (privateCachePath) cachePaths.set(privateCachePath, false);
|
|
1806
|
-
if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
|
|
1807
|
-
if (!cachePaths.size) return;
|
|
1808
|
-
for (const [cachePath, recursive] of cachePaths.entries()) try {
|
|
1809
|
-
await (0, node_fs_promises.rm)(cachePath, {
|
|
1810
|
-
force: true,
|
|
1811
|
-
recursive
|
|
1812
|
-
});
|
|
1813
|
-
} catch (error) {
|
|
1814
|
-
const err = error;
|
|
1815
|
-
if (err?.code === "ENOENT") continue;
|
|
1816
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
//#endregion
|
|
1820
1626
|
//#region src/cli/context.ts
|
|
1821
1627
|
function formatOutputPath(target, baseDir) {
|
|
1822
1628
|
const root = baseDir ?? node_process.default.cwd();
|
|
@@ -1860,7 +1666,7 @@ const FRAMEWORK_DEPS = [
|
|
|
1860
1666
|
];
|
|
1861
1667
|
//#endregion
|
|
1862
1668
|
//#region src/cli/doctor.ts
|
|
1863
|
-
function tryReadJson
|
|
1669
|
+
function tryReadJson(file) {
|
|
1864
1670
|
try {
|
|
1865
1671
|
return JSON.parse((0, node_fs.readFileSync)(file, "utf8"));
|
|
1866
1672
|
} catch {
|
|
@@ -1871,11 +1677,11 @@ function findFirstExisting(cwd, files) {
|
|
|
1871
1677
|
return files.find((file) => (0, node_fs.existsSync)(node_path.default.join(cwd, file)));
|
|
1872
1678
|
}
|
|
1873
1679
|
function readProjectPackageJson(cwd) {
|
|
1874
|
-
return tryReadJson
|
|
1680
|
+
return tryReadJson(node_path.default.join(cwd, "package.json"));
|
|
1875
1681
|
}
|
|
1876
1682
|
function readDependencyVersion(cwd, packageName) {
|
|
1877
1683
|
try {
|
|
1878
|
-
return tryReadJson
|
|
1684
|
+
return tryReadJson((0, node_module.createRequire)(node_path.default.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
|
|
1879
1685
|
} catch {
|
|
1880
1686
|
return;
|
|
1881
1687
|
}
|
|
@@ -2118,43 +1924,6 @@ function resolveCliCwd(value) {
|
|
|
2118
1924
|
return node_path.default.isAbsolute(raw) ? node_path.default.normalize(raw) : node_path.default.resolve(node_process.default.cwd(), raw);
|
|
2119
1925
|
}
|
|
2120
1926
|
//#endregion
|
|
2121
|
-
//#region src/tailwindcss/index.ts
|
|
2122
|
-
function getTailwindcssPackageInfo(options) {
|
|
2123
|
-
return (0, local_pkg.getPackageInfoSync)("tailwindcss", options);
|
|
2124
|
-
}
|
|
2125
|
-
//#endregion
|
|
2126
|
-
//#region src/cli/helpers/patch-cwd.ts
|
|
2127
|
-
/**
|
|
2128
|
-
* Resolve default working directory for `weapp-tw patch`.
|
|
2129
|
-
* Prefer explicit env overrides to avoid cross-package INIT_CWD pollution.
|
|
2130
|
-
*/
|
|
2131
|
-
function normalizeCandidatePath(baseDir, candidate) {
|
|
2132
|
-
if (!candidate) return;
|
|
2133
|
-
return node_path.default.isAbsolute(candidate) ? node_path.default.normalize(candidate) : node_path.default.resolve(baseDir, candidate);
|
|
2134
|
-
}
|
|
2135
|
-
function detectTailwindWorkspace(paths) {
|
|
2136
|
-
for (const candidate of paths) try {
|
|
2137
|
-
if (getTailwindcssPackageInfo({ paths: [candidate] })?.rootPath) return candidate;
|
|
2138
|
-
} catch {}
|
|
2139
|
-
}
|
|
2140
|
-
function resolvePatchDefaultCwd(currentCwd = node_process.default.cwd()) {
|
|
2141
|
-
const baseDir = node_path.default.normalize(currentCwd);
|
|
2142
|
-
const explicitCwd = normalizeCandidatePath(baseDir, node_process.default.env.WEAPP_TW_PATCH_CWD);
|
|
2143
|
-
if (explicitCwd) return explicitCwd;
|
|
2144
|
-
const workspaceRoot = findWorkspaceRoot(baseDir);
|
|
2145
|
-
const initCwd = normalizeCandidatePath(baseDir, node_process.default.env.INIT_CWD);
|
|
2146
|
-
const localPrefix = normalizeCandidatePath(baseDir, node_process.default.env.npm_config_local_prefix);
|
|
2147
|
-
const candidates = [
|
|
2148
|
-
baseDir,
|
|
2149
|
-
workspaceRoot,
|
|
2150
|
-
initCwd,
|
|
2151
|
-
localPrefix
|
|
2152
|
-
].filter(Boolean);
|
|
2153
|
-
const detected = detectTailwindWorkspace([...new Set(candidates)]);
|
|
2154
|
-
if (detected) return detected;
|
|
2155
|
-
return initCwd ?? localPrefix ?? workspaceRoot ?? baseDir;
|
|
2156
|
-
}
|
|
2157
|
-
//#endregion
|
|
2158
1927
|
//#region src/cli/helpers.ts
|
|
2159
1928
|
async function ensureDir(dir) {
|
|
2160
1929
|
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
@@ -2176,212 +1945,11 @@ function commandAction(handler) {
|
|
|
2176
1945
|
};
|
|
2177
1946
|
}
|
|
2178
1947
|
//#endregion
|
|
2179
|
-
//#region src/cli/mount-options/patch-status.ts
|
|
2180
|
-
function formatStatusFilesHint(files) {
|
|
2181
|
-
if (!files?.length) return "";
|
|
2182
|
-
return ` (${files.join(", ")})`;
|
|
2183
|
-
}
|
|
2184
|
-
function logPatchStatusReport(report) {
|
|
2185
|
-
const applied = report.entries.filter((entry) => entry.status === "applied");
|
|
2186
|
-
const pending = report.entries.filter((entry) => entry.status === "not-applied");
|
|
2187
|
-
const skipped = report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported");
|
|
2188
|
-
const packageLabel = `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
|
|
2189
|
-
_weapp_tailwindcss_logger.logger.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
|
|
2190
|
-
if (applied.length) {
|
|
2191
|
-
_weapp_tailwindcss_logger.logger.success("Applied:");
|
|
2192
|
-
applied.forEach((entry) => {
|
|
2193
|
-
_weapp_tailwindcss_logger.logger.success(` - ${entry.name}${formatStatusFilesHint(entry.files)}`);
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
if (pending.length) {
|
|
2197
|
-
_weapp_tailwindcss_logger.logger.warn("Needs attention:");
|
|
2198
|
-
pending.forEach((entry) => {
|
|
2199
|
-
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
2200
|
-
_weapp_tailwindcss_logger.logger.warn(` - ${entry.name}${formatStatusFilesHint(entry.files)}${details}`);
|
|
2201
|
-
});
|
|
2202
|
-
} else _weapp_tailwindcss_logger.logger.success("All applicable patches are applied.");
|
|
2203
|
-
if (skipped.length) {
|
|
2204
|
-
_weapp_tailwindcss_logger.logger.info("Skipped:");
|
|
2205
|
-
skipped.forEach((entry) => {
|
|
2206
|
-
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
2207
|
-
_weapp_tailwindcss_logger.logger.info(` - ${entry.name}${details}`);
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
//#endregion
|
|
2212
|
-
//#region src/cli/patch-options.ts
|
|
2213
|
-
const DEFAULT_EXTEND_LENGTH_UNITS_FEATURE = {
|
|
2214
|
-
enabled: true,
|
|
2215
|
-
units: ["rpx"],
|
|
2216
|
-
overwrite: true
|
|
2217
|
-
};
|
|
2218
|
-
function withDefaultExtendLengthUnits(options) {
|
|
2219
|
-
const normalized = options ?? {};
|
|
2220
|
-
if (normalized.apply?.extendLengthUnits == null) return {
|
|
2221
|
-
...normalized,
|
|
2222
|
-
apply: {
|
|
2223
|
-
...normalized.apply ?? {},
|
|
2224
|
-
extendLengthUnits: DEFAULT_EXTEND_LENGTH_UNITS_FEATURE
|
|
2225
|
-
}
|
|
2226
|
-
};
|
|
2227
|
-
return normalized;
|
|
2228
|
-
}
|
|
2229
|
-
function buildExtendLengthUnitsOverride(options) {
|
|
2230
|
-
if (options?.apply?.extendLengthUnits == null) return { apply: {
|
|
2231
|
-
...options?.apply ?? {},
|
|
2232
|
-
extendLengthUnits: DEFAULT_EXTEND_LENGTH_UNITS_FEATURE
|
|
2233
|
-
} };
|
|
2234
|
-
}
|
|
2235
|
-
//#endregion
|
|
2236
|
-
//#region src/cli/workspace/workspace-io.ts
|
|
2237
|
-
function tryReadJson(file) {
|
|
2238
|
-
try {
|
|
2239
|
-
const content = (0, node_fs.readFileSync)(file, "utf8");
|
|
2240
|
-
return JSON.parse(content);
|
|
2241
|
-
} catch {
|
|
2242
|
-
return;
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
//#endregion
|
|
2246
|
-
//#region src/cli/workspace/workspace-globs.ts
|
|
2247
|
-
function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
|
|
2248
|
-
const pkg = tryReadJson(node_path.default.join(workspaceRoot, "package.json"));
|
|
2249
|
-
if (!pkg?.workspaces) return [];
|
|
2250
|
-
if (Array.isArray(pkg.workspaces)) return pkg.workspaces.filter(Boolean);
|
|
2251
|
-
if (Array.isArray(pkg.workspaces.packages)) return pkg.workspaces.packages.filter(Boolean);
|
|
2252
|
-
return [];
|
|
2253
|
-
}
|
|
2254
|
-
function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
|
|
2255
|
-
const workspaceFile = node_path.default.join(workspaceRoot, "pnpm-workspace.yaml");
|
|
2256
|
-
if (!(0, node_fs.existsSync)(workspaceFile)) return [];
|
|
2257
|
-
try {
|
|
2258
|
-
const parsed = (0, yaml.parse)((0, node_fs.readFileSync)(workspaceFile, "utf8"));
|
|
2259
|
-
return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
|
|
2260
|
-
} catch {
|
|
2261
|
-
return [];
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
//#endregion
|
|
2265
|
-
//#region src/cli/workspace/workspace-lock.ts
|
|
2266
|
-
function parseImportersFromLock(workspaceRoot) {
|
|
2267
|
-
const lockPath = node_path.default.join(workspaceRoot, "pnpm-lock.yaml");
|
|
2268
|
-
if (!(0, node_fs.existsSync)(lockPath)) return [];
|
|
2269
|
-
try {
|
|
2270
|
-
const importers = (0, yaml.parse)((0, node_fs.readFileSync)(lockPath, "utf8"))?.importers;
|
|
2271
|
-
if (!importers) return [];
|
|
2272
|
-
return Object.keys(importers).map((key) => {
|
|
2273
|
-
if (!key || key === ".") return workspaceRoot;
|
|
2274
|
-
return node_path.default.join(workspaceRoot, key);
|
|
2275
|
-
});
|
|
2276
|
-
} catch {
|
|
2277
|
-
return [];
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
//#endregion
|
|
2281
|
-
//#region src/cli/workspace/package-dirs.ts
|
|
2282
|
-
const BACKSLASH_RE$1 = /\\/g;
|
|
2283
|
-
const TRAILING_SLASH_RE = /\/+$/;
|
|
2284
|
-
async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
2285
|
-
const dirs = /* @__PURE__ */ new Set();
|
|
2286
|
-
for (const importerDir of parseImportersFromLock(workspaceRoot)) dirs.add(node_path.default.normalize(importerDir));
|
|
2287
|
-
if (!dirs.size) {
|
|
2288
|
-
let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
|
|
2289
|
-
if (!globs.length) globs = parseWorkspaceGlobsFromPackageJson(workspaceRoot);
|
|
2290
|
-
if (globs.length > 0) {
|
|
2291
|
-
const packageJsonFiles = await (0, fast_glob.default)(globs.map((pattern) => {
|
|
2292
|
-
const normalized = pattern.replace(BACKSLASH_RE$1, "/").replace(TRAILING_SLASH_RE, "");
|
|
2293
|
-
return normalized.endsWith("package.json") ? normalized : `${normalized}/package.json`;
|
|
2294
|
-
}), {
|
|
2295
|
-
cwd: workspaceRoot,
|
|
2296
|
-
absolute: true,
|
|
2297
|
-
onlyFiles: true,
|
|
2298
|
-
unique: true,
|
|
2299
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
2300
|
-
});
|
|
2301
|
-
for (const file of packageJsonFiles) dirs.add(node_path.default.normalize(node_path.default.dirname(file)));
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
if ((0, node_fs.existsSync)(node_path.default.join(workspaceRoot, "package.json"))) dirs.add(node_path.default.normalize(workspaceRoot));
|
|
2305
|
-
return [...dirs];
|
|
2306
|
-
}
|
|
2307
|
-
//#endregion
|
|
2308
|
-
//#region src/cli/workspace/patch-utils.ts
|
|
2309
|
-
function formatDisplayName(workspaceRoot, dir, name) {
|
|
2310
|
-
const relative = node_path.default.relative(workspaceRoot, dir) || ".";
|
|
2311
|
-
return name ? `${name} (${relative})` : relative;
|
|
2312
|
-
}
|
|
2313
|
-
function summarizeWorkspaceResults(results) {
|
|
2314
|
-
const patched = results.filter((result) => result.status === "patched").length;
|
|
2315
|
-
const skipped = results.filter((result) => result.status === "skipped").length;
|
|
2316
|
-
const failed = results.filter((result) => result.status === "failed").length;
|
|
2317
|
-
_weapp_tailwindcss_logger.logger.info("[workspace] 汇总:已补丁 %d,跳过 %d,失败 %d", patched, skipped, failed);
|
|
2318
|
-
}
|
|
2319
|
-
//#endregion
|
|
2320
|
-
//#region src/cli/workspace/patch-package.ts
|
|
2321
|
-
function createWorkspacePatcher(cwd) {
|
|
2322
|
-
return new tailwindcss_patch.TailwindcssPatcher((0, tailwindcss_patch.normalizeOptions)(withDefaultExtendLengthUnits({ projectRoot: cwd })));
|
|
2323
|
-
}
|
|
2324
|
-
async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
2325
|
-
const displayName = formatDisplayName(workspaceRoot, dir, pkgName);
|
|
2326
|
-
if (!getTailwindcssPackageInfo({ paths: [dir] })?.rootPath) {
|
|
2327
|
-
_weapp_tailwindcss_logger.logger.info("[workspace] 跳过 %s(tailwindcss 未安装)。", displayName);
|
|
2328
|
-
return {
|
|
2329
|
-
dir,
|
|
2330
|
-
name: pkgName,
|
|
2331
|
-
status: "skipped",
|
|
2332
|
-
message: "tailwindcss 未安装,已跳过。"
|
|
2333
|
-
};
|
|
2334
|
-
}
|
|
2335
|
-
try {
|
|
2336
|
-
const patcher = createWorkspacePatcher(dir);
|
|
2337
|
-
if (options.clearCache) await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
|
|
2338
|
-
const recorder = createPatchTargetRecorder(dir, patcher, {
|
|
2339
|
-
source: "cli",
|
|
2340
|
-
cwd: dir,
|
|
2341
|
-
recordTarget: options.recordTarget !== false,
|
|
2342
|
-
alwaysRecord: true
|
|
2343
|
-
});
|
|
2344
|
-
if (recorder?.message) _weapp_tailwindcss_logger.logger.info("[workspace] %s %s", displayName, recorder.message);
|
|
2345
|
-
logTailwindcssTarget("cli", patcher, dir);
|
|
2346
|
-
await patcher.patch();
|
|
2347
|
-
if (recorder?.onPatched) await recorder.onPatched();
|
|
2348
|
-
_weapp_tailwindcss_logger.logger.success("[workspace] 已补丁 %s", displayName);
|
|
2349
|
-
return {
|
|
2350
|
-
dir,
|
|
2351
|
-
name: pkgName,
|
|
2352
|
-
status: "patched",
|
|
2353
|
-
message: "已完成 patch。"
|
|
2354
|
-
};
|
|
2355
|
-
} catch (error) {
|
|
2356
|
-
const message = `${error instanceof Error ? error.message : String(error)},${`请在 ${dir} 运行 "weapp-tw patch --cwd ${dir}".`}`;
|
|
2357
|
-
_weapp_tailwindcss_logger.logger.error("[workspace] 补丁失败 %s:%s", displayName, message);
|
|
2358
|
-
return {
|
|
2359
|
-
dir,
|
|
2360
|
-
name: pkgName,
|
|
2361
|
-
status: "failed",
|
|
2362
|
-
message
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2365
|
-
}
|
|
2366
|
-
//#endregion
|
|
2367
|
-
//#region src/cli/workspace.ts
|
|
2368
|
-
async function patchWorkspace(options) {
|
|
2369
|
-
const cwd = options.cwd ?? node_process.default.cwd();
|
|
2370
|
-
const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
|
|
2371
|
-
const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
|
|
2372
|
-
if (packageDirs.length === 0) {
|
|
2373
|
-
_weapp_tailwindcss_logger.logger.warn("未在 %s 检测到 workspace 包,已跳过批量 patch。", workspaceRoot);
|
|
2374
|
-
return;
|
|
2375
|
-
}
|
|
2376
|
-
const results = [];
|
|
2377
|
-
for (const dir of packageDirs) {
|
|
2378
|
-
const pkgJson = tryReadJson(node_path.default.join(dir, "package.json"));
|
|
2379
|
-
results.push(await patchWorkspacePackage(workspaceRoot, dir, pkgJson?.name, options));
|
|
2380
|
-
}
|
|
2381
|
-
summarizeWorkspaceResults(results);
|
|
2382
|
-
}
|
|
2383
|
-
//#endregion
|
|
2384
1948
|
//#region src/cli/mount-options.ts
|
|
1949
|
+
const PATCH_COMMAND_OBSOLETE_NOTICE = "提示:weapp-tailwindcss@5 已由构建运行时接管 Tailwind CSS 处理,weapp-tw patch 已无需执行;请移除 package.json 中的 postinstall 钩子。";
|
|
1950
|
+
function logPatchCommandObsoleteNotice() {
|
|
1951
|
+
_weapp_tailwindcss_logger.logger.warn(PATCH_COMMAND_OBSOLETE_NOTICE);
|
|
1952
|
+
}
|
|
2385
1953
|
function handleCliError(error) {
|
|
2386
1954
|
if (error instanceof Error) {
|
|
2387
1955
|
_weapp_tailwindcss_logger.logger.error(error.message);
|
|
@@ -2399,92 +1967,17 @@ function withCommandErrorHandling(handler) {
|
|
|
2399
1967
|
}
|
|
2400
1968
|
});
|
|
2401
1969
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
1970
|
+
const forwardedCommands = [
|
|
1971
|
+
"extract",
|
|
1972
|
+
"tokens",
|
|
1973
|
+
"init",
|
|
1974
|
+
"migrate",
|
|
1975
|
+
"restore",
|
|
1976
|
+
"validate"
|
|
1977
|
+
];
|
|
2407
1978
|
const mountOptions = {
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
name: "patch",
|
|
2411
|
-
aliases: ["install"],
|
|
2412
|
-
appendDefaultOptions: false,
|
|
2413
|
-
optionDefs: [
|
|
2414
|
-
{
|
|
2415
|
-
flags: "--cwd <dir>",
|
|
2416
|
-
description: "Working directory",
|
|
2417
|
-
config: { default: resolvePatchDefaultCwd() }
|
|
2418
|
-
},
|
|
2419
|
-
{
|
|
2420
|
-
flags: "--record-target",
|
|
2421
|
-
description: "Write tailwindcss target metadata (node_modules/.cache/weapp-tailwindcss/tailwindcss-target.json). Pass \"--record-target false\" to skip.",
|
|
2422
|
-
config: { default: true }
|
|
2423
|
-
},
|
|
2424
|
-
{
|
|
2425
|
-
flags: "--clear-cache",
|
|
2426
|
-
description: "Clear tailwindcss-patch cache before patch (opt-in)"
|
|
2427
|
-
},
|
|
2428
|
-
{
|
|
2429
|
-
flags: "--workspace",
|
|
2430
|
-
description: "Scan pnpm workspace packages and patch each Tailwind CSS dependency"
|
|
2431
|
-
}
|
|
2432
|
-
]
|
|
2433
|
-
},
|
|
2434
|
-
status: {
|
|
2435
|
-
appendDefaultOptions: false,
|
|
2436
|
-
optionDefs: [{
|
|
2437
|
-
flags: "--cwd <dir>",
|
|
2438
|
-
description: "Working directory",
|
|
2439
|
-
config: { default: resolvePatchDefaultCwd() }
|
|
2440
|
-
}, {
|
|
2441
|
-
flags: "--json",
|
|
2442
|
-
description: "Print a JSON report of patch status"
|
|
2443
|
-
}]
|
|
2444
|
-
}
|
|
2445
|
-
},
|
|
2446
|
-
commandHandlers: {
|
|
2447
|
-
install: withCommandErrorHandling(async (ctx) => {
|
|
2448
|
-
const shouldClearCache = toBoolean(ctx.args.clearCache, false);
|
|
2449
|
-
const shouldRecordTarget = toBoolean(ctx.args.recordTarget, true);
|
|
2450
|
-
if (toBoolean(ctx.args.workspace, false)) {
|
|
2451
|
-
await patchWorkspace({
|
|
2452
|
-
cwd: ctx.cwd,
|
|
2453
|
-
clearCache: shouldClearCache,
|
|
2454
|
-
recordTarget: shouldRecordTarget
|
|
2455
|
-
});
|
|
2456
|
-
return;
|
|
2457
|
-
}
|
|
2458
|
-
const patcher = await createPatcherWithDefaultExtendLengthUnits(ctx);
|
|
2459
|
-
if (shouldClearCache) await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
|
|
2460
|
-
const recorder = createPatchTargetRecorder(ctx.cwd, patcher, {
|
|
2461
|
-
source: "cli",
|
|
2462
|
-
cwd: ctx.cwd,
|
|
2463
|
-
recordTarget: shouldRecordTarget,
|
|
2464
|
-
alwaysRecord: true
|
|
2465
|
-
});
|
|
2466
|
-
if (recorder?.message) _weapp_tailwindcss_logger.logger.info(recorder.message);
|
|
2467
|
-
logTailwindcssTarget("cli", patcher, ctx.cwd);
|
|
2468
|
-
await patcher.patch();
|
|
2469
|
-
if (recorder?.onPatched) {
|
|
2470
|
-
const recordPath = await recorder.onPatched();
|
|
2471
|
-
if (recordPath) _weapp_tailwindcss_logger.logger.info(`记录 weapp-tw patch 目标 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
|
|
2472
|
-
}
|
|
2473
|
-
_weapp_tailwindcss_logger.logger.success("Tailwind CSS 运行时补丁已完成。");
|
|
2474
|
-
}),
|
|
2475
|
-
extract: withCommandErrorHandling(async (_ctx, next) => next()),
|
|
2476
|
-
tokens: withCommandErrorHandling(async (_ctx, next) => next()),
|
|
2477
|
-
init: withCommandErrorHandling(async (_ctx, next) => next()),
|
|
2478
|
-
status: withCommandErrorHandling(async (ctx) => {
|
|
2479
|
-
const report = await (await createPatcherWithDefaultExtendLengthUnits(ctx)).getPatchStatus();
|
|
2480
|
-
if (ctx.args.json) {
|
|
2481
|
-
_weapp_tailwindcss_logger.logger.log(JSON.stringify(report, null, 2));
|
|
2482
|
-
return report;
|
|
2483
|
-
}
|
|
2484
|
-
logPatchStatusReport(report);
|
|
2485
|
-
return report;
|
|
2486
|
-
})
|
|
2487
|
-
}
|
|
1979
|
+
commands: [...forwardedCommands],
|
|
1980
|
+
commandHandlers: Object.fromEntries(forwardedCommands.map((command) => [command, withCommandErrorHandling(async (_ctx, next) => next())]))
|
|
2488
1981
|
};
|
|
2489
1982
|
//#endregion
|
|
2490
1983
|
//#region src/cli/vscode-entry.ts
|
|
@@ -2592,6 +2085,23 @@ const cli = (0, tailwindcss_patch.createTailwindcssPatchCli)({
|
|
|
2592
2085
|
name: "weapp-tailwindcss",
|
|
2593
2086
|
mountOptions
|
|
2594
2087
|
});
|
|
2088
|
+
cli.command("patch", "Deprecated no-op: v5 runtime handles Tailwind CSS automatically").alias("install").option("--cwd <dir>", "Ignored working directory").option("--clear-cache", "Ignored compatibility option").option("--record-target [enabled]", "Ignored compatibility option").option("--workspace", "Ignored compatibility option").action(commandAction(async (_options) => {
|
|
2089
|
+
logPatchCommandObsoleteNotice();
|
|
2090
|
+
_weapp_tailwindcss_logger.logger.success("已跳过:当前版本不需要手动执行 Tailwind CSS patch。");
|
|
2091
|
+
}));
|
|
2092
|
+
cli.command("status", "Deprecated no-op: patch status is no longer required").option("--cwd <dir>", "Ignored working directory").option("--json", "Print a JSON no-op report").action(commandAction(async (options) => {
|
|
2093
|
+
const payload = {
|
|
2094
|
+
required: false,
|
|
2095
|
+
status: "unnecessary",
|
|
2096
|
+
message: PATCH_COMMAND_OBSOLETE_NOTICE
|
|
2097
|
+
};
|
|
2098
|
+
if (toBoolean(options.json, false)) {
|
|
2099
|
+
_weapp_tailwindcss_logger.logger.log(JSON.stringify(payload, null, 2));
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
logPatchCommandObsoleteNotice();
|
|
2103
|
+
_weapp_tailwindcss_logger.logger.success("无需检查 Tailwind CSS patch 状态。");
|
|
2104
|
+
}));
|
|
2595
2105
|
cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliSense").option("--cwd <dir>", "Working directory").option("--css <file>", "Path to the CSS file that imports weapp-tailwindcss (required)").option("--output <file>", `Helper output path. Defaults to ${DEFAULT_VSCODE_ENTRY_OUTPUT}`).option("--source <pattern>", "Additional @source glob (can be repeated)").option("--force", "Overwrite the helper file when it already exists").action(commandAction(async (options) => {
|
|
2596
2106
|
const resolvedCwd = resolveCliCwd(options.cwd);
|
|
2597
2107
|
const baseDir = resolvedCwd ?? node_process.default.cwd();
|