tailwindcss-patch 2.0.5-alpha.1 → 2.0.5-alpha.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/index.js DELETED
@@ -1,661 +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
- createPatch: () => createPatch,
37
- ensureDir: () => ensureDir,
38
- ensureFileContent: () => ensureFileContent,
39
- getCacheOptions: () => getCacheOptions,
40
- getClassCacheSet: () => getClassCacheSet,
41
- getClassCaches: () => getClassCaches,
42
- getContexts: () => getContexts,
43
- getInstalledPkgJsonPath: () => getInstalledPkgJsonPath,
44
- getPatchOptions: () => getPatchOptions,
45
- getTailwindcssEntry: () => getTailwindcssEntry,
46
- inspectPostcssPlugin: () => inspectPostcssPlugin,
47
- inspectProcessTailwindFeaturesReturnContext: () => inspectProcessTailwindFeaturesReturnContext,
48
- internalPatch: () => internalPatch,
49
- monkeyPatchForExposingContext: () => monkeyPatchForExposingContext,
50
- requireResolve: () => requireResolve
51
- });
52
- module.exports = __toCommonJS(src_exports);
53
-
54
- // src/core/index.ts
55
- var core_exports = {};
56
- __export(core_exports, {
57
- CacheManager: () => CacheManager,
58
- TailwindcssPatcher: () => TailwindcssPatcher,
59
- createPatch: () => createPatch,
60
- getCacheOptions: () => getCacheOptions,
61
- getClassCacheSet: () => getClassCacheSet,
62
- getClassCaches: () => getClassCaches,
63
- getContexts: () => getContexts,
64
- getInstalledPkgJsonPath: () => getInstalledPkgJsonPath,
65
- getPatchOptions: () => getPatchOptions,
66
- getTailwindcssEntry: () => getTailwindcssEntry,
67
- inspectPostcssPlugin: () => inspectPostcssPlugin,
68
- inspectProcessTailwindFeaturesReturnContext: () => inspectProcessTailwindFeaturesReturnContext,
69
- internalPatch: () => internalPatch,
70
- monkeyPatchForExposingContext: () => monkeyPatchForExposingContext
71
- });
72
-
73
- // src/core/tw-patcher.ts
74
- var import_promises2 = __toESM(require("fs/promises"));
75
- var import_node_path5 = require("path");
76
-
77
- // src/core/exposeContext.ts
78
- var import_node_path = __toESM(require("path"));
79
- var import_node_fs2 = __toESM(require("fs"));
80
-
81
- // src/utils.ts
82
- var import_node_fs = __toESM(require("fs"));
83
- var import_promises = __toESM(require("fs/promises"));
84
- var import_resolve = __toESM(require("resolve"));
85
- var { sync } = import_resolve.default;
86
- function ensureFileContent(filepaths) {
87
- if (typeof filepaths === "string") {
88
- filepaths = [filepaths];
89
- }
90
- let content;
91
- for (const filepath of filepaths) {
92
- if (import_node_fs.default.existsSync(filepath)) {
93
- content = import_node_fs.default.readFileSync(filepath, {
94
- encoding: "utf8"
95
- });
96
- break;
97
- }
98
- }
99
- return content;
100
- }
101
- function requireResolve(id, opts) {
102
- return sync(id, opts);
103
- }
104
- async function ensureDir(p) {
105
- try {
106
- await import_promises.default.access(p);
107
- } catch {
108
- await import_promises.default.mkdir(p, {
109
- recursive: true
110
- });
111
- }
112
- }
113
-
114
- // src/core/exposeContext.ts
115
- function getTailwindcssEntry(basedir = process.cwd()) {
116
- return requireResolve("tailwindcss");
117
- }
118
- function getContexts(basedir) {
119
- const twPath = getTailwindcssEntry(basedir);
120
- const distPath = import_node_path.default.dirname(twPath);
121
- let injectFilePath = import_node_path.default.join(distPath, "plugin.js");
122
- if (!import_node_fs2.default.existsSync(injectFilePath)) {
123
- injectFilePath = import_node_path.default.join(distPath, "index.js");
124
- }
125
- const mo = require(injectFilePath);
126
- if (mo.contextRef) {
127
- return mo.contextRef.value;
128
- }
129
- return [];
130
- }
131
- function getClassCaches(basedir) {
132
- const contexts = getContexts(basedir);
133
- return contexts.map((x) => x.classCache);
134
- }
135
- function getClassCacheSet(basedir, options) {
136
- const classCaches = getClassCaches(basedir);
137
- const classSet = /* @__PURE__ */ new Set();
138
- for (const classCacheMap of classCaches) {
139
- const keys = classCacheMap.keys();
140
- for (const key of keys) {
141
- const v = key.toString();
142
- if (options?.removeUniversalSelector && v === "*") {
143
- continue;
144
- }
145
- classSet.add(v);
146
- }
147
- }
148
- return classSet;
149
- }
150
-
151
- // src/core/cache.ts
152
- var import_node_fs3 = __toESM(require("fs"));
153
- var import_node_path2 = __toESM(require("path"));
154
-
155
- // src/constants.ts
156
- var pkgName = "tailwindcss-patch";
157
-
158
- // src/logger.ts
159
- function log(message, ...optionalParams) {
160
- return console.log(`[${pkgName}]:` + message, ...optionalParams);
161
- }
162
-
163
- // src/core/cache.ts
164
- function getCacheOptions(options) {
165
- let cache;
166
- switch (typeof options) {
167
- case "undefined": {
168
- cache = {
169
- enable: false
170
- };
171
- break;
172
- }
173
- case "boolean": {
174
- cache = {
175
- enable: options
176
- };
177
- break;
178
- }
179
- case "object": {
180
- cache = { ...options, enable: true };
181
- break;
182
- }
183
- }
184
- return cache;
185
- }
186
- var CacheManager = class {
187
- options;
188
- constructor(options = {}) {
189
- this.options = this.getOptions(options);
190
- }
191
- mkdir(cacheDirectory) {
192
- const exists = import_node_fs3.default.existsSync(cacheDirectory);
193
- if (!exists) {
194
- import_node_fs3.default.mkdirSync(cacheDirectory, {
195
- recursive: true
196
- });
197
- }
198
- return cacheDirectory;
199
- }
200
- getOptions(options = {}) {
201
- const cwd = options.cwd ?? process.cwd();
202
- const dir = options.dir ?? import_node_path2.default.resolve(cwd, "node_modules/.cache", pkgName);
203
- const file = options.file ?? "index.json";
204
- const filename = import_node_path2.default.resolve(dir, file);
205
- return {
206
- cwd,
207
- dir,
208
- file,
209
- filename,
210
- strategy: "merge"
211
- };
212
- }
213
- write(data) {
214
- try {
215
- const { dir, filename } = this.options;
216
- this.mkdir(dir);
217
- import_node_fs3.default.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
218
- return filename;
219
- } catch {
220
- log("write cache file fail!");
221
- }
222
- }
223
- read() {
224
- const { filename } = this.options;
225
- try {
226
- if (import_node_fs3.default.existsSync(filename)) {
227
- const data = import_node_fs3.default.readFileSync(filename, "utf8");
228
- return new Set(JSON.parse(data));
229
- }
230
- } catch {
231
- log("parse cache content fail! path:" + filename);
232
- try {
233
- import_node_fs3.default.unlinkSync(filename);
234
- } catch {
235
- log("delete cache file fail! path:" + filename);
236
- }
237
- }
238
- }
239
- };
240
-
241
- // src/core/runtime-patcher.ts
242
- var import_node_path3 = __toESM(require("path"));
243
- var import_node_fs4 = __toESM(require("fs"));
244
- var import_semver = require("semver");
245
-
246
- // ../../node_modules/.pnpm/defu@6.1.2/node_modules/defu/dist/defu.mjs
247
- function isObject(value) {
248
- return value !== null && typeof value === "object";
249
- }
250
- function _defu(baseObject, defaults, namespace = ".", merger) {
251
- if (!isObject(defaults)) {
252
- return _defu(baseObject, {}, namespace, merger);
253
- }
254
- const object = Object.assign({}, defaults);
255
- for (const key in baseObject) {
256
- if (key === "__proto__" || key === "constructor") {
257
- continue;
258
- }
259
- const value = baseObject[key];
260
- if (value === null || value === void 0) {
261
- continue;
262
- }
263
- if (merger && merger(object, key, value, namespace)) {
264
- continue;
265
- }
266
- if (Array.isArray(value) && Array.isArray(object[key])) {
267
- object[key] = [...value, ...object[key]];
268
- } else if (isObject(value) && isObject(object[key])) {
269
- object[key] = _defu(
270
- value,
271
- object[key],
272
- (namespace ? `${namespace}.` : "") + key.toString(),
273
- merger
274
- );
275
- } else {
276
- object[key] = value;
277
- }
278
- }
279
- return object;
280
- }
281
- function createDefu(merger) {
282
- return (...arguments_) => (
283
- // eslint-disable-next-line unicorn/no-array-reduce
284
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
285
- );
286
- }
287
- var defu = createDefu();
288
- var defuFn = createDefu((object, key, currentValue) => {
289
- if (typeof object[key] !== "undefined" && typeof currentValue === "function") {
290
- object[key] = currentValue(object[key]);
291
- return true;
292
- }
293
- });
294
- var defuArrayFn = createDefu((object, key, currentValue) => {
295
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
296
- object[key] = currentValue(object[key]);
297
- return true;
298
- }
299
- });
300
-
301
- // src/core/inspector.ts
302
- var t = __toESM(require("@babel/types"));
303
-
304
- // src/babel/index.ts
305
- var import_generator = __toESM(require("@babel/generator"));
306
- var import_traverse = __toESM(require("@babel/traverse"));
307
- var import_parser = require("@babel/parser");
308
-
309
- // src/core/inspector.ts
310
- function inspectProcessTailwindFeaturesReturnContext(content) {
311
- const ast = (0, import_parser.parse)(content);
312
- let hasPatched = false;
313
- (0, import_traverse.default)(ast, {
314
- FunctionDeclaration(p) {
315
- const n = p.node;
316
- if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
317
- const rts = n.body.body[0];
318
- if (t.isFunctionExpression(rts.argument)) {
319
- const body = rts.argument.body.body;
320
- const lastStatement = body.at(-1);
321
- hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
322
- if (!hasPatched) {
323
- const rts2 = t.returnStatement(t.identifier("context"));
324
- body.push(rts2);
325
- }
326
- }
327
- }
328
- }
329
- });
330
- return {
331
- code: hasPatched ? content : (0, import_generator.default)(ast).code,
332
- hasPatched
333
- };
334
- }
335
- function inspectPostcssPlugin(content) {
336
- const ast = (0, import_parser.parse)(content);
337
- const exportKey = "contextRef";
338
- const variableName = "contextRef";
339
- const valueKey = "value";
340
- let hasPatched = false;
341
- (0, import_traverse.default)(ast, {
342
- Program(p) {
343
- const n = p.node;
344
- const idx = n.body.findIndex((x) => {
345
- return t.isExpressionStatement(x) && t.isAssignmentExpression(x.expression) && t.isMemberExpression(x.expression.left) && t.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
346
- });
347
- if (idx > -1) {
348
- const prevStatement = n.body[idx - 1];
349
- const lastStatement = n.body.at(-1);
350
- const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
351
- const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
352
- hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
353
- if (!hasPatched) {
354
- const statement = t.variableDeclaration("const", [
355
- t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
356
- ]);
357
- n.body.splice(idx, 0, statement);
358
- n.body.push(
359
- t.expressionStatement(
360
- t.assignmentExpression(
361
- "=",
362
- t.memberExpression(t.memberExpression(t.identifier("module"), t.identifier("exports")), t.identifier(exportKey)),
363
- t.identifier(variableName)
364
- )
365
- )
366
- );
367
- }
368
- }
369
- },
370
- FunctionExpression(p) {
371
- if (hasPatched) {
372
- return;
373
- }
374
- const n = p.node;
375
- if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
376
- const returnStatement2 = n.body.body[0];
377
- if (t.isObjectExpression(returnStatement2.argument) && returnStatement2.argument.properties.length === 2) {
378
- const properties = returnStatement2.argument.properties;
379
- if (t.isObjectProperty(properties[0]) && t.isObjectProperty(properties[1])) {
380
- const keyMatched = t.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
381
- const pluginsMatched = t.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
382
- if (pluginsMatched && keyMatched && t.isCallExpression(properties[1].value) && t.isMemberExpression(properties[1].value.callee) && t.isArrayExpression(properties[1].value.callee.object)) {
383
- const pluginsCode = properties[1].value.callee.object.elements;
384
- if (pluginsCode[1] && t.isFunctionExpression(pluginsCode[1])) {
385
- const targetBlockStatement = pluginsCode[1].body;
386
- const lastStatement = targetBlockStatement.body.at(-1);
387
- if (t.isExpressionStatement(lastStatement)) {
388
- const newExpressionStatement = t.expressionStatement(
389
- t.callExpression(
390
- t.memberExpression(
391
- t.memberExpression(t.identifier(variableName), t.identifier("value")),
392
- t.identifier("push")
393
- ),
394
- [lastStatement.expression]
395
- )
396
- );
397
- targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
398
- }
399
- const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
400
- if (ifIdx > -1) {
401
- const ifRoot = targetBlockStatement.body[ifIdx];
402
- if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
403
- const forOf = ifRoot.consequent.body[1];
404
- if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
405
- const if2 = forOf.body.body[0];
406
- if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
407
- const target = if2.consequent.body[0];
408
- const newExpressionStatement = t.expressionStatement(
409
- t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
410
- );
411
- if2.consequent.body[0] = newExpressionStatement;
412
- }
413
- }
414
- }
415
- }
416
- targetBlockStatement.body.unshift(
417
- // contentRef.value = []
418
- // t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
419
- // contentRef.value.length = 0
420
- t.expressionStatement(
421
- t.assignmentExpression(
422
- "=",
423
- t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
424
- t.numericLiteral(0)
425
- )
426
- )
427
- );
428
- }
429
- }
430
- }
431
- }
432
- }
433
- }
434
- // BlockStatement(p) {
435
- // const n = p.node
436
- // if (start && p.parent.type === 'FunctionExpression' && !p.parent.id) {
437
- // n.body.unshift(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression())))
438
- // }
439
- // }
440
- });
441
- return {
442
- code: hasPatched ? content : (0, import_generator.default)(ast).code,
443
- hasPatched
444
- };
445
- }
446
-
447
- // src/defaults.ts
448
- function getDefaultPatchOptions() {
449
- return {
450
- overwrite: true
451
- };
452
- }
453
-
454
- // src/core/runtime-patcher.ts
455
- function getInstalledPkgJsonPath(options = {}) {
456
- try {
457
- const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
458
- paths: options.paths
459
- });
460
- return tmpJsonPath;
461
- } catch (error) {
462
- if (error.code === "MODULE_NOT_FOUND") {
463
- console.warn("Can't find npm pkg: `tailwindcss`, Please ensure it has been installed!");
464
- }
465
- }
466
- }
467
- function getPatchOptions(options = {}) {
468
- return defu(
469
- options,
470
- {
471
- basedir: process.cwd()
472
- },
473
- getDefaultPatchOptions()
474
- );
475
- }
476
- function createPatch(opt) {
477
- return () => {
478
- try {
479
- const pkgJsonPath = getInstalledPkgJsonPath(opt);
480
- return internalPatch(pkgJsonPath, opt);
481
- } catch (error) {
482
- console.warn(`patch tailwindcss failed:` + error.message);
483
- }
484
- };
485
- }
486
- function monkeyPatchForExposingContext(twDir, opt) {
487
- const processTailwindFeaturesFilePath = import_node_path3.default.resolve(twDir, "lib/processTailwindFeatures.js");
488
- const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
489
- const result = {};
490
- if (processTailwindFeaturesContent) {
491
- const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
492
- if (!hasPatched && opt.overwrite) {
493
- import_node_fs4.default.writeFileSync(processTailwindFeaturesFilePath, code, {
494
- encoding: "utf8"
495
- });
496
- console.log("patch tailwindcss processTailwindFeatures for return content successfully!");
497
- }
498
- result.processTailwindFeatures = code;
499
- }
500
- const pluginFilePath = import_node_path3.default.resolve(twDir, "lib/plugin.js");
501
- const indexFilePath = import_node_path3.default.resolve(twDir, "lib/index.js");
502
- const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
503
- if (pluginContent) {
504
- const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
505
- if (!hasPatched && opt.overwrite) {
506
- import_node_fs4.default.writeFileSync(pluginFilePath, code, {
507
- encoding: "utf8"
508
- });
509
- console.log("patch tailwindcss for expose runtime content successfully!");
510
- }
511
- result.plugin = code;
512
- }
513
- opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
514
- return result;
515
- }
516
- function internalPatch(pkgJsonPath, options) {
517
- if (pkgJsonPath) {
518
- const pkgJson = require(pkgJsonPath);
519
- const twDir = import_node_path3.default.dirname(pkgJsonPath);
520
- if ((0, import_semver.gte)(pkgJson.version, "3.0.0")) {
521
- options.version = pkgJson.version;
522
- const result = monkeyPatchForExposingContext(twDir, options);
523
- return result;
524
- }
525
- }
526
- }
527
-
528
- // src/core/postcss.ts
529
- var import_node_path4 = __toESM(require("path"));
530
- var import_postcss = __toESM(require("postcss"));
531
- var import_lilconfig = require("lilconfig");
532
- var import_jiti = __toESM(require("jiti"));
533
- var jiti = (0, import_jiti.default)(__filename);
534
- async function processTailwindcss(options) {
535
- options.cwd = options.cwd ?? process.cwd();
536
- let config = options.config;
537
- if (!(typeof options.config === "string" && import_node_path4.default.isAbsolute(options.config))) {
538
- const moduleName = "tailwind";
539
- const result = await (0, import_lilconfig.lilconfig)("tailwindcss", {
540
- searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
541
- loaders: {
542
- // 默认支持 js 和 cjs 2种格式
543
- ".js": jiti,
544
- ".cjs": jiti,
545
- ".ts": jiti,
546
- ".mjs": jiti
547
- }
548
- }).search(options.cwd);
549
- if (!result) {
550
- throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
551
- }
552
- config = result.filepath;
553
- }
554
- return await (0, import_postcss.default)([
555
- require("tailwindcss")({
556
- config
557
- })
558
- ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
559
- from: void 0
560
- });
561
- }
562
-
563
- // src/core/tw-patcher.ts
564
- var TailwindcssPatcher = class {
565
- rawOptions;
566
- cacheOptions;
567
- patchOptions;
568
- patch;
569
- cacheManager;
570
- constructor(options = {}) {
571
- this.rawOptions = options;
572
- this.cacheOptions = getCacheOptions(options.cache);
573
- this.patchOptions = getPatchOptions(options.patch);
574
- this.patch = createPatch(this.patchOptions);
575
- this.cacheManager = new CacheManager(this.cacheOptions);
576
- }
577
- getPkgEntry(basedir) {
578
- return getTailwindcssEntry(basedir);
579
- }
580
- setCache(set) {
581
- if (this.cacheOptions.enable) {
582
- return this.cacheManager.write(set);
583
- }
584
- }
585
- getCache() {
586
- return this.cacheManager.read();
587
- }
588
- /**
589
- * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
590
- * 详见 taro weapp-tailwindcss 独立分包
591
- * @param basedir
592
- * @returns
593
- */
594
- getClassSet(options) {
595
- const { basedir, cacheStrategy = this.cacheOptions.strategy ?? "merge", removeUniversalSelector = true } = options ?? {};
596
- const set = getClassCacheSet(basedir, {
597
- removeUniversalSelector
598
- });
599
- if (cacheStrategy === "overwrite") {
600
- set.size > 0 && this.setCache(set);
601
- } else if (cacheStrategy === "merge") {
602
- const cacheSet = this.getCache();
603
- if (cacheSet) {
604
- for (const x of cacheSet) {
605
- set.add(x);
606
- }
607
- }
608
- this.setCache(set);
609
- }
610
- return set;
611
- }
612
- getContexts(basedir) {
613
- return getContexts(basedir);
614
- }
615
- async extract(options) {
616
- const { output, tailwindcss } = options ?? {};
617
- if (output && tailwindcss) {
618
- const { removeUniversalSelector, filename, loose } = output;
619
- await processTailwindcss(tailwindcss);
620
- const set = this.getClassSet({
621
- removeUniversalSelector
622
- });
623
- if (filename) {
624
- await ensureDir((0, import_node_path5.dirname)(filename));
625
- const classList = [...set];
626
- await import_promises2.default.writeFile(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
627
- return filename;
628
- }
629
- }
630
- }
631
- };
632
-
633
- // src/core/config.ts
634
- var config_exports = {};
635
- __reExport(config_exports, require("@tailwindcss-mangle/config"));
636
-
637
- // src/core/index.ts
638
- __reExport(core_exports, config_exports);
639
-
640
- // src/index.ts
641
- __reExport(src_exports, core_exports, module.exports);
642
- // Annotate the CommonJS export names for ESM import in node:
643
- 0 && (module.exports = {
644
- CacheManager,
645
- TailwindcssPatcher,
646
- createPatch,
647
- ensureDir,
648
- ensureFileContent,
649
- getCacheOptions,
650
- getClassCacheSet,
651
- getClassCaches,
652
- getContexts,
653
- getInstalledPkgJsonPath,
654
- getPatchOptions,
655
- getTailwindcssEntry,
656
- inspectPostcssPlugin,
657
- inspectProcessTailwindFeaturesReturnContext,
658
- internalPatch,
659
- monkeyPatchForExposingContext,
660
- requireResolve
661
- });