tailwindcss-patch 1.2.3 → 1.2.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/dist/cli.js +4 -4
- package/dist/index.js +11 -12
- package/dist/{patcher-3d84b17b.js → patcher-d1886807.js} +49 -54
- package/dist/types/babel.d.ts +3 -4
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var patcher = require('./patcher-
|
|
4
|
-
require('path');
|
|
5
|
-
require('fs');
|
|
3
|
+
var patcher = require('./patcher-d1886807.js');
|
|
4
|
+
require('node:path');
|
|
5
|
+
require('node:fs');
|
|
6
6
|
require('semver');
|
|
7
7
|
require('@babel/types');
|
|
8
8
|
require('@babel/generator');
|
|
9
|
-
require('@babel/parser');
|
|
10
9
|
require('@babel/traverse');
|
|
10
|
+
require('@babel/parser');
|
|
11
11
|
require('resolve');
|
|
12
12
|
|
|
13
13
|
const opt = patcher.getPatchOptions();
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var path = require('path');
|
|
6
|
-
var fs = require('fs');
|
|
7
|
-
var patcher = require('./patcher-
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var fs = require('node:fs');
|
|
7
|
+
var patcher = require('./patcher-d1886807.js');
|
|
8
8
|
require('semver');
|
|
9
9
|
require('@babel/types');
|
|
10
10
|
require('@babel/generator');
|
|
11
|
-
require('@babel/parser');
|
|
12
11
|
require('@babel/traverse');
|
|
12
|
+
require('@babel/parser');
|
|
13
13
|
require('resolve');
|
|
14
14
|
|
|
15
15
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -40,8 +40,7 @@ function getClassCaches(basedir) {
|
|
|
40
40
|
function getClassCacheSet(basedir) {
|
|
41
41
|
const classCaches = getClassCaches(basedir);
|
|
42
42
|
const classSet = new Set();
|
|
43
|
-
for (
|
|
44
|
-
const classCacheMap = classCaches[i];
|
|
43
|
+
for (const classCacheMap of classCaches) {
|
|
45
44
|
const keys = classCacheMap.keys();
|
|
46
45
|
for (const key of keys) {
|
|
47
46
|
classSet.add(key);
|
|
@@ -82,10 +81,10 @@ function writeCache(data, options = {}) {
|
|
|
82
81
|
try {
|
|
83
82
|
const { dir, filename } = getCacheOptions$1(options);
|
|
84
83
|
mkCacheDirectory(dir);
|
|
85
|
-
fs__default["default"].writeFileSync(filename, JSON.stringify(
|
|
84
|
+
fs__default["default"].writeFileSync(filename, JSON.stringify([...data], undefined, 2), 'utf8');
|
|
86
85
|
return filename;
|
|
87
86
|
}
|
|
88
|
-
catch (
|
|
87
|
+
catch (_a) {
|
|
89
88
|
log('write cache file fail!');
|
|
90
89
|
}
|
|
91
90
|
}
|
|
@@ -93,16 +92,16 @@ function readCache(options = {}) {
|
|
|
93
92
|
const { filename } = getCacheOptions$1(options);
|
|
94
93
|
try {
|
|
95
94
|
if (fs__default["default"].existsSync(filename)) {
|
|
96
|
-
const data = fs__default["default"].readFileSync(filename, '
|
|
95
|
+
const data = fs__default["default"].readFileSync(filename, 'utf8');
|
|
97
96
|
return new Set(JSON.parse(data));
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
|
-
catch (
|
|
99
|
+
catch (_a) {
|
|
101
100
|
log('parse cache content fail! path:' + filename);
|
|
102
101
|
try {
|
|
103
102
|
fs__default["default"].unlinkSync(filename);
|
|
104
103
|
}
|
|
105
|
-
catch (
|
|
104
|
+
catch (_b) {
|
|
106
105
|
log('delete cache file fail! path:' + filename);
|
|
107
106
|
}
|
|
108
107
|
}
|
|
@@ -150,7 +149,7 @@ class TailwindcssPatcher {
|
|
|
150
149
|
}
|
|
151
150
|
getClassSet(basedir) {
|
|
152
151
|
const set = getClassCacheSet(basedir);
|
|
153
|
-
set.size && this.setCache(set);
|
|
152
|
+
set.size > 0 && this.setCache(set);
|
|
154
153
|
return set;
|
|
155
154
|
}
|
|
156
155
|
getContexts(basedir) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var path = require('path');
|
|
4
|
-
var fs = require('fs');
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
5
|
var semver = require('semver');
|
|
6
6
|
var t = require('@babel/types');
|
|
7
7
|
var generate = require('@babel/generator');
|
|
8
|
-
var parser = require('@babel/parser');
|
|
9
8
|
var traverse = require('@babel/traverse');
|
|
9
|
+
var parser = require('@babel/parser');
|
|
10
10
|
var resolve = require('resolve');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -40,11 +40,10 @@ function ensureFileContent(filepaths) {
|
|
|
40
40
|
filepaths = [filepaths];
|
|
41
41
|
}
|
|
42
42
|
let content;
|
|
43
|
-
for (
|
|
44
|
-
const filepath = filepaths[i];
|
|
43
|
+
for (const filepath of filepaths) {
|
|
45
44
|
if (fs__default["default"].existsSync(filepath)) {
|
|
46
45
|
content = fs__default["default"].readFileSync(filepath, {
|
|
47
|
-
encoding: '
|
|
46
|
+
encoding: 'utf8'
|
|
48
47
|
});
|
|
49
48
|
break;
|
|
50
49
|
}
|
|
@@ -62,17 +61,15 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
|
62
61
|
FunctionDeclaration(p) {
|
|
63
62
|
var _a;
|
|
64
63
|
const n = p.node;
|
|
65
|
-
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'processTailwindFeatures') {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
body.push(rts);
|
|
75
|
-
}
|
|
64
|
+
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'processTailwindFeatures' && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
65
|
+
const rts = n.body.body[0];
|
|
66
|
+
if (t__namespace.isFunctionExpression(rts.argument)) {
|
|
67
|
+
const body = rts.argument.body.body;
|
|
68
|
+
const lastStatement = body.at(-1);
|
|
69
|
+
hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === 'context';
|
|
70
|
+
if (!hasPatched) {
|
|
71
|
+
const rts = t__namespace.returnStatement(t__namespace.identifier('context'));
|
|
72
|
+
body.push(rts);
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
}
|
|
@@ -102,7 +99,7 @@ function inspectPostcssPlugin(content) {
|
|
|
102
99
|
});
|
|
103
100
|
if (idx > -1) {
|
|
104
101
|
const prevStatement = n.body[idx - 1];
|
|
105
|
-
const lastStatement = n.body
|
|
102
|
+
const lastStatement = n.body.at(-1);
|
|
106
103
|
const hasPatchedCondition0 = prevStatement &&
|
|
107
104
|
t__namespace.isVariableDeclaration(prevStatement) &&
|
|
108
105
|
prevStatement.declarations.length === 1 &&
|
|
@@ -128,44 +125,42 @@ function inspectPostcssPlugin(content) {
|
|
|
128
125
|
return;
|
|
129
126
|
}
|
|
130
127
|
const n = p.node;
|
|
131
|
-
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss') {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if2.consequent.body[0] = newExpressionStatement;
|
|
163
|
-
}
|
|
128
|
+
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss' && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
129
|
+
const returnStatement = n.body.body[0];
|
|
130
|
+
if (t__namespace.isObjectExpression(returnStatement.argument) && returnStatement.argument.properties.length === 2) {
|
|
131
|
+
const properties = returnStatement.argument.properties;
|
|
132
|
+
if (t__namespace.isObjectProperty(properties[0]) && t__namespace.isObjectProperty(properties[1])) {
|
|
133
|
+
const keyMatched = t__namespace.isIdentifier(properties[0].key) && properties[0].key.name === 'postcssPlugin';
|
|
134
|
+
const pluginsMatched = t__namespace.isIdentifier(properties[1].key) && properties[1].key.name === 'plugins';
|
|
135
|
+
if (pluginsMatched &&
|
|
136
|
+
keyMatched &&
|
|
137
|
+
t__namespace.isCallExpression(properties[1].value) &&
|
|
138
|
+
t__namespace.isMemberExpression(properties[1].value.callee) &&
|
|
139
|
+
t__namespace.isArrayExpression(properties[1].value.callee.object)) {
|
|
140
|
+
const pluginsCode = properties[1].value.callee.object.elements;
|
|
141
|
+
if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
|
|
142
|
+
const targetBlockStatement = pluginsCode[1].body;
|
|
143
|
+
const lastStatement = targetBlockStatement.body.at(-1);
|
|
144
|
+
if (t__namespace.isExpressionStatement(lastStatement)) {
|
|
145
|
+
const newExpressionStatement = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier('value')), t__namespace.identifier('push')), [lastStatement.expression]));
|
|
146
|
+
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
147
|
+
}
|
|
148
|
+
const ifIdx = targetBlockStatement.body.findIndex((x) => t__namespace.isIfStatement(x));
|
|
149
|
+
if (ifIdx > -1) {
|
|
150
|
+
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
151
|
+
if (t__namespace.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t__namespace.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
152
|
+
const forOf = ifRoot.consequent.body[1];
|
|
153
|
+
if (t__namespace.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t__namespace.isIfStatement(forOf.body.body[0])) {
|
|
154
|
+
const if2 = forOf.body.body[0];
|
|
155
|
+
if (t__namespace.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t__namespace.isExpressionStatement(if2.consequent.body[0])) {
|
|
156
|
+
const target = if2.consequent.body[0];
|
|
157
|
+
const newExpressionStatement = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier('value')), t__namespace.identifier('push')), [target.expression]));
|
|
158
|
+
if2.consequent.body[0] = newExpressionStatement;
|
|
164
159
|
}
|
|
165
160
|
}
|
|
166
161
|
}
|
|
167
|
-
targetBlockStatement.body.unshift(t__namespace.expressionStatement(t__namespace.assignmentExpression('=', t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier(valueKey)), t__namespace.identifier('length')), t__namespace.numericLiteral(0))));
|
|
168
162
|
}
|
|
163
|
+
targetBlockStatement.body.unshift(t__namespace.expressionStatement(t__namespace.assignmentExpression('=', t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier(valueKey)), t__namespace.identifier('length')), t__namespace.numericLiteral(0))));
|
|
169
164
|
}
|
|
170
165
|
}
|
|
171
166
|
}
|
|
@@ -262,7 +257,7 @@ function monkeyPatchForExposingContext(twDir, opt) {
|
|
|
262
257
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
263
258
|
if (!hasPatched && opt.overwrite) {
|
|
264
259
|
fs__default["default"].writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
265
|
-
encoding: '
|
|
260
|
+
encoding: 'utf8'
|
|
266
261
|
});
|
|
267
262
|
console.log('patch tailwindcss processTailwindFeatures for return content successfully!');
|
|
268
263
|
}
|
|
@@ -275,7 +270,7 @@ function monkeyPatchForExposingContext(twDir, opt) {
|
|
|
275
270
|
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
276
271
|
if (!hasPatched && opt.overwrite) {
|
|
277
272
|
fs__default["default"].writeFileSync(pluginFilePath, code, {
|
|
278
|
-
encoding: '
|
|
273
|
+
encoding: 'utf8'
|
|
279
274
|
});
|
|
280
275
|
console.log('patch tailwindcss for expose runtime content successfully!');
|
|
281
276
|
}
|
package/dist/types/babel.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { generate, parse, traverse };
|
|
1
|
+
export { default as generate } from '@babel/generator';
|
|
2
|
+
export { default as traverse } from '@babel/traverse';
|
|
3
|
+
export { parse } from '@babel/parser';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "patch tailwindcss for exposing context",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"tailwindcss": "^3.3.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@babel/generator": "^7.22.
|
|
38
|
-
"@babel/parser": "^7.22.
|
|
39
|
-
"@babel/traverse": "^7.22.
|
|
40
|
-
"@babel/types": "^7.22.
|
|
37
|
+
"@babel/generator": "^7.22.5",
|
|
38
|
+
"@babel/parser": "^7.22.5",
|
|
39
|
+
"@babel/traverse": "^7.22.5",
|
|
40
|
+
"@babel/types": "^7.22.5",
|
|
41
41
|
"resolve": "^1.22.2",
|
|
42
42
|
"semver": "^7.5.1"
|
|
43
43
|
},
|