tailwindcss-patch 2.0.1 → 2.0.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,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const cac = require('cac');
3
4
  const index = require('./index.cjs');
4
5
  require('node:path');
5
6
  require('node:fs');
@@ -9,10 +10,11 @@ require('@babel/types');
9
10
  require('@babel/generator');
10
11
  require('@babel/traverse');
11
12
  require('@babel/parser');
12
- const cac = require('cac');
13
+ const config = require('@tailwindcss-mangle/config');
13
14
  require('semver');
14
15
  require('postcss');
15
- require('c12');
16
+ require('lilconfig');
17
+ require('jiti');
16
18
 
17
19
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
18
20
 
@@ -20,7 +22,7 @@ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
20
22
 
21
23
  function init() {
22
24
  const cwd = process.cwd();
23
- return index.initConfig(cwd);
25
+ return config.initConfig(cwd);
24
26
  }
25
27
  const cli = cac__default();
26
28
  cli.command("install", "patch install").action(() => {
@@ -30,13 +32,13 @@ cli.command("install", "patch install").action(() => {
30
32
  });
31
33
  cli.command("init").action(async () => {
32
34
  await init();
33
- console.log("\u2728 tailwindcss-patch config initialized!");
35
+ console.log(`\u2728 ${config.configName}.config.ts initialized!`);
34
36
  });
35
37
  cli.command("extract").action(async () => {
36
- const { config } = await index.getConfig();
37
- if (config) {
38
+ const { config: config$1 } = await config.getConfig();
39
+ if (config$1) {
38
40
  const twPatcher = new index.TailwindcssPatcher();
39
- const p = await twPatcher.extract(config);
41
+ const p = await twPatcher.extract(config$1.patch);
40
42
  console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
41
43
  }
42
44
  });
package/dist/cli.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { getPatchOptions, getConfig, TailwindcssPatcher, initConfig, createPatch } from './index.mjs';
1
+ import cac from 'cac';
2
+ import { getPatchOptions, TailwindcssPatcher, createPatch } from './index.mjs';
2
3
  import 'node:path';
3
4
  import 'node:fs';
4
5
  import 'node:fs/promises';
@@ -7,10 +8,11 @@ import '@babel/types';
7
8
  import '@babel/generator';
8
9
  import '@babel/traverse';
9
10
  import '@babel/parser';
10
- import cac from 'cac';
11
+ import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
11
12
  import 'semver';
12
13
  import 'postcss';
13
- import 'c12';
14
+ import 'lilconfig';
15
+ import 'jiti';
14
16
 
15
17
  function init() {
16
18
  const cwd = process.cwd();
@@ -24,13 +26,13 @@ cli.command("install", "patch install").action(() => {
24
26
  });
25
27
  cli.command("init").action(async () => {
26
28
  await init();
27
- console.log("\u2728 tailwindcss-patch config initialized!");
29
+ console.log(`\u2728 ${configName}.config.ts initialized!`);
28
30
  });
29
31
  cli.command("extract").action(async () => {
30
32
  const { config } = await getConfig();
31
33
  if (config) {
32
34
  const twPatcher = new TailwindcssPatcher();
33
- const p = await twPatcher.extract(config);
35
+ const p = await twPatcher.extract(config.patch);
34
36
  console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
35
37
  }
36
38
  });
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const fs$1 = require('node:fs/promises');
3
4
  const path = require('node:path');
4
5
  const fs = require('node:fs');
5
- const fs$1 = require('node:fs/promises');
6
6
  const pkg = require('resolve');
7
7
  const semver = require('semver');
8
8
  const t = require('@babel/types');
@@ -10,7 +10,9 @@ const generate = require('@babel/generator');
10
10
  const traverse = require('@babel/traverse');
11
11
  const parser = require('@babel/parser');
12
12
  const postcss = require('postcss');
13
- const c12 = require('c12');
13
+ const lilconfig = require('lilconfig');
14
+ const createJiti = require('jiti');
15
+ const config = require('@tailwindcss-mangle/config');
14
16
 
15
17
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
16
18
 
@@ -26,14 +28,15 @@ function _interopNamespaceCompat(e) {
26
28
  return n;
27
29
  }
28
30
 
31
+ const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
29
32
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
30
33
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
31
- const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
32
34
  const pkg__default = /*#__PURE__*/_interopDefaultCompat(pkg);
33
35
  const t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
34
36
  const generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
35
37
  const traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
36
38
  const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
39
+ const createJiti__default = /*#__PURE__*/_interopDefaultCompat(createJiti);
37
40
 
38
41
  const { sync } = pkg__default;
39
42
  function ensureFileContent(filepaths) {
@@ -182,6 +185,48 @@ class CacheManager {
182
185
  }
183
186
  }
184
187
 
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();
229
+
185
230
  function inspectProcessTailwindFeaturesReturnContext(content) {
186
231
  const ast = parser.parse(content);
187
232
  let hasPatched = false;
@@ -319,65 +364,11 @@ function inspectPostcssPlugin(content) {
319
364
  };
320
365
  }
321
366
 
322
- function isObject(value) {
323
- return value !== null && typeof value === "object";
324
- }
325
- function _defu(baseObject, defaults, namespace = ".", merger) {
326
- if (!isObject(defaults)) {
327
- return _defu(baseObject, {}, namespace, merger);
328
- }
329
- const object = Object.assign({}, defaults);
330
- for (const key in baseObject) {
331
- if (key === "__proto__" || key === "constructor") {
332
- continue;
333
- }
334
- const value = baseObject[key];
335
- if (value === null || value === void 0) {
336
- continue;
337
- }
338
- if (merger && merger(object, key, value, namespace)) {
339
- continue;
340
- }
341
- if (Array.isArray(value) && Array.isArray(object[key])) {
342
- object[key] = [...value, ...object[key]];
343
- } else if (isObject(value) && isObject(object[key])) {
344
- object[key] = _defu(
345
- value,
346
- object[key],
347
- (namespace ? `${namespace}.` : "") + key.toString(),
348
- merger
349
- );
350
- } else {
351
- object[key] = value;
352
- }
353
- }
354
- return object;
355
- }
356
- function createDefu(merger) {
357
- return (...arguments_) => (
358
- // eslint-disable-next-line unicorn/no-array-reduce
359
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
360
- );
361
- }
362
- const defu = createDefu();
363
-
364
367
  function getDefaultPatchOptions() {
365
368
  return {
366
369
  overwrite: true
367
370
  };
368
371
  }
369
- function getDefaultUserConfig() {
370
- return {
371
- output: {
372
- filename: ".tw-patch/tw-class-list.json",
373
- removeUniversalSelector: true,
374
- loose: true
375
- },
376
- tailwindcss: {
377
- cwd: process.cwd()
378
- }
379
- };
380
- }
381
372
 
382
373
  function getInstalledPkgJsonPath(options = {}) {
383
374
  try {
@@ -452,17 +443,34 @@ function internalPatch(pkgJsonPath, options) {
452
443
  }
453
444
  }
454
445
 
446
+ const jiti = createJiti__default(__filename);
455
447
  async function processTailwindcss(options) {
456
448
  options.cwd = options.cwd ?? process.cwd();
457
- const config = options.config && path__default.isAbsolute(options.config) ? options.config : path__default.resolve(options.cwd, "tailwind.config.js");
458
- const res = await postcss__default([
449
+ let config = options.config;
450
+ if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
451
+ const moduleName = "tailwind";
452
+ const result = await lilconfig.lilconfig("tailwindcss", {
453
+ searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
454
+ loaders: {
455
+ // 默认支持 js 和 cjs 2种格式
456
+ ".js": jiti,
457
+ ".cjs": jiti,
458
+ ".ts": jiti,
459
+ ".mjs": jiti
460
+ }
461
+ }).search(options.cwd);
462
+ if (!result) {
463
+ throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
464
+ }
465
+ config = result.filepath;
466
+ }
467
+ return await postcss__default([
459
468
  require("tailwindcss")({
460
469
  config
461
470
  })
462
471
  ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
463
472
  from: void 0
464
473
  });
465
- return res;
466
474
  }
467
475
 
468
476
  class TailwindcssPatcher {
@@ -512,7 +520,7 @@ class TailwindcssPatcher {
512
520
  return getContexts(basedir);
513
521
  }
514
522
  async extract(options) {
515
- const { output, tailwindcss } = options;
523
+ const { output, tailwindcss } = options ?? {};
516
524
  if (output && tailwindcss) {
517
525
  const { removeUniversalSelector, filename, loose } = output;
518
526
  await processTailwindcss(tailwindcss);
@@ -529,105 +537,23 @@ class TailwindcssPatcher {
529
537
  }
530
538
  }
531
539
 
532
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
533
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
534
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
535
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
536
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
537
- const dedent = createDedent({});
538
- function createDedent(options) {
539
- dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
540
- return dedent;
541
- function dedent(strings, ...values) {
542
- const raw = typeof strings === "string" ? [strings] : strings.raw;
543
- const {
544
- escapeSpecialCharacters = Array.isArray(strings)
545
- } = options;
546
-
547
- // first, perform interpolation
548
- let result = "";
549
- for (let i = 0; i < raw.length; i++) {
550
- let next = raw[i];
551
- if (escapeSpecialCharacters) {
552
- // handle escaped newlines, backticks, and interpolation characters
553
- next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
554
- }
555
- result += next;
556
- if (i < values.length) {
557
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
558
- result += values[i];
559
- }
560
- }
561
-
562
- // now strip indentation
563
- const lines = result.split("\n");
564
- let mindent = null;
565
- for (const l of lines) {
566
- const m = l.match(/^(\s+)\S+/);
567
- if (m) {
568
- const indent = m[1].length;
569
- if (!mindent) {
570
- // this is the first indented line
571
- mindent = indent;
572
- } else {
573
- mindent = Math.min(mindent, indent);
574
- }
575
- }
576
- }
577
- if (mindent !== null) {
578
- const m = mindent; // appease TypeScript
579
- result = lines
580
- // https://github.com/typescript-eslint/typescript-eslint/issues/7140
581
- // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
582
- .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
583
- }
584
- return result
585
- // dedent eats leading and trailing whitespace too
586
- .trim()
587
- // handle escaped newlines at the end to ensure they don't get stripped too
588
- .replace(/\\n/g, "\n");
589
- }
590
- }
591
-
592
- function getConfig(cwd) {
593
- return c12.loadConfig({
594
- name: "tailwindcss-patch",
595
- defaults: {
596
- ...getDefaultUserConfig()
597
- },
598
- cwd
599
- });
600
- }
601
- const defineConfig = c12.createDefineConfig();
602
- function initConfig(cwd) {
603
- return fs__default$1.writeFile(
604
- path__default.resolve(cwd, "tailwindcss-patch.config.ts"),
605
- dedent`
606
- import { defineConfig } from 'tailwindcss-patch'
607
-
608
- export default defineConfig({})
609
- `,
610
- "utf8"
611
- );
612
- }
613
-
614
540
  exports.CacheManager = CacheManager;
615
541
  exports.TailwindcssPatcher = TailwindcssPatcher;
616
542
  exports.createPatch = createPatch;
617
- exports.defineConfig = defineConfig;
618
543
  exports.ensureDir = ensureDir;
619
544
  exports.ensureFileContent = ensureFileContent;
620
545
  exports.getCacheOptions = getCacheOptions;
621
546
  exports.getClassCacheSet = getClassCacheSet;
622
547
  exports.getClassCaches = getClassCaches;
623
- exports.getConfig = getConfig;
624
548
  exports.getContexts = getContexts;
625
549
  exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
626
550
  exports.getPatchOptions = getPatchOptions;
627
551
  exports.getTailwindcssEntry = getTailwindcssEntry;
628
- exports.initConfig = initConfig;
629
552
  exports.inspectPostcssPlugin = inspectPostcssPlugin;
630
553
  exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
631
554
  exports.internalPatch = internalPatch;
632
555
  exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
633
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];
559
+ });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Rule, Node } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
- import * as c12 from 'c12';
3
+ import { UserConfig } from '@tailwindcss-mangle/config';
4
+ export * from '@tailwindcss-mangle/config';
4
5
  import { SyncOpts } from 'resolve';
5
6
 
6
7
  type CacheStrategy = 'merge' | 'overwrite';
@@ -37,7 +38,7 @@ type TailwindcssClassCache = Map<string, ({
37
38
  } | Rule)[]>;
38
39
  type TailwindcssRuntimeContext = {
39
40
  applyClassCache: Map<any, any>;
40
- candidateRuleCache: Map<string | String, Set<[
41
+ candidateRuleCache: Map<string | string, Set<[
41
42
  {
42
43
  arbitrary: any;
43
44
  index: any;
@@ -49,7 +50,7 @@ type TailwindcssRuntimeContext = {
49
50
  },
50
51
  Node
51
52
  ]>>;
52
- candidateRuleMap: Map<string | String, [object, Node][]>;
53
+ candidateRuleMap: Map<string | string, [object, Node][]>;
53
54
  changedContent: any[];
54
55
  classCache: TailwindcssClassCache;
55
56
  disposables: any[];
@@ -58,7 +59,7 @@ type TailwindcssRuntimeContext = {
58
59
  getVariants: Function;
59
60
  markInvalidUtilityCandidate: Function;
60
61
  markInvalidUtilityNode: Function;
61
- notClassCache: Set<String>;
62
+ notClassCache: Set<string>;
62
63
  offsets: {
63
64
  layerPositions: object;
64
65
  offsets: object;
@@ -73,20 +74,6 @@ type TailwindcssRuntimeContext = {
73
74
  variantMap: Map<string, [[object, Function]]>;
74
75
  variantOptions: Map<string, object>;
75
76
  };
76
- interface UserConfig {
77
- output?: {
78
- filename?: string;
79
- loose?: boolean;
80
- /**
81
- * @description remove * in output json
82
- */
83
- removeUniversalSelector?: boolean;
84
- };
85
- tailwindcss?: {
86
- cwd?: string;
87
- config?: string;
88
- };
89
- }
90
77
  type DeepRequired<T> = {
91
78
  [K in keyof T]: Required<DeepRequired<T[K]>>;
92
79
  };
@@ -127,7 +114,7 @@ declare class TailwindcssPatcher {
127
114
  removeUniversalSelector?: boolean;
128
115
  }): Set<string>;
129
116
  getContexts(basedir?: string): TailwindcssRuntimeContext[];
130
- extract(options: UserConfig): Promise<string | undefined>;
117
+ extract(options: UserConfig['patch']): Promise<string | undefined>;
131
118
  }
132
119
 
133
120
  declare function getTailwindcssEntry(basedir?: string): string;
@@ -155,12 +142,8 @@ declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatch
155
142
  } & Record<string, any>;
156
143
  declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
157
144
 
158
- declare function getConfig(cwd?: string): Promise<c12.ResolvedConfig<UserConfig, c12.ConfigLayerMeta>>;
159
- declare const defineConfig: c12.DefineConfig<UserConfig, c12.ConfigLayerMeta>;
160
- declare function initConfig(cwd: string): Promise<void>;
161
-
162
145
  declare function ensureFileContent(filepaths: string | string[]): string | undefined;
163
146
  declare function requireResolve(id: string, opts?: SyncOpts): string;
164
147
  declare function ensureDir(p: string): Promise<void>;
165
148
 
166
- export { CacheManager, CacheOptions, CacheStrategy, DeepRequired, InternalCacheOptions, InternalPatchOptions, PatchOptions, TailwindcssClassCache, TailwindcssPatcher, TailwindcssPatcherOptions, TailwindcssRuntimeContext, UserConfig, createPatch, defineConfig, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getConfig, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, initConfig, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
149
+ export { CacheManager, CacheOptions, CacheStrategy, DeepRequired, InternalCacheOptions, InternalPatchOptions, PatchOptions, TailwindcssClassCache, TailwindcssPatcher, TailwindcssPatcherOptions, TailwindcssRuntimeContext, createPatch, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
+ import fs$1 from 'node:fs/promises';
1
2
  import path, { dirname } from 'node:path';
2
3
  import fs from 'node:fs';
3
- import fs$1 from 'node:fs/promises';
4
4
  import pkg from 'resolve';
5
5
  import { gte } from 'semver';
6
6
  import * as t from '@babel/types';
@@ -8,7 +8,18 @@ import generate from '@babel/generator';
8
8
  import traverse from '@babel/traverse';
9
9
  import { parse } from '@babel/parser';
10
10
  import postcss from 'postcss';
11
- import { createDefineConfig, loadConfig } from 'c12';
11
+ import { lilconfig } from 'lilconfig';
12
+ import createJiti from 'jiti';
13
+
14
+
15
+ // -- Unbuild CommonJS Shims --
16
+ import __cjs_url__ from 'url';
17
+ import __cjs_path__ from 'path';
18
+ import __cjs_mod__ from 'module';
19
+ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
20
+ const __dirname = __cjs_path__.dirname(__filename);
21
+ const require = __cjs_mod__.createRequire(import.meta.url);
22
+ export * from '@tailwindcss-mangle/config';
12
23
 
13
24
  const { sync } = pkg;
14
25
  function ensureFileContent(filepaths) {
@@ -157,6 +168,48 @@ class CacheManager {
157
168
  }
158
169
  }
159
170
 
171
+ function isObject(value) {
172
+ return value !== null && typeof value === "object";
173
+ }
174
+ function _defu(baseObject, defaults, namespace = ".", merger) {
175
+ if (!isObject(defaults)) {
176
+ return _defu(baseObject, {}, namespace, merger);
177
+ }
178
+ const object = Object.assign({}, defaults);
179
+ for (const key in baseObject) {
180
+ if (key === "__proto__" || key === "constructor") {
181
+ continue;
182
+ }
183
+ const value = baseObject[key];
184
+ if (value === null || value === void 0) {
185
+ continue;
186
+ }
187
+ if (merger && merger(object, key, value, namespace)) {
188
+ continue;
189
+ }
190
+ if (Array.isArray(value) && Array.isArray(object[key])) {
191
+ object[key] = [...value, ...object[key]];
192
+ } else if (isObject(value) && isObject(object[key])) {
193
+ object[key] = _defu(
194
+ value,
195
+ object[key],
196
+ (namespace ? `${namespace}.` : "") + key.toString(),
197
+ merger
198
+ );
199
+ } else {
200
+ object[key] = value;
201
+ }
202
+ }
203
+ return object;
204
+ }
205
+ function createDefu(merger) {
206
+ return (...arguments_) => (
207
+ // eslint-disable-next-line unicorn/no-array-reduce
208
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
209
+ );
210
+ }
211
+ const defu = createDefu();
212
+
160
213
  function inspectProcessTailwindFeaturesReturnContext(content) {
161
214
  const ast = parse(content);
162
215
  let hasPatched = false;
@@ -294,65 +347,11 @@ function inspectPostcssPlugin(content) {
294
347
  };
295
348
  }
296
349
 
297
- function isObject(value) {
298
- return value !== null && typeof value === "object";
299
- }
300
- function _defu(baseObject, defaults, namespace = ".", merger) {
301
- if (!isObject(defaults)) {
302
- return _defu(baseObject, {}, namespace, merger);
303
- }
304
- const object = Object.assign({}, defaults);
305
- for (const key in baseObject) {
306
- if (key === "__proto__" || key === "constructor") {
307
- continue;
308
- }
309
- const value = baseObject[key];
310
- if (value === null || value === void 0) {
311
- continue;
312
- }
313
- if (merger && merger(object, key, value, namespace)) {
314
- continue;
315
- }
316
- if (Array.isArray(value) && Array.isArray(object[key])) {
317
- object[key] = [...value, ...object[key]];
318
- } else if (isObject(value) && isObject(object[key])) {
319
- object[key] = _defu(
320
- value,
321
- object[key],
322
- (namespace ? `${namespace}.` : "") + key.toString(),
323
- merger
324
- );
325
- } else {
326
- object[key] = value;
327
- }
328
- }
329
- return object;
330
- }
331
- function createDefu(merger) {
332
- return (...arguments_) => (
333
- // eslint-disable-next-line unicorn/no-array-reduce
334
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
335
- );
336
- }
337
- const defu = createDefu();
338
-
339
350
  function getDefaultPatchOptions() {
340
351
  return {
341
352
  overwrite: true
342
353
  };
343
354
  }
344
- function getDefaultUserConfig() {
345
- return {
346
- output: {
347
- filename: ".tw-patch/tw-class-list.json",
348
- removeUniversalSelector: true,
349
- loose: true
350
- },
351
- tailwindcss: {
352
- cwd: process.cwd()
353
- }
354
- };
355
- }
356
355
 
357
356
  function getInstalledPkgJsonPath(options = {}) {
358
357
  try {
@@ -427,17 +426,34 @@ function internalPatch(pkgJsonPath, options) {
427
426
  }
428
427
  }
429
428
 
429
+ const jiti = createJiti(__filename);
430
430
  async function processTailwindcss(options) {
431
431
  options.cwd = options.cwd ?? process.cwd();
432
- const config = options.config && path.isAbsolute(options.config) ? options.config : path.resolve(options.cwd, "tailwind.config.js");
433
- const res = await postcss([
432
+ let config = options.config;
433
+ if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
434
+ const moduleName = "tailwind";
435
+ const result = await lilconfig("tailwindcss", {
436
+ searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
437
+ loaders: {
438
+ // 默认支持 js 和 cjs 2种格式
439
+ ".js": jiti,
440
+ ".cjs": jiti,
441
+ ".ts": jiti,
442
+ ".mjs": jiti
443
+ }
444
+ }).search(options.cwd);
445
+ if (!result) {
446
+ throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
447
+ }
448
+ config = result.filepath;
449
+ }
450
+ return await postcss([
434
451
  require("tailwindcss")({
435
452
  config
436
453
  })
437
454
  ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
438
455
  from: void 0
439
456
  });
440
- return res;
441
457
  }
442
458
 
443
459
  class TailwindcssPatcher {
@@ -487,7 +503,7 @@ class TailwindcssPatcher {
487
503
  return getContexts(basedir);
488
504
  }
489
505
  async extract(options) {
490
- const { output, tailwindcss } = options;
506
+ const { output, tailwindcss } = options ?? {};
491
507
  if (output && tailwindcss) {
492
508
  const { removeUniversalSelector, filename, loose } = output;
493
509
  await processTailwindcss(tailwindcss);
@@ -504,95 +520,4 @@ class TailwindcssPatcher {
504
520
  }
505
521
  }
506
522
 
507
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
508
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
509
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
510
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
511
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
512
- const dedent = createDedent({});
513
- function createDedent(options) {
514
- dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
515
- return dedent;
516
- function dedent(strings, ...values) {
517
- const raw = typeof strings === "string" ? [strings] : strings.raw;
518
- const {
519
- escapeSpecialCharacters = Array.isArray(strings)
520
- } = options;
521
-
522
- // first, perform interpolation
523
- let result = "";
524
- for (let i = 0; i < raw.length; i++) {
525
- let next = raw[i];
526
- if (escapeSpecialCharacters) {
527
- // handle escaped newlines, backticks, and interpolation characters
528
- next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
529
- }
530
- result += next;
531
- if (i < values.length) {
532
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
533
- result += values[i];
534
- }
535
- }
536
-
537
- // now strip indentation
538
- const lines = result.split("\n");
539
- let mindent = null;
540
- for (const l of lines) {
541
- const m = l.match(/^(\s+)\S+/);
542
- if (m) {
543
- const indent = m[1].length;
544
- if (!mindent) {
545
- // this is the first indented line
546
- mindent = indent;
547
- } else {
548
- mindent = Math.min(mindent, indent);
549
- }
550
- }
551
- }
552
- if (mindent !== null) {
553
- const m = mindent; // appease TypeScript
554
- result = lines
555
- // https://github.com/typescript-eslint/typescript-eslint/issues/7140
556
- // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
557
- .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
558
- }
559
- return result
560
- // dedent eats leading and trailing whitespace too
561
- .trim()
562
- // handle escaped newlines at the end to ensure they don't get stripped too
563
- .replace(/\\n/g, "\n");
564
- }
565
- }
566
-
567
- function getConfig(cwd) {
568
- return loadConfig({
569
- name: "tailwindcss-patch",
570
- defaults: {
571
- ...getDefaultUserConfig()
572
- },
573
- cwd
574
- });
575
- }
576
- const defineConfig = createDefineConfig();
577
- function initConfig(cwd) {
578
- return fs$1.writeFile(
579
- path.resolve(cwd, "tailwindcss-patch.config.ts"),
580
- dedent`
581
- import { defineConfig } from 'tailwindcss-patch'
582
-
583
-
584
-
585
- // -- Unbuild CommonJS Shims --
586
- import __cjs_url__ from 'url';
587
- import __cjs_path__ from 'path';
588
- import __cjs_mod__ from 'module';
589
- const __filename = __cjs_url__.fileURLToPath(import.meta.url);
590
- const __dirname = __cjs_path__.dirname(__filename);
591
- const require = __cjs_mod__.createRequire(import.meta.url);
592
- export default defineConfig({})
593
- `,
594
- "utf8"
595
- );
596
- }
597
-
598
- export { CacheManager, TailwindcssPatcher, createPatch, defineConfig, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getConfig, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, initConfig, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
523
+ export { CacheManager, TailwindcssPatcher, createPatch, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "patch tailwindcss for exposing context and extract classes",
5
5
  "exports": {
6
6
  ".": {
@@ -57,15 +57,17 @@
57
57
  "tailwindcss": "^3.3.3"
58
58
  },
59
59
  "dependencies": {
60
- "@babel/generator": "^7.22.9",
61
- "@babel/parser": "^7.22.7",
62
- "@babel/traverse": "^7.22.8",
63
- "@babel/types": "^7.22.5",
64
- "c12": "^1.4.2",
60
+ "@babel/generator": "^7.22.10",
61
+ "@babel/parser": "^7.22.10",
62
+ "@babel/traverse": "^7.22.10",
63
+ "@babel/types": "^7.22.10",
65
64
  "cac": "^6.7.14",
65
+ "jiti": "^1.19.1",
66
+ "lilconfig": "^2.1.0",
66
67
  "postcss": "^8.4.27",
67
68
  "resolve": "^1.22.4",
68
- "semver": "^7.5.4"
69
+ "semver": "^7.5.4",
70
+ "@tailwindcss-mangle/config": "^1.0.1"
69
71
  },
70
72
  "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
71
73
  "repository": {