weapp-tailwindcss 4.11.0-alpha.1 → 4.11.0-alpha.2
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/{chunk-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
- package/dist/{chunk-W2EMGF7H.js → chunk-2W24MRCQ.js} +10 -12
- package/dist/chunk-4AFQP74Z.js +24 -0
- package/dist/{chunk-SQG2MOFQ.js → chunk-4TTPYMVM.js} +12 -8
- package/dist/{chunk-4LPOQMFS.js → chunk-5KSBT6GU.js} +396 -219
- package/dist/{chunk-LD7LZ4IK.mjs → chunk-66E76FQE.mjs} +91 -50
- package/dist/{chunk-GWDHNCL2.js → chunk-6O7HJU2F.js} +123 -42
- package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
- package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
- package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
- package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
- package/dist/{chunk-IEZ5RBMG.mjs → chunk-EW2K6CO5.mjs} +365 -188
- package/dist/{chunk-FZNYV7VH.mjs → chunk-HADJCWHU.mjs} +212 -258
- package/dist/{chunk-CZLXTEHN.js → chunk-K7CZXT46.js} +132 -91
- package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
- package/dist/{chunk-G5NLM3AL.js → chunk-LYGLQCWI.js} +278 -324
- package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
- package/dist/{chunk-KKT2DKMW.mjs → chunk-RED7Y22U.mjs} +91 -10
- package/dist/{chunk-R6KEYO3F.mjs → chunk-SJ3SG6DU.mjs} +5 -1
- package/dist/{chunk-JBM3HGHP.mjs → chunk-UCUAXK7F.mjs} +4 -6
- package/dist/cli.js +1006 -147
- package/dist/cli.mjs +942 -107
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +9 -11
- package/dist/core.mjs +6 -8
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +4 -4
- package/dist/defaults.d.mts +2 -2
- package/dist/defaults.d.ts +2 -2
- package/dist/defaults.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/gulp.d.mts +2 -2
- package/dist/gulp.d.ts +2 -2
- package/dist/gulp.js +7 -8
- package/dist/gulp.mjs +6 -7
- package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
- package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -12
- package/dist/index.mjs +9 -10
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +5 -5
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +8 -9
- package/dist/vite.mjs +6 -7
- package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
- package/dist/weapp-tw-runtime-classset-loader.js +29 -2
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +9 -10
- package/dist/webpack.mjs +7 -8
- package/dist/webpack4.d.mts +2 -2
- package/dist/webpack4.d.ts +2 -2
- package/dist/webpack4.js +41 -41
- package/dist/webpack4.mjs +12 -12
- package/package.json +8 -8
- package/dist/chunk-NOKJXG3W.js +0 -29
- package/dist/chunk-QYZCRG7F.mjs +0 -29
package/dist/cli.mjs
CHANGED
|
@@ -1,40 +1,875 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WEAPP_TW_REQUIRED_NODE_VERSION,
|
|
3
|
-
clearTailwindcssPatcherCache,
|
|
4
|
-
createPatchTargetRecorder,
|
|
5
|
-
logTailwindcssTarget
|
|
6
|
-
} from "./chunk-FZNYV7VH.mjs";
|
|
7
|
-
import {
|
|
8
|
-
findWorkspaceRoot,
|
|
9
|
-
logger
|
|
10
|
-
} from "./chunk-IEZ5RBMG.mjs";
|
|
11
|
-
import "./chunk-35EI5JMK.mjs";
|
|
12
|
-
import "./chunk-OOHJLO5M.mjs";
|
|
13
|
-
import "./chunk-DOH7FULQ.mjs";
|
|
14
|
-
|
|
15
1
|
// src/cli.ts
|
|
16
|
-
import
|
|
2
|
+
import process17 from "process";
|
|
17
3
|
import semver from "semver";
|
|
18
4
|
import { createTailwindcssPatchCli } from "tailwindcss-patch";
|
|
19
5
|
|
|
20
6
|
// src/cli/context.ts
|
|
7
|
+
import path12 from "path";
|
|
8
|
+
import process11 from "process";
|
|
9
|
+
|
|
10
|
+
// src/context/index.ts
|
|
11
|
+
import { rm } from "fs/promises";
|
|
12
|
+
import { logger as logger10, pc } from "@weapp-tailwindcss/logger";
|
|
13
|
+
|
|
14
|
+
// src/cache/index.ts
|
|
15
|
+
import { LRUCache } from "lru-cache";
|
|
16
|
+
|
|
17
|
+
// src/cache/md5.ts
|
|
18
|
+
import { md5 } from "@weapp-tailwindcss/shared/node";
|
|
19
|
+
|
|
20
|
+
// src/defaults.ts
|
|
21
|
+
import { isAllowedClassName, MappingChars2String } from "@weapp-core/escape";
|
|
22
|
+
|
|
23
|
+
// src/utils/index.ts
|
|
24
|
+
import { defu, defuOverrideArray, groupBy, isMap, isRegexp, noop, regExpTest, removeExt } from "@weapp-tailwindcss/shared";
|
|
25
|
+
|
|
26
|
+
// src/utils/hbuilderx.ts
|
|
21
27
|
import path from "path";
|
|
22
28
|
import process from "process";
|
|
29
|
+
|
|
30
|
+
// src/utils/uni-platform.ts
|
|
31
|
+
import process2 from "process";
|
|
32
|
+
|
|
33
|
+
// src/debug/index.ts
|
|
34
|
+
import _createDebug from "debug";
|
|
35
|
+
var _debug = _createDebug("weapp-tw");
|
|
36
|
+
function createDebug(prefix) {
|
|
37
|
+
const debug3 = ((formatter, ...args) => {
|
|
38
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(debug3, "enabled", {
|
|
41
|
+
enumerable: false,
|
|
42
|
+
configurable: false,
|
|
43
|
+
get() {
|
|
44
|
+
return _debug.enabled;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return debug3;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/tailwindcss/runtime/cache.ts
|
|
51
|
+
import { statSync } from "fs";
|
|
52
|
+
|
|
53
|
+
// src/tailwindcss/runtime.ts
|
|
54
|
+
var debug = createDebug("[tailwindcss:runtime] ");
|
|
55
|
+
|
|
56
|
+
// src/tailwindcss/targets.ts
|
|
57
|
+
import process5 from "process";
|
|
58
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
59
|
+
|
|
60
|
+
// src/tailwindcss/targets/paths.ts
|
|
61
|
+
import { existsSync as existsSync2 } from "fs";
|
|
62
|
+
import path3 from "path";
|
|
63
|
+
|
|
64
|
+
// src/context/workspace.ts
|
|
65
|
+
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
66
|
+
import path2 from "path";
|
|
67
|
+
function findWorkspaceRoot(startDir) {
|
|
68
|
+
if (!startDir) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
let current = path2.resolve(startDir);
|
|
72
|
+
while (true) {
|
|
73
|
+
const workspaceFile = path2.join(current, "pnpm-workspace.yaml");
|
|
74
|
+
if (existsSync(workspaceFile)) {
|
|
75
|
+
return current;
|
|
76
|
+
}
|
|
77
|
+
const parent = path2.dirname(current);
|
|
78
|
+
if (parent === current) {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
current = parent;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function findNearestPackageRoot(startDir) {
|
|
85
|
+
if (!startDir) {
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
88
|
+
let current = path2.resolve(startDir);
|
|
89
|
+
while (true) {
|
|
90
|
+
const pkgPath = path2.join(current, "package.json");
|
|
91
|
+
if (existsSync(pkgPath)) {
|
|
92
|
+
return current;
|
|
93
|
+
}
|
|
94
|
+
const parent = path2.dirname(current);
|
|
95
|
+
if (parent === current) {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
current = parent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/tailwindcss/targets/paths.ts
|
|
103
|
+
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
104
|
+
var PATCH_INFO_CACHE_RELATIVE_PATH = path3.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
105
|
+
var PATCH_INFO_LEGACY_RELATIVE_PATH = path3.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
106
|
+
function formatRelativeToBase(targetPath, baseDir) {
|
|
107
|
+
if (!baseDir) {
|
|
108
|
+
return path3.normalize(targetPath);
|
|
109
|
+
}
|
|
110
|
+
const relative = path3.relative(baseDir, targetPath);
|
|
111
|
+
if (!relative || relative === ".") {
|
|
112
|
+
return ".";
|
|
113
|
+
}
|
|
114
|
+
if (relative.startsWith("..")) {
|
|
115
|
+
return path3.normalize(targetPath);
|
|
116
|
+
}
|
|
117
|
+
return path3.join(".", relative);
|
|
118
|
+
}
|
|
119
|
+
function resolveRecordLocation(baseDir) {
|
|
120
|
+
const normalizedBase = path3.normalize(baseDir);
|
|
121
|
+
const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
|
|
122
|
+
const packageJsonPath = path3.join(packageRoot, "package.json");
|
|
123
|
+
const hasPackageJson = existsSync2(packageJsonPath);
|
|
124
|
+
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
125
|
+
const recordKey = md5(path3.normalize(recordKeySource));
|
|
126
|
+
const recordDir = path3.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
127
|
+
const recordPath = path3.join(recordDir, PATCH_INFO_FILENAME);
|
|
128
|
+
return {
|
|
129
|
+
normalizedBase,
|
|
130
|
+
packageRoot,
|
|
131
|
+
recordDir,
|
|
132
|
+
recordKey,
|
|
133
|
+
recordPath,
|
|
134
|
+
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function getRecordFileCandidates(baseDir) {
|
|
138
|
+
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
139
|
+
const candidates = /* @__PURE__ */ new Set([
|
|
140
|
+
recordPath,
|
|
141
|
+
path3.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
142
|
+
path3.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
143
|
+
path3.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
144
|
+
]);
|
|
145
|
+
return [...candidates];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/tailwindcss/targets/record-io.ts
|
|
149
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
150
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
151
|
+
import path4 from "path";
|
|
152
|
+
import process3 from "process";
|
|
153
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
154
|
+
|
|
155
|
+
// package.json
|
|
156
|
+
var package_default = {
|
|
157
|
+
name: "weapp-tailwindcss",
|
|
158
|
+
version: "4.11.0-alpha.2",
|
|
159
|
+
description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
|
|
160
|
+
author: "ice breaker <1324318532@qq.com>",
|
|
161
|
+
license: "MIT",
|
|
162
|
+
homepage: "https://tw.icebreaker.top",
|
|
163
|
+
repository: {
|
|
164
|
+
type: "git",
|
|
165
|
+
url: "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
|
|
166
|
+
directory: "packages/weapp-tailwindcss"
|
|
167
|
+
},
|
|
168
|
+
bugs: {
|
|
169
|
+
url: "https://github.com/sonofmagic/weapp-tailwindcss/issues"
|
|
170
|
+
},
|
|
171
|
+
keywords: [
|
|
172
|
+
"tailwindcss",
|
|
173
|
+
"weapp",
|
|
174
|
+
"wechat",
|
|
175
|
+
"mini",
|
|
176
|
+
"miniprogram",
|
|
177
|
+
"mini app",
|
|
178
|
+
"weapp-tw",
|
|
179
|
+
"weapp-tailwindcss",
|
|
180
|
+
"taro",
|
|
181
|
+
"uni-app",
|
|
182
|
+
"remax",
|
|
183
|
+
"rax",
|
|
184
|
+
"mpx",
|
|
185
|
+
"jit",
|
|
186
|
+
"mp",
|
|
187
|
+
"android",
|
|
188
|
+
"ios",
|
|
189
|
+
"\u5C0F\u7A0B\u5E8F",
|
|
190
|
+
"vite",
|
|
191
|
+
"postcss",
|
|
192
|
+
"webpack",
|
|
193
|
+
"webpack-plugin",
|
|
194
|
+
"gulp",
|
|
195
|
+
"gulp-plugin"
|
|
196
|
+
],
|
|
197
|
+
exports: {
|
|
198
|
+
".": {
|
|
199
|
+
style: "./index.css",
|
|
200
|
+
types: "./dist/index.d.ts",
|
|
201
|
+
import: "./dist/index.mjs",
|
|
202
|
+
require: "./dist/index.js"
|
|
203
|
+
},
|
|
204
|
+
"./escape": {
|
|
205
|
+
types: "./dist/escape.d.ts",
|
|
206
|
+
import: "./dist/escape.mjs",
|
|
207
|
+
require: "./dist/escape.js"
|
|
208
|
+
},
|
|
209
|
+
"./vite": {
|
|
210
|
+
types: "./dist/vite.d.ts",
|
|
211
|
+
import: "./dist/vite.mjs",
|
|
212
|
+
require: "./dist/vite.js"
|
|
213
|
+
},
|
|
214
|
+
"./webpack": {
|
|
215
|
+
types: "./dist/webpack.d.ts",
|
|
216
|
+
import: "./dist/webpack.mjs",
|
|
217
|
+
require: "./dist/webpack.js"
|
|
218
|
+
},
|
|
219
|
+
"./webpack4": {
|
|
220
|
+
types: "./dist/webpack4.d.ts",
|
|
221
|
+
import: "./dist/webpack4.mjs",
|
|
222
|
+
require: "./dist/webpack4.js"
|
|
223
|
+
},
|
|
224
|
+
"./core": {
|
|
225
|
+
types: "./dist/core.d.ts",
|
|
226
|
+
import: "./dist/core.mjs",
|
|
227
|
+
require: "./dist/core.js"
|
|
228
|
+
},
|
|
229
|
+
"./gulp": {
|
|
230
|
+
types: "./dist/gulp.d.ts",
|
|
231
|
+
import: "./dist/gulp.mjs",
|
|
232
|
+
require: "./dist/gulp.js"
|
|
233
|
+
},
|
|
234
|
+
"./defaults": {
|
|
235
|
+
types: "./dist/defaults.d.ts",
|
|
236
|
+
import: "./dist/defaults.mjs",
|
|
237
|
+
require: "./dist/defaults.js"
|
|
238
|
+
},
|
|
239
|
+
"./presets": {
|
|
240
|
+
types: "./dist/presets.d.ts",
|
|
241
|
+
import: "./dist/presets.mjs",
|
|
242
|
+
require: "./dist/presets.js"
|
|
243
|
+
},
|
|
244
|
+
"./reset": {
|
|
245
|
+
types: "./dist/reset.d.ts",
|
|
246
|
+
import: "./dist/reset.mjs",
|
|
247
|
+
require: "./dist/reset.js"
|
|
248
|
+
},
|
|
249
|
+
"./css-macro/postcss": {
|
|
250
|
+
types: "./dist/css-macro/postcss.d.ts",
|
|
251
|
+
import: "./dist/css-macro/postcss.mjs",
|
|
252
|
+
require: "./dist/css-macro/postcss.js"
|
|
253
|
+
},
|
|
254
|
+
"./css-macro": {
|
|
255
|
+
types: "./dist/css-macro.d.ts",
|
|
256
|
+
import: "./dist/css-macro.mjs",
|
|
257
|
+
require: "./dist/css-macro.js"
|
|
258
|
+
},
|
|
259
|
+
"./types": {
|
|
260
|
+
types: "./dist/types.d.ts",
|
|
261
|
+
import: "./dist/types.mjs",
|
|
262
|
+
require: "./dist/types.js"
|
|
263
|
+
},
|
|
264
|
+
"./postcss-html-transform": {
|
|
265
|
+
types: "./dist/postcss-html-transform.d.ts",
|
|
266
|
+
import: "./dist/postcss-html-transform.mjs",
|
|
267
|
+
require: "./dist/postcss-html-transform.js"
|
|
268
|
+
},
|
|
269
|
+
"./package.json": "./package.json",
|
|
270
|
+
"./index.css": "./index.css",
|
|
271
|
+
"./index": "./index.css",
|
|
272
|
+
"./preflight.css": "./preflight.css",
|
|
273
|
+
"./preflight": "./preflight.css",
|
|
274
|
+
"./theme.css": "./theme.css",
|
|
275
|
+
"./theme": "./theme.css",
|
|
276
|
+
"./utilities.css": "./utilities.css",
|
|
277
|
+
"./utilities": "./utilities.css",
|
|
278
|
+
"./with-layer.css": "./with-layer.css",
|
|
279
|
+
"./with-layer": "./with-layer.css",
|
|
280
|
+
"./uni-app-x": "./uni-app-x.css",
|
|
281
|
+
"./uni-app-x.css": "./uni-app-x.css",
|
|
282
|
+
"./css": "./css/index.css",
|
|
283
|
+
"./*": "./*"
|
|
284
|
+
},
|
|
285
|
+
main: "./dist/index.js",
|
|
286
|
+
module: "./dist/index.mjs",
|
|
287
|
+
types: "./dist/index.d.ts",
|
|
288
|
+
style: "index.css",
|
|
289
|
+
typesVersions: {
|
|
290
|
+
"*": {
|
|
291
|
+
"*": [
|
|
292
|
+
"./dist/*",
|
|
293
|
+
"./dist/index.d.ts"
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
bin: {
|
|
298
|
+
"weapp-tailwindcss-webpack-plugin": "bin/weapp-tailwindcss.js",
|
|
299
|
+
"weapp-tailwindcss": "bin/weapp-tailwindcss.js",
|
|
300
|
+
"weapp-tw": "bin/weapp-tailwindcss.js"
|
|
301
|
+
},
|
|
302
|
+
files: [
|
|
303
|
+
"bin",
|
|
304
|
+
"css",
|
|
305
|
+
"dist",
|
|
306
|
+
"index.css",
|
|
307
|
+
"preflight.css",
|
|
308
|
+
"theme.css",
|
|
309
|
+
"uni-app-x.css",
|
|
310
|
+
"utilities.css",
|
|
311
|
+
"with-layer.css"
|
|
312
|
+
],
|
|
313
|
+
engines: {
|
|
314
|
+
node: "^18.17.0 || >=20.5.0"
|
|
315
|
+
},
|
|
316
|
+
scripts: {
|
|
317
|
+
dev: "tsup --watch --sourcemap",
|
|
318
|
+
build: "tsup && node scripts/ensure-escape-dts.mjs",
|
|
319
|
+
"build:tsc": "cross-env NODE_ENV=development tsc --build tsconfig.json",
|
|
320
|
+
"build:cli": "cd plugins/cli && pnpm run build",
|
|
321
|
+
"build:css": "tsx scripts/build-css.ts",
|
|
322
|
+
"build:weapp-theme": "tsx scripts/build-weapp-theme.ts",
|
|
323
|
+
test: "npm run postinstall && vitest run",
|
|
324
|
+
"test:dev": "vitest",
|
|
325
|
+
"test:ui": "vitest --ui",
|
|
326
|
+
bench: "vitest bench --config ./vitest.config.ts",
|
|
327
|
+
"bench:vite-perf": "tsx scripts/vite-perf-bench.ts",
|
|
328
|
+
"bench:vite-perf:summary": "tsx scripts/vite-perf-summary.ts",
|
|
329
|
+
"bench:js-handlers": "tsx scripts/js-bench.ts",
|
|
330
|
+
"bench:js-diff": "tsx scripts/js-bench-diff.ts",
|
|
331
|
+
tsd: "tsd",
|
|
332
|
+
clean: "tsx scripts/clean.ts",
|
|
333
|
+
"get-decl": "tsx scripts/get-decl.ts",
|
|
334
|
+
"ls:pack": "npm pack --dry-run",
|
|
335
|
+
"cli:patch": "node bin/weapp-tailwindcss.js patch",
|
|
336
|
+
colors: "tsx scripts/colors.ts",
|
|
337
|
+
release: "tsx scripts/release.ts",
|
|
338
|
+
lint: "eslint .",
|
|
339
|
+
"lint:fix": "eslint ./src --fix",
|
|
340
|
+
postinstall: "node bin/weapp-tailwindcss.js patch",
|
|
341
|
+
"bench:vite-dev-hmr": "tsx scripts/vite-dev-hmr-bench.ts",
|
|
342
|
+
"test:watch-hmr": "node --import tsx scripts/watch-hmr-regression/index.ts"
|
|
343
|
+
},
|
|
344
|
+
publishConfig: {
|
|
345
|
+
access: "public",
|
|
346
|
+
registry: "https://registry.npmjs.org"
|
|
347
|
+
},
|
|
348
|
+
dependencies: {
|
|
349
|
+
"@ast-core/escape": "~1.0.1",
|
|
350
|
+
"@babel/parser": "~7.29.2",
|
|
351
|
+
"@babel/traverse": "~7.29.0",
|
|
352
|
+
"@babel/types": "~7.29.0",
|
|
353
|
+
"@tailwindcss-mangle/config": "^6.1.3",
|
|
354
|
+
"@vue/compiler-dom": "catalog:vue3",
|
|
355
|
+
"@vue/compiler-sfc": "catalog:vue3",
|
|
356
|
+
"@weapp-core/escape": "~7.0.0",
|
|
357
|
+
"@weapp-core/regex": "~1.0.1",
|
|
358
|
+
"@weapp-tailwindcss/logger": "workspace:*",
|
|
359
|
+
"@weapp-tailwindcss/postcss": "workspace:*",
|
|
360
|
+
"@weapp-tailwindcss/shared": "workspace:*",
|
|
361
|
+
cac: "6.7.14",
|
|
362
|
+
debug: "~4.4.3",
|
|
363
|
+
"fast-glob": "^3.3.3",
|
|
364
|
+
htmlparser2: "10.1.0",
|
|
365
|
+
"loader-utils": "2.0.4",
|
|
366
|
+
"local-pkg": "^1.1.2",
|
|
367
|
+
"lru-cache": "10.4.3",
|
|
368
|
+
"magic-string": "0.30.21",
|
|
369
|
+
semver: "~7.7.4",
|
|
370
|
+
"tailwindcss-patch": "catalog:tailwindcssPatch",
|
|
371
|
+
"webpack-sources": "3.3.4",
|
|
372
|
+
yaml: "^2.8.3"
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// src/constants.ts
|
|
377
|
+
var WEAPP_TW_REQUIRED_NODE_VERSION = "18.17.0";
|
|
378
|
+
var WEAPP_TW_VERSION = package_default.version;
|
|
379
|
+
|
|
380
|
+
// src/tailwindcss/targets/record-io.ts
|
|
381
|
+
var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
382
|
+
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
383
|
+
const normalizedPath = path4.normalize(recordPath);
|
|
384
|
+
if (loggedInvalidPatchRecords.has(normalizedPath)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
loggedInvalidPatchRecords.add(normalizedPath);
|
|
388
|
+
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
389
|
+
const baseDisplay = formatRelativeToBase(path4.normalize(baseDir), process3.cwd());
|
|
390
|
+
const reasonMessage = reason ? `\uFF1A${reason}` : "";
|
|
391
|
+
logger.warn(
|
|
392
|
+
`\u68C0\u6D4B\u5230\u635F\u574F\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55 ${fileDisplay}${reasonMessage}\u3002\u8BF7\u5728 ${baseDisplay} \u91CD\u65B0\u6267\u884C "weapp-tw patch --record-target" \u6216\u5220\u9664\u8BE5\u6587\u4EF6\u540E\u518D\u8FD0\u884C\u3002`
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
function readPatchTargetRecord(baseDir) {
|
|
396
|
+
if (!baseDir) {
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
const normalizedBase = path4.normalize(baseDir);
|
|
400
|
+
for (const recordPath of getRecordFileCandidates(normalizedBase)) {
|
|
401
|
+
if (!existsSync3(recordPath)) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
try {
|
|
405
|
+
const content = readFileSync2(recordPath, "utf8");
|
|
406
|
+
const parsed = JSON.parse(content);
|
|
407
|
+
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
408
|
+
warnInvalidPatchTargetRecord(normalizedBase, recordPath, "\u7F3A\u5C11 tailwindPackagePath \u5B57\u6BB5");
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
baseDir: normalizedBase,
|
|
413
|
+
path: recordPath,
|
|
414
|
+
record: parsed
|
|
415
|
+
};
|
|
416
|
+
} catch (error) {
|
|
417
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
418
|
+
warnInvalidPatchTargetRecord(normalizedBase, recordPath, reason);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return void 0;
|
|
423
|
+
}
|
|
424
|
+
async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
425
|
+
if (!baseDir || !patcher?.packageInfo?.rootPath) {
|
|
426
|
+
return void 0;
|
|
427
|
+
}
|
|
428
|
+
const normalizedBase = path4.normalize(baseDir);
|
|
429
|
+
const location = resolveRecordLocation(normalizedBase);
|
|
430
|
+
const recordPath = options?.recordPath ? path4.normalize(options.recordPath) : location.recordPath;
|
|
431
|
+
const record = {
|
|
432
|
+
tailwindPackagePath: path4.normalize(patcher.packageInfo.rootPath),
|
|
433
|
+
packageVersion: patcher.packageInfo.version,
|
|
434
|
+
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
435
|
+
source: options?.source ?? "cli",
|
|
436
|
+
tailwindcssBasedir: normalizedBase,
|
|
437
|
+
cwd: options?.cwd ? path4.normalize(options.cwd) : normalizedBase,
|
|
438
|
+
patchVersion: WEAPP_TW_VERSION,
|
|
439
|
+
packageJsonPath: options?.packageJsonPath ?? location.packageJsonPath,
|
|
440
|
+
recordKey: options?.recordKey ?? location.recordKey
|
|
441
|
+
};
|
|
442
|
+
try {
|
|
443
|
+
await mkdir(path4.dirname(recordPath), { recursive: true });
|
|
444
|
+
await writeFile(recordPath, `${JSON.stringify(record, null, 2)}
|
|
445
|
+
`, "utf8");
|
|
446
|
+
return recordPath;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
const baseDisplay = formatRelativeToBase(normalizedBase, process3.cwd());
|
|
449
|
+
logger.warn(
|
|
450
|
+
'\u81EA\u52A8\u66F4\u65B0 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\u5931\u8D25\uFF0C\u8BF7\u5728 %s \u8FD0\u884C "weapp-tw patch --cwd %s"\u3002',
|
|
451
|
+
baseDisplay,
|
|
452
|
+
normalizedBase
|
|
453
|
+
);
|
|
454
|
+
logger.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
455
|
+
return void 0;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/tailwindcss/targets/recorder.ts
|
|
460
|
+
import path5 from "path";
|
|
461
|
+
import process4 from "process";
|
|
462
|
+
function findPatchTargetRecord(baseDir) {
|
|
463
|
+
const visited = /* @__PURE__ */ new Set();
|
|
464
|
+
const fallback = baseDir ?? process4.cwd();
|
|
465
|
+
let current = path5.resolve(fallback);
|
|
466
|
+
while (!visited.has(current)) {
|
|
467
|
+
const record = readPatchTargetRecord(current);
|
|
468
|
+
if (record) {
|
|
469
|
+
return record;
|
|
470
|
+
}
|
|
471
|
+
const parent = path5.dirname(current);
|
|
472
|
+
if (parent === current) {
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
visited.add(current);
|
|
476
|
+
current = parent;
|
|
477
|
+
}
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
481
|
+
if (!baseDir || !patcher?.packageInfo?.rootPath || options?.recordTarget === false) {
|
|
482
|
+
return void 0;
|
|
483
|
+
}
|
|
484
|
+
const normalizedBase = path5.normalize(baseDir);
|
|
485
|
+
const recorded = findPatchTargetRecord(normalizedBase);
|
|
486
|
+
const location = resolveRecordLocation(normalizedBase);
|
|
487
|
+
const expectedPath = path5.normalize(patcher.packageInfo.rootPath);
|
|
488
|
+
let reason;
|
|
489
|
+
if (!recorded) {
|
|
490
|
+
reason = "missing";
|
|
491
|
+
} else {
|
|
492
|
+
const normalizedRecorded = path5.normalize(recorded.record.tailwindPackagePath);
|
|
493
|
+
if (normalizedRecorded !== expectedPath) {
|
|
494
|
+
reason = "mismatch";
|
|
495
|
+
} else if (path5.normalize(recorded.path) !== path5.normalize(location.recordPath) || !recorded.record.recordKey || recorded.record.recordKey !== location.recordKey) {
|
|
496
|
+
reason = "migrate";
|
|
497
|
+
} else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) {
|
|
498
|
+
reason = "stale";
|
|
499
|
+
} else if (options?.cwd && recorded.record.cwd && path5.normalize(recorded.record.cwd) !== path5.normalize(options.cwd)) {
|
|
500
|
+
reason = "metadata";
|
|
501
|
+
} else if (!recorded.record.cwd && options?.cwd) {
|
|
502
|
+
reason = "metadata";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const shouldPersist = options?.alwaysRecord || !recorded || Boolean(reason);
|
|
506
|
+
if (!shouldPersist) {
|
|
507
|
+
return void 0;
|
|
508
|
+
}
|
|
509
|
+
let message;
|
|
510
|
+
switch (reason) {
|
|
511
|
+
case "mismatch":
|
|
512
|
+
message = "\u68C0\u6D4B\u5230 Tailwind CSS \u76EE\u6807\u8BB0\u5F55\u4E0E\u5F53\u524D\u89E3\u6790\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u6B63\u5728\u81EA\u52A8\u91CD\u65B0 patch \u5E76\u5237\u65B0\u7F13\u5B58\u3002";
|
|
513
|
+
break;
|
|
514
|
+
case "migrate":
|
|
515
|
+
case "stale":
|
|
516
|
+
message = "\u6B63\u5728\u5237\u65B0\u5F53\u524D\u5B50\u5305\u7684 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\uFF0C\u786E\u4FDD\u7F13\u5B58\u9694\u79BB\u3002";
|
|
517
|
+
break;
|
|
518
|
+
case "missing":
|
|
519
|
+
message = "\u672A\u627E\u5230\u5F53\u524D\u5B50\u5305\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55\uFF0C\u6B63\u5728\u751F\u6210\u3002";
|
|
520
|
+
break;
|
|
521
|
+
default:
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
|
|
525
|
+
cwd: options?.cwd ?? normalizedBase,
|
|
526
|
+
source: options?.source ?? "cli",
|
|
527
|
+
recordPath: location.recordPath,
|
|
528
|
+
recordKey: location.recordKey,
|
|
529
|
+
packageJsonPath: location.packageJsonPath
|
|
530
|
+
});
|
|
531
|
+
return {
|
|
532
|
+
recordPath: location.recordPath,
|
|
533
|
+
message,
|
|
534
|
+
reason,
|
|
535
|
+
onPatched
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/tailwindcss/targets.ts
|
|
540
|
+
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
541
|
+
const packageInfo = patcher?.packageInfo;
|
|
542
|
+
const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
|
|
543
|
+
if (!packageInfo?.rootPath) {
|
|
544
|
+
logger2.warn(
|
|
545
|
+
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
546
|
+
label,
|
|
547
|
+
baseDir ?? process5.cwd()
|
|
548
|
+
);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
552
|
+
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
553
|
+
logger2.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// src/tailwindcss/v4/config.ts
|
|
557
|
+
import { logger as logger3 } from "@weapp-tailwindcss/logger";
|
|
558
|
+
|
|
559
|
+
// src/tailwindcss/v4/patcher.ts
|
|
560
|
+
import { logger as logger5 } from "@weapp-tailwindcss/logger";
|
|
561
|
+
|
|
562
|
+
// src/tailwindcss/patcher.ts
|
|
563
|
+
import path7 from "path";
|
|
564
|
+
import process7 from "process";
|
|
565
|
+
import { logger as logger4 } from "@weapp-tailwindcss/logger";
|
|
566
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
567
|
+
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
568
|
+
|
|
569
|
+
// src/tailwindcss/patcher-resolve.ts
|
|
570
|
+
import { existsSync as existsSync4 } from "fs";
|
|
571
|
+
import { createRequire } from "module";
|
|
572
|
+
import path6 from "path";
|
|
573
|
+
import process6 from "process";
|
|
574
|
+
import { fileURLToPath } from "url";
|
|
575
|
+
|
|
576
|
+
// src/tailwindcss/v4/css-entries.ts
|
|
577
|
+
import path8 from "path";
|
|
578
|
+
|
|
579
|
+
// src/context/compiler-context-cache.ts
|
|
580
|
+
import { Buffer } from "buffer";
|
|
581
|
+
import path9 from "path";
|
|
582
|
+
import process8 from "process";
|
|
583
|
+
import { logger as logger6 } from "@weapp-tailwindcss/logger";
|
|
584
|
+
var globalCacheHolder = globalThis;
|
|
585
|
+
var compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
586
|
+
|
|
587
|
+
// src/context/handlers.ts
|
|
588
|
+
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
589
|
+
|
|
590
|
+
// src/babel/index.ts
|
|
591
|
+
import _babelTraverse from "@babel/traverse";
|
|
592
|
+
import { parse, parseExpression } from "@babel/parser";
|
|
593
|
+
function _interopDefaultCompat(e) {
|
|
594
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
595
|
+
}
|
|
596
|
+
var traverse = _interopDefaultCompat(_babelTraverse);
|
|
597
|
+
|
|
598
|
+
// src/utils/nameMatcher.ts
|
|
599
|
+
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
600
|
+
|
|
601
|
+
// src/js/babel/parse.ts
|
|
602
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
603
|
+
var parseCache = new LRUCache2(
|
|
604
|
+
{
|
|
605
|
+
max: 1024
|
|
606
|
+
}
|
|
607
|
+
);
|
|
608
|
+
|
|
609
|
+
// src/js/babel/process.ts
|
|
610
|
+
import MagicString from "magic-string";
|
|
611
|
+
|
|
612
|
+
// src/js/handlers.ts
|
|
613
|
+
import { jsStringEscape } from "@ast-core/escape";
|
|
614
|
+
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
615
|
+
|
|
616
|
+
// src/wxml/shared.ts
|
|
617
|
+
import { escape, MappingChars2String as MappingChars2String2 } from "@weapp-core/escape";
|
|
618
|
+
|
|
619
|
+
// src/js/handlers.ts
|
|
620
|
+
var debug2 = createDebug("[js:handlers] ");
|
|
621
|
+
|
|
622
|
+
// src/js/evalTransforms.ts
|
|
623
|
+
import { jsStringEscape as jsStringEscape2 } from "@ast-core/escape";
|
|
624
|
+
|
|
625
|
+
// src/wxml/utils/codegen/legacy-rewriter.ts
|
|
626
|
+
import MagicString2 from "magic-string";
|
|
627
|
+
|
|
628
|
+
// src/wxml/utils/codegen/legacy-visitor.ts
|
|
629
|
+
import * as t from "@babel/types";
|
|
630
|
+
|
|
631
|
+
// src/wxml/utils/codegen.ts
|
|
632
|
+
var WRAP_EXPRESSION_HANDLER_OPTIONS = Object.freeze({
|
|
633
|
+
wrapExpression: true
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
// src/wxml/utils/custom-template.ts
|
|
637
|
+
import { Parser } from "htmlparser2";
|
|
638
|
+
import MagicString4 from "magic-string";
|
|
639
|
+
|
|
640
|
+
// src/wxml/utils/template-fragments.ts
|
|
641
|
+
import MagicString3 from "magic-string";
|
|
642
|
+
|
|
643
|
+
// src/wxml/whitespace.ts
|
|
644
|
+
var WHITESPACE_CODES = /* @__PURE__ */ new Set([
|
|
645
|
+
9,
|
|
646
|
+
// 制表符 \t
|
|
647
|
+
10,
|
|
648
|
+
// 换行符 \n
|
|
649
|
+
11,
|
|
650
|
+
// 垂直制表符 \v
|
|
651
|
+
12,
|
|
652
|
+
// 换页符 \f
|
|
653
|
+
13,
|
|
654
|
+
// 回车符 \r
|
|
655
|
+
32,
|
|
656
|
+
// 空格
|
|
657
|
+
160,
|
|
658
|
+
// 不间断空格 \u00A0
|
|
659
|
+
65279
|
|
660
|
+
// 零宽无断行空格 \uFEFF
|
|
661
|
+
]);
|
|
662
|
+
function isWhitespace(char) {
|
|
663
|
+
if (char.length === 0) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
return WHITESPACE_CODES.has(char.charCodeAt(0));
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// src/wxml/Tokenizer.ts
|
|
670
|
+
var Tokenizer = class {
|
|
671
|
+
constructor() {
|
|
672
|
+
this.reset();
|
|
673
|
+
}
|
|
674
|
+
processChar(char, index) {
|
|
675
|
+
switch (this.state) {
|
|
676
|
+
case 0 /* START */:
|
|
677
|
+
if (isWhitespace(char)) {
|
|
678
|
+
} else if (char === "{") {
|
|
679
|
+
this.state = 2 /* OPEN_BRACE */;
|
|
680
|
+
this.bufferStartIndex = index;
|
|
681
|
+
this.buffer += char;
|
|
682
|
+
this.expressionBuffer = char;
|
|
683
|
+
this.expressionStartIndex = index;
|
|
684
|
+
} else {
|
|
685
|
+
this.state = 1 /* TEXT */;
|
|
686
|
+
this.bufferStartIndex = index;
|
|
687
|
+
this.buffer += char;
|
|
688
|
+
}
|
|
689
|
+
break;
|
|
690
|
+
case 1 /* TEXT */:
|
|
691
|
+
if (isWhitespace(char)) {
|
|
692
|
+
this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
|
|
693
|
+
this.buffer = "";
|
|
694
|
+
this.expressions = [];
|
|
695
|
+
this.state = 0 /* START */;
|
|
696
|
+
} else if (char === "{") {
|
|
697
|
+
this.buffer += char;
|
|
698
|
+
this.expressionBuffer = char;
|
|
699
|
+
this.expressionStartIndex = index;
|
|
700
|
+
this.state = 2 /* OPEN_BRACE */;
|
|
701
|
+
} else {
|
|
702
|
+
this.buffer += char;
|
|
703
|
+
}
|
|
704
|
+
break;
|
|
705
|
+
case 2 /* OPEN_BRACE */:
|
|
706
|
+
if (char === "}") {
|
|
707
|
+
this.buffer += char;
|
|
708
|
+
this.expressionBuffer += char;
|
|
709
|
+
this.state = 3 /* POTENTIAL_CLOSE */;
|
|
710
|
+
} else {
|
|
711
|
+
this.buffer += char;
|
|
712
|
+
this.expressionBuffer += char;
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
case 3 /* POTENTIAL_CLOSE */:
|
|
716
|
+
if (char === "}") {
|
|
717
|
+
this.buffer += char;
|
|
718
|
+
this.expressionBuffer += char;
|
|
719
|
+
this.expressions.push({
|
|
720
|
+
start: this.expressionStartIndex,
|
|
721
|
+
end: index + 1,
|
|
722
|
+
value: this.expressionBuffer
|
|
723
|
+
});
|
|
724
|
+
this.expressionBuffer = "";
|
|
725
|
+
this.state = 4 /* BRACES_COMPLETE */;
|
|
726
|
+
} else {
|
|
727
|
+
this.buffer += char;
|
|
728
|
+
this.expressionBuffer += char;
|
|
729
|
+
this.state = 2 /* OPEN_BRACE */;
|
|
730
|
+
}
|
|
731
|
+
break;
|
|
732
|
+
case 4 /* BRACES_COMPLETE */:
|
|
733
|
+
if (isWhitespace(char)) {
|
|
734
|
+
this.tokens.push({
|
|
735
|
+
start: this.bufferStartIndex,
|
|
736
|
+
end: index,
|
|
737
|
+
value: this.buffer,
|
|
738
|
+
expressions: this.expressions
|
|
739
|
+
});
|
|
740
|
+
this.buffer = "";
|
|
741
|
+
this.expressions = [];
|
|
742
|
+
this.state = 0 /* START */;
|
|
743
|
+
} else if (char === "{") {
|
|
744
|
+
this.expressionStartIndex = index;
|
|
745
|
+
this.expressionBuffer = char;
|
|
746
|
+
this.buffer += char;
|
|
747
|
+
this.state = 2 /* OPEN_BRACE */;
|
|
748
|
+
} else {
|
|
749
|
+
this.buffer += char;
|
|
750
|
+
this.state = 1 /* TEXT */;
|
|
751
|
+
}
|
|
752
|
+
break;
|
|
753
|
+
default:
|
|
754
|
+
throw new Error("Unexpected state");
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
run(input) {
|
|
758
|
+
this.reset();
|
|
759
|
+
for (let i = 0; i < input.length; i++) {
|
|
760
|
+
const char = input[i];
|
|
761
|
+
this.processChar(char, i);
|
|
762
|
+
}
|
|
763
|
+
if (this.buffer.length > 0) {
|
|
764
|
+
this.tokens.push({
|
|
765
|
+
start: this.bufferStartIndex,
|
|
766
|
+
end: input.length,
|
|
767
|
+
value: this.buffer,
|
|
768
|
+
expressions: this.expressions
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
const tokens = this.tokens;
|
|
772
|
+
this.reset();
|
|
773
|
+
return tokens;
|
|
774
|
+
}
|
|
775
|
+
reset() {
|
|
776
|
+
this.state = 0 /* START */;
|
|
777
|
+
this.buffer = "";
|
|
778
|
+
this.tokens = [];
|
|
779
|
+
this.bufferStartIndex = 0;
|
|
780
|
+
this.expressionBuffer = "";
|
|
781
|
+
this.expressionStartIndex = 0;
|
|
782
|
+
this.expressions = [];
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
// src/wxml/utils/template-fragments.ts
|
|
787
|
+
var sharedTokenizer = new Tokenizer();
|
|
788
|
+
|
|
789
|
+
// src/context/logger.ts
|
|
790
|
+
import { logger as logger7 } from "@weapp-tailwindcss/logger";
|
|
791
|
+
|
|
792
|
+
// src/context/tailwindcss.ts
|
|
793
|
+
import { logger as logger9 } from "@weapp-tailwindcss/logger";
|
|
794
|
+
|
|
795
|
+
// src/context/tailwindcss/basedir.ts
|
|
796
|
+
import { createRequire as createRequire2 } from "module";
|
|
797
|
+
import path10 from "path";
|
|
798
|
+
import process9 from "process";
|
|
799
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
800
|
+
import { logger as logger8 } from "@weapp-tailwindcss/logger";
|
|
801
|
+
|
|
802
|
+
// src/context/tailwindcss/rax.ts
|
|
803
|
+
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "fs";
|
|
804
|
+
import path11 from "path";
|
|
805
|
+
import process10 from "process";
|
|
806
|
+
|
|
807
|
+
// src/context/index.ts
|
|
808
|
+
async function clearTailwindcssPatcherCache(patcher, options) {
|
|
809
|
+
if (!patcher) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
const cacheOptions = patcher.options?.cache;
|
|
813
|
+
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (typeof patcher.clearCache === "function") {
|
|
817
|
+
try {
|
|
818
|
+
await patcher.clearCache({ scope: "all" });
|
|
819
|
+
} catch (error) {
|
|
820
|
+
logger10.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (!options?.removeDirectory) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const cachePaths = /* @__PURE__ */ new Map();
|
|
827
|
+
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
828
|
+
if (normalizedCacheOptions?.path) {
|
|
829
|
+
cachePaths.set(normalizedCacheOptions.path, false);
|
|
830
|
+
}
|
|
831
|
+
const privateCachePath = patcher?.cacheStore?.options?.path;
|
|
832
|
+
if (privateCachePath) {
|
|
833
|
+
cachePaths.set(privateCachePath, false);
|
|
834
|
+
}
|
|
835
|
+
if (options?.removeDirectory && normalizedCacheOptions?.dir) {
|
|
836
|
+
cachePaths.set(normalizedCacheOptions.dir, true);
|
|
837
|
+
}
|
|
838
|
+
if (!cachePaths.size) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
for (const [cachePath, recursive] of cachePaths.entries()) {
|
|
842
|
+
try {
|
|
843
|
+
await rm(cachePath, { force: true, recursive });
|
|
844
|
+
} catch (error) {
|
|
845
|
+
const err = error;
|
|
846
|
+
if (err?.code === "ENOENT") {
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
logger10.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// src/cli/context.ts
|
|
23
855
|
function formatOutputPath(target, baseDir) {
|
|
24
|
-
const root = baseDir ??
|
|
25
|
-
const relative =
|
|
856
|
+
const root = baseDir ?? process11.cwd();
|
|
857
|
+
const relative = path12.relative(root, target);
|
|
26
858
|
if (!relative) {
|
|
27
859
|
return ".";
|
|
28
860
|
}
|
|
29
861
|
if (relative.startsWith("..")) {
|
|
30
|
-
return
|
|
862
|
+
return path12.normalize(target);
|
|
31
863
|
}
|
|
32
|
-
return relative.startsWith(".") ? relative : `.${
|
|
864
|
+
return relative.startsWith(".") ? relative : `.${path12.sep}${relative}`;
|
|
33
865
|
}
|
|
34
866
|
|
|
35
867
|
// src/cli/helpers.ts
|
|
36
|
-
import { mkdir } from "fs/promises";
|
|
37
|
-
import
|
|
868
|
+
import { mkdir as mkdir2 } from "fs/promises";
|
|
869
|
+
import process14 from "process";
|
|
870
|
+
|
|
871
|
+
// src/logger/index.ts
|
|
872
|
+
import { logger as logger11 } from "@weapp-tailwindcss/logger";
|
|
38
873
|
|
|
39
874
|
// src/cli/helpers/options/parse.ts
|
|
40
875
|
function readStringOption(flag, value) {
|
|
@@ -89,19 +924,19 @@ function toBoolean(value, fallback) {
|
|
|
89
924
|
}
|
|
90
925
|
|
|
91
926
|
// src/cli/helpers/options/resolve.ts
|
|
92
|
-
import
|
|
93
|
-
import
|
|
927
|
+
import path13 from "path";
|
|
928
|
+
import process12 from "process";
|
|
94
929
|
function resolveCliCwd(value) {
|
|
95
930
|
const raw = readStringOption("cwd", value);
|
|
96
931
|
if (!raw) {
|
|
97
932
|
return void 0;
|
|
98
933
|
}
|
|
99
|
-
return
|
|
934
|
+
return path13.isAbsolute(raw) ? path13.normalize(raw) : path13.resolve(process12.cwd(), raw);
|
|
100
935
|
}
|
|
101
936
|
|
|
102
937
|
// src/cli/helpers/patch-cwd.ts
|
|
103
|
-
import
|
|
104
|
-
import
|
|
938
|
+
import path14 from "path";
|
|
939
|
+
import process13 from "process";
|
|
105
940
|
|
|
106
941
|
// src/tailwindcss/index.ts
|
|
107
942
|
import { getPackageInfoSync } from "local-pkg";
|
|
@@ -114,7 +949,7 @@ function normalizeCandidatePath(baseDir, candidate) {
|
|
|
114
949
|
if (!candidate) {
|
|
115
950
|
return void 0;
|
|
116
951
|
}
|
|
117
|
-
return
|
|
952
|
+
return path14.isAbsolute(candidate) ? path14.normalize(candidate) : path14.resolve(baseDir, candidate);
|
|
118
953
|
}
|
|
119
954
|
function detectTailwindWorkspace(paths) {
|
|
120
955
|
for (const candidate of paths) {
|
|
@@ -128,15 +963,15 @@ function detectTailwindWorkspace(paths) {
|
|
|
128
963
|
}
|
|
129
964
|
return void 0;
|
|
130
965
|
}
|
|
131
|
-
function resolvePatchDefaultCwd(currentCwd =
|
|
132
|
-
const baseDir =
|
|
133
|
-
const explicitCwd = normalizeCandidatePath(baseDir,
|
|
966
|
+
function resolvePatchDefaultCwd(currentCwd = process13.cwd()) {
|
|
967
|
+
const baseDir = path14.normalize(currentCwd);
|
|
968
|
+
const explicitCwd = normalizeCandidatePath(baseDir, process13.env.WEAPP_TW_PATCH_CWD);
|
|
134
969
|
if (explicitCwd) {
|
|
135
970
|
return explicitCwd;
|
|
136
971
|
}
|
|
137
972
|
const workspaceRoot = findWorkspaceRoot(baseDir);
|
|
138
|
-
const initCwd = normalizeCandidatePath(baseDir,
|
|
139
|
-
const localPrefix = normalizeCandidatePath(baseDir,
|
|
973
|
+
const initCwd = normalizeCandidatePath(baseDir, process13.env.INIT_CWD);
|
|
974
|
+
const localPrefix = normalizeCandidatePath(baseDir, process13.env.npm_config_local_prefix);
|
|
140
975
|
const candidates = [
|
|
141
976
|
baseDir,
|
|
142
977
|
workspaceRoot,
|
|
@@ -152,16 +987,16 @@ function resolvePatchDefaultCwd(currentCwd = process3.cwd()) {
|
|
|
152
987
|
|
|
153
988
|
// src/cli/helpers.ts
|
|
154
989
|
async function ensureDir(dir) {
|
|
155
|
-
await
|
|
990
|
+
await mkdir2(dir, { recursive: true });
|
|
156
991
|
}
|
|
157
992
|
function handleCliError(error) {
|
|
158
993
|
if (error instanceof Error) {
|
|
159
|
-
|
|
160
|
-
if (error.stack &&
|
|
161
|
-
|
|
994
|
+
logger11.error(error.message);
|
|
995
|
+
if (error.stack && process14.env.WEAPP_TW_DEBUG === "1") {
|
|
996
|
+
logger11.error(error.stack);
|
|
162
997
|
}
|
|
163
998
|
} else {
|
|
164
|
-
|
|
999
|
+
logger11.error(String(error));
|
|
165
1000
|
}
|
|
166
1001
|
}
|
|
167
1002
|
function commandAction(handler) {
|
|
@@ -170,13 +1005,13 @@ function commandAction(handler) {
|
|
|
170
1005
|
await handler(...args);
|
|
171
1006
|
} catch (error) {
|
|
172
1007
|
handleCliError(error);
|
|
173
|
-
|
|
1008
|
+
process14.exitCode = 1;
|
|
174
1009
|
}
|
|
175
1010
|
};
|
|
176
1011
|
}
|
|
177
1012
|
|
|
178
1013
|
// src/cli/mount-options.ts
|
|
179
|
-
import
|
|
1014
|
+
import process16 from "process";
|
|
180
1015
|
|
|
181
1016
|
// src/cli/mount-options/patch-status.ts
|
|
182
1017
|
function formatStatusFilesHint(files) {
|
|
@@ -192,27 +1027,27 @@ function logPatchStatusReport(report) {
|
|
|
192
1027
|
(entry) => entry.status === "skipped" || entry.status === "unsupported"
|
|
193
1028
|
);
|
|
194
1029
|
const packageLabel = `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
|
|
195
|
-
|
|
1030
|
+
logger11.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
|
|
196
1031
|
if (applied.length) {
|
|
197
|
-
|
|
1032
|
+
logger11.success("Applied:");
|
|
198
1033
|
applied.forEach((entry) => {
|
|
199
|
-
|
|
1034
|
+
logger11.success(` - ${entry.name}${formatStatusFilesHint(entry.files)}`);
|
|
200
1035
|
});
|
|
201
1036
|
}
|
|
202
1037
|
if (pending.length) {
|
|
203
|
-
|
|
1038
|
+
logger11.warn("Needs attention:");
|
|
204
1039
|
pending.forEach((entry) => {
|
|
205
1040
|
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
206
|
-
|
|
1041
|
+
logger11.warn(` - ${entry.name}${formatStatusFilesHint(entry.files)}${details}`);
|
|
207
1042
|
});
|
|
208
1043
|
} else {
|
|
209
|
-
|
|
1044
|
+
logger11.success("All applicable patches are applied.");
|
|
210
1045
|
}
|
|
211
1046
|
if (skipped.length) {
|
|
212
|
-
|
|
1047
|
+
logger11.info("Skipped:");
|
|
213
1048
|
skipped.forEach((entry) => {
|
|
214
1049
|
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
215
|
-
|
|
1050
|
+
logger11.info(` - ${entry.name}${details}`);
|
|
216
1051
|
});
|
|
217
1052
|
}
|
|
218
1053
|
}
|
|
@@ -251,24 +1086,24 @@ function buildExtendLengthUnitsOverride(options) {
|
|
|
251
1086
|
}
|
|
252
1087
|
|
|
253
1088
|
// src/cli/workspace.ts
|
|
254
|
-
import
|
|
255
|
-
import
|
|
1089
|
+
import path19 from "path";
|
|
1090
|
+
import process15 from "process";
|
|
256
1091
|
|
|
257
1092
|
// src/cli/workspace/package-dirs.ts
|
|
258
|
-
import { existsSync as
|
|
259
|
-
import
|
|
1093
|
+
import { existsSync as existsSync8 } from "fs";
|
|
1094
|
+
import path17 from "path";
|
|
260
1095
|
import fg from "fast-glob";
|
|
261
1096
|
|
|
262
1097
|
// src/cli/workspace/workspace-globs.ts
|
|
263
|
-
import { existsSync, readFileSync as
|
|
264
|
-
import
|
|
1098
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
1099
|
+
import path15 from "path";
|
|
265
1100
|
import { parse as parseYaml } from "yaml";
|
|
266
1101
|
|
|
267
1102
|
// src/cli/workspace/workspace-io.ts
|
|
268
|
-
import { readFileSync } from "fs";
|
|
1103
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
269
1104
|
function tryReadJson(file) {
|
|
270
1105
|
try {
|
|
271
|
-
const content =
|
|
1106
|
+
const content = readFileSync4(file, "utf8");
|
|
272
1107
|
return JSON.parse(content);
|
|
273
1108
|
} catch {
|
|
274
1109
|
return void 0;
|
|
@@ -277,7 +1112,7 @@ function tryReadJson(file) {
|
|
|
277
1112
|
|
|
278
1113
|
// src/cli/workspace/workspace-globs.ts
|
|
279
1114
|
function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
|
|
280
|
-
const pkgJsonPath =
|
|
1115
|
+
const pkgJsonPath = path15.join(workspaceRoot, "package.json");
|
|
281
1116
|
const pkg = tryReadJson(pkgJsonPath);
|
|
282
1117
|
if (!pkg?.workspaces) {
|
|
283
1118
|
return [];
|
|
@@ -291,12 +1126,12 @@ function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
|
|
|
291
1126
|
return [];
|
|
292
1127
|
}
|
|
293
1128
|
function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
|
|
294
|
-
const workspaceFile =
|
|
295
|
-
if (!
|
|
1129
|
+
const workspaceFile = path15.join(workspaceRoot, "pnpm-workspace.yaml");
|
|
1130
|
+
if (!existsSync6(workspaceFile)) {
|
|
296
1131
|
return [];
|
|
297
1132
|
}
|
|
298
1133
|
try {
|
|
299
|
-
const parsed = parseYaml(
|
|
1134
|
+
const parsed = parseYaml(readFileSync5(workspaceFile, "utf8"));
|
|
300
1135
|
return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
|
|
301
1136
|
} catch {
|
|
302
1137
|
return [];
|
|
@@ -304,16 +1139,16 @@ function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
|
|
|
304
1139
|
}
|
|
305
1140
|
|
|
306
1141
|
// src/cli/workspace/workspace-lock.ts
|
|
307
|
-
import { existsSync as
|
|
308
|
-
import
|
|
1142
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
|
|
1143
|
+
import path16 from "path";
|
|
309
1144
|
import { parse as parseYaml2 } from "yaml";
|
|
310
1145
|
function parseImportersFromLock(workspaceRoot) {
|
|
311
|
-
const lockPath =
|
|
312
|
-
if (!
|
|
1146
|
+
const lockPath = path16.join(workspaceRoot, "pnpm-lock.yaml");
|
|
1147
|
+
if (!existsSync7(lockPath)) {
|
|
313
1148
|
return [];
|
|
314
1149
|
}
|
|
315
1150
|
try {
|
|
316
|
-
const parsed = parseYaml2(
|
|
1151
|
+
const parsed = parseYaml2(readFileSync6(lockPath, "utf8"));
|
|
317
1152
|
const importers = parsed?.importers;
|
|
318
1153
|
if (!importers) {
|
|
319
1154
|
return [];
|
|
@@ -322,7 +1157,7 @@ function parseImportersFromLock(workspaceRoot) {
|
|
|
322
1157
|
if (!key || key === ".") {
|
|
323
1158
|
return workspaceRoot;
|
|
324
1159
|
}
|
|
325
|
-
return
|
|
1160
|
+
return path16.join(workspaceRoot, key);
|
|
326
1161
|
});
|
|
327
1162
|
} catch {
|
|
328
1163
|
return [];
|
|
@@ -335,7 +1170,7 @@ var TRAILING_SLASH_RE = /\/+$/;
|
|
|
335
1170
|
async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
336
1171
|
const dirs = /* @__PURE__ */ new Set();
|
|
337
1172
|
for (const importerDir of parseImportersFromLock(workspaceRoot)) {
|
|
338
|
-
dirs.add(
|
|
1173
|
+
dirs.add(path17.normalize(importerDir));
|
|
339
1174
|
}
|
|
340
1175
|
if (!dirs.size) {
|
|
341
1176
|
let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
|
|
@@ -355,31 +1190,31 @@ async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
|
355
1190
|
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
356
1191
|
});
|
|
357
1192
|
for (const file of packageJsonFiles) {
|
|
358
|
-
dirs.add(
|
|
1193
|
+
dirs.add(path17.normalize(path17.dirname(file)));
|
|
359
1194
|
}
|
|
360
1195
|
}
|
|
361
1196
|
}
|
|
362
|
-
const rootPkg =
|
|
363
|
-
if (
|
|
364
|
-
dirs.add(
|
|
1197
|
+
const rootPkg = path17.join(workspaceRoot, "package.json");
|
|
1198
|
+
if (existsSync8(rootPkg)) {
|
|
1199
|
+
dirs.add(path17.normalize(workspaceRoot));
|
|
365
1200
|
}
|
|
366
1201
|
return [...dirs];
|
|
367
1202
|
}
|
|
368
1203
|
|
|
369
1204
|
// src/cli/workspace/patch-package.ts
|
|
370
|
-
import { normalizeOptions, TailwindcssPatcher } from "tailwindcss-patch";
|
|
1205
|
+
import { normalizeOptions, TailwindcssPatcher as TailwindcssPatcher2 } from "tailwindcss-patch";
|
|
371
1206
|
|
|
372
1207
|
// src/cli/workspace/patch-utils.ts
|
|
373
|
-
import
|
|
1208
|
+
import path18 from "path";
|
|
374
1209
|
function formatDisplayName(workspaceRoot, dir, name) {
|
|
375
|
-
const relative =
|
|
1210
|
+
const relative = path18.relative(workspaceRoot, dir) || ".";
|
|
376
1211
|
return name ? `${name} (${relative})` : relative;
|
|
377
1212
|
}
|
|
378
1213
|
function summarizeWorkspaceResults(results) {
|
|
379
1214
|
const patched = results.filter((result) => result.status === "patched").length;
|
|
380
1215
|
const skipped = results.filter((result) => result.status === "skipped").length;
|
|
381
1216
|
const failed = results.filter((result) => result.status === "failed").length;
|
|
382
|
-
|
|
1217
|
+
logger11.info("[workspace] \u6C47\u603B\uFF1A\u5DF2\u8865\u4E01 %d\uFF0C\u8DF3\u8FC7 %d\uFF0C\u5931\u8D25 %d", patched, skipped, failed);
|
|
383
1218
|
}
|
|
384
1219
|
|
|
385
1220
|
// src/cli/workspace/patch-package.ts
|
|
@@ -389,13 +1224,13 @@ function createWorkspacePatcher(cwd) {
|
|
|
389
1224
|
projectRoot: cwd
|
|
390
1225
|
})
|
|
391
1226
|
);
|
|
392
|
-
return new
|
|
1227
|
+
return new TailwindcssPatcher2(normalized);
|
|
393
1228
|
}
|
|
394
1229
|
async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
395
1230
|
const displayName = formatDisplayName(workspaceRoot, dir, pkgName);
|
|
396
1231
|
const tailwindInfo = getTailwindcssPackageInfo({ paths: [dir] });
|
|
397
1232
|
if (!tailwindInfo?.rootPath) {
|
|
398
|
-
|
|
1233
|
+
logger11.info("[workspace] \u8DF3\u8FC7 %s\uFF08tailwindcss \u672A\u5B89\u88C5\uFF09\u3002", displayName);
|
|
399
1234
|
return {
|
|
400
1235
|
dir,
|
|
401
1236
|
name: pkgName,
|
|
@@ -415,14 +1250,14 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
|
415
1250
|
alwaysRecord: true
|
|
416
1251
|
});
|
|
417
1252
|
if (recorder?.message) {
|
|
418
|
-
|
|
1253
|
+
logger11.info("[workspace] %s %s", displayName, recorder.message);
|
|
419
1254
|
}
|
|
420
1255
|
logTailwindcssTarget("cli", patcher, dir);
|
|
421
1256
|
await patcher.patch();
|
|
422
1257
|
if (recorder?.onPatched) {
|
|
423
1258
|
await recorder.onPatched();
|
|
424
1259
|
}
|
|
425
|
-
|
|
1260
|
+
logger11.success("[workspace] \u5DF2\u8865\u4E01 %s", displayName);
|
|
426
1261
|
return {
|
|
427
1262
|
dir,
|
|
428
1263
|
name: pkgName,
|
|
@@ -433,7 +1268,7 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
|
433
1268
|
const reason = error instanceof Error ? error.message : String(error);
|
|
434
1269
|
const suggestion = `\u8BF7\u5728 ${dir} \u8FD0\u884C "weapp-tw patch --cwd ${dir}".`;
|
|
435
1270
|
const message = `${reason}\uFF0C${suggestion}`;
|
|
436
|
-
|
|
1271
|
+
logger11.error("[workspace] \u8865\u4E01\u5931\u8D25 %s\uFF1A%s", displayName, message);
|
|
437
1272
|
return {
|
|
438
1273
|
dir,
|
|
439
1274
|
name: pkgName,
|
|
@@ -445,16 +1280,16 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
|
445
1280
|
|
|
446
1281
|
// src/cli/workspace.ts
|
|
447
1282
|
async function patchWorkspace(options) {
|
|
448
|
-
const cwd = options.cwd ??
|
|
1283
|
+
const cwd = options.cwd ?? process15.cwd();
|
|
449
1284
|
const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
|
|
450
1285
|
const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
|
|
451
1286
|
if (packageDirs.length === 0) {
|
|
452
|
-
|
|
1287
|
+
logger11.warn("\u672A\u5728 %s \u68C0\u6D4B\u5230 workspace \u5305\uFF0C\u5DF2\u8DF3\u8FC7\u6279\u91CF patch\u3002", workspaceRoot);
|
|
453
1288
|
return;
|
|
454
1289
|
}
|
|
455
1290
|
const results = [];
|
|
456
1291
|
for (const dir of packageDirs) {
|
|
457
|
-
const pkgJsonPath =
|
|
1292
|
+
const pkgJsonPath = path19.join(dir, "package.json");
|
|
458
1293
|
const pkgJson = tryReadJson(pkgJsonPath);
|
|
459
1294
|
results.push(await patchWorkspacePackage(workspaceRoot, dir, pkgJson?.name, options));
|
|
460
1295
|
}
|
|
@@ -464,12 +1299,12 @@ async function patchWorkspace(options) {
|
|
|
464
1299
|
// src/cli/mount-options.ts
|
|
465
1300
|
function handleCliError2(error) {
|
|
466
1301
|
if (error instanceof Error) {
|
|
467
|
-
|
|
468
|
-
if (error.stack &&
|
|
469
|
-
|
|
1302
|
+
logger11.error(error.message);
|
|
1303
|
+
if (error.stack && process16.env.WEAPP_TW_DEBUG === "1") {
|
|
1304
|
+
logger11.error(error.stack);
|
|
470
1305
|
}
|
|
471
1306
|
} else {
|
|
472
|
-
|
|
1307
|
+
logger11.error(String(error));
|
|
473
1308
|
}
|
|
474
1309
|
}
|
|
475
1310
|
function withCommandErrorHandling(handler) {
|
|
@@ -478,7 +1313,7 @@ function withCommandErrorHandling(handler) {
|
|
|
478
1313
|
return await handler(ctx, next);
|
|
479
1314
|
} catch (error) {
|
|
480
1315
|
handleCliError2(error);
|
|
481
|
-
|
|
1316
|
+
process16.exitCode = 1;
|
|
482
1317
|
return void 0;
|
|
483
1318
|
}
|
|
484
1319
|
});
|
|
@@ -557,17 +1392,17 @@ var mountOptions = {
|
|
|
557
1392
|
alwaysRecord: true
|
|
558
1393
|
});
|
|
559
1394
|
if (recorder?.message) {
|
|
560
|
-
|
|
1395
|
+
logger11.info(recorder.message);
|
|
561
1396
|
}
|
|
562
1397
|
logTailwindcssTarget("cli", patcher, ctx.cwd);
|
|
563
1398
|
await patcher.patch();
|
|
564
1399
|
if (recorder?.onPatched) {
|
|
565
1400
|
const recordPath = await recorder.onPatched();
|
|
566
1401
|
if (recordPath) {
|
|
567
|
-
|
|
1402
|
+
logger11.info(`\u8BB0\u5F55 weapp-tw patch \u76EE\u6807 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
|
|
568
1403
|
}
|
|
569
1404
|
}
|
|
570
|
-
|
|
1405
|
+
logger11.success("Tailwind CSS \u8FD0\u884C\u65F6\u8865\u4E01\u5DF2\u5B8C\u6210\u3002");
|
|
571
1406
|
}),
|
|
572
1407
|
extract: withCommandErrorHandling(async (_ctx, next) => next()),
|
|
573
1408
|
tokens: withCommandErrorHandling(async (_ctx, next) => next()),
|
|
@@ -576,7 +1411,7 @@ var mountOptions = {
|
|
|
576
1411
|
const patcher = await createPatcherWithDefaultExtendLengthUnits(ctx);
|
|
577
1412
|
const report = await patcher.getPatchStatus();
|
|
578
1413
|
if (ctx.args.json) {
|
|
579
|
-
|
|
1414
|
+
logger11.log(JSON.stringify(report, null, 2));
|
|
580
1415
|
return report;
|
|
581
1416
|
}
|
|
582
1417
|
logPatchStatusReport(report);
|
|
@@ -587,8 +1422,8 @@ var mountOptions = {
|
|
|
587
1422
|
|
|
588
1423
|
// src/cli/vscode-entry.ts
|
|
589
1424
|
import { constants } from "fs";
|
|
590
|
-
import { access, writeFile } from "fs/promises";
|
|
591
|
-
import
|
|
1425
|
+
import { access, writeFile as writeFile2 } from "fs/promises";
|
|
1426
|
+
import path20 from "path";
|
|
592
1427
|
var DEFAULT_VSCODE_ENTRY_OUTPUT = ".vscode/weapp-tailwindcss.intellisense.css";
|
|
593
1428
|
var DEFAULT_VSCODE_SOURCES = [
|
|
594
1429
|
'not "./dist"',
|
|
@@ -661,16 +1496,16 @@ function formatSource(pattern) {
|
|
|
661
1496
|
}
|
|
662
1497
|
function resolveOutputPath(baseDir, output) {
|
|
663
1498
|
const target = output ?? DEFAULT_VSCODE_ENTRY_OUTPUT;
|
|
664
|
-
return
|
|
1499
|
+
return path20.isAbsolute(target) ? path20.normalize(target) : path20.resolve(baseDir, target);
|
|
665
1500
|
}
|
|
666
1501
|
function resolveCssEntry(baseDir, entry) {
|
|
667
|
-
return
|
|
1502
|
+
return path20.isAbsolute(entry) ? path20.normalize(entry) : path20.resolve(baseDir, entry);
|
|
668
1503
|
}
|
|
669
1504
|
function toRelativeImport(fromFile, targetFile) {
|
|
670
|
-
const fromDir =
|
|
671
|
-
let relative =
|
|
1505
|
+
const fromDir = path20.dirname(fromFile);
|
|
1506
|
+
let relative = path20.relative(fromDir, targetFile);
|
|
672
1507
|
if (!relative) {
|
|
673
|
-
relative =
|
|
1508
|
+
relative = path20.basename(targetFile);
|
|
674
1509
|
}
|
|
675
1510
|
if (!relative.startsWith(".")) {
|
|
676
1511
|
relative = `./${relative}`;
|
|
@@ -682,7 +1517,7 @@ async function generateVscodeIntellisenseEntry(options) {
|
|
|
682
1517
|
const cssEntryPath = resolveCssEntry(baseDir, options.cssEntry);
|
|
683
1518
|
await assertFileExists(cssEntryPath);
|
|
684
1519
|
const outputPath = resolveOutputPath(baseDir, options.output);
|
|
685
|
-
await ensureDir(
|
|
1520
|
+
await ensureDir(path20.dirname(outputPath));
|
|
686
1521
|
await assertCanWrite(outputPath, options.force);
|
|
687
1522
|
const sources = options.sources && options.sources.length > 0 ? options.sources : DEFAULT_VSCODE_SOURCES;
|
|
688
1523
|
const formattedSources = sources.map(formatSource).filter((statement) => Boolean(statement));
|
|
@@ -701,16 +1536,16 @@ async function generateVscodeIntellisenseEntry(options) {
|
|
|
701
1536
|
`@import '${cssImport}';`,
|
|
702
1537
|
""
|
|
703
1538
|
].filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join("\n");
|
|
704
|
-
await
|
|
1539
|
+
await writeFile2(outputPath, `${content}
|
|
705
1540
|
`, "utf8");
|
|
706
1541
|
return { outputPath, cssEntryPath };
|
|
707
1542
|
}
|
|
708
1543
|
|
|
709
1544
|
// src/cli.ts
|
|
710
|
-
|
|
711
|
-
if (semver.lt(
|
|
712
|
-
|
|
713
|
-
`You are using Node.js ${
|
|
1545
|
+
process17.title = "node (weapp-tailwindcss)";
|
|
1546
|
+
if (semver.lt(process17.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION)) {
|
|
1547
|
+
logger11.warn(
|
|
1548
|
+
`You are using Node.js ${process17.versions.node}. For weapp-tailwindcss, Node.js version >= v${WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
|
|
714
1549
|
);
|
|
715
1550
|
}
|
|
716
1551
|
var cli = createTailwindcssPatchCli({
|
|
@@ -720,7 +1555,7 @@ var cli = createTailwindcssPatchCli({
|
|
|
720
1555
|
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(
|
|
721
1556
|
commandAction(async (options) => {
|
|
722
1557
|
const resolvedCwd = resolveCliCwd(options.cwd);
|
|
723
|
-
const baseDir = resolvedCwd ??
|
|
1558
|
+
const baseDir = resolvedCwd ?? process17.cwd();
|
|
724
1559
|
const cssEntry = readStringOption("css", options.css);
|
|
725
1560
|
if (!cssEntry) {
|
|
726
1561
|
throw new Error('Option "--css" is required.');
|
|
@@ -735,11 +1570,11 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
|
|
|
735
1570
|
sources,
|
|
736
1571
|
force
|
|
737
1572
|
});
|
|
738
|
-
|
|
1573
|
+
logger11.success(
|
|
739
1574
|
`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`
|
|
740
1575
|
);
|
|
741
1576
|
})
|
|
742
1577
|
);
|
|
743
1578
|
cli.help();
|
|
744
|
-
cli.version(
|
|
1579
|
+
cli.version(process17.env.npm_package_version ?? "0.0.0");
|
|
745
1580
|
cli.parse();
|