tailwindcss-patch 2.0.4 → 2.0.5

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