tailwindcss-patch 5.0.2 → 6.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 +5 -2
- package/bin/tw-patch.js +1 -1
- package/dist/{chunk-LOQK6LST.js → chunk-AZHCF3SW.mjs} +155 -135
- package/dist/{cli.cjs → chunk-P7C42UCO.js} +287 -297
- package/dist/cli.js +17 -17
- package/dist/cli.mjs +35 -0
- package/dist/{index.d.cts → index.d.mts} +17 -13
- package/dist/index.d.ts +17 -13
- package/dist/index.js +24 -23
- package/dist/index.mjs +24 -0
- package/package.json +26 -19
- package/dist/index.cjs +0 -962
- /package/dist/{cli.d.cts → cli.d.mts} +0 -0
package/dist/index.cjs
DELETED
|
@@ -1,962 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var src_exports = {};
|
|
33
|
-
__export(src_exports, {
|
|
34
|
-
CacheManager: () => CacheManager,
|
|
35
|
-
TailwindcssPatcher: () => TailwindcssPatcher,
|
|
36
|
-
defineConfig: () => config_exports.defineConfig,
|
|
37
|
-
getCacheOptions: () => getCacheOptions,
|
|
38
|
-
internalPatch: () => internalPatch,
|
|
39
|
-
logger: () => logger_default,
|
|
40
|
-
monkeyPatchForExposingContextV2: () => monkeyPatchForExposingContextV2,
|
|
41
|
-
monkeyPatchForExposingContextV3: () => monkeyPatchForExposingContextV3,
|
|
42
|
-
monkeyPatchForSupportingCustomUnit: () => monkeyPatchForSupportingCustomUnit
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(src_exports);
|
|
45
|
-
|
|
46
|
-
// ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.0_postcss@8.4.47_tsx@4.19.2_typescript@5.6.3_yaml@2.6.0/node_modules/tsup/assets/cjs_shims.js
|
|
47
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
48
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
49
|
-
|
|
50
|
-
// src/config.ts
|
|
51
|
-
var config_exports = {};
|
|
52
|
-
__reExport(config_exports, require("@tailwindcss-mangle/config"));
|
|
53
|
-
|
|
54
|
-
// src/core/cache.ts
|
|
55
|
-
var import_node_process = __toESM(require("process"), 1);
|
|
56
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
57
|
-
var import_pathe = __toESM(require("pathe"), 1);
|
|
58
|
-
|
|
59
|
-
// src/constants.ts
|
|
60
|
-
var pkgName = "tailwindcss-patch";
|
|
61
|
-
|
|
62
|
-
// src/logger.ts
|
|
63
|
-
var import_consola = require("consola");
|
|
64
|
-
var logger = (0, import_consola.createConsola)();
|
|
65
|
-
var logger_default = logger;
|
|
66
|
-
|
|
67
|
-
// src/core/cache.ts
|
|
68
|
-
function getCacheOptions(options) {
|
|
69
|
-
let cache;
|
|
70
|
-
switch (typeof options) {
|
|
71
|
-
case "undefined": {
|
|
72
|
-
cache = {
|
|
73
|
-
enable: false
|
|
74
|
-
};
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case "boolean": {
|
|
78
|
-
cache = {
|
|
79
|
-
enable: options
|
|
80
|
-
};
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case "object": {
|
|
84
|
-
cache = { ...options, enable: true };
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return cache;
|
|
89
|
-
}
|
|
90
|
-
var CacheManager = class {
|
|
91
|
-
options;
|
|
92
|
-
constructor(options = {}) {
|
|
93
|
-
this.options = this.getOptions(options);
|
|
94
|
-
}
|
|
95
|
-
getOptions(options = {}) {
|
|
96
|
-
const cwd = options.cwd ?? import_node_process.default.cwd();
|
|
97
|
-
const dir = options.dir ?? import_pathe.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
98
|
-
const file = options.file ?? "index.json";
|
|
99
|
-
const filename = import_pathe.default.resolve(dir, file);
|
|
100
|
-
return {
|
|
101
|
-
cwd,
|
|
102
|
-
dir,
|
|
103
|
-
file,
|
|
104
|
-
filename,
|
|
105
|
-
strategy: "merge"
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
write(data) {
|
|
109
|
-
try {
|
|
110
|
-
const { dir, filename } = this.options;
|
|
111
|
-
import_fs_extra.default.ensureDirSync(dir);
|
|
112
|
-
import_fs_extra.default.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
113
|
-
return filename;
|
|
114
|
-
} catch {
|
|
115
|
-
logger_default.error("write cache file fail!");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
read() {
|
|
119
|
-
const { filename } = this.options;
|
|
120
|
-
try {
|
|
121
|
-
if (import_fs_extra.default.existsSync(filename)) {
|
|
122
|
-
const data = import_fs_extra.default.readFileSync(filename, "utf8");
|
|
123
|
-
return new Set(JSON.parse(data));
|
|
124
|
-
}
|
|
125
|
-
} catch {
|
|
126
|
-
logger_default.error(`parse cache content fail! path:${filename}`);
|
|
127
|
-
try {
|
|
128
|
-
import_fs_extra.default.unlinkSync(filename);
|
|
129
|
-
} catch {
|
|
130
|
-
logger_default.error(`delete cache file fail! path:${filename}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// src/core/patcher.ts
|
|
137
|
-
var import_node_module3 = require("module");
|
|
138
|
-
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
139
|
-
var import_pathe7 = __toESM(require("pathe"), 1);
|
|
140
|
-
|
|
141
|
-
// src/defaults.ts
|
|
142
|
-
var import_node_process2 = __toESM(require("process"), 1);
|
|
143
|
-
|
|
144
|
-
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
145
|
-
function isPlainObject(value) {
|
|
146
|
-
if (value === null || typeof value !== "object") {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
const prototype = Object.getPrototypeOf(value);
|
|
150
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
if (Symbol.iterator in value) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
if (Symbol.toStringTag in value) {
|
|
157
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
158
|
-
}
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
162
|
-
if (!isPlainObject(defaults)) {
|
|
163
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
164
|
-
}
|
|
165
|
-
const object = Object.assign({}, defaults);
|
|
166
|
-
for (const key in baseObject) {
|
|
167
|
-
if (key === "__proto__" || key === "constructor") {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
const value = baseObject[key];
|
|
171
|
-
if (value === null || value === void 0) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
178
|
-
object[key] = [...value, ...object[key]];
|
|
179
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
180
|
-
object[key] = _defu(
|
|
181
|
-
value,
|
|
182
|
-
object[key],
|
|
183
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
184
|
-
merger
|
|
185
|
-
);
|
|
186
|
-
} else {
|
|
187
|
-
object[key] = value;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return object;
|
|
191
|
-
}
|
|
192
|
-
function createDefu(merger) {
|
|
193
|
-
return (...arguments_) => (
|
|
194
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
195
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
var defu = createDefu();
|
|
199
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
200
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
201
|
-
object[key] = currentValue(object[key]);
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
206
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
207
|
-
object[key] = currentValue(object[key]);
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
// ../shared/src/utils.ts
|
|
213
|
-
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
214
|
-
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
215
|
-
obj[key] = value;
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
var preserveClassNames = [
|
|
220
|
-
// https://tailwindcss.com/docs/transition-timing-function start
|
|
221
|
-
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
222
|
-
"ease-out",
|
|
223
|
-
"ease-linear",
|
|
224
|
-
"ease-in",
|
|
225
|
-
"ease-in-out"
|
|
226
|
-
// https://tailwindcss.com/docs/transition-timing-function end
|
|
227
|
-
];
|
|
228
|
-
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
229
|
-
acc[cur] = true;
|
|
230
|
-
return acc;
|
|
231
|
-
}, {});
|
|
232
|
-
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
233
|
-
|
|
234
|
-
// src/defaults.ts
|
|
235
|
-
function getDefaultPatchOptions() {
|
|
236
|
-
return {
|
|
237
|
-
applyPatches: {
|
|
238
|
-
exportContext: true,
|
|
239
|
-
extendLengthUnits: false
|
|
240
|
-
},
|
|
241
|
-
overwrite: true
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function getPatchOptions(options) {
|
|
245
|
-
return defu(
|
|
246
|
-
options,
|
|
247
|
-
{
|
|
248
|
-
basedir: import_node_process2.default.cwd()
|
|
249
|
-
},
|
|
250
|
-
getDefaultPatchOptions()
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/utils.ts
|
|
255
|
-
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
256
|
-
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
257
|
-
var import_resolve = __toESM(require("resolve"), 1);
|
|
258
|
-
var { sync } = import_resolve.default;
|
|
259
|
-
function requireResolve(id, opts) {
|
|
260
|
-
return sync(id, opts);
|
|
261
|
-
}
|
|
262
|
-
function searchPackageJSON(dir) {
|
|
263
|
-
let packageJsonPath;
|
|
264
|
-
while (true) {
|
|
265
|
-
if (!dir) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const newDir = import_pathe2.default.dirname(dir);
|
|
269
|
-
if (newDir === dir) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
dir = newDir;
|
|
273
|
-
packageJsonPath = import_pathe2.default.join(dir, "package.json");
|
|
274
|
-
if (import_fs_extra2.default.existsSync(packageJsonPath)) {
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return packageJsonPath;
|
|
279
|
-
}
|
|
280
|
-
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
281
|
-
return requireResolve(name, opts);
|
|
282
|
-
}
|
|
283
|
-
function getPackageJsonPath(name, options = {}) {
|
|
284
|
-
const entry = getTailwindcssEntry(name, options);
|
|
285
|
-
if (!entry) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
return searchPackageJSON(entry);
|
|
289
|
-
}
|
|
290
|
-
function getPackageInfoSync(name, options = {}) {
|
|
291
|
-
const packageJsonPath = getPackageJsonPath(name, options);
|
|
292
|
-
if (!packageJsonPath) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const packageJson = JSON.parse(import_fs_extra2.default.readFileSync(packageJsonPath, "utf8"));
|
|
296
|
-
return {
|
|
297
|
-
name,
|
|
298
|
-
version: packageJson.version,
|
|
299
|
-
rootPath: import_pathe2.default.dirname(packageJsonPath),
|
|
300
|
-
packageJsonPath,
|
|
301
|
-
packageJson
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function isObject(val) {
|
|
305
|
-
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/core/postcss.ts
|
|
309
|
-
var import_node_module = require("module");
|
|
310
|
-
var import_node_process3 = __toESM(require("process"), 1);
|
|
311
|
-
var import_jiti = require("jiti");
|
|
312
|
-
var import_lilconfig = require("lilconfig");
|
|
313
|
-
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
314
|
-
var import_postcss = __toESM(require("postcss"), 1);
|
|
315
|
-
var jiti = (0, import_jiti.createJiti)(importMetaUrl);
|
|
316
|
-
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
317
|
-
async function processTailwindcss(options) {
|
|
318
|
-
const { config: userConfig, cwd } = defu(options, {
|
|
319
|
-
cwd: import_node_process3.default.cwd()
|
|
320
|
-
});
|
|
321
|
-
let config = userConfig;
|
|
322
|
-
if (!(typeof config === "string" && import_pathe3.default.isAbsolute(config))) {
|
|
323
|
-
const moduleName = "tailwind";
|
|
324
|
-
const result = await (0, import_lilconfig.lilconfig)("tailwindcss", {
|
|
325
|
-
searchPlaces: [
|
|
326
|
-
`${moduleName}.config.js`,
|
|
327
|
-
`${moduleName}.config.cjs`,
|
|
328
|
-
`${moduleName}.config.mjs`,
|
|
329
|
-
`${moduleName}.config.ts`,
|
|
330
|
-
`${moduleName}.config.cts`,
|
|
331
|
-
`${moduleName}.config.mts`
|
|
332
|
-
],
|
|
333
|
-
loaders: {
|
|
334
|
-
// 默认支持 js 和 cjs 2种格式
|
|
335
|
-
".js": jiti,
|
|
336
|
-
".cjs": jiti,
|
|
337
|
-
".mjs": jiti,
|
|
338
|
-
".ts": jiti,
|
|
339
|
-
".cts": jiti,
|
|
340
|
-
".mts": jiti
|
|
341
|
-
}
|
|
342
|
-
}).search(cwd);
|
|
343
|
-
if (!result) {
|
|
344
|
-
throw new Error(`No TailwindCSS Config found in: ${cwd}`);
|
|
345
|
-
}
|
|
346
|
-
config = result.filepath;
|
|
347
|
-
}
|
|
348
|
-
const id = requireResolve("tailwindcss", {
|
|
349
|
-
basedir: cwd
|
|
350
|
-
});
|
|
351
|
-
return await (0, import_postcss.default)([
|
|
352
|
-
require2(id)({
|
|
353
|
-
config
|
|
354
|
-
})
|
|
355
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
356
|
-
from: void 0
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// src/core/runtime.ts
|
|
361
|
-
var import_node_module2 = require("module");
|
|
362
|
-
var import_pathe6 = __toESM(require("pathe"), 1);
|
|
363
|
-
var import_semver = require("semver");
|
|
364
|
-
|
|
365
|
-
// src/core/patches/exportContext/index.ts
|
|
366
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
367
|
-
var import_pathe4 = __toESM(require("pathe"), 1);
|
|
368
|
-
|
|
369
|
-
// src/core/patches/exportContext/postcss-v2.ts
|
|
370
|
-
var t = __toESM(require("@babel/types"), 1);
|
|
371
|
-
|
|
372
|
-
// src/babel/index.ts
|
|
373
|
-
var import_generator = __toESM(require("@babel/generator"), 1);
|
|
374
|
-
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
375
|
-
var import_parser = require("@babel/parser");
|
|
376
|
-
function _interopDefaultCompat(e) {
|
|
377
|
-
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
378
|
-
}
|
|
379
|
-
var generate = _interopDefaultCompat(import_generator.default);
|
|
380
|
-
var traverse = _interopDefaultCompat(import_traverse.default);
|
|
381
|
-
|
|
382
|
-
// src/core/patches/exportContext/postcss-v2.ts
|
|
383
|
-
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
384
|
-
const ast = (0, import_parser.parse)(content, {
|
|
385
|
-
sourceType: "unambiguous"
|
|
386
|
-
});
|
|
387
|
-
let hasPatched = false;
|
|
388
|
-
traverse(ast, {
|
|
389
|
-
FunctionDeclaration(p) {
|
|
390
|
-
const n = p.node;
|
|
391
|
-
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
392
|
-
const rts = n.body.body[0];
|
|
393
|
-
if (t.isFunctionExpression(rts.argument)) {
|
|
394
|
-
const body = rts.argument.body.body;
|
|
395
|
-
const lastStatement = body[body.length - 1];
|
|
396
|
-
hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
397
|
-
if (!hasPatched) {
|
|
398
|
-
const rts2 = t.returnStatement(t.identifier("context"));
|
|
399
|
-
body.push(rts2);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
return {
|
|
406
|
-
code: hasPatched ? content : generate(ast).code,
|
|
407
|
-
hasPatched
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function inspectPostcssPlugin(content) {
|
|
411
|
-
const ast = (0, import_parser.parse)(content);
|
|
412
|
-
const exportKey = "contextRef";
|
|
413
|
-
const variableName = "contextRef";
|
|
414
|
-
const valueKey = "value";
|
|
415
|
-
let hasPatched = false;
|
|
416
|
-
traverse(ast, {
|
|
417
|
-
Program(p) {
|
|
418
|
-
const n = p.node;
|
|
419
|
-
const idx = n.body.findIndex((x) => {
|
|
420
|
-
return t.isFunctionDeclaration(x) && x.id?.name === "_default";
|
|
421
|
-
});
|
|
422
|
-
if (idx > -1) {
|
|
423
|
-
const prevStatement = n.body[idx - 1];
|
|
424
|
-
const lastStatement = n.body[idx - 2];
|
|
425
|
-
const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
426
|
-
const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
427
|
-
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
428
|
-
if (!hasPatched) {
|
|
429
|
-
const statement = t.variableDeclaration("var", [
|
|
430
|
-
t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
|
|
431
|
-
]);
|
|
432
|
-
n.body.splice(
|
|
433
|
-
idx,
|
|
434
|
-
0,
|
|
435
|
-
statement,
|
|
436
|
-
// exports.contextRef = contextRef;
|
|
437
|
-
t.expressionStatement(
|
|
438
|
-
t.assignmentExpression(
|
|
439
|
-
"=",
|
|
440
|
-
t.memberExpression(t.identifier("exports"), t.identifier(exportKey)),
|
|
441
|
-
t.identifier(variableName)
|
|
442
|
-
)
|
|
443
|
-
)
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
FunctionDeclaration(p) {
|
|
449
|
-
if (hasPatched) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
const n = p.node;
|
|
453
|
-
if (n.id?.name === "_default" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
|
|
454
|
-
const returnStatement3 = n.body.body[0];
|
|
455
|
-
if (t.isCallExpression(returnStatement3.argument) && t.isMemberExpression(returnStatement3.argument.callee) && t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
456
|
-
const targetFn = returnStatement3.argument.callee.object.elements[1];
|
|
457
|
-
if (t.isFunctionExpression(targetFn)) {
|
|
458
|
-
const targetBlockStatement = targetFn.body;
|
|
459
|
-
if (t.isExpressionStatement(targetBlockStatement.body[0]) && t.isAssignmentExpression(targetBlockStatement.body[0].expression) && t.isNumericLiteral(targetBlockStatement.body[0].expression.right)) {
|
|
460
|
-
hasPatched = true;
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
464
|
-
if (t.isExpressionStatement(lastStatement)) {
|
|
465
|
-
const newExpressionStatement = t.expressionStatement(
|
|
466
|
-
t.callExpression(
|
|
467
|
-
t.memberExpression(
|
|
468
|
-
t.memberExpression(t.identifier(variableName), t.identifier("value")),
|
|
469
|
-
t.identifier("push")
|
|
470
|
-
),
|
|
471
|
-
[lastStatement.expression]
|
|
472
|
-
)
|
|
473
|
-
);
|
|
474
|
-
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
475
|
-
}
|
|
476
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
|
|
477
|
-
if (ifIdx > -1) {
|
|
478
|
-
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
479
|
-
if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
480
|
-
const forOf = ifRoot.consequent.body[1];
|
|
481
|
-
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
|
|
482
|
-
const if2 = forOf.body.body[0];
|
|
483
|
-
if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
|
|
484
|
-
const target = if2.consequent.body[0];
|
|
485
|
-
const newExpressionStatement = t.expressionStatement(
|
|
486
|
-
t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
|
|
487
|
-
);
|
|
488
|
-
if2.consequent.body[0] = newExpressionStatement;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
targetBlockStatement.body.unshift(
|
|
494
|
-
// contentRef.value = []
|
|
495
|
-
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
496
|
-
// contentRef.value.length = 0
|
|
497
|
-
t.expressionStatement(
|
|
498
|
-
t.assignmentExpression(
|
|
499
|
-
"=",
|
|
500
|
-
t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
|
|
501
|
-
t.numericLiteral(0)
|
|
502
|
-
)
|
|
503
|
-
)
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
return {
|
|
511
|
-
code: hasPatched ? content : generate(ast).code,
|
|
512
|
-
hasPatched
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// src/core/patches/exportContext/postcss-v3.ts
|
|
517
|
-
var t2 = __toESM(require("@babel/types"), 1);
|
|
518
|
-
function inspectProcessTailwindFeaturesReturnContext2(content) {
|
|
519
|
-
const ast = (0, import_parser.parse)(content);
|
|
520
|
-
let hasPatched = false;
|
|
521
|
-
traverse(ast, {
|
|
522
|
-
FunctionDeclaration(p) {
|
|
523
|
-
const n = p.node;
|
|
524
|
-
if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
525
|
-
const rts = n.body.body[0];
|
|
526
|
-
if (t2.isFunctionExpression(rts.argument)) {
|
|
527
|
-
const body = rts.argument.body.body;
|
|
528
|
-
const lastStatement = body[body.length - 1];
|
|
529
|
-
hasPatched = t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
|
|
530
|
-
if (!hasPatched) {
|
|
531
|
-
const rts2 = t2.returnStatement(t2.identifier("context"));
|
|
532
|
-
body.push(rts2);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
return {
|
|
539
|
-
code: hasPatched ? content : generate(ast).code,
|
|
540
|
-
hasPatched
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
function inspectPostcssPlugin2(content) {
|
|
544
|
-
const ast = (0, import_parser.parse)(content);
|
|
545
|
-
const exportKey = "contextRef";
|
|
546
|
-
const variableName = "contextRef";
|
|
547
|
-
const valueKey = "value";
|
|
548
|
-
let hasPatched = false;
|
|
549
|
-
traverse(ast, {
|
|
550
|
-
Program(p) {
|
|
551
|
-
const n = p.node;
|
|
552
|
-
const idx = n.body.findIndex((x) => {
|
|
553
|
-
return t2.isExpressionStatement(x) && t2.isAssignmentExpression(x.expression) && t2.isMemberExpression(x.expression.left) && t2.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
|
|
554
|
-
});
|
|
555
|
-
if (idx > -1) {
|
|
556
|
-
const prevStatement = n.body[idx - 1];
|
|
557
|
-
const lastStatement = n.body[n.body.length - 1];
|
|
558
|
-
const hasPatchedCondition0 = prevStatement && t2.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t2.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
|
|
559
|
-
const hasPatchedCondition1 = t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
|
|
560
|
-
hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
|
|
561
|
-
if (!hasPatched) {
|
|
562
|
-
const statement = t2.variableDeclaration("const", [
|
|
563
|
-
t2.variableDeclarator(t2.identifier(variableName), t2.objectExpression([t2.objectProperty(t2.identifier(valueKey), t2.arrayExpression())]))
|
|
564
|
-
]);
|
|
565
|
-
n.body.splice(idx, 0, statement);
|
|
566
|
-
n.body.push(
|
|
567
|
-
t2.expressionStatement(
|
|
568
|
-
t2.assignmentExpression(
|
|
569
|
-
"=",
|
|
570
|
-
t2.memberExpression(t2.memberExpression(t2.identifier("module"), t2.identifier("exports")), t2.identifier(exportKey)),
|
|
571
|
-
t2.identifier(variableName)
|
|
572
|
-
)
|
|
573
|
-
)
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
FunctionExpression(p) {
|
|
579
|
-
if (hasPatched) {
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
const n = p.node;
|
|
583
|
-
if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
|
|
584
|
-
const returnStatement3 = n.body.body[0];
|
|
585
|
-
if (t2.isObjectExpression(returnStatement3.argument) && returnStatement3.argument.properties.length === 2) {
|
|
586
|
-
const properties = returnStatement3.argument.properties;
|
|
587
|
-
if (t2.isObjectProperty(properties[0]) && t2.isObjectProperty(properties[1])) {
|
|
588
|
-
const keyMatched = t2.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
|
|
589
|
-
const pluginsMatched = t2.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
|
|
590
|
-
if (pluginsMatched && keyMatched && t2.isCallExpression(properties[1].value) && t2.isMemberExpression(properties[1].value.callee) && t2.isArrayExpression(properties[1].value.callee.object)) {
|
|
591
|
-
const pluginsCode = properties[1].value.callee.object.elements;
|
|
592
|
-
if (pluginsCode[1] && t2.isFunctionExpression(pluginsCode[1])) {
|
|
593
|
-
const targetBlockStatement = pluginsCode[1].body;
|
|
594
|
-
const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
|
|
595
|
-
if (t2.isExpressionStatement(lastStatement)) {
|
|
596
|
-
const newExpressionStatement = t2.expressionStatement(
|
|
597
|
-
t2.callExpression(
|
|
598
|
-
t2.memberExpression(
|
|
599
|
-
t2.memberExpression(t2.identifier(variableName), t2.identifier("value")),
|
|
600
|
-
t2.identifier("push")
|
|
601
|
-
),
|
|
602
|
-
[lastStatement.expression]
|
|
603
|
-
)
|
|
604
|
-
);
|
|
605
|
-
targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
|
|
606
|
-
}
|
|
607
|
-
const ifIdx = targetBlockStatement.body.findIndex((x) => t2.isIfStatement(x));
|
|
608
|
-
if (ifIdx > -1) {
|
|
609
|
-
const ifRoot = targetBlockStatement.body[ifIdx];
|
|
610
|
-
if (t2.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t2.isForOfStatement(ifRoot.consequent.body[1])) {
|
|
611
|
-
const forOf = ifRoot.consequent.body[1];
|
|
612
|
-
if (t2.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t2.isIfStatement(forOf.body.body[0])) {
|
|
613
|
-
const if2 = forOf.body.body[0];
|
|
614
|
-
if (t2.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t2.isExpressionStatement(if2.consequent.body[0])) {
|
|
615
|
-
const target = if2.consequent.body[0];
|
|
616
|
-
const newExpressionStatement = t2.expressionStatement(
|
|
617
|
-
t2.callExpression(t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier("value")), t2.identifier("push")), [target.expression])
|
|
618
|
-
);
|
|
619
|
-
if2.consequent.body[0] = newExpressionStatement;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
targetBlockStatement.body.unshift(
|
|
625
|
-
// contentRef.value = []
|
|
626
|
-
// t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
|
|
627
|
-
// contentRef.value.length = 0
|
|
628
|
-
t2.expressionStatement(
|
|
629
|
-
t2.assignmentExpression(
|
|
630
|
-
"=",
|
|
631
|
-
t2.memberExpression(t2.memberExpression(t2.identifier(variableName), t2.identifier(valueKey)), t2.identifier("length")),
|
|
632
|
-
t2.numericLiteral(0)
|
|
633
|
-
)
|
|
634
|
-
)
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
// BlockStatement(p) {
|
|
643
|
-
// const n = p.node
|
|
644
|
-
// if (start && p.parent.type === 'FunctionExpression' && !p.parent.id) {
|
|
645
|
-
// n.body.unshift(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression())))
|
|
646
|
-
// }
|
|
647
|
-
// }
|
|
648
|
-
});
|
|
649
|
-
return {
|
|
650
|
-
code: hasPatched ? content : generate(ast).code,
|
|
651
|
-
hasPatched
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// src/core/patches/exportContext/index.ts
|
|
656
|
-
function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
657
|
-
const k0 = "lib/processTailwindFeatures.js";
|
|
658
|
-
const processTailwindFeaturesFilePath = import_pathe4.default.resolve(twDir, k0);
|
|
659
|
-
const processTailwindFeaturesContent = import_fs_extra3.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
660
|
-
const result = {};
|
|
661
|
-
if (processTailwindFeaturesContent) {
|
|
662
|
-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext2(processTailwindFeaturesContent);
|
|
663
|
-
if (!hasPatched && opt.overwrite) {
|
|
664
|
-
import_fs_extra3.default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
665
|
-
encoding: "utf8"
|
|
666
|
-
});
|
|
667
|
-
logger_default.success("patch tailwindcss processTailwindFeatures for return context successfully!");
|
|
668
|
-
}
|
|
669
|
-
result[k0] = code;
|
|
670
|
-
}
|
|
671
|
-
let injectFilepath;
|
|
672
|
-
let k1;
|
|
673
|
-
const try0 = "lib/plugin.js";
|
|
674
|
-
const try1 = "lib/index.js";
|
|
675
|
-
const pluginFilePath = import_pathe4.default.resolve(twDir, try0);
|
|
676
|
-
const indexFilePath = import_pathe4.default.resolve(twDir, try1);
|
|
677
|
-
if (import_fs_extra3.default.existsSync(pluginFilePath)) {
|
|
678
|
-
k1 = try0;
|
|
679
|
-
injectFilepath = pluginFilePath;
|
|
680
|
-
} else if (import_fs_extra3.default.existsSync(indexFilePath)) {
|
|
681
|
-
k1 = try1;
|
|
682
|
-
injectFilepath = indexFilePath;
|
|
683
|
-
}
|
|
684
|
-
if (injectFilepath && k1) {
|
|
685
|
-
const pluginContent = import_fs_extra3.default.readFileSync(injectFilepath, "utf8");
|
|
686
|
-
if (pluginContent) {
|
|
687
|
-
const { code, hasPatched } = inspectPostcssPlugin2(pluginContent);
|
|
688
|
-
if (!hasPatched && opt.overwrite) {
|
|
689
|
-
import_fs_extra3.default.writeFileSync(injectFilepath, code, {
|
|
690
|
-
encoding: "utf8"
|
|
691
|
-
});
|
|
692
|
-
logger_default.success("patch tailwindcss for expose runtime context successfully!");
|
|
693
|
-
}
|
|
694
|
-
result[k1] = code;
|
|
695
|
-
}
|
|
696
|
-
return result;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
700
|
-
const k0 = "lib/jit/processTailwindFeatures.js";
|
|
701
|
-
const processTailwindFeaturesFilePath = import_pathe4.default.resolve(twDir, k0);
|
|
702
|
-
const processTailwindFeaturesContent = import_fs_extra3.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
703
|
-
const result = {};
|
|
704
|
-
if (processTailwindFeaturesContent) {
|
|
705
|
-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
706
|
-
if (!hasPatched && opt.overwrite) {
|
|
707
|
-
import_fs_extra3.default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
708
|
-
encoding: "utf8"
|
|
709
|
-
});
|
|
710
|
-
logger_default.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
711
|
-
}
|
|
712
|
-
result[k0] = code;
|
|
713
|
-
}
|
|
714
|
-
const k1 = "lib/jit/index.js";
|
|
715
|
-
const indexFilePath = import_pathe4.default.resolve(twDir, k1);
|
|
716
|
-
const pluginContent = import_fs_extra3.default.readFileSync(indexFilePath, "utf8");
|
|
717
|
-
if (pluginContent) {
|
|
718
|
-
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
719
|
-
if (!hasPatched && opt.overwrite) {
|
|
720
|
-
import_fs_extra3.default.writeFileSync(indexFilePath, code, {
|
|
721
|
-
encoding: "utf8"
|
|
722
|
-
});
|
|
723
|
-
logger_default.success("patch tailwindcss for expose runtime content successfully!");
|
|
724
|
-
}
|
|
725
|
-
result[k1] = code;
|
|
726
|
-
}
|
|
727
|
-
return result;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// src/core/patches/supportCustomUnits/index.ts
|
|
731
|
-
var t3 = __toESM(require("@babel/types"), 1);
|
|
732
|
-
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
733
|
-
var import_pathe5 = __toESM(require("pathe"), 1);
|
|
734
|
-
function findAstNode(content, options) {
|
|
735
|
-
const { variableName, units } = options;
|
|
736
|
-
const ast = (0, import_parser.parse)(content);
|
|
737
|
-
let arrayRef;
|
|
738
|
-
let changed = false;
|
|
739
|
-
traverse(ast, {
|
|
740
|
-
Identifier(path8) {
|
|
741
|
-
if (path8.node.name === variableName && t3.isVariableDeclarator(path8.parent) && t3.isArrayExpression(path8.parent.init)) {
|
|
742
|
-
arrayRef = path8.parent.init;
|
|
743
|
-
const set = new Set(path8.parent.init.elements.map((x) => x.value));
|
|
744
|
-
for (let i = 0; i < units.length; i++) {
|
|
745
|
-
const unit = units[i];
|
|
746
|
-
if (!set.has(unit)) {
|
|
747
|
-
path8.parent.init.elements = path8.parent.init.elements.map((x) => {
|
|
748
|
-
if (t3.isStringLiteral(x)) {
|
|
749
|
-
return {
|
|
750
|
-
type: x?.type,
|
|
751
|
-
value: x?.value
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
return x;
|
|
755
|
-
});
|
|
756
|
-
path8.parent.init.elements.push({
|
|
757
|
-
type: "StringLiteral",
|
|
758
|
-
value: unit
|
|
759
|
-
});
|
|
760
|
-
changed = true;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
return {
|
|
767
|
-
arrayRef,
|
|
768
|
-
changed
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
772
|
-
const opts = defuOverrideArray(options, {
|
|
773
|
-
units: ["rpx"],
|
|
774
|
-
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
775
|
-
variableName: "lengthUnits",
|
|
776
|
-
overwrite: true
|
|
777
|
-
});
|
|
778
|
-
const { lengthUnitsFilePath, overwrite, destPath } = opts;
|
|
779
|
-
const dataTypesFilePath = import_pathe5.default.resolve(rootDir, lengthUnitsFilePath);
|
|
780
|
-
const dataTypesFileContent = import_fs_extra4.default.readFileSync(dataTypesFilePath, {
|
|
781
|
-
encoding: "utf8"
|
|
782
|
-
});
|
|
783
|
-
const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
|
|
784
|
-
if (arrayRef && changed) {
|
|
785
|
-
const { code } = generate(arrayRef, {
|
|
786
|
-
jsescOption: {
|
|
787
|
-
quotes: "single"
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
if (arrayRef.start && arrayRef.end) {
|
|
791
|
-
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
792
|
-
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
793
|
-
const newCode = prev + code + next;
|
|
794
|
-
if (overwrite) {
|
|
795
|
-
import_fs_extra4.default.writeFileSync(destPath ?? dataTypesFilePath, newCode, {
|
|
796
|
-
encoding: "utf8"
|
|
797
|
-
});
|
|
798
|
-
logger_default.success("patch tailwindcss for custom length unit successfully!");
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return {
|
|
802
|
-
[opts.lengthUnitsFilePath]: code
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
// src/core/runtime.ts
|
|
808
|
-
var require3 = (0, import_node_module2.createRequire)(importMetaUrl);
|
|
809
|
-
function internalPatch(pkgJsonPath, options) {
|
|
810
|
-
if (pkgJsonPath) {
|
|
811
|
-
const pkgJson = require3(pkgJsonPath);
|
|
812
|
-
const twDir = import_pathe6.default.dirname(pkgJsonPath);
|
|
813
|
-
options.version = pkgJson.version;
|
|
814
|
-
if ((0, import_semver.gte)(pkgJson.version, "3.0.0")) {
|
|
815
|
-
let result = {};
|
|
816
|
-
if (options.applyPatches?.exportContext) {
|
|
817
|
-
result = monkeyPatchForExposingContextV3(twDir, options);
|
|
818
|
-
}
|
|
819
|
-
if (options.applyPatches?.extendLengthUnits) {
|
|
820
|
-
try {
|
|
821
|
-
Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
|
|
822
|
-
overwrite: options.overwrite
|
|
823
|
-
})));
|
|
824
|
-
} catch {
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
return result;
|
|
828
|
-
} else if ((0, import_semver.gte)(pkgJson.version, "2.0.0")) {
|
|
829
|
-
if (options.applyPatches?.exportContext) {
|
|
830
|
-
return monkeyPatchForExposingContextV2(twDir, options);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// src/core/patcher.ts
|
|
837
|
-
var require4 = (0, import_node_module3.createRequire)(importMetaUrl);
|
|
838
|
-
var TailwindcssPatcher = class {
|
|
839
|
-
rawOptions;
|
|
840
|
-
cacheOptions;
|
|
841
|
-
patchOptions;
|
|
842
|
-
patch;
|
|
843
|
-
cacheManager;
|
|
844
|
-
packageInfo;
|
|
845
|
-
majorVersion;
|
|
846
|
-
constructor(options = {}) {
|
|
847
|
-
this.rawOptions = options;
|
|
848
|
-
this.cacheOptions = getCacheOptions(options.cache);
|
|
849
|
-
this.patchOptions = getPatchOptions(options.patch);
|
|
850
|
-
this.cacheManager = new CacheManager(this.cacheOptions);
|
|
851
|
-
this.packageInfo = getPackageInfoSync("tailwindcss", { basedir: this.patchOptions.basedir });
|
|
852
|
-
if (this.packageInfo && this.packageInfo.version) {
|
|
853
|
-
this.majorVersion = Number.parseInt(this.packageInfo.version[0]);
|
|
854
|
-
}
|
|
855
|
-
this.patch = () => {
|
|
856
|
-
try {
|
|
857
|
-
return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
|
|
858
|
-
} catch (error) {
|
|
859
|
-
logger_default.error(`patch tailwindcss failed: ${error.message}`);
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
setCache(set) {
|
|
864
|
-
if (this.cacheOptions.enable) {
|
|
865
|
-
return this.cacheManager.write(set);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
getCache() {
|
|
869
|
-
return this.cacheManager.read();
|
|
870
|
-
}
|
|
871
|
-
getContexts() {
|
|
872
|
-
if (this.packageInfo) {
|
|
873
|
-
const distPath = import_pathe7.default.join(this.packageInfo.rootPath, "lib");
|
|
874
|
-
let injectFilePath;
|
|
875
|
-
if (this.majorVersion === 2) {
|
|
876
|
-
injectFilePath = import_pathe7.default.join(distPath, "jit/index.js");
|
|
877
|
-
} else {
|
|
878
|
-
injectFilePath = import_pathe7.default.join(distPath, "plugin.js");
|
|
879
|
-
if (!import_fs_extra5.default.existsSync(injectFilePath)) {
|
|
880
|
-
injectFilePath = import_pathe7.default.join(distPath, "index.js");
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
if (injectFilePath) {
|
|
884
|
-
const mo = require4(injectFilePath);
|
|
885
|
-
if (mo.contextRef) {
|
|
886
|
-
return mo.contextRef.value;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return [];
|
|
891
|
-
}
|
|
892
|
-
getClassCaches() {
|
|
893
|
-
const contexts = this.getContexts();
|
|
894
|
-
return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
|
|
895
|
-
}
|
|
896
|
-
getClassCacheSet(options) {
|
|
897
|
-
const classCaches = this.getClassCaches();
|
|
898
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
899
|
-
for (const classCacheMap of classCaches) {
|
|
900
|
-
const keys = classCacheMap.keys();
|
|
901
|
-
for (const key of keys) {
|
|
902
|
-
const v = key.toString();
|
|
903
|
-
if (options?.removeUniversalSelector && v === "*") {
|
|
904
|
-
continue;
|
|
905
|
-
}
|
|
906
|
-
classSet.add(v);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
return classSet;
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
|
|
913
|
-
*/
|
|
914
|
-
getClassSet(options) {
|
|
915
|
-
const { cacheStrategy = this.cacheOptions.strategy ?? "merge", removeUniversalSelector = true } = options ?? {};
|
|
916
|
-
const set = this.getClassCacheSet({
|
|
917
|
-
removeUniversalSelector
|
|
918
|
-
});
|
|
919
|
-
if (cacheStrategy === "overwrite") {
|
|
920
|
-
set.size > 0 && this.setCache(set);
|
|
921
|
-
} else if (cacheStrategy === "merge") {
|
|
922
|
-
const cacheSet = this.getCache();
|
|
923
|
-
if (cacheSet) {
|
|
924
|
-
for (const x of cacheSet) {
|
|
925
|
-
set.add(x);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
this.setCache(set);
|
|
929
|
-
}
|
|
930
|
-
return set;
|
|
931
|
-
}
|
|
932
|
-
async extract(options) {
|
|
933
|
-
const { output, tailwindcss } = options ?? {};
|
|
934
|
-
if (output && tailwindcss) {
|
|
935
|
-
const { removeUniversalSelector, filename, loose } = output;
|
|
936
|
-
await processTailwindcss(tailwindcss);
|
|
937
|
-
const set = this.getClassSet({
|
|
938
|
-
removeUniversalSelector
|
|
939
|
-
});
|
|
940
|
-
if (filename) {
|
|
941
|
-
await import_fs_extra5.default.ensureDir(import_pathe7.default.dirname(filename));
|
|
942
|
-
const classList = [...set];
|
|
943
|
-
await import_fs_extra5.default.outputJSON(filename, classList, {
|
|
944
|
-
spaces: loose ? 2 : void 0
|
|
945
|
-
});
|
|
946
|
-
return filename;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
952
|
-
0 && (module.exports = {
|
|
953
|
-
CacheManager,
|
|
954
|
-
TailwindcssPatcher,
|
|
955
|
-
defineConfig,
|
|
956
|
-
getCacheOptions,
|
|
957
|
-
internalPatch,
|
|
958
|
-
logger,
|
|
959
|
-
monkeyPatchForExposingContextV2,
|
|
960
|
-
monkeyPatchForExposingContextV3,
|
|
961
|
-
monkeyPatchForSupportingCustomUnit
|
|
962
|
-
});
|