tailwindcss-patch 6.0.0 → 6.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.
@@ -52,22 +52,21 @@ var CacheManager = class {
52
52
  strategy: "merge"
53
53
  };
54
54
  }
55
- write(data) {
55
+ async write(data) {
56
56
  try {
57
- const { dir, filename } = this.options;
58
- fs.ensureDirSync(dir);
59
- fs.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
57
+ const { filename } = this.options;
58
+ await fs.outputJSON(filename, [...data]);
60
59
  return filename;
61
60
  } catch {
62
61
  logger_default.error("write cache file fail!");
63
62
  }
64
63
  }
65
- read() {
64
+ async read() {
66
65
  const { filename } = this.options;
67
66
  try {
68
- if (fs.existsSync(filename)) {
69
- const data = fs.readFileSync(filename, "utf8");
70
- return new Set(JSON.parse(data));
67
+ if (await fs.exists(filename)) {
68
+ const data = await fs.readJSON(filename);
69
+ return new Set(data);
71
70
  }
72
71
  } catch {
73
72
  logger_default.error(`parse cache content fail! path:${filename}`);
@@ -783,6 +782,9 @@ var TailwindcssPatcher = class {
783
782
  if (packageInfo.version) {
784
783
  this.majorVersion = Number.parseInt(packageInfo.version[0]);
785
784
  }
785
+ if (this.patchOptions.tailwindcss?.version) {
786
+ this.majorVersion = this.patchOptions.tailwindcss.version;
787
+ }
786
788
  this.packageInfo = packageInfo;
787
789
  this.patch = () => {
788
790
  try {
@@ -825,9 +827,9 @@ var TailwindcssPatcher = class {
825
827
  const contexts = this.getContexts();
826
828
  return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
827
829
  }
828
- async getClassCacheSet(options) {
830
+ async getClassCacheSet() {
829
831
  const classSet = /* @__PURE__ */ new Set();
830
- const { output, tailwindcss } = options ?? {};
832
+ const { output, tailwindcss } = this.patchOptions;
831
833
  if (this.majorVersion === 4) {
832
834
  const { v4 } = tailwindcss ?? {};
833
835
  if (Array.isArray(v4?.cssEntries)) {
@@ -888,17 +890,13 @@ var TailwindcssPatcher = class {
888
890
  /**
889
891
  * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
890
892
  */
891
- async getClassSet(options) {
892
- const { output, tailwindcss } = options ?? {};
893
+ async getClassSet() {
893
894
  const cacheStrategy = this.cacheOptions.strategy ?? "merge";
894
- const set = await this.getClassCacheSet({
895
- output,
896
- tailwindcss
897
- });
895
+ const set = await this.getClassCacheSet();
898
896
  if (cacheStrategy === "overwrite") {
899
897
  set.size > 0 && this.setCache(set);
900
898
  } else if (cacheStrategy === "merge") {
901
- const cacheSet = this.getCache();
899
+ const cacheSet = await this.getCache();
902
900
  if (cacheSet) {
903
901
  for (const x of cacheSet) {
904
902
  set.add(x);
@@ -918,10 +916,7 @@ var TailwindcssPatcher = class {
918
916
  majorVersion: this.majorVersion
919
917
  });
920
918
  }
921
- const set = await this.getClassSet({
922
- output,
923
- tailwindcss
924
- });
919
+ const set = await this.getClassSet();
925
920
  if (filename) {
926
921
  const classList = [...set];
927
922
  await fs4.outputJSON(filename, classList, {
@@ -56,22 +56,21 @@ var CacheManager = class {
56
56
  strategy: "merge"
57
57
  };
58
58
  }
59
- write(data) {
59
+ async write(data) {
60
60
  try {
61
- const { dir, filename } = this.options;
62
- _fsextra2.default.ensureDirSync(dir);
63
- _fsextra2.default.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
61
+ const { filename } = this.options;
62
+ await _fsextra2.default.outputJSON(filename, [...data]);
64
63
  return filename;
65
64
  } catch (e2) {
66
65
  logger_default.error("write cache file fail!");
67
66
  }
68
67
  }
69
- read() {
68
+ async read() {
70
69
  const { filename } = this.options;
71
70
  try {
72
- if (_fsextra2.default.existsSync(filename)) {
73
- const data = _fsextra2.default.readFileSync(filename, "utf8");
74
- return new Set(JSON.parse(data));
71
+ if (await _fsextra2.default.exists(filename)) {
72
+ const data = await _fsextra2.default.readJSON(filename);
73
+ return new Set(data);
75
74
  }
76
75
  } catch (e3) {
77
76
  logger_default.error(`parse cache content fail! path:${filename}`);
@@ -787,10 +786,13 @@ var TailwindcssPatcher = (_class = class {
787
786
  if (packageInfo.version) {
788
787
  this.majorVersion = Number.parseInt(packageInfo.version[0]);
789
788
  }
789
+ if (_optionalChain([this, 'access', _23 => _23.patchOptions, 'access', _24 => _24.tailwindcss, 'optionalAccess', _25 => _25.version])) {
790
+ this.majorVersion = this.patchOptions.tailwindcss.version;
791
+ }
790
792
  this.packageInfo = packageInfo;
791
793
  this.patch = () => {
792
794
  try {
793
- return internalPatch(_optionalChain([this, 'access', _23 => _23.packageInfo, 'optionalAccess', _24 => _24.packageJsonPath]), this.patchOptions);
795
+ return internalPatch(_optionalChain([this, 'access', _26 => _26.packageInfo, 'optionalAccess', _27 => _27.packageJsonPath]), this.patchOptions);
794
796
  } catch (error) {
795
797
  logger_default.error(`patch tailwindcss failed: ${error.message}`);
796
798
  }
@@ -829,12 +831,12 @@ var TailwindcssPatcher = (_class = class {
829
831
  const contexts = this.getContexts();
830
832
  return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
831
833
  }
832
- async getClassCacheSet(options) {
834
+ async getClassCacheSet() {
833
835
  const classSet = /* @__PURE__ */ new Set();
834
- const { output, tailwindcss } = _nullishCoalesce(options, () => ( {}));
836
+ const { output, tailwindcss } = this.patchOptions;
835
837
  if (this.majorVersion === 4) {
836
838
  const { v4 } = _nullishCoalesce(tailwindcss, () => ( {}));
837
- if (Array.isArray(_optionalChain([v4, 'optionalAccess', _25 => _25.cssEntries]))) {
839
+ if (Array.isArray(_optionalChain([v4, 'optionalAccess', _28 => _28.cssEntries]))) {
838
840
  const results = (await Promise.all(
839
841
  v4.cssEntries.map(async (x) => {
840
842
  if (await _fsextra2.default.exists(x)) {
@@ -846,11 +848,11 @@ var TailwindcssPatcher = (_class = class {
846
848
  )).filter((x) => x);
847
849
  for (const css of results) {
848
850
  const candidates = await extractValidCandidates({
849
- base: _optionalChain([v4, 'optionalAccess', _26 => _26.base]),
851
+ base: _optionalChain([v4, 'optionalAccess', _29 => _29.base]),
850
852
  css,
851
- sources: _optionalChain([v4, 'optionalAccess', _27 => _27.sources, 'optionalAccess', _28 => _28.map, 'call', _29 => _29((x) => {
853
+ sources: _optionalChain([v4, 'optionalAccess', _30 => _30.sources, 'optionalAccess', _31 => _31.map, 'call', _32 => _32((x) => {
852
854
  return {
853
- base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _30 => _30.base]))), () => ( _process2.default.cwd())),
855
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _33 => _33.base]))), () => ( _process2.default.cwd())),
854
856
  pattern: x.pattern
855
857
  };
856
858
  })])
@@ -861,11 +863,11 @@ var TailwindcssPatcher = (_class = class {
861
863
  }
862
864
  } else {
863
865
  const candidates = await extractValidCandidates({
864
- base: _optionalChain([v4, 'optionalAccess', _31 => _31.base]),
865
- css: _optionalChain([v4, 'optionalAccess', _32 => _32.css]),
866
- sources: _optionalChain([v4, 'optionalAccess', _33 => _33.sources, 'optionalAccess', _34 => _34.map, 'call', _35 => _35((x) => {
866
+ base: _optionalChain([v4, 'optionalAccess', _34 => _34.base]),
867
+ css: _optionalChain([v4, 'optionalAccess', _35 => _35.css]),
868
+ sources: _optionalChain([v4, 'optionalAccess', _36 => _36.sources, 'optionalAccess', _37 => _37.map, 'call', _38 => _38((x) => {
867
869
  return {
868
- base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _36 => _36.base]))), () => ( _process2.default.cwd())),
870
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _39 => _39.base]))), () => ( _process2.default.cwd())),
869
871
  pattern: x.pattern
870
872
  };
871
873
  })])
@@ -880,7 +882,7 @@ var TailwindcssPatcher = (_class = class {
880
882
  const keys = classCacheMap.keys();
881
883
  for (const key of keys) {
882
884
  const v = key.toString();
883
- if (_optionalChain([output, 'optionalAccess', _37 => _37.removeUniversalSelector]) && v === "*") {
885
+ if (_optionalChain([output, 'optionalAccess', _40 => _40.removeUniversalSelector]) && v === "*") {
884
886
  continue;
885
887
  }
886
888
  classSet.add(v);
@@ -892,17 +894,13 @@ var TailwindcssPatcher = (_class = class {
892
894
  /**
893
895
  * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
894
896
  */
895
- async getClassSet(options) {
896
- const { output, tailwindcss } = _nullishCoalesce(options, () => ( {}));
897
+ async getClassSet() {
897
898
  const cacheStrategy = _nullishCoalesce(this.cacheOptions.strategy, () => ( "merge"));
898
- const set = await this.getClassCacheSet({
899
- output,
900
- tailwindcss
901
- });
899
+ const set = await this.getClassCacheSet();
902
900
  if (cacheStrategy === "overwrite") {
903
901
  set.size > 0 && this.setCache(set);
904
902
  } else if (cacheStrategy === "merge") {
905
- const cacheSet = this.getCache();
903
+ const cacheSet = await this.getCache();
906
904
  if (cacheSet) {
907
905
  for (const x of cacheSet) {
908
906
  set.add(x);
@@ -922,10 +920,7 @@ var TailwindcssPatcher = (_class = class {
922
920
  majorVersion: this.majorVersion
923
921
  });
924
922
  }
925
- const set = await this.getClassSet({
926
- output,
927
- tailwindcss
928
- });
923
+ const set = await this.getClassSet();
929
924
  if (filename) {
930
925
  const classList = [...set];
931
926
  await _fsextra2.default.outputJSON(filename, classList, {
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkP7C42UCOjs = require('./chunk-P7C42UCO.js');
5
+ var _chunkS6WAH32Wjs = require('./chunk-S6WAH32W.js');
6
6
 
7
7
  // src/cli.ts
8
8
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
@@ -14,21 +14,21 @@ function init() {
14
14
  }
15
15
  var cli = _cac2.default.call(void 0, );
16
16
  cli.command("install", "patch install").action(() => {
17
- const twPatcher = new (0, _chunkP7C42UCOjs.TailwindcssPatcher)({
18
- patch: _chunkP7C42UCOjs.getPatchOptions.call(void 0, )
17
+ const twPatcher = new (0, _chunkS6WAH32Wjs.TailwindcssPatcher)({
18
+ patch: _chunkS6WAH32Wjs.getPatchOptions.call(void 0, )
19
19
  });
20
20
  twPatcher.patch();
21
21
  });
22
22
  cli.command("init").action(async () => {
23
23
  await init();
24
- _chunkP7C42UCOjs.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
24
+ _chunkS6WAH32Wjs.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
25
25
  });
26
26
  cli.command("extract").action(async () => {
27
27
  const { config } = await _config.getConfig.call(void 0, );
28
28
  if (config) {
29
- const twPatcher = new (0, _chunkP7C42UCOjs.TailwindcssPatcher)();
29
+ const twPatcher = new (0, _chunkS6WAH32Wjs.TailwindcssPatcher)();
30
30
  const p = await twPatcher.extract(config.patch);
31
- _chunkP7C42UCOjs.logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p}`);
31
+ _chunkS6WAH32Wjs.logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p}`);
32
32
  }
33
33
  });
34
34
  cli.help();
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  TailwindcssPatcher,
3
3
  getPatchOptions,
4
4
  logger_default
5
- } from "./chunk-AZHCF3SW.mjs";
5
+ } from "./chunk-NHBD2ICP.mjs";
6
6
 
7
7
  // src/cli.ts
8
8
  import process from "node:process";
package/dist/index.d.mts CHANGED
@@ -1,16 +1,19 @@
1
+ import { PatchUserConfig } from '@tailwindcss-mangle/config';
2
+ export { TailwindcssUserConfig, defineConfig } from '@tailwindcss-mangle/config';
3
+ import { PackageJson } from 'pkg-types';
1
4
  import { Node, Rule } from 'postcss';
2
5
  import { Config } from 'tailwindcss';
3
- import { PatchUserConfig } from '@tailwindcss-mangle/config';
4
- export { defineConfig } from '@tailwindcss-mangle/config';
5
6
  import { GlobEntry } from '@tailwindcss/oxide';
6
7
  import * as consola from 'consola';
7
8
 
8
9
  type CacheStrategy = 'merge' | 'overwrite';
10
+
9
11
  interface PackageInfo {
10
12
  name: string;
11
13
  version: string | undefined;
12
14
  rootPath: string;
13
15
  packageJsonPath: string;
16
+ packageJson: PackageJson;
14
17
  }
15
18
  interface CacheOptions {
16
19
  dir?: string;
@@ -21,7 +24,7 @@ interface CacheOptions {
21
24
  interface InternalCacheOptions extends CacheOptions {
22
25
  enable?: boolean;
23
26
  }
24
- interface PatchOptions {
27
+ interface PatchOptions extends PatchUserConfig {
25
28
  overwrite?: boolean;
26
29
  paths?: string[];
27
30
  basedir?: string;
@@ -100,8 +103,8 @@ declare class CacheManager {
100
103
  getOptions(options?: CacheOptions): Required<CacheOptions> & {
101
104
  filename: string;
102
105
  };
103
- write(data: Set<string>): string | undefined;
104
- read(): Set<string> | undefined;
106
+ write(data: Set<string>): Promise<string | undefined>;
107
+ read(): Promise<Set<string> | undefined>;
105
108
  }
106
109
 
107
110
  interface ExtractValidCandidatesOption {
@@ -120,15 +123,15 @@ declare class TailwindcssPatcher {
120
123
  packageInfo: PackageInfo;
121
124
  majorVersion?: number;
122
125
  constructor(options?: TailwindcssPatcherOptions);
123
- setCache(set: Set<string>): string | undefined;
124
- getCache(): Set<string> | undefined;
126
+ setCache(set: Set<string>): Promise<string | undefined> | undefined;
127
+ getCache(): Promise<Set<string> | undefined>;
125
128
  getContexts(): TailwindcssRuntimeContext[];
126
129
  getClassCaches(): TailwindcssClassCache[];
127
- getClassCacheSet(options?: PatchUserConfig): Promise<Set<string>>;
130
+ getClassCacheSet(): Promise<Set<string>>;
128
131
  /**
129
132
  * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
130
133
  */
131
- getClassSet(options?: PatchUserConfig): Promise<Set<string>>;
134
+ getClassSet(): Promise<Set<string>>;
132
135
  extract(options?: PatchUserConfig): Promise<string | undefined>;
133
136
  extractValidCandidates: typeof extractValidCandidates;
134
137
  }
package/dist/index.d.ts CHANGED
@@ -1,16 +1,19 @@
1
+ import { PatchUserConfig } from '@tailwindcss-mangle/config';
2
+ export { TailwindcssUserConfig, defineConfig } from '@tailwindcss-mangle/config';
3
+ import { PackageJson } from 'pkg-types';
1
4
  import { Node, Rule } from 'postcss';
2
5
  import { Config } from 'tailwindcss';
3
- import { PatchUserConfig } from '@tailwindcss-mangle/config';
4
- export { defineConfig } from '@tailwindcss-mangle/config';
5
6
  import { GlobEntry } from '@tailwindcss/oxide';
6
7
  import * as consola from 'consola';
7
8
 
8
9
  type CacheStrategy = 'merge' | 'overwrite';
10
+
9
11
  interface PackageInfo {
10
12
  name: string;
11
13
  version: string | undefined;
12
14
  rootPath: string;
13
15
  packageJsonPath: string;
16
+ packageJson: PackageJson;
14
17
  }
15
18
  interface CacheOptions {
16
19
  dir?: string;
@@ -21,7 +24,7 @@ interface CacheOptions {
21
24
  interface InternalCacheOptions extends CacheOptions {
22
25
  enable?: boolean;
23
26
  }
24
- interface PatchOptions {
27
+ interface PatchOptions extends PatchUserConfig {
25
28
  overwrite?: boolean;
26
29
  paths?: string[];
27
30
  basedir?: string;
@@ -100,8 +103,8 @@ declare class CacheManager {
100
103
  getOptions(options?: CacheOptions): Required<CacheOptions> & {
101
104
  filename: string;
102
105
  };
103
- write(data: Set<string>): string | undefined;
104
- read(): Set<string> | undefined;
106
+ write(data: Set<string>): Promise<string | undefined>;
107
+ read(): Promise<Set<string> | undefined>;
105
108
  }
106
109
 
107
110
  interface ExtractValidCandidatesOption {
@@ -120,15 +123,15 @@ declare class TailwindcssPatcher {
120
123
  packageInfo: PackageInfo;
121
124
  majorVersion?: number;
122
125
  constructor(options?: TailwindcssPatcherOptions);
123
- setCache(set: Set<string>): string | undefined;
124
- getCache(): Set<string> | undefined;
126
+ setCache(set: Set<string>): Promise<string | undefined> | undefined;
127
+ getCache(): Promise<Set<string> | undefined>;
125
128
  getContexts(): TailwindcssRuntimeContext[];
126
129
  getClassCaches(): TailwindcssClassCache[];
127
- getClassCacheSet(options?: PatchUserConfig): Promise<Set<string>>;
130
+ getClassCacheSet(): Promise<Set<string>>;
128
131
  /**
129
132
  * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
130
133
  */
131
- getClassSet(options?: PatchUserConfig): Promise<Set<string>>;
134
+ getClassSet(): Promise<Set<string>>;
132
135
  extract(options?: PatchUserConfig): Promise<string | undefined>;
133
136
  extractValidCandidates: typeof extractValidCandidates;
134
137
  }
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkP7C42UCOjs = require('./chunk-P7C42UCO.js');
10
+ var _chunkS6WAH32Wjs = require('./chunk-S6WAH32W.js');
11
11
 
12
12
  // src/index.ts
13
13
  var _config = require('@tailwindcss-mangle/config');
@@ -21,4 +21,4 @@ var _config = require('@tailwindcss-mangle/config');
21
21
 
22
22
 
23
23
 
24
- exports.CacheManager = _chunkP7C42UCOjs.CacheManager; exports.TailwindcssPatcher = _chunkP7C42UCOjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunkP7C42UCOjs.getCacheOptions; exports.internalPatch = _chunkP7C42UCOjs.internalPatch; exports.logger = _chunkP7C42UCOjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunkP7C42UCOjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunkP7C42UCOjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnit = _chunkP7C42UCOjs.monkeyPatchForSupportingCustomUnit;
24
+ exports.CacheManager = _chunkS6WAH32Wjs.CacheManager; exports.TailwindcssPatcher = _chunkS6WAH32Wjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunkS6WAH32Wjs.getCacheOptions; exports.internalPatch = _chunkS6WAH32Wjs.internalPatch; exports.logger = _chunkS6WAH32Wjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunkS6WAH32Wjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunkS6WAH32Wjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnit = _chunkS6WAH32Wjs.monkeyPatchForSupportingCustomUnit;
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  monkeyPatchForExposingContextV2,
8
8
  monkeyPatchForExposingContextV3,
9
9
  monkeyPatchForSupportingCustomUnit
10
- } from "./chunk-AZHCF3SW.mjs";
10
+ } from "./chunk-NHBD2ICP.mjs";
11
11
 
12
12
  // src/index.ts
13
13
  import { defineConfig } from "@tailwindcss-mangle/config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "patch tailwindcss for exposing context and extract classes",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "postcss": "^8.5.2",
63
63
  "semver": "^7.7.1",
64
64
  "tailwindcss-config": "^1.0.0",
65
- "@tailwindcss-mangle/config": "^5.0.0"
65
+ "@tailwindcss-mangle/config": "^5.0.1"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@tailwindcss/node": "^4.0.6",