tailwindcss-patch 1.0.1 → 1.0.3
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var patcher = require('./patcher-
|
|
3
|
+
var patcher = require('./patcher-90d636ff.js');
|
|
4
4
|
require('path');
|
|
5
5
|
require('fs');
|
|
6
6
|
require('semver');
|
|
@@ -10,5 +10,5 @@ require('@babel/parser');
|
|
|
10
10
|
require('@babel/traverse');
|
|
11
11
|
require('resolve');
|
|
12
12
|
|
|
13
|
-
const patch = patcher.createPatch(
|
|
13
|
+
const patch = patcher.createPatch();
|
|
14
14
|
patch();
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var fs = require('fs');
|
|
7
|
-
var patcher = require('./patcher-
|
|
7
|
+
var patcher = require('./patcher-90d636ff.js');
|
|
8
8
|
require('semver');
|
|
9
9
|
require('@babel/types');
|
|
10
10
|
require('@babel/generator');
|
|
@@ -53,11 +53,13 @@ function getClassCacheSet() {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
exports.createPatch = patcher.createPatch;
|
|
56
|
+
exports.ensureFileContent = patcher.ensureFileContent;
|
|
56
57
|
exports.getInstalledPkgJsonPath = patcher.getInstalledPkgJsonPath;
|
|
57
58
|
exports.inspectPostcssPlugin = patcher.inspectPostcssPlugin;
|
|
58
59
|
exports.inspectProcessTailwindFeaturesReturnContext = patcher.inspectProcessTailwindFeaturesReturnContext;
|
|
59
60
|
exports.internalPatch = patcher.internalPatch;
|
|
60
61
|
exports.monkeyPatchForExposingContext = patcher.monkeyPatchForExposingContext;
|
|
62
|
+
exports.requireResolve = patcher.requireResolve;
|
|
61
63
|
exports.getClassCacheSet = getClassCacheSet;
|
|
62
64
|
exports.getClassCaches = getClassCaches;
|
|
63
65
|
exports.getContexts = getContexts;
|
|
@@ -60,15 +60,15 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
|
60
60
|
let hasPatched = false;
|
|
61
61
|
traverse__default["default"](ast, {
|
|
62
62
|
FunctionDeclaration(p) {
|
|
63
|
-
var _a
|
|
63
|
+
var _a;
|
|
64
64
|
const n = p.node;
|
|
65
65
|
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'processTailwindFeatures') {
|
|
66
|
-
if (n.body.body.length === 1 && n.body.body[0]
|
|
66
|
+
if (n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
67
67
|
const rts = n.body.body[0];
|
|
68
68
|
if (t__namespace.isFunctionExpression(rts.argument)) {
|
|
69
69
|
const body = rts.argument.body.body;
|
|
70
70
|
const lastStatement = body[body.length - 1];
|
|
71
|
-
hasPatched = lastStatement
|
|
71
|
+
hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === 'context';
|
|
72
72
|
if (!hasPatched) {
|
|
73
73
|
const rts = t__namespace.returnStatement(t__namespace.identifier('context'));
|
|
74
74
|
body.push(rts);
|
|
@@ -94,23 +94,23 @@ function inspectPostcssPlugin(content) {
|
|
|
94
94
|
const n = p.node;
|
|
95
95
|
const idx = n.body.findIndex((x) => {
|
|
96
96
|
var _a;
|
|
97
|
-
return (x
|
|
98
|
-
x.expression
|
|
99
|
-
x.expression.left
|
|
100
|
-
x.expression.right
|
|
97
|
+
return (t__namespace.isExpressionStatement(x) &&
|
|
98
|
+
t__namespace.isAssignmentExpression(x.expression) &&
|
|
99
|
+
t__namespace.isMemberExpression(x.expression.left) &&
|
|
100
|
+
t__namespace.isFunctionExpression(x.expression.right) &&
|
|
101
101
|
((_a = x.expression.right.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss');
|
|
102
102
|
});
|
|
103
103
|
if (idx > -1) {
|
|
104
104
|
const prevStatement = n.body[idx - 1];
|
|
105
105
|
const lastStatement = n.body[n.body.length - 1];
|
|
106
106
|
const hasPatchedCondition0 = prevStatement &&
|
|
107
|
-
prevStatement
|
|
107
|
+
t__namespace.isVariableDeclaration(prevStatement) &&
|
|
108
108
|
prevStatement.declarations.length === 1 &&
|
|
109
|
-
prevStatement.declarations[0].id
|
|
109
|
+
t__namespace.isIdentifier(prevStatement.declarations[0].id) &&
|
|
110
110
|
prevStatement.declarations[0].id.name === variableName;
|
|
111
|
-
const hasPatchedCondition1 = lastStatement
|
|
112
|
-
lastStatement.expression
|
|
113
|
-
lastStatement.expression.right
|
|
111
|
+
const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) &&
|
|
112
|
+
t__namespace.isAssignmentExpression(lastStatement.expression) &&
|
|
113
|
+
t__namespace.isIdentifier(lastStatement.expression.right) &&
|
|
114
114
|
lastStatement.expression.right.name === variableName;
|
|
115
115
|
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
116
116
|
if (!hasPatched) {
|
|
@@ -123,40 +123,40 @@ function inspectPostcssPlugin(content) {
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
FunctionExpression(p) {
|
|
126
|
-
var _a
|
|
126
|
+
var _a;
|
|
127
127
|
if (hasPatched) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
const n = p.node;
|
|
131
131
|
if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss') {
|
|
132
|
-
if (n.body.body.length === 1 && n.body.body[0]
|
|
132
|
+
if (n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
|
|
133
133
|
const returnStatement = n.body.body[0];
|
|
134
|
-
if ((
|
|
134
|
+
if (t__namespace.isObjectExpression(returnStatement.argument) && returnStatement.argument.properties.length === 2) {
|
|
135
135
|
const properties = returnStatement.argument.properties;
|
|
136
|
-
if (properties[0]
|
|
137
|
-
const keyMatched = properties[0].key
|
|
138
|
-
const pluginsMatched = properties[1].key
|
|
136
|
+
if (t__namespace.isObjectProperty(properties[0]) && t__namespace.isObjectProperty(properties[1])) {
|
|
137
|
+
const keyMatched = t__namespace.isIdentifier(properties[0].key) && properties[0].key.name === 'postcssPlugin';
|
|
138
|
+
const pluginsMatched = t__namespace.isIdentifier(properties[1].key) && properties[1].key.name === 'plugins';
|
|
139
139
|
if (pluginsMatched &&
|
|
140
140
|
keyMatched &&
|
|
141
|
-
properties[1].value
|
|
142
|
-
properties[1].value.callee
|
|
143
|
-
properties[1].value.callee.object
|
|
141
|
+
t__namespace.isCallExpression(properties[1].value) &&
|
|
142
|
+
t__namespace.isMemberExpression(properties[1].value.callee) &&
|
|
143
|
+
t__namespace.isArrayExpression(properties[1].value.callee.object)) {
|
|
144
144
|
const pluginsCode = properties[1].value.callee.object.elements;
|
|
145
|
-
if (pluginsCode[1] && pluginsCode[1]
|
|
145
|
+
if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
|
|
146
146
|
const targetBlockStatement = pluginsCode[1].body;
|
|
147
147
|
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
148
|
-
if (lastStatement
|
|
148
|
+
if (t__namespace.isExpressionStatement(lastStatement)) {
|
|
149
149
|
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]));
|
|
150
150
|
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
151
151
|
}
|
|
152
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) => x
|
|
152
|
+
const ifIdx = targetBlockStatement.body.findIndex((x) => t__namespace.isIfStatement(x));
|
|
153
153
|
if (ifIdx > -1) {
|
|
154
154
|
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
155
|
-
if (ifRoot.consequent
|
|
155
|
+
if (t__namespace.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t__namespace.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
156
156
|
const forOf = ifRoot.consequent.body[1];
|
|
157
|
-
if (forOf.body
|
|
157
|
+
if (t__namespace.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t__namespace.isIfStatement(forOf.body.body[0])) {
|
|
158
158
|
const if2 = forOf.body.body[0];
|
|
159
|
-
if (if2.consequent
|
|
159
|
+
if (t__namespace.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t__namespace.isExpressionStatement(if2.consequent.body[0])) {
|
|
160
160
|
const target = if2.consequent.body[0];
|
|
161
161
|
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]));
|
|
162
162
|
if2.consequent.body[0] = newExpressionStatement;
|
|
@@ -225,37 +225,35 @@ const defaultOptions = {
|
|
|
225
225
|
overwrite: true
|
|
226
226
|
};
|
|
227
227
|
|
|
228
|
-
function getInstalledPkgJsonPath(options) {
|
|
228
|
+
function getInstalledPkgJsonPath(options = {}) {
|
|
229
229
|
var _a;
|
|
230
230
|
try {
|
|
231
231
|
const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
|
|
232
232
|
paths: options.paths,
|
|
233
233
|
basedir: (_a = options.basedir) !== null && _a !== void 0 ? _a : process.cwd()
|
|
234
234
|
});
|
|
235
|
-
|
|
236
|
-
if (semver.gte(pkgJson.version, '3.0.0')) {
|
|
237
|
-
return tmpJsonPath;
|
|
238
|
-
}
|
|
235
|
+
return tmpJsonPath;
|
|
239
236
|
}
|
|
240
237
|
catch (error) {
|
|
241
238
|
if (error.code === 'MODULE_NOT_FOUND') {
|
|
242
|
-
console.warn(
|
|
239
|
+
console.warn("Can't find npm pkg: `tailwindcss`, Please ensure it has been installed!");
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
242
|
}
|
|
246
|
-
function createPatch(options) {
|
|
243
|
+
function createPatch(options = {}) {
|
|
247
244
|
const opt = defu(options, defaultOptions);
|
|
248
245
|
return () => {
|
|
249
246
|
try {
|
|
250
|
-
|
|
247
|
+
const pkgJsonPath = getInstalledPkgJsonPath(options);
|
|
248
|
+
return internalPatch(pkgJsonPath, opt);
|
|
251
249
|
}
|
|
252
250
|
catch (error) {
|
|
253
251
|
console.warn(`patch tailwindcss failed:` + error.message);
|
|
254
252
|
}
|
|
255
253
|
};
|
|
256
254
|
}
|
|
257
|
-
function monkeyPatchForExposingContext(
|
|
258
|
-
const processTailwindFeaturesFilePath = path__default["default"].resolve(
|
|
255
|
+
function monkeyPatchForExposingContext(twDir, opt) {
|
|
256
|
+
const processTailwindFeaturesFilePath = path__default["default"].resolve(twDir, 'lib/processTailwindFeatures.js');
|
|
259
257
|
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
|
|
260
258
|
const result = {};
|
|
261
259
|
if (processTailwindFeaturesContent) {
|
|
@@ -268,8 +266,8 @@ function monkeyPatchForExposingContext(rootDir, opt) {
|
|
|
268
266
|
}
|
|
269
267
|
result.processTailwindFeatures = code;
|
|
270
268
|
}
|
|
271
|
-
const pluginFilePath = path__default["default"].resolve(
|
|
272
|
-
const indexFilePath = path__default["default"].resolve(
|
|
269
|
+
const pluginFilePath = path__default["default"].resolve(twDir, 'lib/plugin.js');
|
|
270
|
+
const indexFilePath = path__default["default"].resolve(twDir, 'lib/index.js');
|
|
273
271
|
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
|
|
274
272
|
if (pluginContent) {
|
|
275
273
|
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
@@ -281,17 +279,22 @@ function monkeyPatchForExposingContext(rootDir, opt) {
|
|
|
281
279
|
}
|
|
282
280
|
result.plugin = code;
|
|
283
281
|
}
|
|
282
|
+
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result);
|
|
284
283
|
return result;
|
|
285
284
|
}
|
|
286
285
|
function internalPatch(pkgJsonPath, options) {
|
|
287
286
|
if (pkgJsonPath) {
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
|
|
287
|
+
const pkgJson = require(pkgJsonPath);
|
|
288
|
+
const twDir = path__default["default"].dirname(pkgJsonPath);
|
|
289
|
+
if (semver.gte(pkgJson.version, '3.0.0')) {
|
|
290
|
+
const result = monkeyPatchForExposingContext(twDir, options);
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
295
|
|
|
294
296
|
exports.createPatch = createPatch;
|
|
297
|
+
exports.ensureFileContent = ensureFileContent;
|
|
295
298
|
exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
|
|
296
299
|
exports.inspectPostcssPlugin = inspectPostcssPlugin;
|
|
297
300
|
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/patcher.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PatchOptions, InternalPatchOptions } from './type';
|
|
2
|
-
export declare function getInstalledPkgJsonPath(options
|
|
3
|
-
export declare function createPatch(options
|
|
4
|
-
export declare function monkeyPatchForExposingContext(
|
|
2
|
+
export declare function getInstalledPkgJsonPath(options?: PatchOptions): string | undefined;
|
|
3
|
+
export declare function createPatch(options?: PatchOptions): () => any;
|
|
4
|
+
export declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatchOptions): {
|
|
5
5
|
processTailwindFeatures?: string | undefined;
|
|
6
6
|
plugin?: string | undefined;
|
|
7
|
-
}
|
|
7
|
+
} & Record<string, any>;
|
|
8
8
|
export declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export interface PatchOptions {
|
|
|
2
2
|
overwrite?: boolean;
|
|
3
3
|
paths?: string[];
|
|
4
4
|
basedir?: string;
|
|
5
|
+
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
5
6
|
}
|
|
6
7
|
export interface InternalPatchOptions {
|
|
7
8
|
overwrite: boolean;
|
|
8
9
|
paths?: string[];
|
|
9
10
|
basedir?: string;
|
|
11
|
+
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
10
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "patch tailwindcss for exposing context",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/babel__generator": "^7.6.4",
|
|
27
|
-
"@types/babel__traverse": "^7.18.
|
|
27
|
+
"@types/babel__traverse": "^7.18.4",
|
|
28
28
|
"@types/resolve": "^1.20.2",
|
|
29
29
|
"@types/semver": "^7.3.13",
|
|
30
30
|
"defu": "^6.1.2",
|
|
31
31
|
"pkg-types": "^1.0.2",
|
|
32
|
-
"postcss": "^8.4.
|
|
33
|
-
"tailwindcss": "^3.3.
|
|
32
|
+
"postcss": "^8.4.23",
|
|
33
|
+
"tailwindcss": "^3.3.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/generator": "^7.21.4",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@babel/traverse": "^7.21.4",
|
|
39
39
|
"@babel/types": "^7.21.4",
|
|
40
40
|
"resolve": "^1.22.2",
|
|
41
|
-
"semver": "^7.
|
|
41
|
+
"semver": "^7.5.0"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
|
|
44
44
|
"repository": {
|