tailwindcss-patch 2.0.5 → 2.1.1

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