tailwindcss-patch 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +46 -17
- package/dist/index.mjs +40 -11
- package/package.json +16 -16
package/dist/cli.cjs
CHANGED
|
@@ -8,10 +8,10 @@ require('node:fs');
|
|
|
8
8
|
require('node:fs/promises');
|
|
9
9
|
require('resolve');
|
|
10
10
|
require('@babel/types');
|
|
11
|
+
require('semver');
|
|
11
12
|
require('@babel/generator');
|
|
12
13
|
require('@babel/traverse');
|
|
13
14
|
require('@babel/parser');
|
|
14
|
-
require('semver');
|
|
15
15
|
require('postcss');
|
|
16
16
|
require('lilconfig');
|
|
17
17
|
require('jiti');
|
package/dist/cli.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import 'node:fs';
|
|
|
6
6
|
import 'node:fs/promises';
|
|
7
7
|
import 'resolve';
|
|
8
8
|
import '@babel/types';
|
|
9
|
+
import 'semver';
|
|
9
10
|
import '@babel/generator';
|
|
10
11
|
import '@babel/traverse';
|
|
11
12
|
import '@babel/parser';
|
|
12
|
-
import 'semver';
|
|
13
13
|
import 'postcss';
|
|
14
14
|
import 'lilconfig';
|
|
15
15
|
import 'jiti';
|
package/dist/index.cjs
CHANGED
|
@@ -6,8 +6,8 @@ const fs = require('node:fs');
|
|
|
6
6
|
const pkg = require('resolve');
|
|
7
7
|
const semver = require('semver');
|
|
8
8
|
const t = require('@babel/types');
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const _babelGenerate = require('@babel/generator');
|
|
10
|
+
const _babelTraverse = require('@babel/traverse');
|
|
11
11
|
const parser = require('@babel/parser');
|
|
12
12
|
const postcss = require('postcss');
|
|
13
13
|
const lilconfig = require('lilconfig');
|
|
@@ -33,8 +33,8 @@ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
|
33
33
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
34
34
|
const pkg__default = /*#__PURE__*/_interopDefaultCompat(pkg);
|
|
35
35
|
const t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
36
|
-
const
|
|
37
|
-
const
|
|
36
|
+
const _babelGenerate__default = /*#__PURE__*/_interopDefaultCompat(_babelGenerate);
|
|
37
|
+
const _babelTraverse__default = /*#__PURE__*/_interopDefaultCompat(_babelTraverse);
|
|
38
38
|
const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
39
39
|
const createJiti__default = /*#__PURE__*/_interopDefaultCompat(createJiti);
|
|
40
40
|
|
|
@@ -194,11 +194,25 @@ class CacheManager {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
function
|
|
198
|
-
|
|
197
|
+
function isPlainObject(value) {
|
|
198
|
+
if (value === null || typeof value !== "object") {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const prototype = Object.getPrototypeOf(value);
|
|
202
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (Symbol.iterator in value) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (Symbol.toStringTag in value) {
|
|
209
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
199
212
|
}
|
|
213
|
+
|
|
200
214
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
201
|
-
if (!
|
|
215
|
+
if (!isPlainObject(defaults)) {
|
|
202
216
|
return _defu(baseObject, {}, namespace, merger);
|
|
203
217
|
}
|
|
204
218
|
const object = Object.assign({}, defaults);
|
|
@@ -215,7 +229,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
|
215
229
|
}
|
|
216
230
|
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
217
231
|
object[key] = [...value, ...object[key]];
|
|
218
|
-
} else if (
|
|
232
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
219
233
|
object[key] = _defu(
|
|
220
234
|
value,
|
|
221
235
|
object[key],
|
|
@@ -236,17 +250,23 @@ function createDefu(merger) {
|
|
|
236
250
|
}
|
|
237
251
|
const defu = createDefu();
|
|
238
252
|
|
|
253
|
+
function _interopDefaultCompat$1(e) {
|
|
254
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
255
|
+
}
|
|
256
|
+
const generate = _interopDefaultCompat$1(_babelGenerate__default);
|
|
257
|
+
const traverse = _interopDefaultCompat$1(_babelTraverse__default);
|
|
258
|
+
|
|
239
259
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
240
260
|
const ast = parser.parse(content);
|
|
241
261
|
let hasPatched = false;
|
|
242
|
-
|
|
262
|
+
traverse(ast, {
|
|
243
263
|
FunctionDeclaration(p) {
|
|
244
264
|
const n = p.node;
|
|
245
265
|
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
246
266
|
const rts = n.body.body[0];
|
|
247
267
|
if (t__namespace.isFunctionExpression(rts.argument)) {
|
|
248
268
|
const body = rts.argument.body.body;
|
|
249
|
-
const lastStatement = body.
|
|
269
|
+
const lastStatement = body[body.length - 1];
|
|
250
270
|
hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
251
271
|
if (!hasPatched) {
|
|
252
272
|
const rts2 = t__namespace.returnStatement(t__namespace.identifier("context"));
|
|
@@ -257,7 +277,7 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
|
257
277
|
}
|
|
258
278
|
});
|
|
259
279
|
return {
|
|
260
|
-
code: hasPatched ? content :
|
|
280
|
+
code: hasPatched ? content : generate(ast).code,
|
|
261
281
|
hasPatched
|
|
262
282
|
};
|
|
263
283
|
}
|
|
@@ -267,7 +287,7 @@ function inspectPostcssPlugin(content) {
|
|
|
267
287
|
const variableName = "contextRef";
|
|
268
288
|
const valueKey = "value";
|
|
269
289
|
let hasPatched = false;
|
|
270
|
-
|
|
290
|
+
traverse(ast, {
|
|
271
291
|
Program(p) {
|
|
272
292
|
const n = p.node;
|
|
273
293
|
const idx = n.body.findIndex((x) => {
|
|
@@ -275,7 +295,7 @@ function inspectPostcssPlugin(content) {
|
|
|
275
295
|
});
|
|
276
296
|
if (idx > -1) {
|
|
277
297
|
const prevStatement = n.body[idx - 1];
|
|
278
|
-
const lastStatement = n.body.
|
|
298
|
+
const lastStatement = n.body[n.body.length - 1];
|
|
279
299
|
const hasPatchedCondition0 = prevStatement && t__namespace.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t__namespace.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
280
300
|
const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) && t__namespace.isAssignmentExpression(lastStatement.expression) && t__namespace.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
281
301
|
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
@@ -312,7 +332,7 @@ function inspectPostcssPlugin(content) {
|
|
|
312
332
|
const pluginsCode = properties[1].value.callee.object.elements;
|
|
313
333
|
if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
|
|
314
334
|
const targetBlockStatement = pluginsCode[1].body;
|
|
315
|
-
const lastStatement = targetBlockStatement.body.
|
|
335
|
+
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
316
336
|
if (t__namespace.isExpressionStatement(lastStatement)) {
|
|
317
337
|
const newExpressionStatement = t__namespace.expressionStatement(
|
|
318
338
|
t__namespace.callExpression(
|
|
@@ -368,7 +388,7 @@ function inspectPostcssPlugin(content) {
|
|
|
368
388
|
// }
|
|
369
389
|
});
|
|
370
390
|
return {
|
|
371
|
-
code: hasPatched ? content :
|
|
391
|
+
code: hasPatched ? content : generate(ast).code,
|
|
372
392
|
hasPatched
|
|
373
393
|
};
|
|
374
394
|
}
|
|
@@ -459,13 +479,22 @@ async function processTailwindcss(options) {
|
|
|
459
479
|
if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
|
|
460
480
|
const moduleName = "tailwind";
|
|
461
481
|
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
462
|
-
searchPlaces: [
|
|
482
|
+
searchPlaces: [
|
|
483
|
+
`${moduleName}.config.js`,
|
|
484
|
+
`${moduleName}.config.cjs`,
|
|
485
|
+
`${moduleName}.config.mjs`,
|
|
486
|
+
`${moduleName}.config.ts`,
|
|
487
|
+
`${moduleName}.config.cts`,
|
|
488
|
+
`${moduleName}.config.mts`
|
|
489
|
+
],
|
|
463
490
|
loaders: {
|
|
464
491
|
// 默认支持 js 和 cjs 2种格式
|
|
465
492
|
".js": jiti,
|
|
466
493
|
".cjs": jiti,
|
|
494
|
+
".mjs": jiti,
|
|
467
495
|
".ts": jiti,
|
|
468
|
-
".
|
|
496
|
+
".cts": jiti,
|
|
497
|
+
".mts": jiti
|
|
469
498
|
}
|
|
470
499
|
}).search(options.cwd);
|
|
471
500
|
if (!result) {
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import fs from 'node:fs';
|
|
|
4
4
|
import pkg from 'resolve';
|
|
5
5
|
import { gte } from 'semver';
|
|
6
6
|
import * as t from '@babel/types';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import _babelGenerate from '@babel/generator';
|
|
8
|
+
import _babelTraverse from '@babel/traverse';
|
|
9
9
|
import { parse } from '@babel/parser';
|
|
10
10
|
import postcss from 'postcss';
|
|
11
11
|
import { lilconfig } from 'lilconfig';
|
|
@@ -177,11 +177,25 @@ class CacheManager {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
function
|
|
181
|
-
|
|
180
|
+
function isPlainObject(value) {
|
|
181
|
+
if (value === null || typeof value !== "object") {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const prototype = Object.getPrototypeOf(value);
|
|
185
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (Symbol.iterator in value) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (Symbol.toStringTag in value) {
|
|
192
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
182
195
|
}
|
|
196
|
+
|
|
183
197
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
184
|
-
if (!
|
|
198
|
+
if (!isPlainObject(defaults)) {
|
|
185
199
|
return _defu(baseObject, {}, namespace, merger);
|
|
186
200
|
}
|
|
187
201
|
const object = Object.assign({}, defaults);
|
|
@@ -198,7 +212,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
|
198
212
|
}
|
|
199
213
|
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
200
214
|
object[key] = [...value, ...object[key]];
|
|
201
|
-
} else if (
|
|
215
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
202
216
|
object[key] = _defu(
|
|
203
217
|
value,
|
|
204
218
|
object[key],
|
|
@@ -219,6 +233,12 @@ function createDefu(merger) {
|
|
|
219
233
|
}
|
|
220
234
|
const defu = createDefu();
|
|
221
235
|
|
|
236
|
+
function _interopDefaultCompat(e) {
|
|
237
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
238
|
+
}
|
|
239
|
+
const generate = _interopDefaultCompat(_babelGenerate);
|
|
240
|
+
const traverse = _interopDefaultCompat(_babelTraverse);
|
|
241
|
+
|
|
222
242
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
223
243
|
const ast = parse(content);
|
|
224
244
|
let hasPatched = false;
|
|
@@ -229,7 +249,7 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
|
229
249
|
const rts = n.body.body[0];
|
|
230
250
|
if (t.isFunctionExpression(rts.argument)) {
|
|
231
251
|
const body = rts.argument.body.body;
|
|
232
|
-
const lastStatement = body.
|
|
252
|
+
const lastStatement = body[body.length - 1];
|
|
233
253
|
hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
234
254
|
if (!hasPatched) {
|
|
235
255
|
const rts2 = t.returnStatement(t.identifier("context"));
|
|
@@ -258,7 +278,7 @@ function inspectPostcssPlugin(content) {
|
|
|
258
278
|
});
|
|
259
279
|
if (idx > -1) {
|
|
260
280
|
const prevStatement = n.body[idx - 1];
|
|
261
|
-
const lastStatement = n.body.
|
|
281
|
+
const lastStatement = n.body[n.body.length - 1];
|
|
262
282
|
const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
263
283
|
const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
264
284
|
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
@@ -295,7 +315,7 @@ function inspectPostcssPlugin(content) {
|
|
|
295
315
|
const pluginsCode = properties[1].value.callee.object.elements;
|
|
296
316
|
if (pluginsCode[1] && t.isFunctionExpression(pluginsCode[1])) {
|
|
297
317
|
const targetBlockStatement = pluginsCode[1].body;
|
|
298
|
-
const lastStatement = targetBlockStatement.body.
|
|
318
|
+
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
299
319
|
if (t.isExpressionStatement(lastStatement)) {
|
|
300
320
|
const newExpressionStatement = t.expressionStatement(
|
|
301
321
|
t.callExpression(
|
|
@@ -442,13 +462,22 @@ async function processTailwindcss(options) {
|
|
|
442
462
|
if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
|
|
443
463
|
const moduleName = "tailwind";
|
|
444
464
|
const result = await lilconfig("tailwindcss", {
|
|
445
|
-
searchPlaces: [
|
|
465
|
+
searchPlaces: [
|
|
466
|
+
`${moduleName}.config.js`,
|
|
467
|
+
`${moduleName}.config.cjs`,
|
|
468
|
+
`${moduleName}.config.mjs`,
|
|
469
|
+
`${moduleName}.config.ts`,
|
|
470
|
+
`${moduleName}.config.cts`,
|
|
471
|
+
`${moduleName}.config.mts`
|
|
472
|
+
],
|
|
446
473
|
loaders: {
|
|
447
474
|
// 默认支持 js 和 cjs 2种格式
|
|
448
475
|
".js": jiti,
|
|
449
476
|
".cjs": jiti,
|
|
477
|
+
".mjs": jiti,
|
|
450
478
|
".ts": jiti,
|
|
451
|
-
".
|
|
479
|
+
".cts": jiti,
|
|
480
|
+
".mts": jiti
|
|
452
481
|
}
|
|
453
482
|
}).search(options.cwd);
|
|
454
483
|
if (!result) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "patch tailwindcss for exposing context and extract classes",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/babel__generator": "^7.6.
|
|
37
|
-
"@types/babel__traverse": "^7.20.
|
|
38
|
-
"@types/resolve": "^1.20.
|
|
39
|
-
"@types/semver": "^7.5.
|
|
40
|
-
"pkg-types": "^1.
|
|
41
|
-
"tailwindcss": "^3.
|
|
36
|
+
"@types/babel__generator": "^7.6.8",
|
|
37
|
+
"@types/babel__traverse": "^7.20.5",
|
|
38
|
+
"@types/resolve": "^1.20.6",
|
|
39
|
+
"@types/semver": "^7.5.8",
|
|
40
|
+
"pkg-types": "^1.1.1",
|
|
41
|
+
"tailwindcss": "^3.4.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@babel/generator": "^7.
|
|
45
|
-
"@babel/parser": "^7.
|
|
46
|
-
"@babel/traverse": "^7.
|
|
47
|
-
"@babel/types": "^7.
|
|
44
|
+
"@babel/generator": "^7.24.5",
|
|
45
|
+
"@babel/parser": "^7.24.5",
|
|
46
|
+
"@babel/traverse": "^7.24.5",
|
|
47
|
+
"@babel/types": "^7.24.5",
|
|
48
48
|
"cac": "^6.7.14",
|
|
49
|
-
"jiti": "^1.
|
|
50
|
-
"lilconfig": "^
|
|
51
|
-
"postcss": "^8.4.
|
|
52
|
-
"resolve": "^1.22.
|
|
53
|
-
"semver": "^7.
|
|
49
|
+
"jiti": "^1.21.0",
|
|
50
|
+
"lilconfig": "^3.1.1",
|
|
51
|
+
"postcss": "^8.4.38",
|
|
52
|
+
"resolve": "^1.22.8",
|
|
53
|
+
"semver": "^7.6.2",
|
|
54
54
|
"@tailwindcss-mangle/config": "^2.2.2"
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
|