tailwindcss-patch 2.0.5 → 2.1.1
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 +48 -13
- package/dist/cli.cjs +46 -0
- package/dist/cli.mjs +20 -13
- package/dist/{chunk-PZNRLYGX.mjs → index.cjs} +180 -253
- package/dist/index.mjs +522 -63
- package/package.json +4 -20
- package/dist/cli.d.mts +0 -2
- package/dist/cli.js +0 -643
- package/dist/index.d.mts +0 -149
- package/dist/index.js +0 -661
|
@@ -1,41 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs$1 = require('node:fs/promises');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const pkg = require('resolve');
|
|
7
|
+
const semver = require('semver');
|
|
8
|
+
const t = require('@babel/types');
|
|
9
|
+
const generate = require('@babel/generator');
|
|
10
|
+
const traverse = require('@babel/traverse');
|
|
11
|
+
const parser = require('@babel/parser');
|
|
12
|
+
const postcss = require('postcss');
|
|
13
|
+
const lilconfig = require('lilconfig');
|
|
14
|
+
const createJiti = require('jiti');
|
|
15
|
+
const config = require('@tailwindcss-mangle/config');
|
|
16
|
+
|
|
17
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
|
+
|
|
19
|
+
function _interopNamespaceCompat(e) {
|
|
20
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
21
|
+
const n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
for (const k in e) {
|
|
24
|
+
n[k] = e[k];
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
n.default = e;
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
32
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
33
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
34
|
+
const pkg__default = /*#__PURE__*/_interopDefaultCompat(pkg);
|
|
35
|
+
const t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
36
|
+
const generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
|
|
37
|
+
const traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
|
|
38
|
+
const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
39
|
+
const createJiti__default = /*#__PURE__*/_interopDefaultCompat(createJiti);
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
import fss from "node:fs";
|
|
28
|
-
import fs from "node:fs/promises";
|
|
29
|
-
import pkg from "resolve";
|
|
30
|
-
var { sync } = pkg;
|
|
41
|
+
const { sync } = pkg__default;
|
|
31
42
|
function ensureFileContent(filepaths) {
|
|
32
43
|
if (typeof filepaths === "string") {
|
|
33
44
|
filepaths = [filepaths];
|
|
34
45
|
}
|
|
35
46
|
let content;
|
|
36
47
|
for (const filepath of filepaths) {
|
|
37
|
-
if (
|
|
38
|
-
content =
|
|
48
|
+
if (fs__default.existsSync(filepath)) {
|
|
49
|
+
content = fs__default.readFileSync(filepath, {
|
|
39
50
|
encoding: "utf8"
|
|
40
51
|
});
|
|
41
52
|
break;
|
|
@@ -48,28 +59,25 @@ function requireResolve(id, opts) {
|
|
|
48
59
|
}
|
|
49
60
|
async function ensureDir(p) {
|
|
50
61
|
try {
|
|
51
|
-
await
|
|
62
|
+
await fs__default$1.access(p);
|
|
52
63
|
} catch {
|
|
53
|
-
await
|
|
64
|
+
await fs__default$1.mkdir(p, {
|
|
54
65
|
recursive: true
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
// src/core/exposeContext.ts
|
|
60
|
-
import path from "node:path";
|
|
61
|
-
import fs2 from "node:fs";
|
|
62
70
|
function getTailwindcssEntry(basedir = process.cwd()) {
|
|
63
71
|
return requireResolve("tailwindcss");
|
|
64
72
|
}
|
|
65
73
|
function getContexts(basedir) {
|
|
66
74
|
const twPath = getTailwindcssEntry(basedir);
|
|
67
|
-
const distPath =
|
|
68
|
-
let injectFilePath =
|
|
69
|
-
if (!
|
|
70
|
-
injectFilePath =
|
|
75
|
+
const distPath = path__default.dirname(twPath);
|
|
76
|
+
let injectFilePath = path__default.join(distPath, "plugin.js");
|
|
77
|
+
if (!fs__default.existsSync(injectFilePath)) {
|
|
78
|
+
injectFilePath = path__default.join(distPath, "index.js");
|
|
71
79
|
}
|
|
72
|
-
const mo =
|
|
80
|
+
const mo = require(injectFilePath);
|
|
73
81
|
if (mo.contextRef) {
|
|
74
82
|
return mo.contextRef.value;
|
|
75
83
|
}
|
|
@@ -95,19 +103,12 @@ function getClassCacheSet(basedir, options) {
|
|
|
95
103
|
return classSet;
|
|
96
104
|
}
|
|
97
105
|
|
|
98
|
-
|
|
99
|
-
import fs3 from "node:fs";
|
|
100
|
-
import path2 from "node:path";
|
|
106
|
+
const pkgName = "tailwindcss-patch";
|
|
101
107
|
|
|
102
|
-
// src/constants.ts
|
|
103
|
-
var pkgName = "tailwindcss-patch";
|
|
104
|
-
|
|
105
|
-
// src/logger.ts
|
|
106
108
|
function log(message, ...optionalParams) {
|
|
107
109
|
return console.log(`[${pkgName}]:` + message, ...optionalParams);
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
// src/core/cache.ts
|
|
111
112
|
function getCacheOptions(options) {
|
|
112
113
|
let cache;
|
|
113
114
|
switch (typeof options) {
|
|
@@ -130,15 +131,14 @@ function getCacheOptions(options) {
|
|
|
130
131
|
}
|
|
131
132
|
return cache;
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
options;
|
|
134
|
+
class CacheManager {
|
|
135
135
|
constructor(options = {}) {
|
|
136
136
|
this.options = this.getOptions(options);
|
|
137
137
|
}
|
|
138
138
|
mkdir(cacheDirectory) {
|
|
139
|
-
const exists =
|
|
139
|
+
const exists = fs__default.existsSync(cacheDirectory);
|
|
140
140
|
if (!exists) {
|
|
141
|
-
|
|
141
|
+
fs__default.mkdirSync(cacheDirectory, {
|
|
142
142
|
recursive: true
|
|
143
143
|
});
|
|
144
144
|
}
|
|
@@ -146,9 +146,9 @@ var CacheManager = class {
|
|
|
146
146
|
}
|
|
147
147
|
getOptions(options = {}) {
|
|
148
148
|
const cwd = options.cwd ?? process.cwd();
|
|
149
|
-
const dir = options.dir ??
|
|
149
|
+
const dir = options.dir ?? path__default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
150
150
|
const file = options.file ?? "index.json";
|
|
151
|
-
const filename =
|
|
151
|
+
const filename = path__default.resolve(dir, file);
|
|
152
152
|
return {
|
|
153
153
|
cwd,
|
|
154
154
|
dir,
|
|
@@ -161,7 +161,7 @@ var CacheManager = class {
|
|
|
161
161
|
try {
|
|
162
162
|
const { dir, filename } = this.options;
|
|
163
163
|
this.mkdir(dir);
|
|
164
|
-
|
|
164
|
+
fs__default.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
165
165
|
return filename;
|
|
166
166
|
} catch {
|
|
167
167
|
log("write cache file fail!");
|
|
@@ -170,44 +170,77 @@ var CacheManager = class {
|
|
|
170
170
|
read() {
|
|
171
171
|
const { filename } = this.options;
|
|
172
172
|
try {
|
|
173
|
-
if (
|
|
174
|
-
const data =
|
|
173
|
+
if (fs__default.existsSync(filename)) {
|
|
174
|
+
const data = fs__default.readFileSync(filename, "utf8");
|
|
175
175
|
return new Set(JSON.parse(data));
|
|
176
176
|
}
|
|
177
177
|
} catch {
|
|
178
178
|
log("parse cache content fail! path:" + filename);
|
|
179
179
|
try {
|
|
180
|
-
|
|
180
|
+
fs__default.unlinkSync(filename);
|
|
181
181
|
} catch {
|
|
182
182
|
log("delete cache file fail! path:" + filename);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// src/core/inspector.ts
|
|
189
|
-
import * as t from "@babel/types";
|
|
186
|
+
}
|
|
190
187
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
function isObject(value) {
|
|
189
|
+
return value !== null && typeof value === "object";
|
|
190
|
+
}
|
|
191
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
192
|
+
if (!isObject(defaults)) {
|
|
193
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
194
|
+
}
|
|
195
|
+
const object = Object.assign({}, defaults);
|
|
196
|
+
for (const key in baseObject) {
|
|
197
|
+
if (key === "__proto__" || key === "constructor") {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const value = baseObject[key];
|
|
201
|
+
if (value === null || value === void 0) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
208
|
+
object[key] = [...value, ...object[key]];
|
|
209
|
+
} else if (isObject(value) && isObject(object[key])) {
|
|
210
|
+
object[key] = _defu(
|
|
211
|
+
value,
|
|
212
|
+
object[key],
|
|
213
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
214
|
+
merger
|
|
215
|
+
);
|
|
216
|
+
} else {
|
|
217
|
+
object[key] = value;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return object;
|
|
221
|
+
}
|
|
222
|
+
function createDefu(merger) {
|
|
223
|
+
return (...arguments_) => (
|
|
224
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
225
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
const defu = createDefu();
|
|
195
229
|
|
|
196
|
-
// src/core/inspector.ts
|
|
197
230
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
198
|
-
const ast = parse(content);
|
|
231
|
+
const ast = parser.parse(content);
|
|
199
232
|
let hasPatched = false;
|
|
200
|
-
|
|
233
|
+
traverse__default(ast, {
|
|
201
234
|
FunctionDeclaration(p) {
|
|
202
235
|
const n = p.node;
|
|
203
|
-
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 &&
|
|
236
|
+
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
204
237
|
const rts = n.body.body[0];
|
|
205
|
-
if (
|
|
238
|
+
if (t__namespace.isFunctionExpression(rts.argument)) {
|
|
206
239
|
const body = rts.argument.body.body;
|
|
207
240
|
const lastStatement = body.at(-1);
|
|
208
|
-
hasPatched =
|
|
241
|
+
hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
209
242
|
if (!hasPatched) {
|
|
210
|
-
const rts2 =
|
|
243
|
+
const rts2 = t__namespace.returnStatement(t__namespace.identifier("context"));
|
|
211
244
|
body.push(rts2);
|
|
212
245
|
}
|
|
213
246
|
}
|
|
@@ -215,39 +248,39 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
|
215
248
|
}
|
|
216
249
|
});
|
|
217
250
|
return {
|
|
218
|
-
code: hasPatched ? content :
|
|
251
|
+
code: hasPatched ? content : generate__default(ast).code,
|
|
219
252
|
hasPatched
|
|
220
253
|
};
|
|
221
254
|
}
|
|
222
255
|
function inspectPostcssPlugin(content) {
|
|
223
|
-
const ast = parse(content);
|
|
256
|
+
const ast = parser.parse(content);
|
|
224
257
|
const exportKey = "contextRef";
|
|
225
258
|
const variableName = "contextRef";
|
|
226
259
|
const valueKey = "value";
|
|
227
260
|
let hasPatched = false;
|
|
228
|
-
|
|
261
|
+
traverse__default(ast, {
|
|
229
262
|
Program(p) {
|
|
230
263
|
const n = p.node;
|
|
231
264
|
const idx = n.body.findIndex((x) => {
|
|
232
|
-
return
|
|
265
|
+
return t__namespace.isExpressionStatement(x) && t__namespace.isAssignmentExpression(x.expression) && t__namespace.isMemberExpression(x.expression.left) && t__namespace.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
|
|
233
266
|
});
|
|
234
267
|
if (idx > -1) {
|
|
235
268
|
const prevStatement = n.body[idx - 1];
|
|
236
269
|
const lastStatement = n.body.at(-1);
|
|
237
|
-
const hasPatchedCondition0 = prevStatement &&
|
|
238
|
-
const hasPatchedCondition1 =
|
|
270
|
+
const hasPatchedCondition0 = prevStatement && t__namespace.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t__namespace.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
271
|
+
const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) && t__namespace.isAssignmentExpression(lastStatement.expression) && t__namespace.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
239
272
|
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
240
273
|
if (!hasPatched) {
|
|
241
|
-
const statement =
|
|
242
|
-
|
|
274
|
+
const statement = t__namespace.variableDeclaration("const", [
|
|
275
|
+
t__namespace.variableDeclarator(t__namespace.identifier(variableName), t__namespace.objectExpression([t__namespace.objectProperty(t__namespace.identifier(valueKey), t__namespace.arrayExpression())]))
|
|
243
276
|
]);
|
|
244
277
|
n.body.splice(idx, 0, statement);
|
|
245
278
|
n.body.push(
|
|
246
|
-
|
|
247
|
-
|
|
279
|
+
t__namespace.expressionStatement(
|
|
280
|
+
t__namespace.assignmentExpression(
|
|
248
281
|
"=",
|
|
249
|
-
|
|
250
|
-
|
|
282
|
+
t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier("module"), t__namespace.identifier("exports")), t__namespace.identifier(exportKey)),
|
|
283
|
+
t__namespace.identifier(variableName)
|
|
251
284
|
)
|
|
252
285
|
)
|
|
253
286
|
);
|
|
@@ -259,41 +292,41 @@ function inspectPostcssPlugin(content) {
|
|
|
259
292
|
return;
|
|
260
293
|
}
|
|
261
294
|
const n = p.node;
|
|
262
|
-
if (n.id?.name === "tailwindcss" && n.body.body.length === 1 &&
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const properties =
|
|
266
|
-
if (
|
|
267
|
-
const keyMatched =
|
|
268
|
-
const pluginsMatched =
|
|
269
|
-
if (pluginsMatched && keyMatched &&
|
|
295
|
+
if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
296
|
+
const returnStatement = n.body.body[0];
|
|
297
|
+
if (t__namespace.isObjectExpression(returnStatement.argument) && returnStatement.argument.properties.length === 2) {
|
|
298
|
+
const properties = returnStatement.argument.properties;
|
|
299
|
+
if (t__namespace.isObjectProperty(properties[0]) && t__namespace.isObjectProperty(properties[1])) {
|
|
300
|
+
const keyMatched = t__namespace.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
|
|
301
|
+
const pluginsMatched = t__namespace.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
|
|
302
|
+
if (pluginsMatched && keyMatched && t__namespace.isCallExpression(properties[1].value) && t__namespace.isMemberExpression(properties[1].value.callee) && t__namespace.isArrayExpression(properties[1].value.callee.object)) {
|
|
270
303
|
const pluginsCode = properties[1].value.callee.object.elements;
|
|
271
|
-
if (pluginsCode[1] &&
|
|
304
|
+
if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
|
|
272
305
|
const targetBlockStatement = pluginsCode[1].body;
|
|
273
306
|
const lastStatement = targetBlockStatement.body.at(-1);
|
|
274
|
-
if (
|
|
275
|
-
const newExpressionStatement =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
307
|
+
if (t__namespace.isExpressionStatement(lastStatement)) {
|
|
308
|
+
const newExpressionStatement = t__namespace.expressionStatement(
|
|
309
|
+
t__namespace.callExpression(
|
|
310
|
+
t__namespace.memberExpression(
|
|
311
|
+
t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier("value")),
|
|
312
|
+
t__namespace.identifier("push")
|
|
280
313
|
),
|
|
281
314
|
[lastStatement.expression]
|
|
282
315
|
)
|
|
283
316
|
);
|
|
284
317
|
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
285
318
|
}
|
|
286
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) =>
|
|
319
|
+
const ifIdx = targetBlockStatement.body.findIndex((x) => t__namespace.isIfStatement(x));
|
|
287
320
|
if (ifIdx > -1) {
|
|
288
321
|
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
289
|
-
if (
|
|
322
|
+
if (t__namespace.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t__namespace.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
290
323
|
const forOf = ifRoot.consequent.body[1];
|
|
291
|
-
if (
|
|
324
|
+
if (t__namespace.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t__namespace.isIfStatement(forOf.body.body[0])) {
|
|
292
325
|
const if2 = forOf.body.body[0];
|
|
293
|
-
if (
|
|
326
|
+
if (t__namespace.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t__namespace.isExpressionStatement(if2.consequent.body[0])) {
|
|
294
327
|
const target = if2.consequent.body[0];
|
|
295
|
-
const newExpressionStatement =
|
|
296
|
-
|
|
328
|
+
const newExpressionStatement = t__namespace.expressionStatement(
|
|
329
|
+
t__namespace.callExpression(t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier("value")), t__namespace.identifier("push")), [target.expression])
|
|
297
330
|
);
|
|
298
331
|
if2.consequent.body[0] = newExpressionStatement;
|
|
299
332
|
}
|
|
@@ -304,11 +337,11 @@ function inspectPostcssPlugin(content) {
|
|
|
304
337
|
// contentRef.value = []
|
|
305
338
|
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
306
339
|
// contentRef.value.length = 0
|
|
307
|
-
|
|
308
|
-
|
|
340
|
+
t__namespace.expressionStatement(
|
|
341
|
+
t__namespace.assignmentExpression(
|
|
309
342
|
"=",
|
|
310
|
-
|
|
311
|
-
|
|
343
|
+
t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier(valueKey)), t__namespace.identifier("length")),
|
|
344
|
+
t__namespace.numericLiteral(0)
|
|
312
345
|
)
|
|
313
346
|
)
|
|
314
347
|
);
|
|
@@ -326,79 +359,17 @@ function inspectPostcssPlugin(content) {
|
|
|
326
359
|
// }
|
|
327
360
|
});
|
|
328
361
|
return {
|
|
329
|
-
code: hasPatched ? content :
|
|
362
|
+
code: hasPatched ? content : generate__default(ast).code,
|
|
330
363
|
hasPatched
|
|
331
364
|
};
|
|
332
365
|
}
|
|
333
366
|
|
|
334
|
-
// src/core/runtime-patcher.ts
|
|
335
|
-
import path3 from "node:path";
|
|
336
|
-
import fs4 from "node:fs";
|
|
337
|
-
import { gte } from "semver";
|
|
338
|
-
|
|
339
|
-
// ../../node_modules/.pnpm/defu@6.1.2/node_modules/defu/dist/defu.mjs
|
|
340
|
-
function isObject(value) {
|
|
341
|
-
return value !== null && typeof value === "object";
|
|
342
|
-
}
|
|
343
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
344
|
-
if (!isObject(defaults)) {
|
|
345
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
346
|
-
}
|
|
347
|
-
const object = Object.assign({}, defaults);
|
|
348
|
-
for (const key in baseObject) {
|
|
349
|
-
if (key === "__proto__" || key === "constructor") {
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
const value = baseObject[key];
|
|
353
|
-
if (value === null || value === void 0) {
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
360
|
-
object[key] = [...value, ...object[key]];
|
|
361
|
-
} else if (isObject(value) && isObject(object[key])) {
|
|
362
|
-
object[key] = _defu(
|
|
363
|
-
value,
|
|
364
|
-
object[key],
|
|
365
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
366
|
-
merger
|
|
367
|
-
);
|
|
368
|
-
} else {
|
|
369
|
-
object[key] = value;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return object;
|
|
373
|
-
}
|
|
374
|
-
function createDefu(merger) {
|
|
375
|
-
return (...arguments_) => (
|
|
376
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
377
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
var defu = createDefu();
|
|
381
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
382
|
-
if (typeof object[key] !== "undefined" && typeof currentValue === "function") {
|
|
383
|
-
object[key] = currentValue(object[key]);
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
388
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
389
|
-
object[key] = currentValue(object[key]);
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
// src/defaults.ts
|
|
395
367
|
function getDefaultPatchOptions() {
|
|
396
368
|
return {
|
|
397
369
|
overwrite: true
|
|
398
370
|
};
|
|
399
371
|
}
|
|
400
372
|
|
|
401
|
-
// src/core/runtime-patcher.ts
|
|
402
373
|
function getInstalledPkgJsonPath(options = {}) {
|
|
403
374
|
try {
|
|
404
375
|
const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
|
|
@@ -431,26 +402,26 @@ function createPatch(opt) {
|
|
|
431
402
|
};
|
|
432
403
|
}
|
|
433
404
|
function monkeyPatchForExposingContext(twDir, opt) {
|
|
434
|
-
const processTailwindFeaturesFilePath =
|
|
405
|
+
const processTailwindFeaturesFilePath = path__default.resolve(twDir, "lib/processTailwindFeatures.js");
|
|
435
406
|
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
|
|
436
407
|
const result = {};
|
|
437
408
|
if (processTailwindFeaturesContent) {
|
|
438
409
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
439
410
|
if (!hasPatched && opt.overwrite) {
|
|
440
|
-
|
|
411
|
+
fs__default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
441
412
|
encoding: "utf8"
|
|
442
413
|
});
|
|
443
414
|
console.log("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
444
415
|
}
|
|
445
416
|
result.processTailwindFeatures = code;
|
|
446
417
|
}
|
|
447
|
-
const pluginFilePath =
|
|
448
|
-
const indexFilePath =
|
|
418
|
+
const pluginFilePath = path__default.resolve(twDir, "lib/plugin.js");
|
|
419
|
+
const indexFilePath = path__default.resolve(twDir, "lib/index.js");
|
|
449
420
|
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
|
|
450
421
|
if (pluginContent) {
|
|
451
422
|
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
452
423
|
if (!hasPatched && opt.overwrite) {
|
|
453
|
-
|
|
424
|
+
fs__default.writeFileSync(pluginFilePath, code, {
|
|
454
425
|
encoding: "utf8"
|
|
455
426
|
});
|
|
456
427
|
console.log("patch tailwindcss for expose runtime content successfully!");
|
|
@@ -462,9 +433,9 @@ function monkeyPatchForExposingContext(twDir, opt) {
|
|
|
462
433
|
}
|
|
463
434
|
function internalPatch(pkgJsonPath, options) {
|
|
464
435
|
if (pkgJsonPath) {
|
|
465
|
-
const pkgJson =
|
|
466
|
-
const twDir =
|
|
467
|
-
if (gte(pkgJson.version, "3.0.0")) {
|
|
436
|
+
const pkgJson = require(pkgJsonPath);
|
|
437
|
+
const twDir = path__default.dirname(pkgJsonPath);
|
|
438
|
+
if (semver.gte(pkgJson.version, "3.0.0")) {
|
|
468
439
|
options.version = pkgJson.version;
|
|
469
440
|
const result = monkeyPatchForExposingContext(twDir, options);
|
|
470
441
|
return result;
|
|
@@ -472,22 +443,13 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
472
443
|
}
|
|
473
444
|
}
|
|
474
445
|
|
|
475
|
-
|
|
476
|
-
import fs5 from "node:fs/promises";
|
|
477
|
-
import { dirname } from "node:path";
|
|
478
|
-
|
|
479
|
-
// src/core/postcss.ts
|
|
480
|
-
import path4 from "node:path";
|
|
481
|
-
import postcss from "postcss";
|
|
482
|
-
import { lilconfig } from "lilconfig";
|
|
483
|
-
import createJiti from "jiti";
|
|
484
|
-
var jiti = createJiti(__filename);
|
|
446
|
+
const jiti = createJiti__default(__filename);
|
|
485
447
|
async function processTailwindcss(options) {
|
|
486
448
|
options.cwd = options.cwd ?? process.cwd();
|
|
487
449
|
let config = options.config;
|
|
488
|
-
if (!(typeof options.config === "string" &&
|
|
450
|
+
if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
|
|
489
451
|
const moduleName = "tailwind";
|
|
490
|
-
const result = await lilconfig("tailwindcss", {
|
|
452
|
+
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
491
453
|
searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
|
|
492
454
|
loaders: {
|
|
493
455
|
// 默认支持 js 和 cjs 2种格式
|
|
@@ -502,8 +464,8 @@ async function processTailwindcss(options) {
|
|
|
502
464
|
}
|
|
503
465
|
config = result.filepath;
|
|
504
466
|
}
|
|
505
|
-
return await
|
|
506
|
-
|
|
467
|
+
return await postcss__default([
|
|
468
|
+
require("tailwindcss")({
|
|
507
469
|
config
|
|
508
470
|
})
|
|
509
471
|
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
@@ -511,13 +473,7 @@ async function processTailwindcss(options) {
|
|
|
511
473
|
});
|
|
512
474
|
}
|
|
513
475
|
|
|
514
|
-
|
|
515
|
-
var TailwindcssPatcher = class {
|
|
516
|
-
rawOptions;
|
|
517
|
-
cacheOptions;
|
|
518
|
-
patchOptions;
|
|
519
|
-
patch;
|
|
520
|
-
cacheManager;
|
|
476
|
+
class TailwindcssPatcher {
|
|
521
477
|
constructor(options = {}) {
|
|
522
478
|
this.rawOptions = options;
|
|
523
479
|
this.cacheOptions = getCacheOptions(options.cache);
|
|
@@ -572,61 +528,32 @@ var TailwindcssPatcher = class {
|
|
|
572
528
|
removeUniversalSelector
|
|
573
529
|
});
|
|
574
530
|
if (filename) {
|
|
575
|
-
await ensureDir(dirname(filename));
|
|
531
|
+
await ensureDir(path.dirname(filename));
|
|
576
532
|
const classList = [...set];
|
|
577
|
-
await
|
|
533
|
+
await fs__default$1.writeFile(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
|
|
578
534
|
return filename;
|
|
579
535
|
}
|
|
580
536
|
}
|
|
581
537
|
}
|
|
582
|
-
}
|
|
538
|
+
}
|
|
583
539
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
540
|
+
exports.CacheManager = CacheManager;
|
|
541
|
+
exports.TailwindcssPatcher = TailwindcssPatcher;
|
|
542
|
+
exports.createPatch = createPatch;
|
|
543
|
+
exports.ensureDir = ensureDir;
|
|
544
|
+
exports.ensureFileContent = ensureFileContent;
|
|
545
|
+
exports.getCacheOptions = getCacheOptions;
|
|
546
|
+
exports.getClassCacheSet = getClassCacheSet;
|
|
547
|
+
exports.getClassCaches = getClassCaches;
|
|
548
|
+
exports.getContexts = getContexts;
|
|
549
|
+
exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
|
|
550
|
+
exports.getPatchOptions = getPatchOptions;
|
|
551
|
+
exports.getTailwindcssEntry = getTailwindcssEntry;
|
|
552
|
+
exports.inspectPostcssPlugin = inspectPostcssPlugin;
|
|
553
|
+
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
|
|
554
|
+
exports.internalPatch = internalPatch;
|
|
555
|
+
exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
|
|
556
|
+
exports.requireResolve = requireResolve;
|
|
557
|
+
Object.keys(config).forEach(function (k) {
|
|
558
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = config[k];
|
|
601
559
|
});
|
|
602
|
-
|
|
603
|
-
// src/core/config.ts
|
|
604
|
-
var config_exports = {};
|
|
605
|
-
__reExport(config_exports, config_star);
|
|
606
|
-
import * as config_star from "@tailwindcss-mangle/config";
|
|
607
|
-
|
|
608
|
-
// src/core/index.ts
|
|
609
|
-
__reExport(core_exports, config_exports);
|
|
610
|
-
|
|
611
|
-
export {
|
|
612
|
-
__export,
|
|
613
|
-
__reExport,
|
|
614
|
-
ensureFileContent,
|
|
615
|
-
requireResolve,
|
|
616
|
-
ensureDir,
|
|
617
|
-
getTailwindcssEntry,
|
|
618
|
-
getContexts,
|
|
619
|
-
getClassCaches,
|
|
620
|
-
getClassCacheSet,
|
|
621
|
-
getCacheOptions,
|
|
622
|
-
CacheManager,
|
|
623
|
-
inspectProcessTailwindFeaturesReturnContext,
|
|
624
|
-
inspectPostcssPlugin,
|
|
625
|
-
getInstalledPkgJsonPath,
|
|
626
|
-
getPatchOptions,
|
|
627
|
-
createPatch,
|
|
628
|
-
monkeyPatchForExposingContext,
|
|
629
|
-
internalPatch,
|
|
630
|
-
TailwindcssPatcher,
|
|
631
|
-
core_exports
|
|
632
|
-
};
|