tailwindcss-patch 1.0.0 → 1.0.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.
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var patcher = require('./patcher-e9a851ca.js');
3
+ var patcher = require('./patcher-7787d13f.js');
4
4
  require('path');
5
5
  require('fs');
6
6
  require('semver');
@@ -8,6 +8,7 @@ require('@babel/types');
8
8
  require('@babel/generator');
9
9
  require('@babel/parser');
10
10
  require('@babel/traverse');
11
+ require('resolve');
11
12
 
12
13
  const patch = patcher.createPatch({});
13
14
  patch();
package/dist/index.js CHANGED
@@ -4,20 +4,27 @@ 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-e9a851ca.js');
7
+ var patcher = require('./patcher-7787d13f.js');
8
8
  require('semver');
9
9
  require('@babel/types');
10
10
  require('@babel/generator');
11
11
  require('@babel/parser');
12
12
  require('@babel/traverse');
13
+ require('resolve');
13
14
 
14
15
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
16
17
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
17
18
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
18
19
 
19
- function getContexts() {
20
- const distPath = path__default["default"].dirname(require.resolve('tailwindcss/lib'));
20
+ function getTailwindcssEntry(basedir = process.cwd()) {
21
+ return patcher.requireResolve('tailwindcss', {
22
+ basedir
23
+ });
24
+ }
25
+ function getContexts(basedir) {
26
+ const twPath = getTailwindcssEntry(basedir);
27
+ const distPath = path__default["default"].dirname(twPath);
21
28
  let injectFilePath = path__default["default"].join(distPath, 'plugin.js');
22
29
  if (!fs__default["default"].existsSync(injectFilePath)) {
23
30
  injectFilePath = path__default["default"].join(distPath, 'index.js');
@@ -54,3 +61,4 @@ exports.monkeyPatchForExposingContext = patcher.monkeyPatchForExposingContext;
54
61
  exports.getClassCacheSet = getClassCacheSet;
55
62
  exports.getClassCaches = getClassCaches;
56
63
  exports.getContexts = getContexts;
64
+ exports.getTailwindcssEntry = getTailwindcssEntry;
@@ -7,6 +7,7 @@ var t = require('@babel/types');
7
7
  var generate = require('@babel/generator');
8
8
  var parser = require('@babel/parser');
9
9
  var traverse = require('@babel/traverse');
10
+ var resolve = require('resolve');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -34,6 +35,26 @@ var t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
34
35
  var generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
35
36
  var traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
36
37
 
38
+ function ensureFileContent(filepaths) {
39
+ if (typeof filepaths === 'string') {
40
+ filepaths = [filepaths];
41
+ }
42
+ let content;
43
+ for (let i = 0; i < filepaths.length; i++) {
44
+ const filepath = filepaths[i];
45
+ if (fs__default["default"].existsSync(filepath)) {
46
+ content = fs__default["default"].readFileSync(filepath, {
47
+ encoding: 'utf-8'
48
+ });
49
+ break;
50
+ }
51
+ }
52
+ return content;
53
+ }
54
+ function requireResolve(id, opts) {
55
+ return resolve.sync(id, opts);
56
+ }
57
+
37
58
  function inspectProcessTailwindFeaturesReturnContext(content) {
38
59
  const ast = parser.parse(content);
39
60
  let hasPatched = false;
@@ -204,27 +225,12 @@ const defaultOptions = {
204
225
  overwrite: true
205
226
  };
206
227
 
207
- function ensureFileContent(filepaths) {
208
- if (typeof filepaths === 'string') {
209
- filepaths = [filepaths];
210
- }
211
- let content;
212
- for (let i = 0; i < filepaths.length; i++) {
213
- const filepath = filepaths[i];
214
- if (fs__default["default"].existsSync(filepath)) {
215
- content = fs__default["default"].readFileSync(filepath, {
216
- encoding: 'utf-8'
217
- });
218
- break;
219
- }
220
- }
221
- return content;
222
- }
223
-
224
228
  function getInstalledPkgJsonPath(options) {
229
+ var _a;
225
230
  try {
226
- const tmpJsonPath = require.resolve(`tailwindcss/package.json`, {
227
- paths: options.paths
231
+ const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
232
+ paths: options.paths,
233
+ basedir: (_a = options.basedir) !== null && _a !== void 0 ? _a : process.cwd()
228
234
  });
229
235
  const pkgJson = require(tmpJsonPath);
230
236
  if (semver.gte(pkgJson.version, '3.0.0')) {
@@ -233,7 +239,7 @@ function getInstalledPkgJsonPath(options) {
233
239
  }
234
240
  catch (error) {
235
241
  if (error.code === 'MODULE_NOT_FOUND') {
236
- console.warn('没有找到`tailwindcss`包,请确认是否安装。');
242
+ console.warn('Can\'t find npm pkg: `tailwindcss`, Please ensure it has been installed!');
237
243
  }
238
244
  }
239
245
  }
@@ -291,3 +297,4 @@ exports.inspectPostcssPlugin = inspectPostcssPlugin;
291
297
  exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
292
298
  exports.internalPatch = internalPatch;
293
299
  exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
300
+ exports.requireResolve = requireResolve;
@@ -1,5 +1,6 @@
1
1
  import type { Rule } from 'postcss';
2
- export declare function getContexts(): any[];
2
+ export declare function getTailwindcssEntry(basedir?: string): string;
3
+ export declare function getContexts(basedir?: string): any[];
3
4
  export declare function getClassCaches(): Map<string, ({
4
5
  layer: string;
5
6
  options: Record<string, any>;
@@ -1,8 +1,10 @@
1
1
  export interface PatchOptions {
2
2
  overwrite?: boolean;
3
3
  paths?: string[];
4
+ basedir?: string;
4
5
  }
5
6
  export interface InternalPatchOptions {
6
7
  overwrite: boolean;
7
8
  paths?: string[];
9
+ basedir?: string;
8
10
  }
@@ -1 +1,3 @@
1
+ import { type SyncOpts } from 'resolve';
1
2
  export declare function ensureFileContent(filepaths: string | string[]): string | undefined;
3
+ export declare function requireResolve(id: string, opts?: SyncOpts): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "patch tailwindcss for exposing context",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -25,6 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@types/babel__generator": "^7.6.4",
27
27
  "@types/babel__traverse": "^7.18.3",
28
+ "@types/resolve": "^1.20.2",
28
29
  "@types/semver": "^7.3.13",
29
30
  "defu": "^6.1.2",
30
31
  "pkg-types": "^1.0.2",
@@ -36,6 +37,7 @@
36
37
  "@babel/parser": "^7.21.4",
37
38
  "@babel/traverse": "^7.21.4",
38
39
  "@babel/types": "^7.21.4",
40
+ "resolve": "^1.22.2",
39
41
  "semver": "^7.4.0"
40
42
  },
41
43
  "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",