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