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