tailwindcss-patch 1.2.7 → 2.0.0
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 +63 -6
- package/bin/tw-patch.js +3 -3
- package/dist/cli.cjs +115 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +107 -0
- package/dist/index.cjs +554 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.mjs +519 -0
- package/package.json +34 -11
- package/dist/cli.js +0 -15
- package/dist/index.js +0 -191
- package/dist/patcher-a07f477f.js +0 -302
- package/dist/types/babel.d.ts +0 -3
- package/dist/types/cache.d.ts +0 -7
- package/dist/types/class.d.ts +0 -17
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/defaults.d.ts +0 -2
- package/dist/types/exposeContext.d.ts +0 -5
- package/dist/types/index.d.ts +0 -6
- package/dist/types/inspector.d.ts +0 -8
- package/dist/types/logger.d.ts +0 -1
- package/dist/types/patcher.d.ts +0 -9
- package/dist/types/type.d.ts +0 -72
- package/dist/types/utils.d.ts +0 -3
package/package.json
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "patch tailwindcss for exposing context",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"typesVersions": {
|
|
13
|
+
"*": {
|
|
14
|
+
"*": [
|
|
15
|
+
"./dist/*",
|
|
16
|
+
"./dist/index.d.ts"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
6
21
|
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "dist/
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
8
23
|
"bin": {
|
|
9
24
|
"tw-patch": "bin/tw-patch.js",
|
|
10
25
|
"tailwindcss-patch": "bin/tw-patch.js"
|
|
@@ -28,9 +43,9 @@
|
|
|
28
43
|
"@types/babel__traverse": "^7.20.1",
|
|
29
44
|
"@types/resolve": "^1.20.2",
|
|
30
45
|
"@types/semver": "^7.5.0",
|
|
46
|
+
"dedent": "^1.5.1",
|
|
31
47
|
"defu": "^6.1.2",
|
|
32
48
|
"pkg-types": "^1.0.3",
|
|
33
|
-
"postcss": "^8.4.26",
|
|
34
49
|
"tailwindcss": "^3.3.3"
|
|
35
50
|
},
|
|
36
51
|
"dependencies": {
|
|
@@ -38,7 +53,11 @@
|
|
|
38
53
|
"@babel/parser": "^7.22.7",
|
|
39
54
|
"@babel/traverse": "^7.22.8",
|
|
40
55
|
"@babel/types": "^7.22.5",
|
|
41
|
-
"
|
|
56
|
+
"c12": "^1.4.2",
|
|
57
|
+
"cac": "^6.7.14",
|
|
58
|
+
"postcss": "^8.4.27",
|
|
59
|
+
"postcss-load-config": "^4.0.1",
|
|
60
|
+
"resolve": "^1.22.4",
|
|
42
61
|
"semver": "^7.5.4"
|
|
43
62
|
},
|
|
44
63
|
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
|
|
@@ -46,12 +65,16 @@
|
|
|
46
65
|
"type": "git",
|
|
47
66
|
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
|
|
48
67
|
},
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/sonofmagic/tailwindcss-mangle/issues"
|
|
70
|
+
},
|
|
71
|
+
"directories": {
|
|
72
|
+
"test": "test"
|
|
73
|
+
},
|
|
49
74
|
"scripts": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"dev
|
|
53
|
-
"
|
|
54
|
-
"test": "npm run patch && jest",
|
|
55
|
-
"patch": "ts-node src/cli.ts"
|
|
75
|
+
"build": "unbuild",
|
|
76
|
+
"test": "vitest run --coverage.enabled",
|
|
77
|
+
"test:dev": "vitest",
|
|
78
|
+
"cli": "node bin/tw-patch.js install"
|
|
56
79
|
}
|
|
57
80
|
}
|
package/dist/cli.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var patcher = require('./patcher-a07f477f.js');
|
|
4
|
-
require('node:path');
|
|
5
|
-
require('node:fs');
|
|
6
|
-
require('semver');
|
|
7
|
-
require('@babel/types');
|
|
8
|
-
require('@babel/generator');
|
|
9
|
-
require('@babel/traverse');
|
|
10
|
-
require('@babel/parser');
|
|
11
|
-
require('resolve');
|
|
12
|
-
|
|
13
|
-
const opt = patcher.getPatchOptions();
|
|
14
|
-
const patch = patcher.createPatch(opt);
|
|
15
|
-
patch();
|
package/dist/index.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var path = require('node:path');
|
|
6
|
-
var fs = require('node:fs');
|
|
7
|
-
var patcher = require('./patcher-a07f477f.js');
|
|
8
|
-
require('semver');
|
|
9
|
-
require('@babel/types');
|
|
10
|
-
require('@babel/generator');
|
|
11
|
-
require('@babel/traverse');
|
|
12
|
-
require('@babel/parser');
|
|
13
|
-
require('resolve');
|
|
14
|
-
|
|
15
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
-
|
|
17
|
-
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
18
|
-
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
19
|
-
|
|
20
|
-
function getTailwindcssEntry(basedir = process.cwd()) {
|
|
21
|
-
return patcher.requireResolve('tailwindcss');
|
|
22
|
-
}
|
|
23
|
-
function getContexts(basedir) {
|
|
24
|
-
const twPath = getTailwindcssEntry(basedir);
|
|
25
|
-
const distPath = path__default["default"].dirname(twPath);
|
|
26
|
-
let injectFilePath = path__default["default"].join(distPath, 'plugin.js');
|
|
27
|
-
if (!fs__default["default"].existsSync(injectFilePath)) {
|
|
28
|
-
injectFilePath = path__default["default"].join(distPath, 'index.js');
|
|
29
|
-
}
|
|
30
|
-
const mo = require(injectFilePath);
|
|
31
|
-
if (mo.contextRef) {
|
|
32
|
-
return mo.contextRef.value;
|
|
33
|
-
}
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
function getClassCaches(basedir) {
|
|
37
|
-
const contexts = getContexts(basedir);
|
|
38
|
-
return contexts.map((x) => x.classCache);
|
|
39
|
-
}
|
|
40
|
-
function getClassCacheSet(basedir) {
|
|
41
|
-
const classCaches = getClassCaches(basedir);
|
|
42
|
-
const classSet = new Set();
|
|
43
|
-
for (const classCacheMap of classCaches) {
|
|
44
|
-
const keys = classCacheMap.keys();
|
|
45
|
-
for (const key of keys) {
|
|
46
|
-
classSet.add(key.toString());
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return classSet;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const pkgName = 'tailwindcss-patch';
|
|
53
|
-
|
|
54
|
-
function log(message, ...optionalParams) {
|
|
55
|
-
return console.log(`[${pkgName}]:` + message, ...optionalParams);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function mkCacheDirectory(cacheDirectory) {
|
|
59
|
-
const exists = fs__default["default"].existsSync(cacheDirectory);
|
|
60
|
-
if (!exists) {
|
|
61
|
-
fs__default["default"].mkdirSync(cacheDirectory, {
|
|
62
|
-
recursive: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return cacheDirectory;
|
|
66
|
-
}
|
|
67
|
-
function getCacheOptions$1(options = {}) {
|
|
68
|
-
var _a, _b, _c;
|
|
69
|
-
const cwd = (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd();
|
|
70
|
-
const dir = (_b = options.dir) !== null && _b !== void 0 ? _b : path__default["default"].resolve(cwd, 'node_modules/.cache', pkgName);
|
|
71
|
-
const file = (_c = options.file) !== null && _c !== void 0 ? _c : 'index.json';
|
|
72
|
-
const filename = path__default["default"].resolve(dir, file);
|
|
73
|
-
return {
|
|
74
|
-
cwd,
|
|
75
|
-
dir,
|
|
76
|
-
file,
|
|
77
|
-
filename,
|
|
78
|
-
strategy: 'merge'
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function writeCache(data, options = {}) {
|
|
82
|
-
try {
|
|
83
|
-
const { dir, filename } = getCacheOptions$1(options);
|
|
84
|
-
mkCacheDirectory(dir);
|
|
85
|
-
fs__default["default"].writeFileSync(filename, JSON.stringify([...data], undefined, 2), 'utf8');
|
|
86
|
-
return filename;
|
|
87
|
-
}
|
|
88
|
-
catch (_a) {
|
|
89
|
-
log('write cache file fail!');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function readCache(options = {}) {
|
|
93
|
-
const { filename } = getCacheOptions$1(options);
|
|
94
|
-
try {
|
|
95
|
-
if (fs__default["default"].existsSync(filename)) {
|
|
96
|
-
const data = fs__default["default"].readFileSync(filename, 'utf8');
|
|
97
|
-
return new Set(JSON.parse(data));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (_a) {
|
|
101
|
-
log('parse cache content fail! path:' + filename);
|
|
102
|
-
try {
|
|
103
|
-
fs__default["default"].unlinkSync(filename);
|
|
104
|
-
}
|
|
105
|
-
catch (_b) {
|
|
106
|
-
log('delete cache file fail! path:' + filename);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function getCacheOptions(options) {
|
|
112
|
-
let cache;
|
|
113
|
-
switch (typeof options) {
|
|
114
|
-
case 'undefined': {
|
|
115
|
-
cache = {
|
|
116
|
-
enable: false
|
|
117
|
-
};
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
case 'boolean': {
|
|
121
|
-
cache = {
|
|
122
|
-
enable: options
|
|
123
|
-
};
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case 'object': {
|
|
127
|
-
cache = Object.assign(Object.assign({}, options), { enable: true });
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return cache;
|
|
132
|
-
}
|
|
133
|
-
class TailwindcssPatcher {
|
|
134
|
-
constructor(options = {}) {
|
|
135
|
-
this.rawOptions = options;
|
|
136
|
-
this.cacheOptions = getCacheOptions(options.cache);
|
|
137
|
-
this.patchOptions = patcher.getPatchOptions(options.patch);
|
|
138
|
-
this.patch = patcher.createPatch(this.patchOptions);
|
|
139
|
-
}
|
|
140
|
-
getPkgEntry(basedir) {
|
|
141
|
-
return getTailwindcssEntry(basedir);
|
|
142
|
-
}
|
|
143
|
-
setCache(set) {
|
|
144
|
-
if (this.cacheOptions.enable) {
|
|
145
|
-
return writeCache(set, this.cacheOptions);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
getCache() {
|
|
149
|
-
return readCache(this.cacheOptions);
|
|
150
|
-
}
|
|
151
|
-
getClassSet(options) {
|
|
152
|
-
var _a;
|
|
153
|
-
if (options === void 0) { options = {
|
|
154
|
-
cacheStrategy: (_a = this.cacheOptions.strategy) !== null && _a !== void 0 ? _a : 'merge'
|
|
155
|
-
}; }
|
|
156
|
-
const { basedir, cacheStrategy } = options;
|
|
157
|
-
const set = getClassCacheSet(basedir);
|
|
158
|
-
if (cacheStrategy === 'overwrite') {
|
|
159
|
-
set.size > 0 && this.setCache(set);
|
|
160
|
-
}
|
|
161
|
-
else if (cacheStrategy === 'merge') {
|
|
162
|
-
const cacheSet = this.getCache();
|
|
163
|
-
if (cacheSet) {
|
|
164
|
-
for (const x of cacheSet) {
|
|
165
|
-
set.add(x);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
this.setCache(set);
|
|
169
|
-
}
|
|
170
|
-
return set;
|
|
171
|
-
}
|
|
172
|
-
getContexts(basedir) {
|
|
173
|
-
return getContexts(basedir);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
exports.createPatch = patcher.createPatch;
|
|
178
|
-
exports.ensureFileContent = patcher.ensureFileContent;
|
|
179
|
-
exports.getInstalledPkgJsonPath = patcher.getInstalledPkgJsonPath;
|
|
180
|
-
exports.getPatchOptions = patcher.getPatchOptions;
|
|
181
|
-
exports.inspectPostcssPlugin = patcher.inspectPostcssPlugin;
|
|
182
|
-
exports.inspectProcessTailwindFeaturesReturnContext = patcher.inspectProcessTailwindFeaturesReturnContext;
|
|
183
|
-
exports.internalPatch = patcher.internalPatch;
|
|
184
|
-
exports.monkeyPatchForExposingContext = patcher.monkeyPatchForExposingContext;
|
|
185
|
-
exports.requireResolve = patcher.requireResolve;
|
|
186
|
-
exports.TailwindcssPatcher = TailwindcssPatcher;
|
|
187
|
-
exports.getCacheOptions = getCacheOptions;
|
|
188
|
-
exports.getClassCacheSet = getClassCacheSet;
|
|
189
|
-
exports.getClassCaches = getClassCaches;
|
|
190
|
-
exports.getContexts = getContexts;
|
|
191
|
-
exports.getTailwindcssEntry = getTailwindcssEntry;
|
package/dist/patcher-a07f477f.js
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('node:path');
|
|
4
|
-
var fs = require('node:fs');
|
|
5
|
-
var semver = require('semver');
|
|
6
|
-
var t = require('@babel/types');
|
|
7
|
-
var generate = require('@babel/generator');
|
|
8
|
-
var traverse = require('@babel/traverse');
|
|
9
|
-
var parser = require('@babel/parser');
|
|
10
|
-
var resolve = require('resolve');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
function _interopNamespaceCompat(e) {
|
|
15
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
16
|
-
var n = Object.create(null);
|
|
17
|
-
if (e) {
|
|
18
|
-
Object.keys(e).forEach(function (k) {
|
|
19
|
-
if (k !== 'default') {
|
|
20
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () { return e[k]; }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
n["default"] = e;
|
|
29
|
-
return Object.freeze(n);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
33
|
-
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
34
|
-
var t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
35
|
-
var generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
|
|
36
|
-
var traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
|
|
37
|
-
|
|
38
|
-
function ensureFileContent(filepaths) {
|
|
39
|
-
if (typeof filepaths === 'string') {
|
|
40
|
-
filepaths = [filepaths];
|
|
41
|
-
}
|
|
42
|
-
let content;
|
|
43
|
-
for (const filepath of filepaths) {
|
|
44
|
-
if (fs__default["default"].existsSync(filepath)) {
|
|
45
|
-
content = fs__default["default"].readFileSync(filepath, {
|
|
46
|
-
encoding: 'utf8'
|
|
47
|
-
});
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return content;
|
|
52
|
-
}
|
|
53
|
-
function requireResolve(id, opts) {
|
|
54
|
-
return resolve.sync(id, opts);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
58
|
-
const ast = parser.parse(content);
|
|
59
|
-
let hasPatched = false;
|
|
60
|
-
traverse__default["default"](ast, {
|
|
61
|
-
FunctionDeclaration(p) {
|
|
62
|
-
var _a;
|
|
63
|
-
const n = p.node;
|
|
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);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
code: hasPatched ? content : generate__default["default"](ast).code,
|
|
80
|
-
hasPatched
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function inspectPostcssPlugin(content) {
|
|
84
|
-
const ast = parser.parse(content);
|
|
85
|
-
const exportKey = 'contextRef';
|
|
86
|
-
const variableName = 'contextRef';
|
|
87
|
-
const valueKey = 'value';
|
|
88
|
-
let hasPatched = false;
|
|
89
|
-
traverse__default["default"](ast, {
|
|
90
|
-
Program(p) {
|
|
91
|
-
const n = p.node;
|
|
92
|
-
const idx = n.body.findIndex((x) => {
|
|
93
|
-
var _a;
|
|
94
|
-
return (t__namespace.isExpressionStatement(x) &&
|
|
95
|
-
t__namespace.isAssignmentExpression(x.expression) &&
|
|
96
|
-
t__namespace.isMemberExpression(x.expression.left) &&
|
|
97
|
-
t__namespace.isFunctionExpression(x.expression.right) &&
|
|
98
|
-
((_a = x.expression.right.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss');
|
|
99
|
-
});
|
|
100
|
-
if (idx > -1) {
|
|
101
|
-
const prevStatement = n.body[idx - 1];
|
|
102
|
-
const lastStatement = n.body.at(-1);
|
|
103
|
-
const hasPatchedCondition0 = prevStatement &&
|
|
104
|
-
t__namespace.isVariableDeclaration(prevStatement) &&
|
|
105
|
-
prevStatement.declarations.length === 1 &&
|
|
106
|
-
t__namespace.isIdentifier(prevStatement.declarations[0].id) &&
|
|
107
|
-
prevStatement.declarations[0].id.name === variableName;
|
|
108
|
-
const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) &&
|
|
109
|
-
t__namespace.isAssignmentExpression(lastStatement.expression) &&
|
|
110
|
-
t__namespace.isIdentifier(lastStatement.expression.right) &&
|
|
111
|
-
lastStatement.expression.right.name === variableName;
|
|
112
|
-
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
113
|
-
if (!hasPatched) {
|
|
114
|
-
const statement = t__namespace.variableDeclaration('const', [
|
|
115
|
-
t__namespace.variableDeclarator(t__namespace.identifier(variableName), t__namespace.objectExpression([t__namespace.objectProperty(t__namespace.identifier(valueKey), t__namespace.arrayExpression())]))
|
|
116
|
-
]);
|
|
117
|
-
n.body.splice(idx, 0, statement);
|
|
118
|
-
n.body.push(t__namespace.expressionStatement(t__namespace.assignmentExpression('=', t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier('module'), t__namespace.identifier('exports')), t__namespace.identifier(exportKey)), t__namespace.identifier(variableName))));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
FunctionExpression(p) {
|
|
123
|
-
var _a;
|
|
124
|
-
if (hasPatched) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const n = p.node;
|
|
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;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
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))));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return {
|
|
172
|
-
code: hasPatched ? content : generate__default["default"](ast).code,
|
|
173
|
-
hasPatched
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function isObject(value) {
|
|
178
|
-
return value !== null && typeof value === "object";
|
|
179
|
-
}
|
|
180
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
181
|
-
if (!isObject(defaults)) {
|
|
182
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
183
|
-
}
|
|
184
|
-
const object = Object.assign({}, defaults);
|
|
185
|
-
for (const key in baseObject) {
|
|
186
|
-
if (key === "__proto__" || key === "constructor") {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
const value = baseObject[key];
|
|
190
|
-
if (value === null || value === void 0) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
197
|
-
object[key] = [...value, ...object[key]];
|
|
198
|
-
} else if (isObject(value) && isObject(object[key])) {
|
|
199
|
-
object[key] = _defu(
|
|
200
|
-
value,
|
|
201
|
-
object[key],
|
|
202
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
203
|
-
merger
|
|
204
|
-
);
|
|
205
|
-
} else {
|
|
206
|
-
object[key] = value;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return object;
|
|
210
|
-
}
|
|
211
|
-
function createDefu(merger) {
|
|
212
|
-
return (...arguments_) => (
|
|
213
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
214
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
const defu = createDefu();
|
|
218
|
-
|
|
219
|
-
const defaultOptions = {
|
|
220
|
-
overwrite: true
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
function getInstalledPkgJsonPath(options = {}) {
|
|
224
|
-
try {
|
|
225
|
-
const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
|
|
226
|
-
paths: options.paths
|
|
227
|
-
});
|
|
228
|
-
return tmpJsonPath;
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
232
|
-
console.warn("Can't find npm pkg: `tailwindcss`, Please ensure it has been installed!");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function getPatchOptions(options = {}) {
|
|
237
|
-
return defu(options, {
|
|
238
|
-
basedir: process.cwd()
|
|
239
|
-
}, defaultOptions);
|
|
240
|
-
}
|
|
241
|
-
function createPatch(opt) {
|
|
242
|
-
return () => {
|
|
243
|
-
try {
|
|
244
|
-
const pkgJsonPath = getInstalledPkgJsonPath(opt);
|
|
245
|
-
return internalPatch(pkgJsonPath, opt);
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
console.warn(`patch tailwindcss failed:` + error.message);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function monkeyPatchForExposingContext(twDir, opt) {
|
|
253
|
-
const processTailwindFeaturesFilePath = path__default["default"].resolve(twDir, 'lib/processTailwindFeatures.js');
|
|
254
|
-
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
|
|
255
|
-
const result = {};
|
|
256
|
-
if (processTailwindFeaturesContent) {
|
|
257
|
-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
258
|
-
if (!hasPatched && opt.overwrite) {
|
|
259
|
-
fs__default["default"].writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
260
|
-
encoding: 'utf8'
|
|
261
|
-
});
|
|
262
|
-
console.log('patch tailwindcss processTailwindFeatures for return content successfully!');
|
|
263
|
-
}
|
|
264
|
-
result.processTailwindFeatures = code;
|
|
265
|
-
}
|
|
266
|
-
const pluginFilePath = path__default["default"].resolve(twDir, 'lib/plugin.js');
|
|
267
|
-
const indexFilePath = path__default["default"].resolve(twDir, 'lib/index.js');
|
|
268
|
-
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
|
|
269
|
-
if (pluginContent) {
|
|
270
|
-
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
271
|
-
if (!hasPatched && opt.overwrite) {
|
|
272
|
-
fs__default["default"].writeFileSync(pluginFilePath, code, {
|
|
273
|
-
encoding: 'utf8'
|
|
274
|
-
});
|
|
275
|
-
console.log('patch tailwindcss for expose runtime content successfully!');
|
|
276
|
-
}
|
|
277
|
-
result.plugin = code;
|
|
278
|
-
}
|
|
279
|
-
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result);
|
|
280
|
-
return result;
|
|
281
|
-
}
|
|
282
|
-
function internalPatch(pkgJsonPath, options) {
|
|
283
|
-
if (pkgJsonPath) {
|
|
284
|
-
const pkgJson = require(pkgJsonPath);
|
|
285
|
-
const twDir = path__default["default"].dirname(pkgJsonPath);
|
|
286
|
-
if (semver.gte(pkgJson.version, '3.0.0')) {
|
|
287
|
-
options.version = pkgJson.version;
|
|
288
|
-
const result = monkeyPatchForExposingContext(twDir, options);
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
exports.createPatch = createPatch;
|
|
295
|
-
exports.ensureFileContent = ensureFileContent;
|
|
296
|
-
exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
|
|
297
|
-
exports.getPatchOptions = getPatchOptions;
|
|
298
|
-
exports.inspectPostcssPlugin = inspectPostcssPlugin;
|
|
299
|
-
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
|
|
300
|
-
exports.internalPatch = internalPatch;
|
|
301
|
-
exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
|
|
302
|
-
exports.requireResolve = requireResolve;
|
package/dist/types/babel.d.ts
DELETED
package/dist/types/cache.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CacheOptions } from './type';
|
|
2
|
-
export declare function mkCacheDirectory(cacheDirectory: string): string;
|
|
3
|
-
export declare function getCacheOptions(options?: CacheOptions): Required<CacheOptions> & {
|
|
4
|
-
filename: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function writeCache(data: Set<string>, options?: CacheOptions): string | undefined;
|
|
7
|
-
export declare function readCache(options?: CacheOptions): Set<string> | undefined;
|
package/dist/types/class.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CacheOptions, InternalCacheOptions, InternalPatchOptions, TailwindcssPatcherOptions, CacheStrategy } from './type';
|
|
2
|
-
export declare function getCacheOptions(options?: CacheOptions | boolean): InternalCacheOptions;
|
|
3
|
-
export declare class TailwindcssPatcher {
|
|
4
|
-
rawOptions: TailwindcssPatcherOptions;
|
|
5
|
-
cacheOptions: InternalCacheOptions;
|
|
6
|
-
patchOptions: InternalPatchOptions;
|
|
7
|
-
patch: () => void;
|
|
8
|
-
constructor(options?: TailwindcssPatcherOptions);
|
|
9
|
-
getPkgEntry(basedir?: string): string;
|
|
10
|
-
setCache(set: Set<string>): string | undefined;
|
|
11
|
-
getCache(): Set<string> | undefined;
|
|
12
|
-
getClassSet(options?: {
|
|
13
|
-
basedir?: string;
|
|
14
|
-
cacheStrategy?: CacheStrategy;
|
|
15
|
-
}): Set<string>;
|
|
16
|
-
getContexts(basedir?: string): import("./type").TailwindcssRuntimeContext[];
|
|
17
|
-
}
|
package/dist/types/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const pkgName = "tailwindcss-patch";
|
package/dist/types/defaults.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { TailwindcssClassCache, TailwindcssRuntimeContext } from './type';
|
|
2
|
-
export declare function getTailwindcssEntry(basedir?: string): string;
|
|
3
|
-
export declare function getContexts(basedir?: string): TailwindcssRuntimeContext[];
|
|
4
|
-
export declare function getClassCaches(basedir?: string): TailwindcssClassCache[];
|
|
5
|
-
export declare function getClassCacheSet(basedir?: string): Set<string>;
|
package/dist/types/index.d.ts
DELETED
package/dist/types/logger.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function log(message?: any, ...optionalParams: any[]): void;
|
package/dist/types/patcher.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PatchOptions, InternalPatchOptions } from './type';
|
|
2
|
-
export declare function getInstalledPkgJsonPath(options?: PatchOptions): string | undefined;
|
|
3
|
-
export declare function getPatchOptions(options?: PatchOptions): InternalPatchOptions;
|
|
4
|
-
export declare function createPatch(opt: InternalPatchOptions): () => any;
|
|
5
|
-
export declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatchOptions): {
|
|
6
|
-
processTailwindFeatures?: string | undefined;
|
|
7
|
-
plugin?: string | undefined;
|
|
8
|
-
} & Record<string, any>;
|
|
9
|
-
export declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|