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