tailwindcss-patch 7.1.5 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -73
- package/dist/chunk-FSTUQMKT.js +1320 -0
- package/dist/chunk-Y45IACSP.mjs +1316 -0
- package/dist/cli.js +131 -38
- package/dist/cli.mjs +132 -38
- package/dist/index.d.mts +237 -87
- package/dist/index.d.ts +237 -87
- package/dist/index.js +6 -2
- package/dist/index.mjs +19 -15
- package/package.json +20 -20
- package/dist/chunk-N2DIY7M3.js +0 -1107
- package/dist/chunk-NS2I2YPX.mjs +0 -1102
package/dist/chunk-N2DIY7M3.js
DELETED
|
@@ -1,1107 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
2
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
3
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
4
|
-
|
|
5
|
-
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
6
|
-
function isPlainObject(value) {
|
|
7
|
-
if (value === null || typeof value !== "object") {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const prototype = Object.getPrototypeOf(value);
|
|
11
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (Symbol.iterator in value) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (Symbol.toStringTag in value) {
|
|
18
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
23
|
-
if (!isPlainObject(defaults)) {
|
|
24
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
25
|
-
}
|
|
26
|
-
const object = Object.assign({}, defaults);
|
|
27
|
-
for (const key in baseObject) {
|
|
28
|
-
if (key === "__proto__" || key === "constructor") {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const value = baseObject[key];
|
|
32
|
-
if (value === null || value === void 0) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
39
|
-
object[key] = [...value, ...object[key]];
|
|
40
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
41
|
-
object[key] = _defu(
|
|
42
|
-
value,
|
|
43
|
-
object[key],
|
|
44
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
45
|
-
merger
|
|
46
|
-
);
|
|
47
|
-
} else {
|
|
48
|
-
object[key] = value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return object;
|
|
52
|
-
}
|
|
53
|
-
function createDefu(merger) {
|
|
54
|
-
return (...arguments_) => (
|
|
55
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
56
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
var defu = createDefu();
|
|
60
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
61
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
62
|
-
object[key] = currentValue(object[key]);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
67
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
68
|
-
object[key] = currentValue(object[key]);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// ../shared/src/utils.ts
|
|
74
|
-
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
75
|
-
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
76
|
-
obj[key] = value;
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
var preserveClassNames = [
|
|
81
|
-
// https://tailwindcss.com/docs/transition-timing-function start
|
|
82
|
-
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
83
|
-
"ease-out",
|
|
84
|
-
"ease-linear",
|
|
85
|
-
"ease-in",
|
|
86
|
-
"ease-in-out"
|
|
87
|
-
// https://tailwindcss.com/docs/transition-timing-function end
|
|
88
|
-
];
|
|
89
|
-
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
90
|
-
acc[cur] = true;
|
|
91
|
-
return acc;
|
|
92
|
-
}, {});
|
|
93
|
-
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
94
|
-
|
|
95
|
-
// src/logger.ts
|
|
96
|
-
var _consola = require('consola');
|
|
97
|
-
var logger = _consola.createConsola.call(void 0, );
|
|
98
|
-
var logger_default = logger;
|
|
99
|
-
|
|
100
|
-
// src/core/cache.ts
|
|
101
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
102
|
-
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
103
|
-
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
104
|
-
|
|
105
|
-
// src/constants.ts
|
|
106
|
-
var pkgName = "tailwindcss-patch";
|
|
107
|
-
|
|
108
|
-
// src/core/cache.ts
|
|
109
|
-
function getCacheOptions(options) {
|
|
110
|
-
let cache;
|
|
111
|
-
switch (typeof options) {
|
|
112
|
-
case "undefined": {
|
|
113
|
-
cache = {
|
|
114
|
-
enable: false
|
|
115
|
-
};
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "boolean": {
|
|
119
|
-
cache = {
|
|
120
|
-
enable: options
|
|
121
|
-
};
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case "object": {
|
|
125
|
-
cache = { ...options, enable: true };
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return cache;
|
|
130
|
-
}
|
|
131
|
-
var CacheManager = class {
|
|
132
|
-
|
|
133
|
-
constructor(options = {}) {
|
|
134
|
-
this.options = this.getOptions(options);
|
|
135
|
-
}
|
|
136
|
-
getOptions(options = {}) {
|
|
137
|
-
const cwd = _nullishCoalesce(options.cwd, () => ( _process2.default.cwd()));
|
|
138
|
-
const dir = _nullishCoalesce(options.dir, () => ( _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName)));
|
|
139
|
-
const file = _nullishCoalesce(options.file, () => ( "index.json"));
|
|
140
|
-
const filename = _pathe2.default.resolve(dir, file);
|
|
141
|
-
return {
|
|
142
|
-
cwd,
|
|
143
|
-
dir,
|
|
144
|
-
file,
|
|
145
|
-
filename,
|
|
146
|
-
strategy: "merge"
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
write(data) {
|
|
150
|
-
try {
|
|
151
|
-
const { filename } = this.options;
|
|
152
|
-
_fsextra2.default.outputJSONSync(filename, [...data]);
|
|
153
|
-
return filename;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
logger_default.error(error);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
read() {
|
|
159
|
-
const { filename } = this.options;
|
|
160
|
-
const isExisted = _fsextra2.default.existsSync(filename);
|
|
161
|
-
try {
|
|
162
|
-
if (isExisted) {
|
|
163
|
-
const data = _fsextra2.default.readJSONSync(filename);
|
|
164
|
-
return new Set(_nullishCoalesce(data, () => ( [])));
|
|
165
|
-
}
|
|
166
|
-
} catch (e2) {
|
|
167
|
-
try {
|
|
168
|
-
isExisted && _fsextra2.default.removeSync(filename);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
logger_default.error(error);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return /* @__PURE__ */ new Set();
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/defaults.ts
|
|
178
|
-
|
|
179
|
-
function getDefaultPatchOptions() {
|
|
180
|
-
return {
|
|
181
|
-
packageName: "tailwindcss",
|
|
182
|
-
applyPatches: {
|
|
183
|
-
exportContext: true,
|
|
184
|
-
extendLengthUnits: false
|
|
185
|
-
},
|
|
186
|
-
overwrite: true,
|
|
187
|
-
filter: () => true
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function getPatchOptions(options) {
|
|
191
|
-
return defu(
|
|
192
|
-
options,
|
|
193
|
-
{
|
|
194
|
-
output: {
|
|
195
|
-
removeUniversalSelector: true
|
|
196
|
-
},
|
|
197
|
-
basedir: _process2.default.cwd()
|
|
198
|
-
},
|
|
199
|
-
getDefaultPatchOptions()
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/core/patches/exportContext/index.ts
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// src/core/patches/exportContext/postcss-v2.ts
|
|
208
|
-
var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
|
|
209
|
-
|
|
210
|
-
// src/babel/index.ts
|
|
211
|
-
var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
|
|
212
|
-
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
213
|
-
var _parser = require('@babel/parser');
|
|
214
|
-
function _interopDefaultCompat(e) {
|
|
215
|
-
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
216
|
-
}
|
|
217
|
-
var generate = _interopDefaultCompat(_generator2.default);
|
|
218
|
-
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
219
|
-
|
|
220
|
-
// src/core/patches/exportContext/postcss-v2.ts
|
|
221
|
-
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
222
|
-
const ast = _parser.parse.call(void 0, content, {
|
|
223
|
-
sourceType: "unambiguous"
|
|
224
|
-
});
|
|
225
|
-
let hasPatched = false;
|
|
226
|
-
traverse(ast, {
|
|
227
|
-
FunctionDeclaration(p) {
|
|
228
|
-
const n = p.node;
|
|
229
|
-
if (_optionalChain([n, 'access', _ => _.id, 'optionalAccess', _2 => _2.name]) === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
230
|
-
const rts = n.body.body[0];
|
|
231
|
-
if (t.isFunctionExpression(rts.argument)) {
|
|
232
|
-
const body = rts.argument.body.body;
|
|
233
|
-
const lastStatement = body[body.length - 1];
|
|
234
|
-
hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
235
|
-
if (!hasPatched) {
|
|
236
|
-
const rts2 = t.returnStatement(t.identifier("context"));
|
|
237
|
-
body.push(rts2);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
return {
|
|
244
|
-
code: hasPatched ? content : generate(ast).code,
|
|
245
|
-
hasPatched
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
function inspectPostcssPlugin(content) {
|
|
249
|
-
const ast = _parser.parse.call(void 0, content);
|
|
250
|
-
const exportKey = "contextRef";
|
|
251
|
-
const variableName = "contextRef";
|
|
252
|
-
const valueKey = "value";
|
|
253
|
-
let hasPatched = false;
|
|
254
|
-
traverse(ast, {
|
|
255
|
-
Program(p) {
|
|
256
|
-
const n = p.node;
|
|
257
|
-
const idx = n.body.findIndex((x) => {
|
|
258
|
-
return t.isFunctionDeclaration(x) && _optionalChain([x, 'access', _3 => _3.id, 'optionalAccess', _4 => _4.name]) === "_default";
|
|
259
|
-
});
|
|
260
|
-
if (idx > -1) {
|
|
261
|
-
const prevStatement = n.body[idx - 1];
|
|
262
|
-
const lastStatement = n.body[idx - 2];
|
|
263
|
-
const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
264
|
-
const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
265
|
-
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
266
|
-
if (!hasPatched) {
|
|
267
|
-
const statement = t.variableDeclaration("var", [
|
|
268
|
-
t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
|
|
269
|
-
]);
|
|
270
|
-
n.body.splice(
|
|
271
|
-
idx,
|
|
272
|
-
0,
|
|
273
|
-
statement,
|
|
274
|
-
// exports.contextRef = contextRef;
|
|
275
|
-
t.expressionStatement(
|
|
276
|
-
t.assignmentExpression(
|
|
277
|
-
"=",
|
|
278
|
-
t.memberExpression(t.identifier("exports"), t.identifier(exportKey)),
|
|
279
|
-
t.identifier(variableName)
|
|
280
|
-
)
|
|
281
|
-
)
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
FunctionDeclaration(p) {
|
|
287
|
-
if (hasPatched) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const n = p.node;
|
|
291
|
-
if (_optionalChain([n, 'access', _5 => _5.id, 'optionalAccess', _6 => _6.name]) === "_default" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
292
|
-
const returnStatement3 = n.body.body[0];
|
|
293
|
-
if (t.isCallExpression(returnStatement3.argument) && t.isMemberExpression(returnStatement3.argument.callee) && t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
294
|
-
const targetFn = returnStatement3.argument.callee.object.elements[1];
|
|
295
|
-
if (t.isFunctionExpression(targetFn)) {
|
|
296
|
-
const targetBlockStatement = targetFn.body;
|
|
297
|
-
if (t.isExpressionStatement(targetBlockStatement.body[0]) && t.isAssignmentExpression(targetBlockStatement.body[0].expression) && t.isNumericLiteral(targetBlockStatement.body[0].expression.right)) {
|
|
298
|
-
hasPatched = true;
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
302
|
-
if (t.isExpressionStatement(lastStatement)) {
|
|
303
|
-
const newExpressionStatement = t.expressionStatement(
|
|
304
|
-
t.callExpression(
|
|
305
|
-
t.memberExpression(
|
|
306
|
-
t.memberExpression(t.identifier(variableName), t.identifier("value")),
|
|
307
|
-
t.identifier("push")
|
|
308
|
-
),
|
|
309
|
-
[lastStatement.expression]
|
|
310
|
-
)
|
|
311
|
-
);
|
|
312
|
-
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
313
|
-
}
|
|
314
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
|
|
315
|
-
if (ifIdx > -1) {
|
|
316
|
-
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
317
|
-
if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
318
|
-
const forOf = ifRoot.consequent.body[1];
|
|
319
|
-
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
|
|
320
|
-
const if2 = forOf.body.body[0];
|
|
321
|
-
if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
|
|
322
|
-
const target = if2.consequent.body[0];
|
|
323
|
-
const newExpressionStatement = t.expressionStatement(
|
|
324
|
-
t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
|
|
325
|
-
);
|
|
326
|
-
if2.consequent.body[0] = newExpressionStatement;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
targetBlockStatement.body.unshift(
|
|
332
|
-
// contentRef.value = []
|
|
333
|
-
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
334
|
-
// contentRef.value.length = 0
|
|
335
|
-
t.expressionStatement(
|
|
336
|
-
t.assignmentExpression(
|
|
337
|
-
"=",
|
|
338
|
-
t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
|
|
339
|
-
t.numericLiteral(0)
|
|
340
|
-
)
|
|
341
|
-
)
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
return {
|
|
349
|
-
code: hasPatched ? content : generate(ast).code,
|
|
350
|
-
hasPatched
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// src/core/patches/exportContext/postcss-v3.ts
|
|
355
|
-
|
|
356
|
-
function inspectProcessTailwindFeaturesReturnContext2(content) {
|
|
357
|
-
const ast = _parser.parse.call(void 0, content);
|
|
358
|
-
let hasPatched = false;
|
|
359
|
-
traverse(ast, {
|
|
360
|
-
FunctionDeclaration(p) {
|
|
361
|
-
const n = p.node;
|
|
362
|
-
if (_optionalChain([n, 'access', _7 => _7.id, 'optionalAccess', _8 => _8.name]) === "processTailwindFeatures" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
363
|
-
const rts = n.body.body[0];
|
|
364
|
-
if (t2.isFunctionExpression(rts.argument)) {
|
|
365
|
-
const body = rts.argument.body.body;
|
|
366
|
-
const lastStatement = body[body.length - 1];
|
|
367
|
-
hasPatched = t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
368
|
-
if (!hasPatched) {
|
|
369
|
-
const rts2 = t2.returnStatement(t2.identifier("context"));
|
|
370
|
-
body.push(rts2);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
return {
|
|
377
|
-
code: hasPatched ? content : generate(ast).code,
|
|
378
|
-
hasPatched
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
function inspectPostcssPlugin2(content) {
|
|
382
|
-
const ast = _parser.parse.call(void 0, content);
|
|
383
|
-
const exportKey = "contextRef";
|
|
384
|
-
const variableName = "contextRef";
|
|
385
|
-
const valueKey = "value";
|
|
386
|
-
let hasPatched = false;
|
|
387
|
-
traverse(ast, {
|
|
388
|
-
Program(p) {
|
|
389
|
-
const n = p.node;
|
|
390
|
-
const idx = n.body.findIndex((x) => {
|
|
391
|
-
return t2.isExpressionStatement(x) && t2.isAssignmentExpression(x.expression) && t2.isMemberExpression(x.expression.left) && t2.isFunctionExpression(x.expression.right) && _optionalChain([x, 'access', _9 => _9.expression, 'access', _10 => _10.right, 'access', _11 => _11.id, 'optionalAccess', _12 => _12.name]) === "tailwindcss";
|
|
392
|
-
});
|
|
393
|
-
if (idx > -1) {
|
|
394
|
-
const prevStatement = n.body[idx - 1];
|
|
395
|
-
const lastStatement = n.body[n.body.length - 1];
|
|
396
|
-
const hasPatchedCondition0 = prevStatement && t2.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t2.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
397
|
-
const hasPatchedCondition1 = t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
398
|
-
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
399
|
-
if (!hasPatched) {
|
|
400
|
-
const statement = t2.variableDeclaration("const", [
|
|
401
|
-
t2.variableDeclarator(t2.identifier(variableName), t2.objectExpression([t2.objectProperty(t2.identifier(valueKey), t2.arrayExpression())]))
|
|
402
|
-
]);
|
|
403
|
-
n.body.splice(idx, 0, statement);
|
|
404
|
-
n.body.push(
|
|
405
|
-
t2.expressionStatement(
|
|
406
|
-
t2.assignmentExpression(
|
|
407
|
-
"=",
|
|
408
|
-
t2.memberExpression(t2.memberExpression(t2.identifier("module"), t2.identifier("exports")), t2.identifier(exportKey)),
|
|
409
|
-
t2.identifier(variableName)
|
|
410
|
-
)
|
|
411
|
-
)
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
FunctionExpression(p) {
|
|
417
|
-
if (hasPatched) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
const n = p.node;
|
|
421
|
-
if (_optionalChain([n, 'access', _13 => _13.id, 'optionalAccess', _14 => _14.name]) === "tailwindcss" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
422
|
-
const returnStatement3 = n.body.body[0];
|
|
423
|
-
if (t2.isObjectExpression(returnStatement3.argument) && returnStatement3.argument.properties.length === 2) {
|
|
424
|
-
const properties = returnStatement3.argument.properties;
|
|
425
|
-
if (t2.isObjectProperty(properties[0]) && t2.isObjectProperty(properties[1])) {
|
|
426
|
-
const keyMatched = t2.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
|
|
427
|
-
const pluginsMatched = t2.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
|
|
428
|
-
if (pluginsMatched && keyMatched && t2.isCallExpression(properties[1].value) && t2.isMemberExpression(properties[1].value.callee) && t2.isArrayExpression(properties[1].value.callee.object)) {
|
|
429
|
-
const pluginsCode = properties[1].value.callee.object.elements;
|
|
430
|
-
if (pluginsCode[1] && t2.isFunctionExpression(pluginsCode[1])) {
|
|
431
|
-
const targetBlockStatement = pluginsCode[1].body;
|
|
432
|
-
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
433
|
-
if (t2.isExpressionStatement(lastStatement)) {
|
|
434
|
-
const newExpressionStatement = t2.expressionStatement(
|
|
435
|
-
t2.callExpression(
|
|
436
|
-
t2.memberExpression(
|
|
437
|
-
t2.memberExpression(t2.identifier(variableName), t2.identifier("value")),
|
|
438
|
-
t2.identifier("push")
|
|
439
|
-
),
|
|
440
|
-
[lastStatement.expression]
|
|
441
|
-
)
|
|
442
|
-
);
|
|
443
|
-
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
444
|
-
}
|
|
445
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) => t2.isIfStatement(x));
|
|
446
|
-
if (ifIdx > -1) {
|
|
447
|
-
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
448
|
-
if (t2.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t2.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
449
|
-
const forOf = ifRoot.consequent.body[1];
|
|
450
|
-
if (t2.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t2.isIfStatement(forOf.body.body[0])) {
|
|
451
|
-
const if2 = forOf.body.body[0];
|
|
452
|
-
if (t2.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t2.isExpressionStatement(if2.consequent.body[0])) {
|
|
453
|
-
const target = if2.consequent.body[0];
|
|
454
|
-
const newExpressionStatement = t2.expressionStatement(
|
|
455
|
-
t2.callExpression(t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier("value")), t2.identifier("push")), [target.expression])
|
|
456
|
-
);
|
|
457
|
-
if2.consequent.body[0] = newExpressionStatement;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
targetBlockStatement.body.unshift(
|
|
463
|
-
// contentRef.value = []
|
|
464
|
-
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
465
|
-
// contentRef.value.length = 0
|
|
466
|
-
t2.expressionStatement(
|
|
467
|
-
t2.assignmentExpression(
|
|
468
|
-
"=",
|
|
469
|
-
t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier(valueKey)), t2.identifier("length")),
|
|
470
|
-
t2.numericLiteral(0)
|
|
471
|
-
)
|
|
472
|
-
)
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
// BlockStatement(p) {
|
|
481
|
-
// const n = p.node
|
|
482
|
-
// if (start && p.parent.type === 'FunctionExpression' && !p.parent.id) {
|
|
483
|
-
// n.body.unshift(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression())))
|
|
484
|
-
// }
|
|
485
|
-
// }
|
|
486
|
-
});
|
|
487
|
-
return {
|
|
488
|
-
code: hasPatched ? content : generate(ast).code,
|
|
489
|
-
hasPatched
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// src/core/patches/exportContext/index.ts
|
|
494
|
-
function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
495
|
-
const k0 = "lib/processTailwindFeatures.js";
|
|
496
|
-
const processTailwindFeaturesFilePath = _pathe2.default.resolve(twDir, k0);
|
|
497
|
-
const processTailwindFeaturesContent = _fsextra2.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
498
|
-
const result = {};
|
|
499
|
-
if (processTailwindFeaturesContent) {
|
|
500
|
-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext2(processTailwindFeaturesContent);
|
|
501
|
-
if (!hasPatched && opt.overwrite) {
|
|
502
|
-
_fsextra2.default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
503
|
-
encoding: "utf8"
|
|
504
|
-
});
|
|
505
|
-
logger_default.success("patch tailwindcss processTailwindFeatures for return context successfully!");
|
|
506
|
-
}
|
|
507
|
-
result[k0] = code;
|
|
508
|
-
}
|
|
509
|
-
let injectFilepath;
|
|
510
|
-
let k1;
|
|
511
|
-
const try0 = "lib/plugin.js";
|
|
512
|
-
const try1 = "lib/index.js";
|
|
513
|
-
const pluginFilePath = _pathe2.default.resolve(twDir, try0);
|
|
514
|
-
const indexFilePath = _pathe2.default.resolve(twDir, try1);
|
|
515
|
-
if (_fsextra2.default.existsSync(pluginFilePath)) {
|
|
516
|
-
k1 = try0;
|
|
517
|
-
injectFilepath = pluginFilePath;
|
|
518
|
-
} else if (_fsextra2.default.existsSync(indexFilePath)) {
|
|
519
|
-
k1 = try1;
|
|
520
|
-
injectFilepath = indexFilePath;
|
|
521
|
-
}
|
|
522
|
-
if (injectFilepath && k1) {
|
|
523
|
-
const pluginContent = _fsextra2.default.readFileSync(injectFilepath, "utf8");
|
|
524
|
-
if (pluginContent) {
|
|
525
|
-
const { code, hasPatched } = inspectPostcssPlugin2(pluginContent);
|
|
526
|
-
if (!hasPatched && opt.overwrite) {
|
|
527
|
-
_fsextra2.default.writeFileSync(injectFilepath, code, {
|
|
528
|
-
encoding: "utf8"
|
|
529
|
-
});
|
|
530
|
-
logger_default.success("patch tailwindcss for expose runtime context successfully!");
|
|
531
|
-
}
|
|
532
|
-
result[k1] = code;
|
|
533
|
-
}
|
|
534
|
-
return result;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
538
|
-
const k0 = "lib/jit/processTailwindFeatures.js";
|
|
539
|
-
const processTailwindFeaturesFilePath = _pathe2.default.resolve(twDir, k0);
|
|
540
|
-
const processTailwindFeaturesContent = _fsextra2.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
541
|
-
const result = {};
|
|
542
|
-
if (processTailwindFeaturesContent) {
|
|
543
|
-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
544
|
-
if (!hasPatched && opt.overwrite) {
|
|
545
|
-
_fsextra2.default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
546
|
-
encoding: "utf8"
|
|
547
|
-
});
|
|
548
|
-
logger_default.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
549
|
-
}
|
|
550
|
-
result[k0] = code;
|
|
551
|
-
}
|
|
552
|
-
const k1 = "lib/jit/index.js";
|
|
553
|
-
const indexFilePath = _pathe2.default.resolve(twDir, k1);
|
|
554
|
-
const pluginContent = _fsextra2.default.readFileSync(indexFilePath, "utf8");
|
|
555
|
-
if (pluginContent) {
|
|
556
|
-
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
557
|
-
if (!hasPatched && opt.overwrite) {
|
|
558
|
-
_fsextra2.default.writeFileSync(indexFilePath, code, {
|
|
559
|
-
encoding: "utf8"
|
|
560
|
-
});
|
|
561
|
-
logger_default.success("patch tailwindcss for expose runtime content successfully!");
|
|
562
|
-
}
|
|
563
|
-
result[k1] = code;
|
|
564
|
-
}
|
|
565
|
-
return result;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// src/core/patches/supportCustomUnits/index.ts
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
// src/utils.ts
|
|
574
|
-
function isObject(val) {
|
|
575
|
-
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
576
|
-
}
|
|
577
|
-
function spliceChangesIntoString(str, changes) {
|
|
578
|
-
if (!changes[0]) {
|
|
579
|
-
return str;
|
|
580
|
-
}
|
|
581
|
-
changes.sort((a, b) => {
|
|
582
|
-
return a.end - b.end || a.start - b.start;
|
|
583
|
-
});
|
|
584
|
-
let result = "";
|
|
585
|
-
let previous = changes[0];
|
|
586
|
-
result += str.slice(0, previous.start);
|
|
587
|
-
result += previous.replacement;
|
|
588
|
-
for (let i = 1; i < changes.length; ++i) {
|
|
589
|
-
const change = changes[i];
|
|
590
|
-
result += str.slice(previous.end, change.start);
|
|
591
|
-
result += change.replacement;
|
|
592
|
-
previous = change;
|
|
593
|
-
}
|
|
594
|
-
result += str.slice(previous.end);
|
|
595
|
-
return result;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// src/core/patches/supportCustomUnits/index.ts
|
|
599
|
-
function findAstNode(content, options) {
|
|
600
|
-
const { variableName, units } = options;
|
|
601
|
-
const ast = _parser.parse.call(void 0, content);
|
|
602
|
-
let arrayRef;
|
|
603
|
-
let changed = false;
|
|
604
|
-
traverse(ast, {
|
|
605
|
-
Identifier(path7) {
|
|
606
|
-
if (path7.node.name === variableName && t3.isVariableDeclarator(path7.parent) && t3.isArrayExpression(path7.parent.init)) {
|
|
607
|
-
arrayRef = path7.parent.init;
|
|
608
|
-
const set = new Set(path7.parent.init.elements.map((x) => x.value));
|
|
609
|
-
for (const unit of units) {
|
|
610
|
-
if (!set.has(unit)) {
|
|
611
|
-
path7.parent.init.elements = path7.parent.init.elements.map((x) => {
|
|
612
|
-
if (t3.isStringLiteral(x)) {
|
|
613
|
-
return {
|
|
614
|
-
type: x.type,
|
|
615
|
-
value: x.value
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
return x;
|
|
619
|
-
});
|
|
620
|
-
path7.parent.init.elements.push({
|
|
621
|
-
type: "StringLiteral",
|
|
622
|
-
value: unit
|
|
623
|
-
});
|
|
624
|
-
changed = true;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
return {
|
|
631
|
-
arrayRef,
|
|
632
|
-
changed
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
function monkeyPatchForSupportingCustomUnitV3(rootDir, options) {
|
|
636
|
-
const opts = defuOverrideArray(options, {
|
|
637
|
-
units: ["rpx"],
|
|
638
|
-
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
639
|
-
variableName: "lengthUnits",
|
|
640
|
-
overwrite: true
|
|
641
|
-
});
|
|
642
|
-
const { lengthUnitsFilePath, overwrite, destPath } = opts;
|
|
643
|
-
const dataTypesFilePath = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
|
|
644
|
-
const dataTypesFileContent = _fsextra2.default.readFileSync(dataTypesFilePath, {
|
|
645
|
-
encoding: "utf8"
|
|
646
|
-
});
|
|
647
|
-
const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
|
|
648
|
-
if (arrayRef && changed) {
|
|
649
|
-
const { code } = generate(arrayRef, {
|
|
650
|
-
jsescOption: {
|
|
651
|
-
quotes: "single"
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
if (arrayRef.start && arrayRef.end) {
|
|
655
|
-
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
656
|
-
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
657
|
-
const newCode = prev + code + next;
|
|
658
|
-
if (overwrite) {
|
|
659
|
-
_fsextra2.default.writeFileSync(_nullishCoalesce(destPath, () => ( dataTypesFilePath)), newCode, {
|
|
660
|
-
encoding: "utf8"
|
|
661
|
-
});
|
|
662
|
-
logger_default.success("patch tailwindcss for custom length unit successfully!");
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
return {
|
|
666
|
-
[opts.lengthUnitsFilePath]: code
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
function monkeyPatchForSupportingCustomUnitV4(rootDir, options) {
|
|
671
|
-
const opts = defuOverrideArray(options, {
|
|
672
|
-
units: ["rpx"],
|
|
673
|
-
overwrite: true
|
|
674
|
-
});
|
|
675
|
-
const distPath = _pathe2.default.resolve(rootDir, "dist");
|
|
676
|
-
const list = _fsextra2.default.readdirSync(distPath);
|
|
677
|
-
const chunks = list.filter((x) => x.endsWith("js"));
|
|
678
|
-
const guessUnitStart = /\[\s*["']cm["'],\s*["']mm["'],[\w,"]+\]/;
|
|
679
|
-
const guessFiles = chunks.reduce((acc, chunkName) => {
|
|
680
|
-
const guessFile = _pathe2.default.join(distPath, chunkName);
|
|
681
|
-
const code = _fsextra2.default.readFileSync(guessFile, "utf8");
|
|
682
|
-
const matches = guessUnitStart.exec(code);
|
|
683
|
-
if (matches && code) {
|
|
684
|
-
acc.push({
|
|
685
|
-
code,
|
|
686
|
-
hasPatched: false,
|
|
687
|
-
file: guessFile,
|
|
688
|
-
matches
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
return acc;
|
|
692
|
-
}, []);
|
|
693
|
-
for (const item of guessFiles) {
|
|
694
|
-
const { matches, code, file } = item;
|
|
695
|
-
const match = matches[0];
|
|
696
|
-
const ast = _parser.parse.call(void 0, match, {
|
|
697
|
-
sourceType: "unambiguous"
|
|
698
|
-
});
|
|
699
|
-
traverse(ast, {
|
|
700
|
-
ArrayExpression(path7) {
|
|
701
|
-
for (const unit of opts.units) {
|
|
702
|
-
if (path7.node.elements.some((x) => t3.isStringLiteral(x) && x.value === unit)) {
|
|
703
|
-
item.hasPatched = true;
|
|
704
|
-
break;
|
|
705
|
-
}
|
|
706
|
-
path7.node.elements.push(t3.stringLiteral(unit));
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
if (item.hasPatched) {
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
const { code: replacement } = generate(ast, {
|
|
714
|
-
minified: true
|
|
715
|
-
});
|
|
716
|
-
item.code = spliceChangesIntoString(code, [
|
|
717
|
-
{
|
|
718
|
-
start: matches.index,
|
|
719
|
-
end: matches.index + match.length,
|
|
720
|
-
replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
|
|
721
|
-
}
|
|
722
|
-
]);
|
|
723
|
-
if (opts.overwrite && file) {
|
|
724
|
-
_fsextra2.default.writeFileSync(file, item.code, {
|
|
725
|
-
encoding: "utf8"
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
if (guessFiles.some((x) => !x.hasPatched)) {
|
|
730
|
-
logger_default.success("patch tailwindcss for custom length unit successfully!");
|
|
731
|
-
}
|
|
732
|
-
return {
|
|
733
|
-
files: guessFiles
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// src/core/runtime.ts
|
|
738
|
-
var _module = require('module');
|
|
739
|
-
|
|
740
|
-
var _semver = require('semver');
|
|
741
|
-
var require2 = _module.createRequire.call(void 0, importMetaUrl);
|
|
742
|
-
function internalPatch(pkgJsonPath, options) {
|
|
743
|
-
if (pkgJsonPath) {
|
|
744
|
-
let pkgJson;
|
|
745
|
-
let twDir;
|
|
746
|
-
if (typeof pkgJsonPath === "string") {
|
|
747
|
-
pkgJson = require2(pkgJsonPath);
|
|
748
|
-
twDir = _pathe2.default.dirname(pkgJsonPath);
|
|
749
|
-
options.version = pkgJson.version;
|
|
750
|
-
} else if (typeof pkgJsonPath === "object") {
|
|
751
|
-
pkgJson = pkgJsonPath.packageJson;
|
|
752
|
-
twDir = pkgJsonPath.rootPath;
|
|
753
|
-
options.version = pkgJsonPath.version;
|
|
754
|
-
} else {
|
|
755
|
-
throw new TypeError("tailwindcss not found");
|
|
756
|
-
}
|
|
757
|
-
if (_semver.gte.call(void 0, pkgJson.version, "4.0.0")) {
|
|
758
|
-
try {
|
|
759
|
-
if (_optionalChain([options, 'access', _15 => _15.applyPatches, 'optionalAccess', _16 => _16.extendLengthUnits])) {
|
|
760
|
-
return monkeyPatchForSupportingCustomUnitV4(twDir, options);
|
|
761
|
-
}
|
|
762
|
-
} catch (e3) {
|
|
763
|
-
}
|
|
764
|
-
} else if (_semver.gte.call(void 0, pkgJson.version, "3.0.0")) {
|
|
765
|
-
let result = {};
|
|
766
|
-
if (_optionalChain([options, 'access', _17 => _17.applyPatches, 'optionalAccess', _18 => _18.exportContext])) {
|
|
767
|
-
result = monkeyPatchForExposingContextV3(twDir, options);
|
|
768
|
-
}
|
|
769
|
-
if (_optionalChain([options, 'access', _19 => _19.applyPatches, 'optionalAccess', _20 => _20.extendLengthUnits])) {
|
|
770
|
-
try {
|
|
771
|
-
Object.assign(_nullishCoalesce(result, () => ( {})), monkeyPatchForSupportingCustomUnitV3(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
|
|
772
|
-
overwrite: options.overwrite
|
|
773
|
-
})));
|
|
774
|
-
} catch (e4) {
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return result;
|
|
778
|
-
} else if (_semver.gte.call(void 0, pkgJson.version, "2.0.0")) {
|
|
779
|
-
if (_optionalChain([options, 'access', _21 => _21.applyPatches, 'optionalAccess', _22 => _22.exportContext])) {
|
|
780
|
-
return monkeyPatchForExposingContextV2(twDir, options);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// src/core/patcher.ts
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
var _localpkg = require('local-pkg');
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
// src/core/candidates.ts
|
|
794
|
-
|
|
795
|
-
function importNode() {
|
|
796
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
|
|
797
|
-
}
|
|
798
|
-
function importOxide() {
|
|
799
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
|
|
800
|
-
}
|
|
801
|
-
async function extractRawCandidates(sources) {
|
|
802
|
-
const { Scanner } = await importOxide();
|
|
803
|
-
const scanner = new Scanner({
|
|
804
|
-
sources
|
|
805
|
-
});
|
|
806
|
-
const candidates = scanner.scan();
|
|
807
|
-
return candidates;
|
|
808
|
-
}
|
|
809
|
-
async function extractValidCandidates(options) {
|
|
810
|
-
const defaultCwd = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _23 => _23.cwd]), () => ( _process2.default.cwd()));
|
|
811
|
-
const { sources, base, css } = defuOverrideArray(
|
|
812
|
-
// @ts-ignore
|
|
813
|
-
options,
|
|
814
|
-
{
|
|
815
|
-
css: '@import "tailwindcss";',
|
|
816
|
-
base: defaultCwd,
|
|
817
|
-
sources: [
|
|
818
|
-
{
|
|
819
|
-
base: defaultCwd,
|
|
820
|
-
pattern: "**/*",
|
|
821
|
-
negated: false
|
|
822
|
-
}
|
|
823
|
-
]
|
|
824
|
-
}
|
|
825
|
-
);
|
|
826
|
-
const { __unstable__loadDesignSystem } = await importNode();
|
|
827
|
-
const designSystem = await __unstable__loadDesignSystem(css, { base });
|
|
828
|
-
const candidates = await extractRawCandidates(sources);
|
|
829
|
-
const validCandidates = candidates.filter(
|
|
830
|
-
(rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
|
|
831
|
-
);
|
|
832
|
-
return validCandidates;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
// src/core/postcss.ts
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
840
|
-
var _tailwindcssconfig = require('tailwindcss-config');
|
|
841
|
-
var require3 = _module.createRequire.call(void 0, importMetaUrl);
|
|
842
|
-
async function processTailwindcss(options) {
|
|
843
|
-
const { config: userConfig, cwd, majorVersion, postcssPlugin } = defu(options, {
|
|
844
|
-
cwd: _process2.default.cwd(),
|
|
845
|
-
majorVersion: 3
|
|
846
|
-
});
|
|
847
|
-
let config = userConfig;
|
|
848
|
-
if (!(typeof config === "string" && _pathe2.default.isAbsolute(config))) {
|
|
849
|
-
const result = await _tailwindcssconfig.loadConfig.call(void 0, {
|
|
850
|
-
cwd
|
|
851
|
-
});
|
|
852
|
-
if (!result) {
|
|
853
|
-
throw new Error(`No TailwindCSS Config found in: ${cwd}`);
|
|
854
|
-
}
|
|
855
|
-
config = result.filepath;
|
|
856
|
-
}
|
|
857
|
-
const targetPostcssPlugin = _nullishCoalesce(postcssPlugin, () => ( (majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
|
|
858
|
-
if (majorVersion === 4) {
|
|
859
|
-
return await _postcss2.default.call(void 0, [
|
|
860
|
-
require3(targetPostcssPlugin)({
|
|
861
|
-
config
|
|
862
|
-
})
|
|
863
|
-
]).process("@import 'tailwindcss';", {
|
|
864
|
-
from: void 0
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
return await _postcss2.default.call(void 0, [
|
|
868
|
-
require3(targetPostcssPlugin)({
|
|
869
|
-
config
|
|
870
|
-
})
|
|
871
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
872
|
-
from: void 0
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
// src/core/patcher.ts
|
|
877
|
-
var require4 = _module.createRequire.call(void 0, importMetaUrl);
|
|
878
|
-
var TailwindcssPatcher = (_class = class {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
constructor(options = {}) {;_class.prototype.__init.call(this);
|
|
888
|
-
this.rawOptions = options;
|
|
889
|
-
this.cacheOptions = getCacheOptions(options.cache);
|
|
890
|
-
this.patchOptions = getPatchOptions(options.patch);
|
|
891
|
-
this.cacheManager = new CacheManager(this.cacheOptions);
|
|
892
|
-
this.filter = function filter(className) {
|
|
893
|
-
if (_optionalChain([this, 'access', _24 => _24.patchOptions, 'access', _25 => _25.output, 'optionalAccess', _26 => _26.removeUniversalSelector]) && className === "*") {
|
|
894
|
-
return false;
|
|
895
|
-
}
|
|
896
|
-
return Boolean(_optionalChain([this, 'access', _27 => _27.patchOptions, 'access', _28 => _28.filter, 'optionalCall', _29 => _29(className)]));
|
|
897
|
-
};
|
|
898
|
-
const packageInfo = _localpkg.getPackageInfoSync.call(void 0,
|
|
899
|
-
_nullishCoalesce(this.patchOptions.packageName, () => ( "tailwindcss")),
|
|
900
|
-
this.patchOptions.resolve
|
|
901
|
-
);
|
|
902
|
-
if (!packageInfo) {
|
|
903
|
-
throw new Error("tailwindcss not found");
|
|
904
|
-
}
|
|
905
|
-
if (packageInfo.version) {
|
|
906
|
-
this.majorVersion = Number.parseInt(packageInfo.version[0]);
|
|
907
|
-
}
|
|
908
|
-
if (_optionalChain([this, 'access', _30 => _30.patchOptions, 'access', _31 => _31.tailwindcss, 'optionalAccess', _32 => _32.version])) {
|
|
909
|
-
this.majorVersion = this.patchOptions.tailwindcss.version;
|
|
910
|
-
}
|
|
911
|
-
this.packageInfo = packageInfo;
|
|
912
|
-
this.patch = () => {
|
|
913
|
-
try {
|
|
914
|
-
return internalPatch(this.packageInfo, this.patchOptions);
|
|
915
|
-
} catch (error) {
|
|
916
|
-
logger_default.error(`Patch Tailwind CSS Failed: ${error.message}`);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
setCache(set) {
|
|
921
|
-
if (this.cacheOptions.enable) {
|
|
922
|
-
return this.cacheManager.write(set);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
getCache() {
|
|
926
|
-
return this.cacheManager.read();
|
|
927
|
-
}
|
|
928
|
-
getContexts() {
|
|
929
|
-
if (this.packageInfo) {
|
|
930
|
-
const distPath = _pathe2.default.join(this.packageInfo.rootPath, "lib");
|
|
931
|
-
let injectFilePath;
|
|
932
|
-
if (this.majorVersion === 2) {
|
|
933
|
-
injectFilePath = _pathe2.default.join(distPath, "jit/index.js");
|
|
934
|
-
} else if (this.majorVersion === 3) {
|
|
935
|
-
injectFilePath = _pathe2.default.join(distPath, "plugin.js");
|
|
936
|
-
if (!_fsextra2.default.existsSync(injectFilePath)) {
|
|
937
|
-
injectFilePath = _pathe2.default.join(distPath, "index.js");
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (injectFilePath) {
|
|
941
|
-
const mo = require4(injectFilePath);
|
|
942
|
-
if (mo.contextRef) {
|
|
943
|
-
return mo.contextRef.value;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
return [];
|
|
948
|
-
}
|
|
949
|
-
getClassCaches() {
|
|
950
|
-
const contexts = this.getContexts();
|
|
951
|
-
return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
|
|
952
|
-
}
|
|
953
|
-
async getClassCacheSet() {
|
|
954
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
955
|
-
const { tailwindcss, cwd } = this.patchOptions;
|
|
956
|
-
if (this.majorVersion === 4) {
|
|
957
|
-
const { v4 } = _nullishCoalesce(tailwindcss, () => ( {}));
|
|
958
|
-
if (Array.isArray(_optionalChain([v4, 'optionalAccess', _33 => _33.cssEntries]))) {
|
|
959
|
-
const results = (await Promise.all(
|
|
960
|
-
v4.cssEntries.map(async (x) => {
|
|
961
|
-
if (await _fsextra2.default.exists(x)) {
|
|
962
|
-
const css = await _fsextra2.default.readFile(x, "utf8");
|
|
963
|
-
return css;
|
|
964
|
-
}
|
|
965
|
-
return false;
|
|
966
|
-
})
|
|
967
|
-
)).filter((x) => x);
|
|
968
|
-
for (const css of results) {
|
|
969
|
-
const candidates = await extractValidCandidates({
|
|
970
|
-
cwd,
|
|
971
|
-
base: _optionalChain([v4, 'optionalAccess', _34 => _34.base]),
|
|
972
|
-
css,
|
|
973
|
-
sources: _optionalChain([v4, 'optionalAccess', _35 => _35.sources, 'optionalAccess', _36 => _36.map, 'call', _37 => _37((x) => {
|
|
974
|
-
return {
|
|
975
|
-
base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _38 => _38.base]))), () => ( _process2.default.cwd())),
|
|
976
|
-
pattern: x.pattern,
|
|
977
|
-
negated: x.negated
|
|
978
|
-
};
|
|
979
|
-
})])
|
|
980
|
-
});
|
|
981
|
-
for (const candidate of candidates) {
|
|
982
|
-
_optionalChain([this, 'access', _39 => _39.filter, 'optionalCall', _40 => _40(candidate)]) && classSet.add(candidate);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
} else {
|
|
986
|
-
const candidates = await extractValidCandidates({
|
|
987
|
-
cwd,
|
|
988
|
-
base: _optionalChain([v4, 'optionalAccess', _41 => _41.base]),
|
|
989
|
-
css: _optionalChain([v4, 'optionalAccess', _42 => _42.css]),
|
|
990
|
-
sources: _optionalChain([v4, 'optionalAccess', _43 => _43.sources, 'optionalAccess', _44 => _44.map, 'call', _45 => _45((x) => {
|
|
991
|
-
return {
|
|
992
|
-
base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _46 => _46.base]))), () => ( _process2.default.cwd())),
|
|
993
|
-
pattern: x.pattern,
|
|
994
|
-
negated: x.negated
|
|
995
|
-
};
|
|
996
|
-
})])
|
|
997
|
-
});
|
|
998
|
-
for (const candidate of candidates) {
|
|
999
|
-
_optionalChain([this, 'access', _47 => _47.filter, 'optionalCall', _48 => _48(candidate)]) && classSet.add(candidate);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
} else {
|
|
1003
|
-
const classCaches = this.getClassCaches();
|
|
1004
|
-
for (const classCacheMap of classCaches) {
|
|
1005
|
-
const keys = classCacheMap.keys();
|
|
1006
|
-
for (const key of keys) {
|
|
1007
|
-
const v = key.toString();
|
|
1008
|
-
_optionalChain([this, 'access', _49 => _49.filter, 'optionalCall', _50 => _50(v)]) && classSet.add(v);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
return classSet;
|
|
1013
|
-
}
|
|
1014
|
-
getClassCacheSetV3() {
|
|
1015
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
1016
|
-
const classCaches = this.getClassCaches();
|
|
1017
|
-
for (const classCacheMap of classCaches) {
|
|
1018
|
-
const keys = classCacheMap.keys();
|
|
1019
|
-
for (const key of keys) {
|
|
1020
|
-
const v = key.toString();
|
|
1021
|
-
_optionalChain([this, 'access', _51 => _51.filter, 'optionalCall', _52 => _52(v)]) && classSet.add(v);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return classSet;
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
|
|
1028
|
-
*/
|
|
1029
|
-
async getClassSet() {
|
|
1030
|
-
const cacheStrategy = _nullishCoalesce(this.cacheOptions.strategy, () => ( "merge"));
|
|
1031
|
-
const set = await this.getClassCacheSet();
|
|
1032
|
-
if (cacheStrategy === "overwrite") {
|
|
1033
|
-
set.size > 0 && this.setCache(set);
|
|
1034
|
-
} else if (cacheStrategy === "merge") {
|
|
1035
|
-
const cacheSet = this.getCache();
|
|
1036
|
-
if (cacheSet) {
|
|
1037
|
-
for (const x of cacheSet) {
|
|
1038
|
-
set.add(x);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
this.setCache(set);
|
|
1042
|
-
}
|
|
1043
|
-
return set;
|
|
1044
|
-
}
|
|
1045
|
-
getClassSetV3() {
|
|
1046
|
-
const cacheStrategy = _nullishCoalesce(this.cacheOptions.strategy, () => ( "merge"));
|
|
1047
|
-
const set = this.getClassCacheSetV3();
|
|
1048
|
-
if (cacheStrategy === "overwrite") {
|
|
1049
|
-
set.size > 0 && this.setCache(set);
|
|
1050
|
-
} else if (cacheStrategy === "merge") {
|
|
1051
|
-
const cacheSet = this.getCache();
|
|
1052
|
-
if (cacheSet) {
|
|
1053
|
-
for (const x of cacheSet) {
|
|
1054
|
-
set.add(x);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
this.setCache(set);
|
|
1058
|
-
}
|
|
1059
|
-
return set;
|
|
1060
|
-
}
|
|
1061
|
-
async extract(options) {
|
|
1062
|
-
const { write } = defu(options, { write: true });
|
|
1063
|
-
const { output, tailwindcss } = this.patchOptions;
|
|
1064
|
-
if (tailwindcss) {
|
|
1065
|
-
if (this.majorVersion === 3 || this.majorVersion === 2) {
|
|
1066
|
-
await processTailwindcss({
|
|
1067
|
-
...tailwindcss,
|
|
1068
|
-
majorVersion: this.majorVersion
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
const classSet = await this.getClassSet();
|
|
1072
|
-
const classList = [...classSet];
|
|
1073
|
-
const result = {
|
|
1074
|
-
classList,
|
|
1075
|
-
classSet
|
|
1076
|
-
};
|
|
1077
|
-
if (output) {
|
|
1078
|
-
const { filename, loose } = output;
|
|
1079
|
-
if (filename) {
|
|
1080
|
-
if (write) {
|
|
1081
|
-
await _fsextra2.default.outputJSON(filename, classList, {
|
|
1082
|
-
spaces: loose ? 2 : void 0
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
result.filename = filename;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
return result;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
__init() {this.extractValidCandidates = extractValidCandidates}
|
|
1092
|
-
}, _class);
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
exports.importMetaUrl = importMetaUrl; exports.defuOverrideArray = defuOverrideArray; exports.logger_default = logger_default; exports.getCacheOptions = getCacheOptions; exports.CacheManager = CacheManager; exports.getPatchOptions = getPatchOptions; exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3; exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2; exports.monkeyPatchForSupportingCustomUnitV3 = monkeyPatchForSupportingCustomUnitV3; exports.monkeyPatchForSupportingCustomUnitV4 = monkeyPatchForSupportingCustomUnitV4; exports.internalPatch = internalPatch; exports.TailwindcssPatcher = TailwindcssPatcher;
|