tailwindcss-patch 1.0.1 → 1.0.2

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-7787d13f.js');
3
+ var patcher = require('./patcher-85767405.js');
4
4
  require('path');
5
5
  require('fs');
6
6
  require('semver');
@@ -10,5 +10,5 @@ require('@babel/parser');
10
10
  require('@babel/traverse');
11
11
  require('resolve');
12
12
 
13
- const patch = patcher.createPatch({});
13
+ const patch = patcher.createPatch();
14
14
  patch();
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-7787d13f.js');
7
+ var patcher = require('./patcher-85767405.js');
8
8
  require('semver');
9
9
  require('@babel/types');
10
10
  require('@babel/generator');
@@ -53,11 +53,13 @@ function getClassCacheSet() {
53
53
  }
54
54
 
55
55
  exports.createPatch = patcher.createPatch;
56
+ exports.ensureFileContent = patcher.ensureFileContent;
56
57
  exports.getInstalledPkgJsonPath = patcher.getInstalledPkgJsonPath;
57
58
  exports.inspectPostcssPlugin = patcher.inspectPostcssPlugin;
58
59
  exports.inspectProcessTailwindFeaturesReturnContext = patcher.inspectProcessTailwindFeaturesReturnContext;
59
60
  exports.internalPatch = patcher.internalPatch;
60
61
  exports.monkeyPatchForExposingContext = patcher.monkeyPatchForExposingContext;
62
+ exports.requireResolve = patcher.requireResolve;
61
63
  exports.getClassCacheSet = getClassCacheSet;
62
64
  exports.getClassCaches = getClassCaches;
63
65
  exports.getContexts = getContexts;
@@ -243,19 +243,20 @@ function getInstalledPkgJsonPath(options) {
243
243
  }
244
244
  }
245
245
  }
246
- function createPatch(options) {
246
+ function createPatch(options = {}) {
247
247
  const opt = defu(options, defaultOptions);
248
248
  return () => {
249
249
  try {
250
- return internalPatch(getInstalledPkgJsonPath(options), opt);
250
+ const pkgJsonPath = getInstalledPkgJsonPath(options);
251
+ return internalPatch(pkgJsonPath, opt);
251
252
  }
252
253
  catch (error) {
253
254
  console.warn(`patch tailwindcss failed:` + error.message);
254
255
  }
255
256
  };
256
257
  }
257
- function monkeyPatchForExposingContext(rootDir, opt) {
258
- const processTailwindFeaturesFilePath = path__default["default"].resolve(rootDir, 'lib/processTailwindFeatures.js');
258
+ function monkeyPatchForExposingContext(twDir, opt) {
259
+ const processTailwindFeaturesFilePath = path__default["default"].resolve(twDir, 'lib/processTailwindFeatures.js');
259
260
  const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
260
261
  const result = {};
261
262
  if (processTailwindFeaturesContent) {
@@ -268,8 +269,8 @@ function monkeyPatchForExposingContext(rootDir, opt) {
268
269
  }
269
270
  result.processTailwindFeatures = code;
270
271
  }
271
- const pluginFilePath = path__default["default"].resolve(rootDir, 'lib/plugin.js');
272
- const indexFilePath = path__default["default"].resolve(rootDir, 'lib/index.js');
272
+ const pluginFilePath = path__default["default"].resolve(twDir, 'lib/plugin.js');
273
+ const indexFilePath = path__default["default"].resolve(twDir, 'lib/index.js');
273
274
  const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
274
275
  if (pluginContent) {
275
276
  const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
@@ -281,17 +282,19 @@ function monkeyPatchForExposingContext(rootDir, opt) {
281
282
  }
282
283
  result.plugin = code;
283
284
  }
285
+ opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result);
284
286
  return result;
285
287
  }
286
288
  function internalPatch(pkgJsonPath, options) {
287
289
  if (pkgJsonPath) {
288
- const rootDir = path__default["default"].dirname(pkgJsonPath);
289
- const result = monkeyPatchForExposingContext(rootDir, options);
290
+ const twDir = path__default["default"].dirname(pkgJsonPath);
291
+ const result = monkeyPatchForExposingContext(twDir, options);
290
292
  return result;
291
293
  }
292
294
  }
293
295
 
294
296
  exports.createPatch = createPatch;
297
+ exports.ensureFileContent = ensureFileContent;
295
298
  exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
296
299
  exports.inspectPostcssPlugin = inspectPostcssPlugin;
297
300
  exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
@@ -1,3 +1,5 @@
1
1
  export * from './exposeContext';
2
2
  export * from './inspector';
3
3
  export * from './patcher';
4
+ export * from './utils';
5
+ export * from './type';
@@ -1,8 +1,8 @@
1
1
  import type { PatchOptions, InternalPatchOptions } from './type';
2
2
  export declare function getInstalledPkgJsonPath(options: PatchOptions): string | undefined;
3
- export declare function createPatch(options: PatchOptions): () => any;
4
- export declare function monkeyPatchForExposingContext(rootDir: string, opt: InternalPatchOptions): {
3
+ export declare function createPatch(options?: PatchOptions): () => any;
4
+ export declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatchOptions): {
5
5
  processTailwindFeatures?: string | undefined;
6
6
  plugin?: string | undefined;
7
- };
7
+ } & Record<string, any>;
8
8
  export declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
@@ -2,9 +2,11 @@ export interface PatchOptions {
2
2
  overwrite?: boolean;
3
3
  paths?: string[];
4
4
  basedir?: string;
5
+ custom?: (dir: string, ctx: Record<string, any>) => void;
5
6
  }
6
7
  export interface InternalPatchOptions {
7
8
  overwrite: boolean;
8
9
  paths?: string[];
9
10
  basedir?: string;
11
+ custom?: (dir: string, ctx: Record<string, any>) => void;
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "patch tailwindcss for exposing context",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",