tailwindcss-patch 1.0.2 → 1.0.4

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var patcher = require('./patcher-85767405.js');
3
+ var patcher = require('./patcher-90d636ff.js');
4
4
  require('path');
5
5
  require('fs');
6
6
  require('semver');
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
6
  var fs = require('fs');
7
- var patcher = require('./patcher-85767405.js');
7
+ var patcher = require('./patcher-90d636ff.js');
8
8
  require('semver');
9
9
  require('@babel/types');
10
10
  require('@babel/generator');
@@ -60,15 +60,15 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
60
60
  let hasPatched = false;
61
61
  traverse__default["default"](ast, {
62
62
  FunctionDeclaration(p) {
63
- var _a, _b;
63
+ var _a;
64
64
  const n = p.node;
65
65
  if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'processTailwindFeatures') {
66
- if (n.body.body.length === 1 && n.body.body[0].type === 'ReturnStatement') {
66
+ if (n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
67
67
  const rts = n.body.body[0];
68
68
  if (t__namespace.isFunctionExpression(rts.argument)) {
69
69
  const body = rts.argument.body.body;
70
70
  const lastStatement = body[body.length - 1];
71
- hasPatched = lastStatement.type === 'ReturnStatement' && ((_b = lastStatement.argument) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' && lastStatement.argument.name === 'context';
71
+ hasPatched = t__namespace.isReturnStatement(lastStatement) && t__namespace.isIdentifier(lastStatement.argument) && lastStatement.argument.name === 'context';
72
72
  if (!hasPatched) {
73
73
  const rts = t__namespace.returnStatement(t__namespace.identifier('context'));
74
74
  body.push(rts);
@@ -94,23 +94,23 @@ function inspectPostcssPlugin(content) {
94
94
  const n = p.node;
95
95
  const idx = n.body.findIndex((x) => {
96
96
  var _a;
97
- return (x.type === 'ExpressionStatement' &&
98
- x.expression.type === 'AssignmentExpression' &&
99
- x.expression.left.type === 'MemberExpression' &&
100
- x.expression.right.type === 'FunctionExpression' &&
97
+ return (t__namespace.isExpressionStatement(x) &&
98
+ t__namespace.isAssignmentExpression(x.expression) &&
99
+ t__namespace.isMemberExpression(x.expression.left) &&
100
+ t__namespace.isFunctionExpression(x.expression.right) &&
101
101
  ((_a = x.expression.right.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss');
102
102
  });
103
103
  if (idx > -1) {
104
104
  const prevStatement = n.body[idx - 1];
105
105
  const lastStatement = n.body[n.body.length - 1];
106
106
  const hasPatchedCondition0 = prevStatement &&
107
- prevStatement.type === 'VariableDeclaration' &&
107
+ t__namespace.isVariableDeclaration(prevStatement) &&
108
108
  prevStatement.declarations.length === 1 &&
109
- prevStatement.declarations[0].id.type === 'Identifier' &&
109
+ t__namespace.isIdentifier(prevStatement.declarations[0].id) &&
110
110
  prevStatement.declarations[0].id.name === variableName;
111
- const hasPatchedCondition1 = lastStatement.type === 'ExpressionStatement' &&
112
- lastStatement.expression.type === 'AssignmentExpression' &&
113
- lastStatement.expression.right.type === 'Identifier' &&
111
+ const hasPatchedCondition1 = t__namespace.isExpressionStatement(lastStatement) &&
112
+ t__namespace.isAssignmentExpression(lastStatement.expression) &&
113
+ t__namespace.isIdentifier(lastStatement.expression.right) &&
114
114
  lastStatement.expression.right.name === variableName;
115
115
  hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
116
116
  if (!hasPatched) {
@@ -123,40 +123,40 @@ function inspectPostcssPlugin(content) {
123
123
  }
124
124
  },
125
125
  FunctionExpression(p) {
126
- var _a, _b;
126
+ var _a;
127
127
  if (hasPatched) {
128
128
  return;
129
129
  }
130
130
  const n = p.node;
131
131
  if (((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === 'tailwindcss') {
132
- if (n.body.body.length === 1 && n.body.body[0].type === 'ReturnStatement') {
132
+ if (n.body.body.length === 1 && t__namespace.isReturnStatement(n.body.body[0])) {
133
133
  const returnStatement = n.body.body[0];
134
- if (((_b = returnStatement.argument) === null || _b === void 0 ? void 0 : _b.type) === 'ObjectExpression' && returnStatement.argument.properties.length === 2) {
134
+ if (t__namespace.isObjectExpression(returnStatement.argument) && returnStatement.argument.properties.length === 2) {
135
135
  const properties = returnStatement.argument.properties;
136
- if (properties[0].type === 'ObjectProperty' && properties[1].type === 'ObjectProperty') {
137
- const keyMatched = properties[0].key.type === 'Identifier' && properties[0].key.name === 'postcssPlugin';
138
- const pluginsMatched = properties[1].key.type === 'Identifier' && properties[1].key.name === 'plugins';
136
+ if (t__namespace.isObjectProperty(properties[0]) && t__namespace.isObjectProperty(properties[1])) {
137
+ const keyMatched = t__namespace.isIdentifier(properties[0].key) && properties[0].key.name === 'postcssPlugin';
138
+ const pluginsMatched = t__namespace.isIdentifier(properties[1].key) && properties[1].key.name === 'plugins';
139
139
  if (pluginsMatched &&
140
140
  keyMatched &&
141
- properties[1].value.type === 'CallExpression' &&
142
- properties[1].value.callee.type === 'MemberExpression' &&
143
- properties[1].value.callee.object.type === 'ArrayExpression') {
141
+ t__namespace.isCallExpression(properties[1].value) &&
142
+ t__namespace.isMemberExpression(properties[1].value.callee) &&
143
+ t__namespace.isArrayExpression(properties[1].value.callee.object)) {
144
144
  const pluginsCode = properties[1].value.callee.object.elements;
145
- if (pluginsCode[1] && pluginsCode[1].type === 'FunctionExpression') {
145
+ if (pluginsCode[1] && t__namespace.isFunctionExpression(pluginsCode[1])) {
146
146
  const targetBlockStatement = pluginsCode[1].body;
147
147
  const lastStatement = targetBlockStatement.body[targetBlockStatement.body.length - 1];
148
- if (lastStatement.type === 'ExpressionStatement') {
148
+ if (t__namespace.isExpressionStatement(lastStatement)) {
149
149
  const newExpressionStatement = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier('value')), t__namespace.identifier('push')), [lastStatement.expression]));
150
150
  targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
151
151
  }
152
- const ifIdx = targetBlockStatement.body.findIndex((x) => x.type === 'IfStatement');
152
+ const ifIdx = targetBlockStatement.body.findIndex((x) => t__namespace.isIfStatement(x));
153
153
  if (ifIdx > -1) {
154
154
  const ifRoot = targetBlockStatement.body[ifIdx];
155
- if (ifRoot.consequent.type === 'BlockStatement' && ifRoot.consequent.body[1] && ifRoot.consequent.body[1].type === 'ForOfStatement') {
155
+ if (t__namespace.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t__namespace.isForOfStatement(ifRoot.consequent.body[1])) {
156
156
  const forOf = ifRoot.consequent.body[1];
157
- if (forOf.body.type === 'BlockStatement' && forOf.body.body.length === 1 && forOf.body.body[0].type === 'IfStatement') {
157
+ if (t__namespace.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t__namespace.isIfStatement(forOf.body.body[0])) {
158
158
  const if2 = forOf.body.body[0];
159
- if (if2.consequent.type === 'BlockStatement' && if2.consequent.body.length === 1 && if2.consequent.body[0].type === 'ExpressionStatement') {
159
+ if (t__namespace.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t__namespace.isExpressionStatement(if2.consequent.body[0])) {
160
160
  const target = if2.consequent.body[0];
161
161
  const newExpressionStatement = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier(variableName), t__namespace.identifier('value')), t__namespace.identifier('push')), [target.expression]));
162
162
  if2.consequent.body[0] = newExpressionStatement;
@@ -225,21 +225,18 @@ const defaultOptions = {
225
225
  overwrite: true
226
226
  };
227
227
 
228
- function getInstalledPkgJsonPath(options) {
228
+ function getInstalledPkgJsonPath(options = {}) {
229
229
  var _a;
230
230
  try {
231
231
  const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
232
232
  paths: options.paths,
233
233
  basedir: (_a = options.basedir) !== null && _a !== void 0 ? _a : process.cwd()
234
234
  });
235
- const pkgJson = require(tmpJsonPath);
236
- if (semver.gte(pkgJson.version, '3.0.0')) {
237
- return tmpJsonPath;
238
- }
235
+ return tmpJsonPath;
239
236
  }
240
237
  catch (error) {
241
238
  if (error.code === 'MODULE_NOT_FOUND') {
242
- console.warn('Can\'t find npm pkg: `tailwindcss`, Please ensure it has been installed!');
239
+ console.warn("Can't find npm pkg: `tailwindcss`, Please ensure it has been installed!");
243
240
  }
244
241
  }
245
242
  }
@@ -287,9 +284,12 @@ function monkeyPatchForExposingContext(twDir, opt) {
287
284
  }
288
285
  function internalPatch(pkgJsonPath, options) {
289
286
  if (pkgJsonPath) {
287
+ const pkgJson = require(pkgJsonPath);
290
288
  const twDir = path__default["default"].dirname(pkgJsonPath);
291
- const result = monkeyPatchForExposingContext(twDir, options);
292
- return result;
289
+ if (semver.gte(pkgJson.version, '3.0.0')) {
290
+ const result = monkeyPatchForExposingContext(twDir, options);
291
+ return result;
292
+ }
293
293
  }
294
294
  }
295
295
 
@@ -1,5 +1,5 @@
1
1
  import type { PatchOptions, InternalPatchOptions } from './type';
2
- export declare function getInstalledPkgJsonPath(options: PatchOptions): string | undefined;
2
+ export declare function getInstalledPkgJsonPath(options?: PatchOptions): string | undefined;
3
3
  export declare function createPatch(options?: PatchOptions): () => any;
4
4
  export declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatchOptions): {
5
5
  processTailwindFeatures?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "patch tailwindcss for exposing context",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -24,13 +24,13 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/babel__generator": "^7.6.4",
27
- "@types/babel__traverse": "^7.18.3",
27
+ "@types/babel__traverse": "^7.18.5",
28
28
  "@types/resolve": "^1.20.2",
29
29
  "@types/semver": "^7.3.13",
30
30
  "defu": "^6.1.2",
31
31
  "pkg-types": "^1.0.2",
32
- "postcss": "^8.4.21",
33
- "tailwindcss": "^3.3.1"
32
+ "postcss": "^8.4.23",
33
+ "tailwindcss": "^3.3.2"
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/generator": "^7.21.4",
@@ -38,7 +38,7 @@
38
38
  "@babel/traverse": "^7.21.4",
39
39
  "@babel/types": "^7.21.4",
40
40
  "resolve": "^1.22.2",
41
- "semver": "^7.4.0"
41
+ "semver": "^7.5.0"
42
42
  },
43
43
  "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
44
44
  "repository": {
@@ -51,8 +51,6 @@
51
51
  "dev:tsc": "tsc -p tsconfig.json --sourceMap",
52
52
  "build:tsc": "tsc -p tsconfig.json",
53
53
  "test": "npm run patch && jest",
54
- "postinstall": "echo postinstall",
55
- "preinstall": "npx only-allow pnpm",
56
54
  "patch": "ts-node src/cli.ts"
57
55
  }
58
56
  }