tailwindcss-patch 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const cac = require('cac');
4
+ const config = require('@tailwindcss-mangle/config');
4
5
  const index = require('./index.cjs');
5
6
  require('node:path');
6
7
  require('node:fs');
@@ -10,7 +11,6 @@ require('@babel/types');
10
11
  require('@babel/generator');
11
12
  require('@babel/traverse');
12
13
  require('@babel/parser');
13
- const config = require('@tailwindcss-mangle/config');
14
14
  require('semver');
15
15
  require('postcss');
16
16
  require('lilconfig');
package/dist/cli.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import cac from 'cac';
2
+ import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
2
3
  import { getPatchOptions, TailwindcssPatcher, createPatch } from './index.mjs';
3
4
  import 'node:path';
4
5
  import 'node:fs';
@@ -8,7 +9,6 @@ import '@babel/types';
8
9
  import '@babel/generator';
9
10
  import '@babel/traverse';
10
11
  import '@babel/parser';
11
- import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
12
12
  import 'semver';
13
13
  import 'postcss';
14
14
  import 'lilconfig';
package/dist/index.cjs CHANGED
@@ -67,8 +67,10 @@ async function ensureDir(p) {
67
67
  }
68
68
  }
69
69
 
70
- function getTailwindcssEntry(basedir = process.cwd()) {
71
- return requireResolve("tailwindcss");
70
+ function getTailwindcssEntry(basedir) {
71
+ return requireResolve("tailwindcss", {
72
+ basedir
73
+ });
72
74
  }
73
75
  function getContexts(basedir) {
74
76
  const twPath = getTailwindcssEntry(basedir);
@@ -192,11 +194,25 @@ class CacheManager {
192
194
  }
193
195
  }
194
196
 
195
- function isObject(value) {
196
- return value !== null && typeof value === "object";
197
+ function isPlainObject(value) {
198
+ if (value === null || typeof value !== "object") {
199
+ return false;
200
+ }
201
+ const prototype = Object.getPrototypeOf(value);
202
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
203
+ return false;
204
+ }
205
+ if (Symbol.iterator in value) {
206
+ return false;
207
+ }
208
+ if (Symbol.toStringTag in value) {
209
+ return Object.prototype.toString.call(value) === "[object Module]";
210
+ }
211
+ return true;
197
212
  }
213
+
198
214
  function _defu(baseObject, defaults, namespace = ".", merger) {
199
- if (!isObject(defaults)) {
215
+ if (!isPlainObject(defaults)) {
200
216
  return _defu(baseObject, {}, namespace, merger);
201
217
  }
202
218
  const object = Object.assign({}, defaults);
@@ -213,7 +229,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
213
229
  }
214
230
  if (Array.isArray(value) && Array.isArray(object[key])) {
215
231
  object[key] = [...value, ...object[key]];
216
- } else if (isObject(value) && isObject(object[key])) {
232
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
217
233
  object[key] = _defu(
218
234
  value,
219
235
  object[key],
@@ -244,7 +260,7 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
244
260
  const rts = n.body.body[0];
245
261
  if (t__namespace.isFunctionExpression(rts.argument)) {
246
262
  const body = rts.argument.body.body;
247
- const lastStatement = body.at(-1);
263
+ const lastStatement = body[body.length - 1];
248
264
  hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
249
265
  if (!hasPatched) {
250
266
  const rts2 = t__namespace.returnStatement(t__namespace.identifier("context"));
@@ -273,7 +289,7 @@ function inspectPostcssPlugin(content) {
273
289
  });
274
290
  if (idx > -1) {
275
291
  const prevStatement = n.body[idx - 1];
276
- const lastStatement = n.body.at(-1);
292
+ const lastStatement = n.body[n.body.length - 1];
277
293
  const hasPatchedCondition0 = prevStatement && t__namespace.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t__namespace.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
278
294
  const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) && t__namespace.isAssignmentExpression(lastStatement.expression) && t__namespace.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
279
295
  hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
@@ -310,7 +326,7 @@ function inspectPostcssPlugin(content) {
310
326
  const pluginsCode = properties[1].value.callee.object.elements;
311
327
  if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
312
328
  const targetBlockStatement = pluginsCode[1].body;
313
- const lastStatement = targetBlockStatement.body.at(-1);
329
+ const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
314
330
  if (t__namespace.isExpressionStatement(lastStatement)) {
315
331
  const newExpressionStatement = t__namespace.expressionStatement(
316
332
  t__namespace.callExpression(
@@ -555,6 +571,7 @@ class TailwindcssPatcher {
555
571
  }
556
572
  }
557
573
 
574
+ exports.defineConfig = config.defineConfig;
558
575
  exports.CacheManager = CacheManager;
559
576
  exports.TailwindcssPatcher = TailwindcssPatcher;
560
577
  exports.createPatch = createPatch;
@@ -572,6 +589,3 @@ exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeat
572
589
  exports.internalPatch = internalPatch;
573
590
  exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
574
591
  exports.requireResolve = requireResolve;
575
- Object.keys(config).forEach(function (k) {
576
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = config[k];
577
- });
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Rule, Node } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
  import { UserConfig } from '@tailwindcss-mangle/config';
4
- export * from '@tailwindcss-mangle/config';
4
+ export { defineConfig } from '@tailwindcss-mangle/config';
5
5
  import { SyncOpts } from 'resolve';
6
6
 
7
7
  type CacheStrategy = 'merge' | 'overwrite';
@@ -114,7 +114,7 @@ declare class TailwindcssPatcher {
114
114
  removeUniversalSelector?: boolean;
115
115
  }): Set<string>;
116
116
  getContexts(basedir?: string): TailwindcssRuntimeContext[];
117
- extract(options: UserConfig['patch']): Promise<string | undefined>;
117
+ extract(options?: UserConfig['patch']): Promise<string | undefined>;
118
118
  }
119
119
 
120
120
  declare function getTailwindcssEntry(basedir?: string): string;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Rule, Node } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
  import { UserConfig } from '@tailwindcss-mangle/config';
4
- export * from '@tailwindcss-mangle/config';
4
+ export { defineConfig } from '@tailwindcss-mangle/config';
5
5
  import { SyncOpts } from 'resolve';
6
6
 
7
7
  type CacheStrategy = 'merge' | 'overwrite';
@@ -114,7 +114,7 @@ declare class TailwindcssPatcher {
114
114
  removeUniversalSelector?: boolean;
115
115
  }): Set<string>;
116
116
  getContexts(basedir?: string): TailwindcssRuntimeContext[];
117
- extract(options: UserConfig['patch']): Promise<string | undefined>;
117
+ extract(options?: UserConfig['patch']): Promise<string | undefined>;
118
118
  }
119
119
 
120
120
  declare function getTailwindcssEntry(basedir?: string): string;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Rule, Node } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
  import { UserConfig } from '@tailwindcss-mangle/config';
4
- export * from '@tailwindcss-mangle/config';
4
+ export { defineConfig } from '@tailwindcss-mangle/config';
5
5
  import { SyncOpts } from 'resolve';
6
6
 
7
7
  type CacheStrategy = 'merge' | 'overwrite';
@@ -114,7 +114,7 @@ declare class TailwindcssPatcher {
114
114
  removeUniversalSelector?: boolean;
115
115
  }): Set<string>;
116
116
  getContexts(basedir?: string): TailwindcssRuntimeContext[];
117
- extract(options: UserConfig['patch']): Promise<string | undefined>;
117
+ extract(options?: UserConfig['patch']): Promise<string | undefined>;
118
118
  }
119
119
 
120
120
  declare function getTailwindcssEntry(basedir?: string): string;
package/dist/index.mjs CHANGED
@@ -19,7 +19,7 @@ import __cjs_mod__ from 'module';
19
19
  const __filename = __cjs_url__.fileURLToPath(import.meta.url);
20
20
  const __dirname = __cjs_path__.dirname(__filename);
21
21
  const require = __cjs_mod__.createRequire(import.meta.url);
22
- export * from '@tailwindcss-mangle/config';
22
+ export { defineConfig } from '@tailwindcss-mangle/config';
23
23
 
24
24
  const { sync } = pkg;
25
25
  function ensureFileContent(filepaths) {
@@ -50,8 +50,10 @@ async function ensureDir(p) {
50
50
  }
51
51
  }
52
52
 
53
- function getTailwindcssEntry(basedir = process.cwd()) {
54
- return requireResolve("tailwindcss");
53
+ function getTailwindcssEntry(basedir) {
54
+ return requireResolve("tailwindcss", {
55
+ basedir
56
+ });
55
57
  }
56
58
  function getContexts(basedir) {
57
59
  const twPath = getTailwindcssEntry(basedir);
@@ -175,11 +177,25 @@ class CacheManager {
175
177
  }
176
178
  }
177
179
 
178
- function isObject(value) {
179
- return value !== null && typeof value === "object";
180
+ function isPlainObject(value) {
181
+ if (value === null || typeof value !== "object") {
182
+ return false;
183
+ }
184
+ const prototype = Object.getPrototypeOf(value);
185
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
186
+ return false;
187
+ }
188
+ if (Symbol.iterator in value) {
189
+ return false;
190
+ }
191
+ if (Symbol.toStringTag in value) {
192
+ return Object.prototype.toString.call(value) === "[object Module]";
193
+ }
194
+ return true;
180
195
  }
196
+
181
197
  function _defu(baseObject, defaults, namespace = ".", merger) {
182
- if (!isObject(defaults)) {
198
+ if (!isPlainObject(defaults)) {
183
199
  return _defu(baseObject, {}, namespace, merger);
184
200
  }
185
201
  const object = Object.assign({}, defaults);
@@ -196,7 +212,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
196
212
  }
197
213
  if (Array.isArray(value) && Array.isArray(object[key])) {
198
214
  object[key] = [...value, ...object[key]];
199
- } else if (isObject(value) && isObject(object[key])) {
215
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
200
216
  object[key] = _defu(
201
217
  value,
202
218
  object[key],
@@ -227,7 +243,7 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
227
243
  const rts = n.body.body[0];
228
244
  if (t.isFunctionExpression(rts.argument)) {
229
245
  const body = rts.argument.body.body;
230
- const lastStatement = body.at(-1);
246
+ const lastStatement = body[body.length - 1];
231
247
  hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
232
248
  if (!hasPatched) {
233
249
  const rts2 = t.returnStatement(t.identifier("context"));
@@ -256,7 +272,7 @@ function inspectPostcssPlugin(content) {
256
272
  });
257
273
  if (idx > -1) {
258
274
  const prevStatement = n.body[idx - 1];
259
- const lastStatement = n.body.at(-1);
275
+ const lastStatement = n.body[n.body.length - 1];
260
276
  const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
261
277
  const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
262
278
  hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
@@ -293,7 +309,7 @@ function inspectPostcssPlugin(content) {
293
309
  const pluginsCode = properties[1].value.callee.object.elements;
294
310
  if (pluginsCode[1] && t.isFunctionExpression(pluginsCode[1])) {
295
311
  const targetBlockStatement = pluginsCode[1].body;
296
- const lastStatement = targetBlockStatement.body.at(-1);
312
+ const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
297
313
  if (t.isExpressionStatement(lastStatement)) {
298
314
  const newExpressionStatement = t.expressionStatement(
299
315
  t.callExpression(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "patch tailwindcss for exposing context and extract classes",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.ts",
@@ -33,25 +33,25 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@types/babel__generator": "^7.6.4",
37
- "@types/babel__traverse": "^7.20.1",
38
- "@types/resolve": "^1.20.2",
39
- "@types/semver": "^7.5.2",
36
+ "@types/babel__generator": "^7.6.8",
37
+ "@types/babel__traverse": "^7.20.5",
38
+ "@types/resolve": "^1.20.6",
39
+ "@types/semver": "^7.5.6",
40
40
  "pkg-types": "^1.0.3",
41
- "tailwindcss": "^3.3.3"
41
+ "tailwindcss": "^3.4.1"
42
42
  },
43
43
  "dependencies": {
44
- "@babel/generator": "^7.22.15",
45
- "@babel/parser": "^7.22.16",
46
- "@babel/traverse": "^7.22.19",
47
- "@babel/types": "^7.22.19",
44
+ "@babel/generator": "^7.23.6",
45
+ "@babel/parser": "^7.23.9",
46
+ "@babel/traverse": "^7.23.9",
47
+ "@babel/types": "^7.23.9",
48
48
  "cac": "^6.7.14",
49
- "jiti": "^1.20.0",
50
- "lilconfig": "^2.1.0",
51
- "postcss": "^8.4.29",
52
- "resolve": "^1.22.5",
53
- "semver": "^7.5.4",
54
- "@tailwindcss-mangle/config": "^2.2.1"
49
+ "jiti": "^1.21.0",
50
+ "lilconfig": "^3.0.0",
51
+ "postcss": "^8.4.34",
52
+ "resolve": "^1.22.8",
53
+ "semver": "^7.6.0",
54
+ "@tailwindcss-mangle/config": "^2.2.2"
55
55
  },
56
56
  "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
57
57
  "repository": {