tailwindcss-patch 5.0.0 → 5.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-P2MLMFLP.js +926 -0
- package/dist/cli.cjs +960 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +35 -0
- package/dist/index.cjs +961 -0
- package/dist/index.d.cts +143 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.js +23 -0
- package/package.json +2 -2
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
15
|
+
// src/config.ts
|
|
16
|
+
var config_exports = {};
|
|
17
|
+
__reExport(config_exports, config_star);
|
|
18
|
+
import * as config_star from "@tailwindcss-mangle/config";
|
|
19
|
+
|
|
20
|
+
// src/logger.ts
|
|
21
|
+
import { createConsola } from "consola";
|
|
22
|
+
var logger = createConsola();
|
|
23
|
+
var logger_default = logger;
|
|
24
|
+
|
|
25
|
+
// src/core/cache.ts
|
|
26
|
+
import process from "node:process";
|
|
27
|
+
import fs from "fs-extra";
|
|
28
|
+
import path from "pathe";
|
|
29
|
+
|
|
30
|
+
// src/constants.ts
|
|
31
|
+
var pkgName = "tailwindcss-patch";
|
|
32
|
+
|
|
33
|
+
// src/core/cache.ts
|
|
34
|
+
function getCacheOptions(options) {
|
|
35
|
+
let cache;
|
|
36
|
+
switch (typeof options) {
|
|
37
|
+
case "undefined": {
|
|
38
|
+
cache = {
|
|
39
|
+
enable: false
|
|
40
|
+
};
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "boolean": {
|
|
44
|
+
cache = {
|
|
45
|
+
enable: options
|
|
46
|
+
};
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "object": {
|
|
50
|
+
cache = { ...options, enable: true };
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return cache;
|
|
55
|
+
}
|
|
56
|
+
var CacheManager = class {
|
|
57
|
+
options;
|
|
58
|
+
constructor(options = {}) {
|
|
59
|
+
this.options = this.getOptions(options);
|
|
60
|
+
}
|
|
61
|
+
getOptions(options = {}) {
|
|
62
|
+
const cwd = options.cwd ?? process.cwd();
|
|
63
|
+
const dir = options.dir ?? path.resolve(cwd, "node_modules/.cache", pkgName);
|
|
64
|
+
const file = options.file ?? "index.json";
|
|
65
|
+
const filename = path.resolve(dir, file);
|
|
66
|
+
return {
|
|
67
|
+
cwd,
|
|
68
|
+
dir,
|
|
69
|
+
file,
|
|
70
|
+
filename,
|
|
71
|
+
strategy: "merge"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
write(data) {
|
|
75
|
+
try {
|
|
76
|
+
const { dir, filename } = this.options;
|
|
77
|
+
fs.ensureDirSync(dir);
|
|
78
|
+
fs.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
79
|
+
return filename;
|
|
80
|
+
} catch {
|
|
81
|
+
logger_default.error("write cache file fail!");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
read() {
|
|
85
|
+
const { filename } = this.options;
|
|
86
|
+
try {
|
|
87
|
+
if (fs.existsSync(filename)) {
|
|
88
|
+
const data = fs.readFileSync(filename, "utf8");
|
|
89
|
+
return new Set(JSON.parse(data));
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
logger_default.error(`parse cache content fail! path:${filename}`);
|
|
93
|
+
try {
|
|
94
|
+
fs.unlinkSync(filename);
|
|
95
|
+
} catch {
|
|
96
|
+
logger_default.error(`delete cache file fail! path:${filename}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/defaults.ts
|
|
103
|
+
import process2 from "node:process";
|
|
104
|
+
|
|
105
|
+
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
106
|
+
function isPlainObject(value) {
|
|
107
|
+
if (value === null || typeof value !== "object") {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const prototype = Object.getPrototypeOf(value);
|
|
111
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (Symbol.iterator in value) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (Symbol.toStringTag in value) {
|
|
118
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
123
|
+
if (!isPlainObject(defaults)) {
|
|
124
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
125
|
+
}
|
|
126
|
+
const object = Object.assign({}, defaults);
|
|
127
|
+
for (const key in baseObject) {
|
|
128
|
+
if (key === "__proto__" || key === "constructor") {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const value = baseObject[key];
|
|
132
|
+
if (value === null || value === void 0) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
139
|
+
object[key] = [...value, ...object[key]];
|
|
140
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
141
|
+
object[key] = _defu(
|
|
142
|
+
value,
|
|
143
|
+
object[key],
|
|
144
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
145
|
+
merger
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
148
|
+
object[key] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return object;
|
|
152
|
+
}
|
|
153
|
+
function createDefu(merger) {
|
|
154
|
+
return (...arguments_) => (
|
|
155
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
156
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
var defu = createDefu();
|
|
160
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
161
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
162
|
+
object[key] = currentValue(object[key]);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
167
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
168
|
+
object[key] = currentValue(object[key]);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ../shared/src/utils.ts
|
|
174
|
+
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
175
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
176
|
+
obj[key] = value;
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
var preserveClassNames = [
|
|
181
|
+
// https://tailwindcss.com/docs/transition-timing-function start
|
|
182
|
+
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
183
|
+
"ease-out",
|
|
184
|
+
"ease-linear",
|
|
185
|
+
"ease-in",
|
|
186
|
+
"ease-in-out"
|
|
187
|
+
// https://tailwindcss.com/docs/transition-timing-function end
|
|
188
|
+
];
|
|
189
|
+
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
190
|
+
acc[cur] = true;
|
|
191
|
+
return acc;
|
|
192
|
+
}, {});
|
|
193
|
+
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
194
|
+
|
|
195
|
+
// src/defaults.ts
|
|
196
|
+
function getDefaultPatchOptions() {
|
|
197
|
+
return {
|
|
198
|
+
applyPatches: {
|
|
199
|
+
exportContext: true,
|
|
200
|
+
extendLengthUnits: false
|
|
201
|
+
},
|
|
202
|
+
overwrite: true
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function getPatchOptions(options) {
|
|
206
|
+
return defu(
|
|
207
|
+
options,
|
|
208
|
+
{
|
|
209
|
+
basedir: process2.cwd()
|
|
210
|
+
},
|
|
211
|
+
getDefaultPatchOptions()
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/core/patches/exportContext/index.ts
|
|
216
|
+
import fs2 from "fs-extra";
|
|
217
|
+
import path2 from "pathe";
|
|
218
|
+
|
|
219
|
+
// src/core/patches/exportContext/postcss-v2.ts
|
|
220
|
+
import * as t from "@babel/types";
|
|
221
|
+
|
|
222
|
+
// src/babel/index.ts
|
|
223
|
+
import _babelGenerate from "@babel/generator";
|
|
224
|
+
import _babelTraverse from "@babel/traverse";
|
|
225
|
+
import { parse, parseExpression } from "@babel/parser";
|
|
226
|
+
function _interopDefaultCompat(e) {
|
|
227
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
228
|
+
}
|
|
229
|
+
var generate = _interopDefaultCompat(_babelGenerate);
|
|
230
|
+
var traverse = _interopDefaultCompat(_babelTraverse);
|
|
231
|
+
|
|
232
|
+
// src/core/patches/exportContext/postcss-v2.ts
|
|
233
|
+
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
234
|
+
const ast = parse(content, {
|
|
235
|
+
sourceType: "unambiguous"
|
|
236
|
+
});
|
|
237
|
+
let hasPatched = false;
|
|
238
|
+
traverse(ast, {
|
|
239
|
+
FunctionDeclaration(p) {
|
|
240
|
+
const n = p.node;
|
|
241
|
+
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
242
|
+
const rts = n.body.body[0];
|
|
243
|
+
if (t.isFunctionExpression(rts.argument)) {
|
|
244
|
+
const body = rts.argument.body.body;
|
|
245
|
+
const lastStatement = body[body.length - 1];
|
|
246
|
+
hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
247
|
+
if (!hasPatched) {
|
|
248
|
+
const rts2 = t.returnStatement(t.identifier("context"));
|
|
249
|
+
body.push(rts2);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
code: hasPatched ? content : generate(ast).code,
|
|
257
|
+
hasPatched
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function inspectPostcssPlugin(content) {
|
|
261
|
+
const ast = parse(content);
|
|
262
|
+
const exportKey = "contextRef";
|
|
263
|
+
const variableName = "contextRef";
|
|
264
|
+
const valueKey = "value";
|
|
265
|
+
let hasPatched = false;
|
|
266
|
+
traverse(ast, {
|
|
267
|
+
Program(p) {
|
|
268
|
+
const n = p.node;
|
|
269
|
+
const idx = n.body.findIndex((x) => {
|
|
270
|
+
return t.isFunctionDeclaration(x) && x.id?.name === "_default";
|
|
271
|
+
});
|
|
272
|
+
if (idx > -1) {
|
|
273
|
+
const prevStatement = n.body[idx - 1];
|
|
274
|
+
const lastStatement = n.body[idx - 2];
|
|
275
|
+
const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
276
|
+
const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
277
|
+
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
278
|
+
if (!hasPatched) {
|
|
279
|
+
const statement = t.variableDeclaration("var", [
|
|
280
|
+
t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
|
|
281
|
+
]);
|
|
282
|
+
n.body.splice(
|
|
283
|
+
idx,
|
|
284
|
+
0,
|
|
285
|
+
statement,
|
|
286
|
+
// exports.contextRef = contextRef;
|
|
287
|
+
t.expressionStatement(
|
|
288
|
+
t.assignmentExpression(
|
|
289
|
+
"=",
|
|
290
|
+
t.memberExpression(t.identifier("exports"), t.identifier(exportKey)),
|
|
291
|
+
t.identifier(variableName)
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
FunctionDeclaration(p) {
|
|
299
|
+
if (hasPatched) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const n = p.node;
|
|
303
|
+
if (n.id?.name === "_default" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
304
|
+
const returnStatement3 = n.body.body[0];
|
|
305
|
+
if (t.isCallExpression(returnStatement3.argument) && t.isMemberExpression(returnStatement3.argument.callee) && t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
306
|
+
const targetFn = returnStatement3.argument.callee.object.elements[1];
|
|
307
|
+
if (t.isFunctionExpression(targetFn)) {
|
|
308
|
+
const targetBlockStatement = targetFn.body;
|
|
309
|
+
if (t.isExpressionStatement(targetBlockStatement.body[0]) && t.isAssignmentExpression(targetBlockStatement.body[0].expression) && t.isNumericLiteral(targetBlockStatement.body[0].expression.right)) {
|
|
310
|
+
hasPatched = true;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
314
|
+
if (t.isExpressionStatement(lastStatement)) {
|
|
315
|
+
const newExpressionStatement = t.expressionStatement(
|
|
316
|
+
t.callExpression(
|
|
317
|
+
t.memberExpression(
|
|
318
|
+
t.memberExpression(t.identifier(variableName), t.identifier("value")),
|
|
319
|
+
t.identifier("push")
|
|
320
|
+
),
|
|
321
|
+
[lastStatement.expression]
|
|
322
|
+
)
|
|
323
|
+
);
|
|
324
|
+
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
325
|
+
}
|
|
326
|
+
const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
|
|
327
|
+
if (ifIdx > -1) {
|
|
328
|
+
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
329
|
+
if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
330
|
+
const forOf = ifRoot.consequent.body[1];
|
|
331
|
+
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
|
|
332
|
+
const if2 = forOf.body.body[0];
|
|
333
|
+
if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
|
|
334
|
+
const target = if2.consequent.body[0];
|
|
335
|
+
const newExpressionStatement = t.expressionStatement(
|
|
336
|
+
t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
|
|
337
|
+
);
|
|
338
|
+
if2.consequent.body[0] = newExpressionStatement;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
targetBlockStatement.body.unshift(
|
|
344
|
+
// contentRef.value = []
|
|
345
|
+
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
346
|
+
// contentRef.value.length = 0
|
|
347
|
+
t.expressionStatement(
|
|
348
|
+
t.assignmentExpression(
|
|
349
|
+
"=",
|
|
350
|
+
t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
|
|
351
|
+
t.numericLiteral(0)
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
code: hasPatched ? content : generate(ast).code,
|
|
362
|
+
hasPatched
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/core/patches/exportContext/postcss-v3.ts
|
|
367
|
+
import * as t2 from "@babel/types";
|
|
368
|
+
function inspectProcessTailwindFeaturesReturnContext2(content) {
|
|
369
|
+
const ast = parse(content);
|
|
370
|
+
let hasPatched = false;
|
|
371
|
+
traverse(ast, {
|
|
372
|
+
FunctionDeclaration(p) {
|
|
373
|
+
const n = p.node;
|
|
374
|
+
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
375
|
+
const rts = n.body.body[0];
|
|
376
|
+
if (t2.isFunctionExpression(rts.argument)) {
|
|
377
|
+
const body = rts.argument.body.body;
|
|
378
|
+
const lastStatement = body[body.length - 1];
|
|
379
|
+
hasPatched = t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
380
|
+
if (!hasPatched) {
|
|
381
|
+
const rts2 = t2.returnStatement(t2.identifier("context"));
|
|
382
|
+
body.push(rts2);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
code: hasPatched ? content : generate(ast).code,
|
|
390
|
+
hasPatched
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function inspectPostcssPlugin2(content) {
|
|
394
|
+
const ast = parse(content);
|
|
395
|
+
const exportKey = "contextRef";
|
|
396
|
+
const variableName = "contextRef";
|
|
397
|
+
const valueKey = "value";
|
|
398
|
+
let hasPatched = false;
|
|
399
|
+
traverse(ast, {
|
|
400
|
+
Program(p) {
|
|
401
|
+
const n = p.node;
|
|
402
|
+
const idx = n.body.findIndex((x) => {
|
|
403
|
+
return t2.isExpressionStatement(x) && t2.isAssignmentExpression(x.expression) && t2.isMemberExpression(x.expression.left) && t2.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
|
|
404
|
+
});
|
|
405
|
+
if (idx > -1) {
|
|
406
|
+
const prevStatement = n.body[idx - 1];
|
|
407
|
+
const lastStatement = n.body[n.body.length - 1];
|
|
408
|
+
const hasPatchedCondition0 = prevStatement && t2.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t2.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
409
|
+
const hasPatchedCondition1 = t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
410
|
+
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
411
|
+
if (!hasPatched) {
|
|
412
|
+
const statement = t2.variableDeclaration("const", [
|
|
413
|
+
t2.variableDeclarator(t2.identifier(variableName), t2.objectExpression([t2.objectProperty(t2.identifier(valueKey), t2.arrayExpression())]))
|
|
414
|
+
]);
|
|
415
|
+
n.body.splice(idx, 0, statement);
|
|
416
|
+
n.body.push(
|
|
417
|
+
t2.expressionStatement(
|
|
418
|
+
t2.assignmentExpression(
|
|
419
|
+
"=",
|
|
420
|
+
t2.memberExpression(t2.memberExpression(t2.identifier("module"), t2.identifier("exports")), t2.identifier(exportKey)),
|
|
421
|
+
t2.identifier(variableName)
|
|
422
|
+
)
|
|
423
|
+
)
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
FunctionExpression(p) {
|
|
429
|
+
if (hasPatched) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const n = p.node;
|
|
433
|
+
if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
434
|
+
const returnStatement3 = n.body.body[0];
|
|
435
|
+
if (t2.isObjectExpression(returnStatement3.argument) && returnStatement3.argument.properties.length === 2) {
|
|
436
|
+
const properties = returnStatement3.argument.properties;
|
|
437
|
+
if (t2.isObjectProperty(properties[0]) && t2.isObjectProperty(properties[1])) {
|
|
438
|
+
const keyMatched = t2.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
|
|
439
|
+
const pluginsMatched = t2.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
|
|
440
|
+
if (pluginsMatched && keyMatched && t2.isCallExpression(properties[1].value) && t2.isMemberExpression(properties[1].value.callee) && t2.isArrayExpression(properties[1].value.callee.object)) {
|
|
441
|
+
const pluginsCode = properties[1].value.callee.object.elements;
|
|
442
|
+
if (pluginsCode[1] && t2.isFunctionExpression(pluginsCode[1])) {
|
|
443
|
+
const targetBlockStatement = pluginsCode[1].body;
|
|
444
|
+
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
445
|
+
if (t2.isExpressionStatement(lastStatement)) {
|
|
446
|
+
const newExpressionStatement = t2.expressionStatement(
|
|
447
|
+
t2.callExpression(
|
|
448
|
+
t2.memberExpression(
|
|
449
|
+
t2.memberExpression(t2.identifier(variableName), t2.identifier("value")),
|
|
450
|
+
t2.identifier("push")
|
|
451
|
+
),
|
|
452
|
+
[lastStatement.expression]
|
|
453
|
+
)
|
|
454
|
+
);
|
|
455
|
+
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
456
|
+
}
|
|
457
|
+
const ifIdx = targetBlockStatement.body.findIndex((x) => t2.isIfStatement(x));
|
|
458
|
+
if (ifIdx > -1) {
|
|
459
|
+
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
460
|
+
if (t2.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t2.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
461
|
+
const forOf = ifRoot.consequent.body[1];
|
|
462
|
+
if (t2.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t2.isIfStatement(forOf.body.body[0])) {
|
|
463
|
+
const if2 = forOf.body.body[0];
|
|
464
|
+
if (t2.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t2.isExpressionStatement(if2.consequent.body[0])) {
|
|
465
|
+
const target = if2.consequent.body[0];
|
|
466
|
+
const newExpressionStatement = t2.expressionStatement(
|
|
467
|
+
t2.callExpression(t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier("value")), t2.identifier("push")), [target.expression])
|
|
468
|
+
);
|
|
469
|
+
if2.consequent.body[0] = newExpressionStatement;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
targetBlockStatement.body.unshift(
|
|
475
|
+
// contentRef.value = []
|
|
476
|
+
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
477
|
+
// contentRef.value.length = 0
|
|
478
|
+
t2.expressionStatement(
|
|
479
|
+
t2.assignmentExpression(
|
|
480
|
+
"=",
|
|
481
|
+
t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier(valueKey)), t2.identifier("length")),
|
|
482
|
+
t2.numericLiteral(0)
|
|
483
|
+
)
|
|
484
|
+
)
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// BlockStatement(p) {
|
|
493
|
+
// const n = p.node
|
|
494
|
+
// if (start && p.parent.type === 'FunctionExpression' && !p.parent.id) {
|
|
495
|
+
// n.body.unshift(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression())))
|
|
496
|
+
// }
|
|
497
|
+
// }
|
|
498
|
+
});
|
|
499
|
+
return {
|
|
500
|
+
code: hasPatched ? content : generate(ast).code,
|
|
501
|
+
hasPatched
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/core/patches/exportContext/index.ts
|
|
506
|
+
function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
507
|
+
const k0 = "lib/processTailwindFeatures.js";
|
|
508
|
+
const processTailwindFeaturesFilePath = path2.resolve(twDir, k0);
|
|
509
|
+
const processTailwindFeaturesContent = fs2.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
510
|
+
const result = {};
|
|
511
|
+
if (processTailwindFeaturesContent) {
|
|
512
|
+
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext2(processTailwindFeaturesContent);
|
|
513
|
+
if (!hasPatched && opt.overwrite) {
|
|
514
|
+
fs2.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
515
|
+
encoding: "utf8"
|
|
516
|
+
});
|
|
517
|
+
logger_default.success("patch tailwindcss processTailwindFeatures for return context successfully!");
|
|
518
|
+
}
|
|
519
|
+
result[k0] = code;
|
|
520
|
+
}
|
|
521
|
+
let injectFilepath;
|
|
522
|
+
let k1;
|
|
523
|
+
const try0 = "lib/plugin.js";
|
|
524
|
+
const try1 = "lib/index.js";
|
|
525
|
+
const pluginFilePath = path2.resolve(twDir, try0);
|
|
526
|
+
const indexFilePath = path2.resolve(twDir, try1);
|
|
527
|
+
if (fs2.existsSync(pluginFilePath)) {
|
|
528
|
+
k1 = try0;
|
|
529
|
+
injectFilepath = pluginFilePath;
|
|
530
|
+
} else if (fs2.existsSync(indexFilePath)) {
|
|
531
|
+
k1 = try1;
|
|
532
|
+
injectFilepath = indexFilePath;
|
|
533
|
+
}
|
|
534
|
+
if (injectFilepath && k1) {
|
|
535
|
+
const pluginContent = fs2.readFileSync(injectFilepath, "utf8");
|
|
536
|
+
if (pluginContent) {
|
|
537
|
+
const { code, hasPatched } = inspectPostcssPlugin2(pluginContent);
|
|
538
|
+
if (!hasPatched && opt.overwrite) {
|
|
539
|
+
fs2.writeFileSync(injectFilepath, code, {
|
|
540
|
+
encoding: "utf8"
|
|
541
|
+
});
|
|
542
|
+
logger_default.success("patch tailwindcss for expose runtime context successfully!");
|
|
543
|
+
}
|
|
544
|
+
result[k1] = code;
|
|
545
|
+
}
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
550
|
+
const k0 = "lib/jit/processTailwindFeatures.js";
|
|
551
|
+
const processTailwindFeaturesFilePath = path2.resolve(twDir, k0);
|
|
552
|
+
const processTailwindFeaturesContent = fs2.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
553
|
+
const result = {};
|
|
554
|
+
if (processTailwindFeaturesContent) {
|
|
555
|
+
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
556
|
+
if (!hasPatched && opt.overwrite) {
|
|
557
|
+
fs2.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
558
|
+
encoding: "utf8"
|
|
559
|
+
});
|
|
560
|
+
logger_default.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
561
|
+
}
|
|
562
|
+
result[k0] = code;
|
|
563
|
+
}
|
|
564
|
+
const k1 = "lib/jit/index.js";
|
|
565
|
+
const indexFilePath = path2.resolve(twDir, k1);
|
|
566
|
+
const pluginContent = fs2.readFileSync(indexFilePath, "utf8");
|
|
567
|
+
if (pluginContent) {
|
|
568
|
+
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
569
|
+
if (!hasPatched && opt.overwrite) {
|
|
570
|
+
fs2.writeFileSync(indexFilePath, code, {
|
|
571
|
+
encoding: "utf8"
|
|
572
|
+
});
|
|
573
|
+
logger_default.success("patch tailwindcss for expose runtime content successfully!");
|
|
574
|
+
}
|
|
575
|
+
result[k1] = code;
|
|
576
|
+
}
|
|
577
|
+
return result;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// src/core/patches/supportCustomUnits/index.ts
|
|
581
|
+
import * as t3 from "@babel/types";
|
|
582
|
+
import fs3 from "fs-extra";
|
|
583
|
+
import path3 from "pathe";
|
|
584
|
+
function findAstNode(content, options) {
|
|
585
|
+
const { variableName, units } = options;
|
|
586
|
+
const ast = parse(content);
|
|
587
|
+
let arrayRef;
|
|
588
|
+
let changed = false;
|
|
589
|
+
traverse(ast, {
|
|
590
|
+
Identifier(path8) {
|
|
591
|
+
if (path8.node.name === variableName && t3.isVariableDeclarator(path8.parent) && t3.isArrayExpression(path8.parent.init)) {
|
|
592
|
+
arrayRef = path8.parent.init;
|
|
593
|
+
const set = new Set(path8.parent.init.elements.map((x) => x.value));
|
|
594
|
+
for (let i = 0; i < units.length; i++) {
|
|
595
|
+
const unit = units[i];
|
|
596
|
+
if (!set.has(unit)) {
|
|
597
|
+
path8.parent.init.elements = path8.parent.init.elements.map((x) => {
|
|
598
|
+
if (t3.isStringLiteral(x)) {
|
|
599
|
+
return {
|
|
600
|
+
type: x?.type,
|
|
601
|
+
value: x?.value
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
return x;
|
|
605
|
+
});
|
|
606
|
+
path8.parent.init.elements.push({
|
|
607
|
+
type: "StringLiteral",
|
|
608
|
+
value: unit
|
|
609
|
+
});
|
|
610
|
+
changed = true;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
return {
|
|
617
|
+
arrayRef,
|
|
618
|
+
changed
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
622
|
+
const opts = defuOverrideArray(options, {
|
|
623
|
+
units: ["rpx"],
|
|
624
|
+
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
625
|
+
variableName: "lengthUnits",
|
|
626
|
+
overwrite: true
|
|
627
|
+
});
|
|
628
|
+
const { lengthUnitsFilePath, overwrite, destPath } = opts;
|
|
629
|
+
const dataTypesFilePath = path3.resolve(rootDir, lengthUnitsFilePath);
|
|
630
|
+
const dataTypesFileContent = fs3.readFileSync(dataTypesFilePath, {
|
|
631
|
+
encoding: "utf8"
|
|
632
|
+
});
|
|
633
|
+
const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
|
|
634
|
+
if (arrayRef && changed) {
|
|
635
|
+
const { code } = generate(arrayRef, {
|
|
636
|
+
jsescOption: {
|
|
637
|
+
quotes: "single"
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
if (arrayRef.start && arrayRef.end) {
|
|
641
|
+
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
642
|
+
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
643
|
+
const newCode = prev + code + next;
|
|
644
|
+
if (overwrite) {
|
|
645
|
+
fs3.writeFileSync(destPath ?? dataTypesFilePath, newCode, {
|
|
646
|
+
encoding: "utf8"
|
|
647
|
+
});
|
|
648
|
+
logger_default.success("patch tailwindcss for custom length unit successfully!");
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return {
|
|
652
|
+
[opts.lengthUnitsFilePath]: code
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/core/runtime.ts
|
|
658
|
+
import { createRequire } from "node:module";
|
|
659
|
+
import path4 from "pathe";
|
|
660
|
+
import { gte } from "semver";
|
|
661
|
+
var require2 = createRequire(import.meta.url);
|
|
662
|
+
function internalPatch(pkgJsonPath, options) {
|
|
663
|
+
if (pkgJsonPath) {
|
|
664
|
+
const pkgJson = require2(pkgJsonPath);
|
|
665
|
+
const twDir = path4.dirname(pkgJsonPath);
|
|
666
|
+
options.version = pkgJson.version;
|
|
667
|
+
if (gte(pkgJson.version, "3.0.0")) {
|
|
668
|
+
let result = {};
|
|
669
|
+
if (options.applyPatches?.exportContext) {
|
|
670
|
+
result = monkeyPatchForExposingContextV3(twDir, options);
|
|
671
|
+
}
|
|
672
|
+
if (options.applyPatches?.extendLengthUnits) {
|
|
673
|
+
try {
|
|
674
|
+
Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
|
|
675
|
+
overwrite: options.overwrite
|
|
676
|
+
})));
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return result;
|
|
681
|
+
} else if (gte(pkgJson.version, "2.0.0")) {
|
|
682
|
+
if (options.applyPatches?.exportContext) {
|
|
683
|
+
return monkeyPatchForExposingContextV2(twDir, options);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/core/patcher.ts
|
|
690
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
691
|
+
import fs5 from "fs-extra";
|
|
692
|
+
import path7 from "pathe";
|
|
693
|
+
|
|
694
|
+
// src/utils.ts
|
|
695
|
+
import fs4 from "fs-extra";
|
|
696
|
+
import path5 from "pathe";
|
|
697
|
+
import pkg from "resolve";
|
|
698
|
+
var { sync } = pkg;
|
|
699
|
+
function requireResolve(id, opts) {
|
|
700
|
+
return sync(id, opts);
|
|
701
|
+
}
|
|
702
|
+
function searchPackageJSON(dir) {
|
|
703
|
+
let packageJsonPath;
|
|
704
|
+
while (true) {
|
|
705
|
+
if (!dir) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
const newDir = path5.dirname(dir);
|
|
709
|
+
if (newDir === dir) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
dir = newDir;
|
|
713
|
+
packageJsonPath = path5.join(dir, "package.json");
|
|
714
|
+
if (fs4.existsSync(packageJsonPath)) {
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return packageJsonPath;
|
|
719
|
+
}
|
|
720
|
+
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
721
|
+
return requireResolve(name, opts);
|
|
722
|
+
}
|
|
723
|
+
function getPackageJsonPath(name, options = {}) {
|
|
724
|
+
const entry = getTailwindcssEntry(name, options);
|
|
725
|
+
if (!entry) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
return searchPackageJSON(entry);
|
|
729
|
+
}
|
|
730
|
+
function getPackageInfoSync(name, options = {}) {
|
|
731
|
+
const packageJsonPath = getPackageJsonPath(name, options);
|
|
732
|
+
if (!packageJsonPath) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf8"));
|
|
736
|
+
return {
|
|
737
|
+
name,
|
|
738
|
+
version: packageJson.version,
|
|
739
|
+
rootPath: path5.dirname(packageJsonPath),
|
|
740
|
+
packageJsonPath,
|
|
741
|
+
packageJson
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function isObject(val) {
|
|
745
|
+
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/core/postcss.ts
|
|
749
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
750
|
+
import process3 from "node:process";
|
|
751
|
+
import { lilconfig } from "lilconfig";
|
|
752
|
+
import path6 from "pathe";
|
|
753
|
+
import postcss from "postcss";
|
|
754
|
+
var require3 = createRequire2(import.meta.url);
|
|
755
|
+
async function processTailwindcss(options) {
|
|
756
|
+
const { config: userConfig, cwd } = defu(options, {
|
|
757
|
+
cwd: process3.cwd()
|
|
758
|
+
});
|
|
759
|
+
let config = userConfig;
|
|
760
|
+
if (!(typeof config === "string" && path6.isAbsolute(config))) {
|
|
761
|
+
const moduleName = "tailwind";
|
|
762
|
+
const tsx = (await import("tsx/cjs/api")).require;
|
|
763
|
+
const result = await lilconfig("tailwindcss", {
|
|
764
|
+
searchPlaces: [
|
|
765
|
+
`${moduleName}.config.js`,
|
|
766
|
+
`${moduleName}.config.cjs`,
|
|
767
|
+
`${moduleName}.config.mjs`,
|
|
768
|
+
`${moduleName}.config.ts`,
|
|
769
|
+
`${moduleName}.config.cts`,
|
|
770
|
+
`${moduleName}.config.mts`
|
|
771
|
+
],
|
|
772
|
+
loaders: {
|
|
773
|
+
// 默认支持 js 和 cjs 2种格式
|
|
774
|
+
".js": tsx,
|
|
775
|
+
".cjs": tsx,
|
|
776
|
+
".mjs": tsx,
|
|
777
|
+
".ts": tsx,
|
|
778
|
+
".cts": tsx,
|
|
779
|
+
".mts": tsx
|
|
780
|
+
}
|
|
781
|
+
}).search(cwd);
|
|
782
|
+
if (!result) {
|
|
783
|
+
throw new Error(`No TailwindCSS Config found in: ${cwd}`);
|
|
784
|
+
}
|
|
785
|
+
config = result.filepath;
|
|
786
|
+
}
|
|
787
|
+
const id = requireResolve("tailwindcss", {
|
|
788
|
+
basedir: cwd
|
|
789
|
+
});
|
|
790
|
+
return await postcss([
|
|
791
|
+
require3(id)({
|
|
792
|
+
config
|
|
793
|
+
})
|
|
794
|
+
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
795
|
+
from: void 0
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/core/patcher.ts
|
|
800
|
+
var require4 = createRequire3(import.meta.url);
|
|
801
|
+
var TailwindcssPatcher = class {
|
|
802
|
+
rawOptions;
|
|
803
|
+
cacheOptions;
|
|
804
|
+
patchOptions;
|
|
805
|
+
patch;
|
|
806
|
+
cacheManager;
|
|
807
|
+
packageInfo;
|
|
808
|
+
majorVersion;
|
|
809
|
+
constructor(options = {}) {
|
|
810
|
+
this.rawOptions = options;
|
|
811
|
+
this.cacheOptions = getCacheOptions(options.cache);
|
|
812
|
+
this.patchOptions = getPatchOptions(options.patch);
|
|
813
|
+
this.cacheManager = new CacheManager(this.cacheOptions);
|
|
814
|
+
this.packageInfo = getPackageInfoSync("tailwindcss", { basedir: this.patchOptions.basedir });
|
|
815
|
+
if (this.packageInfo && this.packageInfo.version) {
|
|
816
|
+
this.majorVersion = Number.parseInt(this.packageInfo.version[0]);
|
|
817
|
+
}
|
|
818
|
+
this.patch = () => {
|
|
819
|
+
try {
|
|
820
|
+
return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
|
|
821
|
+
} catch (error) {
|
|
822
|
+
logger_default.error(`patch tailwindcss failed: ${error.message}`);
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
setCache(set) {
|
|
827
|
+
if (this.cacheOptions.enable) {
|
|
828
|
+
return this.cacheManager.write(set);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
getCache() {
|
|
832
|
+
return this.cacheManager.read();
|
|
833
|
+
}
|
|
834
|
+
getContexts() {
|
|
835
|
+
if (this.packageInfo) {
|
|
836
|
+
const distPath = path7.join(this.packageInfo.rootPath, "lib");
|
|
837
|
+
let injectFilePath;
|
|
838
|
+
if (this.majorVersion === 2) {
|
|
839
|
+
injectFilePath = path7.join(distPath, "jit/index.js");
|
|
840
|
+
} else {
|
|
841
|
+
injectFilePath = path7.join(distPath, "plugin.js");
|
|
842
|
+
if (!fs5.existsSync(injectFilePath)) {
|
|
843
|
+
injectFilePath = path7.join(distPath, "index.js");
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (injectFilePath) {
|
|
847
|
+
const mo = require4(injectFilePath);
|
|
848
|
+
if (mo.contextRef) {
|
|
849
|
+
return mo.contextRef.value;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return [];
|
|
854
|
+
}
|
|
855
|
+
getClassCaches() {
|
|
856
|
+
const contexts = this.getContexts();
|
|
857
|
+
return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
|
|
858
|
+
}
|
|
859
|
+
getClassCacheSet(options) {
|
|
860
|
+
const classCaches = this.getClassCaches();
|
|
861
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
862
|
+
for (const classCacheMap of classCaches) {
|
|
863
|
+
const keys = classCacheMap.keys();
|
|
864
|
+
for (const key of keys) {
|
|
865
|
+
const v = key.toString();
|
|
866
|
+
if (options?.removeUniversalSelector && v === "*") {
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
classSet.add(v);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return classSet;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
|
|
876
|
+
*/
|
|
877
|
+
getClassSet(options) {
|
|
878
|
+
const { cacheStrategy = this.cacheOptions.strategy ?? "merge", removeUniversalSelector = true } = options ?? {};
|
|
879
|
+
const set = this.getClassCacheSet({
|
|
880
|
+
removeUniversalSelector
|
|
881
|
+
});
|
|
882
|
+
if (cacheStrategy === "overwrite") {
|
|
883
|
+
set.size > 0 && this.setCache(set);
|
|
884
|
+
} else if (cacheStrategy === "merge") {
|
|
885
|
+
const cacheSet = this.getCache();
|
|
886
|
+
if (cacheSet) {
|
|
887
|
+
for (const x of cacheSet) {
|
|
888
|
+
set.add(x);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
this.setCache(set);
|
|
892
|
+
}
|
|
893
|
+
return set;
|
|
894
|
+
}
|
|
895
|
+
async extract(options) {
|
|
896
|
+
const { output, tailwindcss } = options ?? {};
|
|
897
|
+
if (output && tailwindcss) {
|
|
898
|
+
const { removeUniversalSelector, filename, loose } = output;
|
|
899
|
+
await processTailwindcss(tailwindcss);
|
|
900
|
+
const set = this.getClassSet({
|
|
901
|
+
removeUniversalSelector
|
|
902
|
+
});
|
|
903
|
+
if (filename) {
|
|
904
|
+
await fs5.ensureDir(path7.dirname(filename));
|
|
905
|
+
const classList = [...set];
|
|
906
|
+
await fs5.outputJSON(filename, classList, {
|
|
907
|
+
spaces: loose ? 2 : void 0
|
|
908
|
+
});
|
|
909
|
+
return filename;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
export {
|
|
916
|
+
config_exports,
|
|
917
|
+
logger_default,
|
|
918
|
+
getCacheOptions,
|
|
919
|
+
CacheManager,
|
|
920
|
+
getPatchOptions,
|
|
921
|
+
monkeyPatchForExposingContextV3,
|
|
922
|
+
monkeyPatchForExposingContextV2,
|
|
923
|
+
monkeyPatchForSupportingCustomUnit,
|
|
924
|
+
internalPatch,
|
|
925
|
+
TailwindcssPatcher
|
|
926
|
+
};
|