tailwindcss-patch 2.0.4 → 2.0.5-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.
@@ -1,52 +1,46 @@
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
- }
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
+ }) : x)(function(x) {
8
+ if (typeof require !== "undefined")
9
+ return require.apply(this, arguments);
10
+ throw Error('Dynamic require of "' + x + '" is not supported');
11
+ });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
21
  }
27
- n.default = e;
28
- return n;
29
- }
22
+ return to;
23
+ };
24
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
25
 
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);
26
+ // ../../node_modules/.pnpm/tsup@7.2.0_ts-node@10.9.1_typescript@5.1.6/node_modules/tsup/assets/esm_shims.js
27
+ import { fileURLToPath } from "url";
28
+ var getFilename = () => fileURLToPath(import.meta.url);
29
+ var __filename = /* @__PURE__ */ getFilename();
40
30
 
41
- const { sync } = pkg__default;
31
+ // src/utils.ts
32
+ import fss from "node:fs";
33
+ import fs from "node:fs/promises";
34
+ import pkg from "resolve";
35
+ var { sync } = pkg;
42
36
  function ensureFileContent(filepaths) {
43
37
  if (typeof filepaths === "string") {
44
38
  filepaths = [filepaths];
45
39
  }
46
40
  let content;
47
41
  for (const filepath of filepaths) {
48
- if (fs__default.existsSync(filepath)) {
49
- content = fs__default.readFileSync(filepath, {
42
+ if (fss.existsSync(filepath)) {
43
+ content = fss.readFileSync(filepath, {
50
44
  encoding: "utf8"
51
45
  });
52
46
  break;
@@ -59,25 +53,28 @@ function requireResolve(id, opts) {
59
53
  }
60
54
  async function ensureDir(p) {
61
55
  try {
62
- await fs__default$1.access(p);
56
+ await fs.access(p);
63
57
  } catch {
64
- await fs__default$1.mkdir(p, {
58
+ await fs.mkdir(p, {
65
59
  recursive: true
66
60
  });
67
61
  }
68
62
  }
69
63
 
64
+ // src/core/exposeContext.ts
65
+ import path from "node:path";
66
+ import fs2 from "node:fs";
70
67
  function getTailwindcssEntry(basedir = process.cwd()) {
71
68
  return requireResolve("tailwindcss");
72
69
  }
73
70
  function getContexts(basedir) {
74
71
  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");
72
+ const distPath = path.dirname(twPath);
73
+ let injectFilePath = path.join(distPath, "plugin.js");
74
+ if (!fs2.existsSync(injectFilePath)) {
75
+ injectFilePath = path.join(distPath, "index.js");
79
76
  }
80
- const mo = require(injectFilePath);
77
+ const mo = __require(injectFilePath);
81
78
  if (mo.contextRef) {
82
79
  return mo.contextRef.value;
83
80
  }
@@ -103,12 +100,19 @@ function getClassCacheSet(basedir, options) {
103
100
  return classSet;
104
101
  }
105
102
 
106
- const pkgName = "tailwindcss-patch";
103
+ // src/core/cache.ts
104
+ import fs3 from "node:fs";
105
+ import path2 from "node:path";
106
+
107
+ // src/constants.ts
108
+ var pkgName = "tailwindcss-patch";
107
109
 
110
+ // src/logger.ts
108
111
  function log(message, ...optionalParams) {
109
112
  return console.log(`[${pkgName}]:` + message, ...optionalParams);
110
113
  }
111
114
 
115
+ // src/core/cache.ts
112
116
  function getCacheOptions(options) {
113
117
  let cache;
114
118
  switch (typeof options) {
@@ -131,14 +135,15 @@ function getCacheOptions(options) {
131
135
  }
132
136
  return cache;
133
137
  }
134
- class CacheManager {
138
+ var CacheManager = class {
139
+ options;
135
140
  constructor(options = {}) {
136
141
  this.options = this.getOptions(options);
137
142
  }
138
143
  mkdir(cacheDirectory) {
139
- const exists = fs__default.existsSync(cacheDirectory);
144
+ const exists = fs3.existsSync(cacheDirectory);
140
145
  if (!exists) {
141
- fs__default.mkdirSync(cacheDirectory, {
146
+ fs3.mkdirSync(cacheDirectory, {
142
147
  recursive: true
143
148
  });
144
149
  }
@@ -146,9 +151,9 @@ class CacheManager {
146
151
  }
147
152
  getOptions(options = {}) {
148
153
  const cwd = options.cwd ?? process.cwd();
149
- const dir = options.dir ?? path__default.resolve(cwd, "node_modules/.cache", pkgName);
154
+ const dir = options.dir ?? path2.resolve(cwd, "node_modules/.cache", pkgName);
150
155
  const file = options.file ?? "index.json";
151
- const filename = path__default.resolve(dir, file);
156
+ const filename = path2.resolve(dir, file);
152
157
  return {
153
158
  cwd,
154
159
  dir,
@@ -161,7 +166,7 @@ class CacheManager {
161
166
  try {
162
167
  const { dir, filename } = this.options;
163
168
  this.mkdir(dir);
164
- fs__default.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
169
+ fs3.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
165
170
  return filename;
166
171
  } catch {
167
172
  log("write cache file fail!");
@@ -170,77 +175,44 @@ class CacheManager {
170
175
  read() {
171
176
  const { filename } = this.options;
172
177
  try {
173
- if (fs__default.existsSync(filename)) {
174
- const data = fs__default.readFileSync(filename, "utf8");
178
+ if (fs3.existsSync(filename)) {
179
+ const data = fs3.readFileSync(filename, "utf8");
175
180
  return new Set(JSON.parse(data));
176
181
  }
177
182
  } catch {
178
183
  log("parse cache content fail! path:" + filename);
179
184
  try {
180
- fs__default.unlinkSync(filename);
185
+ fs3.unlinkSync(filename);
181
186
  } catch {
182
187
  log("delete cache file fail! path:" + filename);
183
188
  }
184
189
  }
185
190
  }
186
- }
191
+ };
187
192
 
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();
193
+ // src/core/inspector.ts
194
+ import * as t from "@babel/types";
195
+
196
+ // src/babel/index.ts
197
+ import { default as default2 } from "@babel/generator";
198
+ import { default as default3 } from "@babel/traverse";
199
+ import { parse } from "@babel/parser";
229
200
 
201
+ // src/core/inspector.ts
230
202
  function inspectProcessTailwindFeaturesReturnContext(content) {
231
- const ast = parser.parse(content);
203
+ const ast = parse(content);
232
204
  let hasPatched = false;
233
- traverse__default(ast, {
205
+ default3(ast, {
234
206
  FunctionDeclaration(p) {
235
207
  const n = p.node;
236
- if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
208
+ if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
237
209
  const rts = n.body.body[0];
238
- if (t__namespace.isFunctionExpression(rts.argument)) {
210
+ if (t.isFunctionExpression(rts.argument)) {
239
211
  const body = rts.argument.body.body;
240
212
  const lastStatement = body.at(-1);
241
- hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
213
+ hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
242
214
  if (!hasPatched) {
243
- const rts2 = t__namespace.returnStatement(t__namespace.identifier("context"));
215
+ const rts2 = t.returnStatement(t.identifier("context"));
244
216
  body.push(rts2);
245
217
  }
246
218
  }
@@ -248,39 +220,39 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
248
220
  }
249
221
  });
250
222
  return {
251
- code: hasPatched ? content : generate__default(ast).code,
223
+ code: hasPatched ? content : default2(ast).code,
252
224
  hasPatched
253
225
  };
254
226
  }
255
227
  function inspectPostcssPlugin(content) {
256
- const ast = parser.parse(content);
228
+ const ast = parse(content);
257
229
  const exportKey = "contextRef";
258
230
  const variableName = "contextRef";
259
231
  const valueKey = "value";
260
232
  let hasPatched = false;
261
- traverse__default(ast, {
233
+ default3(ast, {
262
234
  Program(p) {
263
235
  const n = p.node;
264
236
  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";
237
+ return t.isExpressionStatement(x) && t.isAssignmentExpression(x.expression) && t.isMemberExpression(x.expression.left) && t.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
266
238
  });
267
239
  if (idx > -1) {
268
240
  const prevStatement = n.body[idx - 1];
269
241
  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;
242
+ const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
243
+ const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
272
244
  hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
273
245
  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())]))
246
+ const statement = t.variableDeclaration("const", [
247
+ t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
276
248
  ]);
277
249
  n.body.splice(idx, 0, statement);
278
250
  n.body.push(
279
- t__namespace.expressionStatement(
280
- t__namespace.assignmentExpression(
251
+ t.expressionStatement(
252
+ t.assignmentExpression(
281
253
  "=",
282
- t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier("module"), t__namespace.identifier("exports")), t__namespace.identifier(exportKey)),
283
- t__namespace.identifier(variableName)
254
+ t.memberExpression(t.memberExpression(t.identifier("module"), t.identifier("exports")), t.identifier(exportKey)),
255
+ t.identifier(variableName)
284
256
  )
285
257
  )
286
258
  );
@@ -292,41 +264,41 @@ function inspectPostcssPlugin(content) {
292
264
  return;
293
265
  }
294
266
  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)) {
267
+ if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
268
+ const returnStatement2 = n.body.body[0];
269
+ if (t.isObjectExpression(returnStatement2.argument) && returnStatement2.argument.properties.length === 2) {
270
+ const properties = returnStatement2.argument.properties;
271
+ if (t.isObjectProperty(properties[0]) && t.isObjectProperty(properties[1])) {
272
+ const keyMatched = t.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
273
+ const pluginsMatched = t.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
274
+ if (pluginsMatched && keyMatched && t.isCallExpression(properties[1].value) && t.isMemberExpression(properties[1].value.callee) && t.isArrayExpression(properties[1].value.callee.object)) {
303
275
  const pluginsCode = properties[1].value.callee.object.elements;
304
- if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
276
+ if (pluginsCode[1] && t.isFunctionExpression(pluginsCode[1])) {
305
277
  const targetBlockStatement = pluginsCode[1].body;
306
278
  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")
279
+ if (t.isExpressionStatement(lastStatement)) {
280
+ const newExpressionStatement = t.expressionStatement(
281
+ t.callExpression(
282
+ t.memberExpression(
283
+ t.memberExpression(t.identifier(variableName), t.identifier("value")),
284
+ t.identifier("push")
313
285
  ),
314
286
  [lastStatement.expression]
315
287
  )
316
288
  );
317
289
  targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
318
290
  }
319
- const ifIdx = targetBlockStatement.body.findIndex((x) => t__namespace.isIfStatement(x));
291
+ const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
320
292
  if (ifIdx > -1) {
321
293
  const ifRoot = targetBlockStatement.body[ifIdx];
322
- if (t__namespace.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t__namespace.isForOfStatement(ifRoot.consequent.body[1])) {
294
+ if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
323
295
  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])) {
296
+ if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
325
297
  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])) {
298
+ if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
327
299
  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])
300
+ const newExpressionStatement = t.expressionStatement(
301
+ t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
330
302
  );
331
303
  if2.consequent.body[0] = newExpressionStatement;
332
304
  }
@@ -337,11 +309,11 @@ function inspectPostcssPlugin(content) {
337
309
  // contentRef.value = []
338
310
  // t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
339
311
  // contentRef.value.length = 0
340
- t__namespace.expressionStatement(
341
- t__namespace.assignmentExpression(
312
+ t.expressionStatement(
313
+ t.assignmentExpression(
342
314
  "=",
343
- t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier(valueKey)), t__namespace.identifier("length")),
344
- t__namespace.numericLiteral(0)
315
+ t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
316
+ t.numericLiteral(0)
345
317
  )
346
318
  )
347
319
  );
@@ -359,17 +331,79 @@ function inspectPostcssPlugin(content) {
359
331
  // }
360
332
  });
361
333
  return {
362
- code: hasPatched ? content : generate__default(ast).code,
334
+ code: hasPatched ? content : default2(ast).code,
363
335
  hasPatched
364
336
  };
365
337
  }
366
338
 
339
+ // src/core/runtime-patcher.ts
340
+ import path3 from "node:path";
341
+ import fs4 from "node:fs";
342
+ import { gte } from "semver";
343
+
344
+ // ../../node_modules/.pnpm/defu@6.1.2/node_modules/defu/dist/defu.mjs
345
+ function isObject(value) {
346
+ return value !== null && typeof value === "object";
347
+ }
348
+ function _defu(baseObject, defaults, namespace = ".", merger) {
349
+ if (!isObject(defaults)) {
350
+ return _defu(baseObject, {}, namespace, merger);
351
+ }
352
+ const object = Object.assign({}, defaults);
353
+ for (const key in baseObject) {
354
+ if (key === "__proto__" || key === "constructor") {
355
+ continue;
356
+ }
357
+ const value = baseObject[key];
358
+ if (value === null || value === void 0) {
359
+ continue;
360
+ }
361
+ if (merger && merger(object, key, value, namespace)) {
362
+ continue;
363
+ }
364
+ if (Array.isArray(value) && Array.isArray(object[key])) {
365
+ object[key] = [...value, ...object[key]];
366
+ } else if (isObject(value) && isObject(object[key])) {
367
+ object[key] = _defu(
368
+ value,
369
+ object[key],
370
+ (namespace ? `${namespace}.` : "") + key.toString(),
371
+ merger
372
+ );
373
+ } else {
374
+ object[key] = value;
375
+ }
376
+ }
377
+ return object;
378
+ }
379
+ function createDefu(merger) {
380
+ return (...arguments_) => (
381
+ // eslint-disable-next-line unicorn/no-array-reduce
382
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
383
+ );
384
+ }
385
+ var defu = createDefu();
386
+ var defuFn = createDefu((object, key, currentValue) => {
387
+ if (typeof object[key] !== "undefined" && typeof currentValue === "function") {
388
+ object[key] = currentValue(object[key]);
389
+ return true;
390
+ }
391
+ });
392
+ var defuArrayFn = createDefu((object, key, currentValue) => {
393
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
394
+ object[key] = currentValue(object[key]);
395
+ return true;
396
+ }
397
+ });
398
+
399
+ // src/defaults.ts
367
400
  function getDefaultPatchOptions() {
368
401
  return {
369
402
  overwrite: true
370
403
  };
371
404
  }
372
405
 
406
+ // src/core/runtime-patcher.ts
373
407
  function getInstalledPkgJsonPath(options = {}) {
374
408
  try {
375
409
  const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
@@ -402,26 +436,26 @@ function createPatch(opt) {
402
436
  };
403
437
  }
404
438
  function monkeyPatchForExposingContext(twDir, opt) {
405
- const processTailwindFeaturesFilePath = path__default.resolve(twDir, "lib/processTailwindFeatures.js");
439
+ const processTailwindFeaturesFilePath = path3.resolve(twDir, "lib/processTailwindFeatures.js");
406
440
  const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
407
441
  const result = {};
408
442
  if (processTailwindFeaturesContent) {
409
443
  const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
410
444
  if (!hasPatched && opt.overwrite) {
411
- fs__default.writeFileSync(processTailwindFeaturesFilePath, code, {
445
+ fs4.writeFileSync(processTailwindFeaturesFilePath, code, {
412
446
  encoding: "utf8"
413
447
  });
414
448
  console.log("patch tailwindcss processTailwindFeatures for return content successfully!");
415
449
  }
416
450
  result.processTailwindFeatures = code;
417
451
  }
418
- const pluginFilePath = path__default.resolve(twDir, "lib/plugin.js");
419
- const indexFilePath = path__default.resolve(twDir, "lib/index.js");
452
+ const pluginFilePath = path3.resolve(twDir, "lib/plugin.js");
453
+ const indexFilePath = path3.resolve(twDir, "lib/index.js");
420
454
  const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
421
455
  if (pluginContent) {
422
456
  const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
423
457
  if (!hasPatched && opt.overwrite) {
424
- fs__default.writeFileSync(pluginFilePath, code, {
458
+ fs4.writeFileSync(pluginFilePath, code, {
425
459
  encoding: "utf8"
426
460
  });
427
461
  console.log("patch tailwindcss for expose runtime content successfully!");
@@ -433,9 +467,9 @@ function monkeyPatchForExposingContext(twDir, opt) {
433
467
  }
434
468
  function internalPatch(pkgJsonPath, options) {
435
469
  if (pkgJsonPath) {
436
- const pkgJson = require(pkgJsonPath);
437
- const twDir = path__default.dirname(pkgJsonPath);
438
- if (semver.gte(pkgJson.version, "3.0.0")) {
470
+ const pkgJson = __require(pkgJsonPath);
471
+ const twDir = path3.dirname(pkgJsonPath);
472
+ if (gte(pkgJson.version, "3.0.0")) {
439
473
  options.version = pkgJson.version;
440
474
  const result = monkeyPatchForExposingContext(twDir, options);
441
475
  return result;
@@ -443,13 +477,22 @@ function internalPatch(pkgJsonPath, options) {
443
477
  }
444
478
  }
445
479
 
446
- const jiti = createJiti__default(__filename);
480
+ // src/core/tw-patcher.ts
481
+ import fs5 from "node:fs/promises";
482
+ import { dirname } from "node:path";
483
+
484
+ // src/core/postcss.ts
485
+ import path4 from "node:path";
486
+ import postcss from "postcss";
487
+ import { lilconfig } from "lilconfig";
488
+ import createJiti from "jiti";
489
+ var jiti = createJiti(__filename);
447
490
  async function processTailwindcss(options) {
448
491
  options.cwd = options.cwd ?? process.cwd();
449
492
  let config = options.config;
450
- if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
493
+ if (!(typeof options.config === "string" && path4.isAbsolute(options.config))) {
451
494
  const moduleName = "tailwind";
452
- const result = await lilconfig.lilconfig("tailwindcss", {
495
+ const result = await lilconfig("tailwindcss", {
453
496
  searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
454
497
  loaders: {
455
498
  // 默认支持 js 和 cjs 2种格式
@@ -464,8 +507,8 @@ async function processTailwindcss(options) {
464
507
  }
465
508
  config = result.filepath;
466
509
  }
467
- return await postcss__default([
468
- require("tailwindcss")({
510
+ return await postcss([
511
+ __require("tailwindcss")({
469
512
  config
470
513
  })
471
514
  ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
@@ -473,7 +516,13 @@ async function processTailwindcss(options) {
473
516
  });
474
517
  }
475
518
 
476
- class TailwindcssPatcher {
519
+ // src/core/tw-patcher.ts
520
+ var TailwindcssPatcher = class {
521
+ rawOptions;
522
+ cacheOptions;
523
+ patchOptions;
524
+ patch;
525
+ cacheManager;
477
526
  constructor(options = {}) {
478
527
  this.rawOptions = options;
479
528
  this.cacheOptions = getCacheOptions(options.cache);
@@ -528,32 +577,61 @@ class TailwindcssPatcher {
528
577
  removeUniversalSelector
529
578
  });
530
579
  if (filename) {
531
- await ensureDir(path.dirname(filename));
580
+ await ensureDir(dirname(filename));
532
581
  const classList = [...set];
533
- await fs__default$1.writeFile(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
582
+ await fs5.writeFile(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
534
583
  return filename;
535
584
  }
536
585
  }
537
586
  }
538
- }
587
+ };
539
588
 
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];
589
+ // src/core/index.ts
590
+ var core_exports = {};
591
+ __export(core_exports, {
592
+ CacheManager: () => CacheManager,
593
+ TailwindcssPatcher: () => TailwindcssPatcher,
594
+ createPatch: () => createPatch,
595
+ getCacheOptions: () => getCacheOptions,
596
+ getClassCacheSet: () => getClassCacheSet,
597
+ getClassCaches: () => getClassCaches,
598
+ getContexts: () => getContexts,
599
+ getInstalledPkgJsonPath: () => getInstalledPkgJsonPath,
600
+ getPatchOptions: () => getPatchOptions,
601
+ getTailwindcssEntry: () => getTailwindcssEntry,
602
+ inspectPostcssPlugin: () => inspectPostcssPlugin,
603
+ inspectProcessTailwindFeaturesReturnContext: () => inspectProcessTailwindFeaturesReturnContext,
604
+ internalPatch: () => internalPatch,
605
+ monkeyPatchForExposingContext: () => monkeyPatchForExposingContext
559
606
  });
607
+
608
+ // src/core/config.ts
609
+ var config_exports = {};
610
+ __reExport(config_exports, config_star);
611
+ import * as config_star from "@tailwindcss-mangle/config";
612
+
613
+ // src/core/index.ts
614
+ __reExport(core_exports, config_exports);
615
+
616
+ export {
617
+ __export,
618
+ __reExport,
619
+ ensureFileContent,
620
+ requireResolve,
621
+ ensureDir,
622
+ getTailwindcssEntry,
623
+ getContexts,
624
+ getClassCaches,
625
+ getClassCacheSet,
626
+ getCacheOptions,
627
+ CacheManager,
628
+ inspectProcessTailwindFeaturesReturnContext,
629
+ inspectPostcssPlugin,
630
+ getInstalledPkgJsonPath,
631
+ getPatchOptions,
632
+ createPatch,
633
+ monkeyPatchForExposingContext,
634
+ internalPatch,
635
+ TailwindcssPatcher,
636
+ core_exports
637
+ };