tailwindcss-patch 3.1.0-alpha.1 → 4.0.0-alpha.0
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/README.md +0 -24
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -5
- package/dist/index.d.cts +10 -29
- package/dist/index.d.mts +10 -29
- package/dist/index.d.ts +10 -29
- package/dist/index.mjs +1 -1
- package/dist/shared/{tailwindcss-patch.ec6deb5e.mjs → tailwindcss-patch.324d67e5.mjs} +119 -117
- package/dist/shared/{tailwindcss-patch.27719efb.cjs → tailwindcss-patch.3f156bec.cjs} +118 -120
- package/package.json +11 -24
package/README.md
CHANGED
|
@@ -12,9 +12,6 @@ get tailwindcss context at runtime ! extract all classes into file!
|
|
|
12
12
|
- [Nodejs API](#nodejs-api)
|
|
13
13
|
- [Config](#config)
|
|
14
14
|
- [Init Config File](#init-config-file)
|
|
15
|
-
- [Migration form v1 to v2](#migration-form-v1-to-v2)
|
|
16
|
-
- [0. cli command change](#0-cli-command-change)
|
|
17
|
-
- [1. default remove `*` in json array result](#1-default-remove--in-json-array-result)
|
|
18
15
|
- [What's next?](#whats-next)
|
|
19
16
|
|
|
20
17
|
> Nodejs version should >= `16.6.0`
|
|
@@ -112,27 +109,6 @@ export default defineConfig({
|
|
|
112
109
|
})
|
|
113
110
|
```
|
|
114
111
|
|
|
115
|
-
## Migration form v1 to v2
|
|
116
|
-
|
|
117
|
-
### 0. cli command change
|
|
118
|
-
|
|
119
|
-
```diff
|
|
120
|
-
{
|
|
121
|
-
- "tw-patch"
|
|
122
|
-
+ "tw-patch install"
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### 1. default remove `*` in json array result
|
|
127
|
-
|
|
128
|
-
```diff
|
|
129
|
-
[
|
|
130
|
-
- "*",
|
|
131
|
-
"text-[99px]",
|
|
132
|
-
"text-[100px]"
|
|
133
|
-
]
|
|
134
|
-
```
|
|
135
|
-
|
|
136
112
|
## What's next?
|
|
137
113
|
|
|
138
114
|
At the moment I just extracted all the tool classes to actually get the context of `tailwindcss` to analyze. You can add more functionality to this project by giving me `issue` or `pr`.
|
package/dist/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const process = require('node:process');
|
|
4
4
|
const cac = require('cac');
|
|
5
5
|
const config = require('@tailwindcss-mangle/config');
|
|
6
|
-
const index = require('./shared/tailwindcss-patch.
|
|
6
|
+
const index = require('./shared/tailwindcss-patch.3f156bec.cjs');
|
|
7
7
|
require('node:path');
|
|
8
8
|
require('fs-extra');
|
|
9
9
|
require('@babel/types');
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
|
|
4
|
-
import { T as TailwindcssPatcher, g as getPatchOptions, l as logger } from './shared/tailwindcss-patch.
|
|
4
|
+
import { T as TailwindcssPatcher, g as getPatchOptions, l as logger } from './shared/tailwindcss-patch.324d67e5.mjs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'fs-extra';
|
|
7
7
|
import '@babel/types';
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const index = require('./shared/tailwindcss-patch.
|
|
3
|
+
const index = require('./shared/tailwindcss-patch.3f156bec.cjs');
|
|
4
4
|
const config = require('@tailwindcss-mangle/config');
|
|
5
5
|
require('node:path');
|
|
6
6
|
require('fs-extra');
|
|
@@ -20,14 +20,10 @@ require('jiti');
|
|
|
20
20
|
|
|
21
21
|
exports.CacheManager = index.CacheManager;
|
|
22
22
|
exports.TailwindcssPatcher = index.TailwindcssPatcher;
|
|
23
|
-
exports.ensureFileContent = index.ensureFileContent;
|
|
24
23
|
exports.getCacheOptions = index.getCacheOptions;
|
|
25
|
-
exports.getPackageInfoSync = index.getPackageInfoSync;
|
|
26
24
|
exports.internalPatch = index.internalPatch;
|
|
27
|
-
exports.isObject = index.isObject;
|
|
28
25
|
exports.logger = index.logger;
|
|
29
26
|
exports.monkeyPatchForExposingContextV2 = index.monkeyPatchForExposingContextV2;
|
|
30
27
|
exports.monkeyPatchForExposingContextV3 = index.monkeyPatchForExposingContextV3;
|
|
31
28
|
exports.monkeyPatchForSupportingCustomUnit = index.monkeyPatchForSupportingCustomUnit;
|
|
32
|
-
exports.requireResolve = index.requireResolve;
|
|
33
29
|
exports.defineConfig = config.defineConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,8 +2,6 @@ import { Rule, Node } from 'postcss';
|
|
|
2
2
|
import { Config } from 'tailwindcss';
|
|
3
3
|
import { UserConfig } from '@tailwindcss-mangle/config';
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
|
-
import { SyncOpts } from 'resolve';
|
|
6
|
-
import { PackageJson } from 'pkg-types';
|
|
7
5
|
import * as consola from 'consola';
|
|
8
6
|
|
|
9
7
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
@@ -19,17 +17,16 @@ interface CacheOptions {
|
|
|
19
17
|
file?: string;
|
|
20
18
|
strategy?: CacheStrategy;
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
interface InternalCacheOptions extends CacheOptions {
|
|
23
21
|
enable?: boolean;
|
|
24
|
-
}
|
|
22
|
+
}
|
|
25
23
|
interface PatchOptions {
|
|
26
24
|
overwrite?: boolean;
|
|
27
25
|
paths?: string[];
|
|
28
26
|
basedir?: string;
|
|
29
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
27
|
applyPatches?: {
|
|
31
28
|
exportContext?: boolean;
|
|
32
|
-
extendLengthUnits?: boolean;
|
|
29
|
+
extendLengthUnits?: boolean | ILengthUnitsPatchOptions;
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
interface InternalPatchOptions extends PatchOptions {
|
|
@@ -99,7 +96,6 @@ declare class CacheManager {
|
|
|
99
96
|
filename: string;
|
|
100
97
|
};
|
|
101
98
|
constructor(options?: CacheOptions);
|
|
102
|
-
mkdir(cacheDirectory: string): string;
|
|
103
99
|
getOptions(options?: CacheOptions): Required<CacheOptions> & {
|
|
104
100
|
filename: string;
|
|
105
101
|
};
|
|
@@ -133,30 +129,15 @@ declare class TailwindcssPatcher {
|
|
|
133
129
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions):
|
|
137
|
-
|
|
138
|
-
plugin?: string;
|
|
139
|
-
} & Record<string, any>;
|
|
140
|
-
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): {
|
|
141
|
-
processTailwindFeatures?: string;
|
|
142
|
-
plugin?: string;
|
|
143
|
-
} & Record<string, any>;
|
|
144
|
-
|
|
145
|
-
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
132
|
+
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined;
|
|
133
|
+
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>;
|
|
146
134
|
|
|
147
|
-
declare function
|
|
148
|
-
|
|
149
|
-
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
150
|
-
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
151
|
-
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
152
|
-
name: string;
|
|
153
|
-
version: string | undefined;
|
|
154
|
-
rootPath: string;
|
|
155
|
-
packageJsonPath: string;
|
|
156
|
-
packageJson: PackageJson;
|
|
135
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
|
|
136
|
+
[x: string]: string;
|
|
157
137
|
} | undefined;
|
|
158
|
-
|
|
138
|
+
|
|
139
|
+
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
|
|
159
140
|
|
|
160
141
|
declare const logger: consola.ConsolaInstance;
|
|
161
142
|
|
|
162
|
-
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext,
|
|
143
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,6 @@ import { Rule, Node } from 'postcss';
|
|
|
2
2
|
import { Config } from 'tailwindcss';
|
|
3
3
|
import { UserConfig } from '@tailwindcss-mangle/config';
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
|
-
import { SyncOpts } from 'resolve';
|
|
6
|
-
import { PackageJson } from 'pkg-types';
|
|
7
5
|
import * as consola from 'consola';
|
|
8
6
|
|
|
9
7
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
@@ -19,17 +17,16 @@ interface CacheOptions {
|
|
|
19
17
|
file?: string;
|
|
20
18
|
strategy?: CacheStrategy;
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
interface InternalCacheOptions extends CacheOptions {
|
|
23
21
|
enable?: boolean;
|
|
24
|
-
}
|
|
22
|
+
}
|
|
25
23
|
interface PatchOptions {
|
|
26
24
|
overwrite?: boolean;
|
|
27
25
|
paths?: string[];
|
|
28
26
|
basedir?: string;
|
|
29
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
27
|
applyPatches?: {
|
|
31
28
|
exportContext?: boolean;
|
|
32
|
-
extendLengthUnits?: boolean;
|
|
29
|
+
extendLengthUnits?: boolean | ILengthUnitsPatchOptions;
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
interface InternalPatchOptions extends PatchOptions {
|
|
@@ -99,7 +96,6 @@ declare class CacheManager {
|
|
|
99
96
|
filename: string;
|
|
100
97
|
};
|
|
101
98
|
constructor(options?: CacheOptions);
|
|
102
|
-
mkdir(cacheDirectory: string): string;
|
|
103
99
|
getOptions(options?: CacheOptions): Required<CacheOptions> & {
|
|
104
100
|
filename: string;
|
|
105
101
|
};
|
|
@@ -133,30 +129,15 @@ declare class TailwindcssPatcher {
|
|
|
133
129
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions):
|
|
137
|
-
|
|
138
|
-
plugin?: string;
|
|
139
|
-
} & Record<string, any>;
|
|
140
|
-
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): {
|
|
141
|
-
processTailwindFeatures?: string;
|
|
142
|
-
plugin?: string;
|
|
143
|
-
} & Record<string, any>;
|
|
144
|
-
|
|
145
|
-
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
132
|
+
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined;
|
|
133
|
+
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>;
|
|
146
134
|
|
|
147
|
-
declare function
|
|
148
|
-
|
|
149
|
-
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
150
|
-
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
151
|
-
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
152
|
-
name: string;
|
|
153
|
-
version: string | undefined;
|
|
154
|
-
rootPath: string;
|
|
155
|
-
packageJsonPath: string;
|
|
156
|
-
packageJson: PackageJson;
|
|
135
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
|
|
136
|
+
[x: string]: string;
|
|
157
137
|
} | undefined;
|
|
158
|
-
|
|
138
|
+
|
|
139
|
+
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
|
|
159
140
|
|
|
160
141
|
declare const logger: consola.ConsolaInstance;
|
|
161
142
|
|
|
162
|
-
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext,
|
|
143
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { Rule, Node } from 'postcss';
|
|
|
2
2
|
import { Config } from 'tailwindcss';
|
|
3
3
|
import { UserConfig } from '@tailwindcss-mangle/config';
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
|
-
import { SyncOpts } from 'resolve';
|
|
6
|
-
import { PackageJson } from 'pkg-types';
|
|
7
5
|
import * as consola from 'consola';
|
|
8
6
|
|
|
9
7
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
@@ -19,17 +17,16 @@ interface CacheOptions {
|
|
|
19
17
|
file?: string;
|
|
20
18
|
strategy?: CacheStrategy;
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
interface InternalCacheOptions extends CacheOptions {
|
|
23
21
|
enable?: boolean;
|
|
24
|
-
}
|
|
22
|
+
}
|
|
25
23
|
interface PatchOptions {
|
|
26
24
|
overwrite?: boolean;
|
|
27
25
|
paths?: string[];
|
|
28
26
|
basedir?: string;
|
|
29
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
27
|
applyPatches?: {
|
|
31
28
|
exportContext?: boolean;
|
|
32
|
-
extendLengthUnits?: boolean;
|
|
29
|
+
extendLengthUnits?: boolean | ILengthUnitsPatchOptions;
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
interface InternalPatchOptions extends PatchOptions {
|
|
@@ -99,7 +96,6 @@ declare class CacheManager {
|
|
|
99
96
|
filename: string;
|
|
100
97
|
};
|
|
101
98
|
constructor(options?: CacheOptions);
|
|
102
|
-
mkdir(cacheDirectory: string): string;
|
|
103
99
|
getOptions(options?: CacheOptions): Required<CacheOptions> & {
|
|
104
100
|
filename: string;
|
|
105
101
|
};
|
|
@@ -133,30 +129,15 @@ declare class TailwindcssPatcher {
|
|
|
133
129
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions):
|
|
137
|
-
|
|
138
|
-
plugin?: string;
|
|
139
|
-
} & Record<string, any>;
|
|
140
|
-
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): {
|
|
141
|
-
processTailwindFeatures?: string;
|
|
142
|
-
plugin?: string;
|
|
143
|
-
} & Record<string, any>;
|
|
144
|
-
|
|
145
|
-
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
132
|
+
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined;
|
|
133
|
+
declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>;
|
|
146
134
|
|
|
147
|
-
declare function
|
|
148
|
-
|
|
149
|
-
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
150
|
-
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
151
|
-
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
152
|
-
name: string;
|
|
153
|
-
version: string | undefined;
|
|
154
|
-
rootPath: string;
|
|
155
|
-
packageJsonPath: string;
|
|
156
|
-
packageJson: PackageJson;
|
|
135
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
|
|
136
|
+
[x: string]: string;
|
|
157
137
|
} | undefined;
|
|
158
|
-
|
|
138
|
+
|
|
139
|
+
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
|
|
159
140
|
|
|
160
141
|
declare const logger: consola.ConsolaInstance;
|
|
161
142
|
|
|
162
|
-
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext,
|
|
143
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CacheManager, T as TailwindcssPatcher,
|
|
1
|
+
export { C as CacheManager, T as TailwindcssPatcher, c as getCacheOptions, i as internalPatch, l as logger, a as monkeyPatchForExposingContextV2, m as monkeyPatchForExposingContextV3, b as monkeyPatchForSupportingCustomUnit } from './shared/tailwindcss-patch.324d67e5.mjs';
|
|
2
2
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
3
3
|
import 'node:path';
|
|
4
4
|
import 'fs-extra';
|
|
@@ -59,15 +59,6 @@ class CacheManager {
|
|
|
59
59
|
__publicField$1(this, "options");
|
|
60
60
|
this.options = this.getOptions(options);
|
|
61
61
|
}
|
|
62
|
-
mkdir(cacheDirectory) {
|
|
63
|
-
const exists = fs.existsSync(cacheDirectory);
|
|
64
|
-
if (!exists) {
|
|
65
|
-
fs.mkdirSync(cacheDirectory, {
|
|
66
|
-
recursive: true
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return cacheDirectory;
|
|
70
|
-
}
|
|
71
62
|
getOptions(options = {}) {
|
|
72
63
|
const cwd = options.cwd ?? process.cwd();
|
|
73
64
|
const dir = options.dir ?? path.resolve(cwd, "node_modules/.cache", pkgName);
|
|
@@ -84,8 +75,8 @@ class CacheManager {
|
|
|
84
75
|
write(data) {
|
|
85
76
|
try {
|
|
86
77
|
const { dir, filename } = this.options;
|
|
87
|
-
|
|
88
|
-
fs.
|
|
78
|
+
fs.ensureDirSync(dir);
|
|
79
|
+
fs.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
89
80
|
return filename;
|
|
90
81
|
} catch {
|
|
91
82
|
logger.error("write cache file fail!");
|
|
@@ -385,74 +376,10 @@ function inspectPostcssPlugin(content) {
|
|
|
385
376
|
};
|
|
386
377
|
}
|
|
387
378
|
|
|
388
|
-
const { sync } = pkg;
|
|
389
|
-
function ensureFileContent(filepaths) {
|
|
390
|
-
if (typeof filepaths === "string") {
|
|
391
|
-
filepaths = [filepaths];
|
|
392
|
-
}
|
|
393
|
-
let content;
|
|
394
|
-
for (const filepath of filepaths) {
|
|
395
|
-
if (fs.existsSync(filepath)) {
|
|
396
|
-
content = fs.readFileSync(filepath, {
|
|
397
|
-
encoding: "utf8"
|
|
398
|
-
});
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return content;
|
|
403
|
-
}
|
|
404
|
-
function requireResolve(id, opts) {
|
|
405
|
-
return sync(id, opts);
|
|
406
|
-
}
|
|
407
|
-
function searchPackageJSON(dir) {
|
|
408
|
-
let packageJsonPath;
|
|
409
|
-
while (true) {
|
|
410
|
-
if (!dir) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
const newDir = path.dirname(dir);
|
|
414
|
-
if (newDir === dir) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
dir = newDir;
|
|
418
|
-
packageJsonPath = path.join(dir, "package.json");
|
|
419
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
420
|
-
break;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return packageJsonPath;
|
|
424
|
-
}
|
|
425
|
-
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
426
|
-
return requireResolve(name, opts);
|
|
427
|
-
}
|
|
428
|
-
function getPackageJsonPath(name, options = {}) {
|
|
429
|
-
const entry = getTailwindcssEntry(name, options);
|
|
430
|
-
if (!entry) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
return searchPackageJSON(entry);
|
|
434
|
-
}
|
|
435
|
-
function getPackageInfoSync(name, options = {}) {
|
|
436
|
-
const packageJsonPath = getPackageJsonPath(name, options);
|
|
437
|
-
if (!packageJsonPath) {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
441
|
-
return {
|
|
442
|
-
name,
|
|
443
|
-
version: packageJson.version,
|
|
444
|
-
rootPath: path.dirname(packageJsonPath),
|
|
445
|
-
packageJsonPath,
|
|
446
|
-
packageJson
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
function isObject(val) {
|
|
450
|
-
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
379
|
function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
454
|
-
const
|
|
455
|
-
const
|
|
380
|
+
const k0 = "lib/processTailwindFeatures.js";
|
|
381
|
+
const processTailwindFeaturesFilePath = path.resolve(twDir, k0);
|
|
382
|
+
const processTailwindFeaturesContent = fs.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
456
383
|
const result = {};
|
|
457
384
|
if (processTailwindFeaturesContent) {
|
|
458
385
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext$1(processTailwindFeaturesContent);
|
|
@@ -462,27 +389,40 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
462
389
|
});
|
|
463
390
|
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
464
391
|
}
|
|
465
|
-
result
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
392
|
+
result[k0] = code;
|
|
393
|
+
}
|
|
394
|
+
let injectFilepath;
|
|
395
|
+
let k1;
|
|
396
|
+
const try0 = "lib/plugin.js";
|
|
397
|
+
const try1 = "lib/index.js";
|
|
398
|
+
const pluginFilePath = path.resolve(twDir, try0);
|
|
399
|
+
const indexFilePath = path.resolve(twDir, try1);
|
|
400
|
+
if (fs.existsSync(pluginFilePath)) {
|
|
401
|
+
k1 = try0;
|
|
402
|
+
injectFilepath = pluginFilePath;
|
|
403
|
+
} else if (fs.existsSync(indexFilePath)) {
|
|
404
|
+
k1 = try1;
|
|
405
|
+
injectFilepath = indexFilePath;
|
|
406
|
+
}
|
|
407
|
+
if (injectFilepath && k1) {
|
|
408
|
+
const pluginContent = fs.readFileSync(injectFilepath, "utf8");
|
|
409
|
+
if (pluginContent) {
|
|
410
|
+
const { code, hasPatched } = inspectPostcssPlugin$1(pluginContent);
|
|
411
|
+
if (!hasPatched && opt.overwrite) {
|
|
412
|
+
fs.writeFileSync(injectFilepath, code, {
|
|
413
|
+
encoding: "utf8"
|
|
414
|
+
});
|
|
415
|
+
logger.success("patch tailwindcss for expose runtime context successfully!");
|
|
416
|
+
}
|
|
417
|
+
result[k1] = code;
|
|
477
418
|
}
|
|
478
|
-
result
|
|
419
|
+
return result;
|
|
479
420
|
}
|
|
480
|
-
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
481
|
-
return result;
|
|
482
421
|
}
|
|
483
422
|
function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
484
|
-
const
|
|
485
|
-
const
|
|
423
|
+
const k0 = "lib/jit/processTailwindFeatures.js";
|
|
424
|
+
const processTailwindFeaturesFilePath = path.resolve(twDir, k0);
|
|
425
|
+
const processTailwindFeaturesContent = fs.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
486
426
|
const result = {};
|
|
487
427
|
if (processTailwindFeaturesContent) {
|
|
488
428
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
@@ -492,10 +432,11 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
492
432
|
});
|
|
493
433
|
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
494
434
|
}
|
|
495
|
-
result
|
|
435
|
+
result[k0] = code;
|
|
496
436
|
}
|
|
497
|
-
const
|
|
498
|
-
const
|
|
437
|
+
const k1 = "lib/jit/index.js";
|
|
438
|
+
const indexFilePath = path.resolve(twDir, k1);
|
|
439
|
+
const pluginContent = fs.readFileSync(indexFilePath, "utf8");
|
|
499
440
|
if (pluginContent) {
|
|
500
441
|
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
501
442
|
if (!hasPatched && opt.overwrite) {
|
|
@@ -504,9 +445,8 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
504
445
|
});
|
|
505
446
|
logger.success("patch tailwindcss for expose runtime content successfully!");
|
|
506
447
|
}
|
|
507
|
-
result
|
|
448
|
+
result[k1] = code;
|
|
508
449
|
}
|
|
509
|
-
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
510
450
|
return result;
|
|
511
451
|
}
|
|
512
452
|
|
|
@@ -566,6 +506,62 @@ function createDefu(merger) {
|
|
|
566
506
|
}
|
|
567
507
|
const defu = createDefu();
|
|
568
508
|
|
|
509
|
+
const { sync } = pkg;
|
|
510
|
+
const defuOverrideArray = createDefu((obj, key, value) => {
|
|
511
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
512
|
+
obj[key] = value;
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
function requireResolve(id, opts) {
|
|
517
|
+
return sync(id, opts);
|
|
518
|
+
}
|
|
519
|
+
function searchPackageJSON(dir) {
|
|
520
|
+
let packageJsonPath;
|
|
521
|
+
while (true) {
|
|
522
|
+
if (!dir) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const newDir = path.dirname(dir);
|
|
526
|
+
if (newDir === dir) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
dir = newDir;
|
|
530
|
+
packageJsonPath = path.join(dir, "package.json");
|
|
531
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return packageJsonPath;
|
|
536
|
+
}
|
|
537
|
+
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
538
|
+
return requireResolve(name, opts);
|
|
539
|
+
}
|
|
540
|
+
function getPackageJsonPath(name, options = {}) {
|
|
541
|
+
const entry = getTailwindcssEntry(name, options);
|
|
542
|
+
if (!entry) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
return searchPackageJSON(entry);
|
|
546
|
+
}
|
|
547
|
+
function getPackageInfoSync(name, options = {}) {
|
|
548
|
+
const packageJsonPath = getPackageJsonPath(name, options);
|
|
549
|
+
if (!packageJsonPath) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
553
|
+
return {
|
|
554
|
+
name,
|
|
555
|
+
version: packageJson.version,
|
|
556
|
+
rootPath: path.dirname(packageJsonPath),
|
|
557
|
+
packageJsonPath,
|
|
558
|
+
packageJson
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function isObject(val) {
|
|
562
|
+
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
563
|
+
}
|
|
564
|
+
|
|
569
565
|
function findAstNode(content, options) {
|
|
570
566
|
const { variableName, units } = options;
|
|
571
567
|
const ast = parse(content);
|
|
@@ -604,7 +600,7 @@ function findAstNode(content, options) {
|
|
|
604
600
|
};
|
|
605
601
|
}
|
|
606
602
|
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
607
|
-
const opts =
|
|
603
|
+
const opts = defuOverrideArray(options, {
|
|
608
604
|
units: ["rpx"],
|
|
609
605
|
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
610
606
|
variableName: "lengthUnits",
|
|
@@ -633,7 +629,9 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
|
633
629
|
logger.success("patch tailwindcss for custom length unit successfully!");
|
|
634
630
|
}
|
|
635
631
|
}
|
|
636
|
-
return
|
|
632
|
+
return {
|
|
633
|
+
[opts.lengthUnitsFilePath]: code
|
|
634
|
+
};
|
|
637
635
|
}
|
|
638
636
|
}
|
|
639
637
|
|
|
@@ -641,21 +639,22 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
641
639
|
if (pkgJsonPath) {
|
|
642
640
|
const pkgJson = require(pkgJsonPath);
|
|
643
641
|
const twDir = path.dirname(pkgJsonPath);
|
|
642
|
+
options.version = pkgJson.version;
|
|
644
643
|
if (gte(pkgJson.version, "3.0.0")) {
|
|
645
|
-
|
|
644
|
+
let result = {};
|
|
645
|
+
if (options.applyPatches?.exportContext) {
|
|
646
|
+
result = monkeyPatchForExposingContextV3(twDir, options);
|
|
647
|
+
}
|
|
646
648
|
if (options.applyPatches?.extendLengthUnits) {
|
|
647
649
|
try {
|
|
648
|
-
monkeyPatchForSupportingCustomUnit(twDir, {
|
|
650
|
+
Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
|
|
649
651
|
overwrite: options.overwrite
|
|
650
|
-
});
|
|
652
|
+
})));
|
|
651
653
|
} catch {
|
|
652
654
|
}
|
|
653
655
|
}
|
|
654
|
-
|
|
655
|
-
return monkeyPatchForExposingContextV3(twDir, options);
|
|
656
|
-
}
|
|
656
|
+
return result;
|
|
657
657
|
} else if (gte(pkgJson.version, "2.0.0")) {
|
|
658
|
-
options.version = pkgJson.version;
|
|
659
658
|
if (options.applyPatches?.exportContext) {
|
|
660
659
|
return monkeyPatchForExposingContextV2(twDir, options);
|
|
661
660
|
}
|
|
@@ -664,10 +663,13 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
664
663
|
}
|
|
665
664
|
|
|
666
665
|
const jiti = createJiti(__filename);
|
|
666
|
+
|
|
667
667
|
async function processTailwindcss(options) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
668
|
+
const { config: userConfig, cwd } = defu(options, {
|
|
669
|
+
cwd: process.cwd()
|
|
670
|
+
});
|
|
671
|
+
let config = userConfig;
|
|
672
|
+
if (!(typeof config === "string" && path.isAbsolute(config))) {
|
|
671
673
|
const moduleName = "tailwind";
|
|
672
674
|
const result = await lilconfig("tailwindcss", {
|
|
673
675
|
searchPlaces: [
|
|
@@ -687,14 +689,14 @@ async function processTailwindcss(options) {
|
|
|
687
689
|
".cts": jiti,
|
|
688
690
|
".mts": jiti
|
|
689
691
|
}
|
|
690
|
-
}).search(
|
|
692
|
+
}).search(cwd);
|
|
691
693
|
if (!result) {
|
|
692
|
-
throw new Error(`No TailwindCSS Config found in: ${
|
|
694
|
+
throw new Error(`No TailwindCSS Config found in: ${cwd}`);
|
|
693
695
|
}
|
|
694
696
|
config = result.filepath;
|
|
695
697
|
}
|
|
696
698
|
const id = requireResolve("tailwindcss", {
|
|
697
|
-
basedir:
|
|
699
|
+
basedir: cwd
|
|
698
700
|
});
|
|
699
701
|
return await postcss([
|
|
700
702
|
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
@@ -715,7 +717,7 @@ function getDefaultPatchOptions() {
|
|
|
715
717
|
overwrite: true
|
|
716
718
|
};
|
|
717
719
|
}
|
|
718
|
-
function getPatchOptions(options
|
|
720
|
+
function getPatchOptions(options) {
|
|
719
721
|
return defu(
|
|
720
722
|
options,
|
|
721
723
|
{
|
|
@@ -843,4 +845,4 @@ class TailwindcssPatcher {
|
|
|
843
845
|
}
|
|
844
846
|
}
|
|
845
847
|
|
|
846
|
-
export { CacheManager as C, TailwindcssPatcher as T, monkeyPatchForExposingContextV2 as a, monkeyPatchForSupportingCustomUnit as b, getCacheOptions as c,
|
|
848
|
+
export { CacheManager as C, TailwindcssPatcher as T, monkeyPatchForExposingContextV2 as a, monkeyPatchForSupportingCustomUnit as b, getCacheOptions as c, getPatchOptions as g, internalPatch as i, logger as l, monkeyPatchForExposingContextV3 as m };
|
|
@@ -76,15 +76,6 @@ class CacheManager {
|
|
|
76
76
|
__publicField$1(this, "options");
|
|
77
77
|
this.options = this.getOptions(options);
|
|
78
78
|
}
|
|
79
|
-
mkdir(cacheDirectory) {
|
|
80
|
-
const exists = fs__default.existsSync(cacheDirectory);
|
|
81
|
-
if (!exists) {
|
|
82
|
-
fs__default.mkdirSync(cacheDirectory, {
|
|
83
|
-
recursive: true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return cacheDirectory;
|
|
87
|
-
}
|
|
88
79
|
getOptions(options = {}) {
|
|
89
80
|
const cwd = options.cwd ?? process__default.cwd();
|
|
90
81
|
const dir = options.dir ?? path__default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
@@ -101,8 +92,8 @@ class CacheManager {
|
|
|
101
92
|
write(data) {
|
|
102
93
|
try {
|
|
103
94
|
const { dir, filename } = this.options;
|
|
104
|
-
|
|
105
|
-
fs__default.
|
|
95
|
+
fs__default.ensureDirSync(dir);
|
|
96
|
+
fs__default.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
106
97
|
return filename;
|
|
107
98
|
} catch {
|
|
108
99
|
logger.error("write cache file fail!");
|
|
@@ -402,74 +393,10 @@ function inspectPostcssPlugin(content) {
|
|
|
402
393
|
};
|
|
403
394
|
}
|
|
404
395
|
|
|
405
|
-
const { sync } = pkg__default;
|
|
406
|
-
function ensureFileContent(filepaths) {
|
|
407
|
-
if (typeof filepaths === "string") {
|
|
408
|
-
filepaths = [filepaths];
|
|
409
|
-
}
|
|
410
|
-
let content;
|
|
411
|
-
for (const filepath of filepaths) {
|
|
412
|
-
if (fs__default.existsSync(filepath)) {
|
|
413
|
-
content = fs__default.readFileSync(filepath, {
|
|
414
|
-
encoding: "utf8"
|
|
415
|
-
});
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return content;
|
|
420
|
-
}
|
|
421
|
-
function requireResolve(id, opts) {
|
|
422
|
-
return sync(id, opts);
|
|
423
|
-
}
|
|
424
|
-
function searchPackageJSON(dir) {
|
|
425
|
-
let packageJsonPath;
|
|
426
|
-
while (true) {
|
|
427
|
-
if (!dir) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
const newDir = path__default.dirname(dir);
|
|
431
|
-
if (newDir === dir) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
dir = newDir;
|
|
435
|
-
packageJsonPath = path__default.join(dir, "package.json");
|
|
436
|
-
if (fs__default.existsSync(packageJsonPath)) {
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return packageJsonPath;
|
|
441
|
-
}
|
|
442
|
-
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
443
|
-
return requireResolve(name, opts);
|
|
444
|
-
}
|
|
445
|
-
function getPackageJsonPath(name, options = {}) {
|
|
446
|
-
const entry = getTailwindcssEntry(name, options);
|
|
447
|
-
if (!entry) {
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
return searchPackageJSON(entry);
|
|
451
|
-
}
|
|
452
|
-
function getPackageInfoSync(name, options = {}) {
|
|
453
|
-
const packageJsonPath = getPackageJsonPath(name, options);
|
|
454
|
-
if (!packageJsonPath) {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
const packageJson = JSON.parse(fs__default.readFileSync(packageJsonPath, "utf8"));
|
|
458
|
-
return {
|
|
459
|
-
name,
|
|
460
|
-
version: packageJson.version,
|
|
461
|
-
rootPath: path__default.dirname(packageJsonPath),
|
|
462
|
-
packageJsonPath,
|
|
463
|
-
packageJson
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function isObject(val) {
|
|
467
|
-
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
396
|
function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
471
|
-
const
|
|
472
|
-
const
|
|
397
|
+
const k0 = "lib/processTailwindFeatures.js";
|
|
398
|
+
const processTailwindFeaturesFilePath = path__default.resolve(twDir, k0);
|
|
399
|
+
const processTailwindFeaturesContent = fs__default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
473
400
|
const result = {};
|
|
474
401
|
if (processTailwindFeaturesContent) {
|
|
475
402
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext$1(processTailwindFeaturesContent);
|
|
@@ -479,27 +406,40 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
479
406
|
});
|
|
480
407
|
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
481
408
|
}
|
|
482
|
-
result
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
409
|
+
result[k0] = code;
|
|
410
|
+
}
|
|
411
|
+
let injectFilepath;
|
|
412
|
+
let k1;
|
|
413
|
+
const try0 = "lib/plugin.js";
|
|
414
|
+
const try1 = "lib/index.js";
|
|
415
|
+
const pluginFilePath = path__default.resolve(twDir, try0);
|
|
416
|
+
const indexFilePath = path__default.resolve(twDir, try1);
|
|
417
|
+
if (fs__default.existsSync(pluginFilePath)) {
|
|
418
|
+
k1 = try0;
|
|
419
|
+
injectFilepath = pluginFilePath;
|
|
420
|
+
} else if (fs__default.existsSync(indexFilePath)) {
|
|
421
|
+
k1 = try1;
|
|
422
|
+
injectFilepath = indexFilePath;
|
|
423
|
+
}
|
|
424
|
+
if (injectFilepath && k1) {
|
|
425
|
+
const pluginContent = fs__default.readFileSync(injectFilepath, "utf8");
|
|
426
|
+
if (pluginContent) {
|
|
427
|
+
const { code, hasPatched } = inspectPostcssPlugin$1(pluginContent);
|
|
428
|
+
if (!hasPatched && opt.overwrite) {
|
|
429
|
+
fs__default.writeFileSync(injectFilepath, code, {
|
|
430
|
+
encoding: "utf8"
|
|
431
|
+
});
|
|
432
|
+
logger.success("patch tailwindcss for expose runtime context successfully!");
|
|
433
|
+
}
|
|
434
|
+
result[k1] = code;
|
|
494
435
|
}
|
|
495
|
-
result
|
|
436
|
+
return result;
|
|
496
437
|
}
|
|
497
|
-
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
498
|
-
return result;
|
|
499
438
|
}
|
|
500
439
|
function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
501
|
-
const
|
|
502
|
-
const
|
|
440
|
+
const k0 = "lib/jit/processTailwindFeatures.js";
|
|
441
|
+
const processTailwindFeaturesFilePath = path__default.resolve(twDir, k0);
|
|
442
|
+
const processTailwindFeaturesContent = fs__default.readFileSync(processTailwindFeaturesFilePath, "utf8");
|
|
503
443
|
const result = {};
|
|
504
444
|
if (processTailwindFeaturesContent) {
|
|
505
445
|
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
|
|
@@ -509,10 +449,11 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
509
449
|
});
|
|
510
450
|
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
511
451
|
}
|
|
512
|
-
result
|
|
452
|
+
result[k0] = code;
|
|
513
453
|
}
|
|
514
|
-
const
|
|
515
|
-
const
|
|
454
|
+
const k1 = "lib/jit/index.js";
|
|
455
|
+
const indexFilePath = path__default.resolve(twDir, k1);
|
|
456
|
+
const pluginContent = fs__default.readFileSync(indexFilePath, "utf8");
|
|
516
457
|
if (pluginContent) {
|
|
517
458
|
const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
|
|
518
459
|
if (!hasPatched && opt.overwrite) {
|
|
@@ -521,9 +462,8 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
521
462
|
});
|
|
522
463
|
logger.success("patch tailwindcss for expose runtime content successfully!");
|
|
523
464
|
}
|
|
524
|
-
result
|
|
465
|
+
result[k1] = code;
|
|
525
466
|
}
|
|
526
|
-
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
527
467
|
return result;
|
|
528
468
|
}
|
|
529
469
|
|
|
@@ -583,6 +523,62 @@ function createDefu(merger) {
|
|
|
583
523
|
}
|
|
584
524
|
const defu = createDefu();
|
|
585
525
|
|
|
526
|
+
const { sync } = pkg__default;
|
|
527
|
+
const defuOverrideArray = createDefu((obj, key, value) => {
|
|
528
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
529
|
+
obj[key] = value;
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
function requireResolve(id, opts) {
|
|
534
|
+
return sync(id, opts);
|
|
535
|
+
}
|
|
536
|
+
function searchPackageJSON(dir) {
|
|
537
|
+
let packageJsonPath;
|
|
538
|
+
while (true) {
|
|
539
|
+
if (!dir) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const newDir = path__default.dirname(dir);
|
|
543
|
+
if (newDir === dir) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
dir = newDir;
|
|
547
|
+
packageJsonPath = path__default.join(dir, "package.json");
|
|
548
|
+
if (fs__default.existsSync(packageJsonPath)) {
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return packageJsonPath;
|
|
553
|
+
}
|
|
554
|
+
function getTailwindcssEntry(name = "tailwindcss", opts) {
|
|
555
|
+
return requireResolve(name, opts);
|
|
556
|
+
}
|
|
557
|
+
function getPackageJsonPath(name, options = {}) {
|
|
558
|
+
const entry = getTailwindcssEntry(name, options);
|
|
559
|
+
if (!entry) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
return searchPackageJSON(entry);
|
|
563
|
+
}
|
|
564
|
+
function getPackageInfoSync(name, options = {}) {
|
|
565
|
+
const packageJsonPath = getPackageJsonPath(name, options);
|
|
566
|
+
if (!packageJsonPath) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const packageJson = JSON.parse(fs__default.readFileSync(packageJsonPath, "utf8"));
|
|
570
|
+
return {
|
|
571
|
+
name,
|
|
572
|
+
version: packageJson.version,
|
|
573
|
+
rootPath: path__default.dirname(packageJsonPath),
|
|
574
|
+
packageJsonPath,
|
|
575
|
+
packageJson
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function isObject(val) {
|
|
579
|
+
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
580
|
+
}
|
|
581
|
+
|
|
586
582
|
function findAstNode(content, options) {
|
|
587
583
|
const { variableName, units } = options;
|
|
588
584
|
const ast = parser.parse(content);
|
|
@@ -621,7 +617,7 @@ function findAstNode(content, options) {
|
|
|
621
617
|
};
|
|
622
618
|
}
|
|
623
619
|
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
624
|
-
const opts =
|
|
620
|
+
const opts = defuOverrideArray(options, {
|
|
625
621
|
units: ["rpx"],
|
|
626
622
|
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
627
623
|
variableName: "lengthUnits",
|
|
@@ -650,7 +646,9 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
|
650
646
|
logger.success("patch tailwindcss for custom length unit successfully!");
|
|
651
647
|
}
|
|
652
648
|
}
|
|
653
|
-
return
|
|
649
|
+
return {
|
|
650
|
+
[opts.lengthUnitsFilePath]: code
|
|
651
|
+
};
|
|
654
652
|
}
|
|
655
653
|
}
|
|
656
654
|
|
|
@@ -658,21 +656,22 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
658
656
|
if (pkgJsonPath) {
|
|
659
657
|
const pkgJson = require(pkgJsonPath);
|
|
660
658
|
const twDir = path__default.dirname(pkgJsonPath);
|
|
659
|
+
options.version = pkgJson.version;
|
|
661
660
|
if (semver.gte(pkgJson.version, "3.0.0")) {
|
|
662
|
-
|
|
661
|
+
let result = {};
|
|
662
|
+
if (options.applyPatches?.exportContext) {
|
|
663
|
+
result = monkeyPatchForExposingContextV3(twDir, options);
|
|
664
|
+
}
|
|
663
665
|
if (options.applyPatches?.extendLengthUnits) {
|
|
664
666
|
try {
|
|
665
|
-
monkeyPatchForSupportingCustomUnit(twDir, {
|
|
667
|
+
Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
|
|
666
668
|
overwrite: options.overwrite
|
|
667
|
-
});
|
|
669
|
+
})));
|
|
668
670
|
} catch {
|
|
669
671
|
}
|
|
670
672
|
}
|
|
671
|
-
|
|
672
|
-
return monkeyPatchForExposingContextV3(twDir, options);
|
|
673
|
-
}
|
|
673
|
+
return result;
|
|
674
674
|
} else if (semver.gte(pkgJson.version, "2.0.0")) {
|
|
675
|
-
options.version = pkgJson.version;
|
|
676
675
|
if (options.applyPatches?.exportContext) {
|
|
677
676
|
return monkeyPatchForExposingContextV2(twDir, options);
|
|
678
677
|
}
|
|
@@ -681,10 +680,13 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
681
680
|
}
|
|
682
681
|
|
|
683
682
|
const jiti = createJiti__default(__filename);
|
|
683
|
+
|
|
684
684
|
async function processTailwindcss(options) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
685
|
+
const { config: userConfig, cwd } = defu(options, {
|
|
686
|
+
cwd: process__default.cwd()
|
|
687
|
+
});
|
|
688
|
+
let config = userConfig;
|
|
689
|
+
if (!(typeof config === "string" && path__default.isAbsolute(config))) {
|
|
688
690
|
const moduleName = "tailwind";
|
|
689
691
|
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
690
692
|
searchPlaces: [
|
|
@@ -704,14 +706,14 @@ async function processTailwindcss(options) {
|
|
|
704
706
|
".cts": jiti,
|
|
705
707
|
".mts": jiti
|
|
706
708
|
}
|
|
707
|
-
}).search(
|
|
709
|
+
}).search(cwd);
|
|
708
710
|
if (!result) {
|
|
709
|
-
throw new Error(`No TailwindCSS Config found in: ${
|
|
711
|
+
throw new Error(`No TailwindCSS Config found in: ${cwd}`);
|
|
710
712
|
}
|
|
711
713
|
config = result.filepath;
|
|
712
714
|
}
|
|
713
715
|
const id = requireResolve("tailwindcss", {
|
|
714
|
-
basedir:
|
|
716
|
+
basedir: cwd
|
|
715
717
|
});
|
|
716
718
|
return await postcss__default([
|
|
717
719
|
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
@@ -732,7 +734,7 @@ function getDefaultPatchOptions() {
|
|
|
732
734
|
overwrite: true
|
|
733
735
|
};
|
|
734
736
|
}
|
|
735
|
-
function getPatchOptions(options
|
|
737
|
+
function getPatchOptions(options) {
|
|
736
738
|
return defu(
|
|
737
739
|
options,
|
|
738
740
|
{
|
|
@@ -862,14 +864,10 @@ class TailwindcssPatcher {
|
|
|
862
864
|
|
|
863
865
|
exports.CacheManager = CacheManager;
|
|
864
866
|
exports.TailwindcssPatcher = TailwindcssPatcher;
|
|
865
|
-
exports.ensureFileContent = ensureFileContent;
|
|
866
867
|
exports.getCacheOptions = getCacheOptions;
|
|
867
|
-
exports.getPackageInfoSync = getPackageInfoSync;
|
|
868
868
|
exports.getPatchOptions = getPatchOptions;
|
|
869
869
|
exports.internalPatch = internalPatch;
|
|
870
|
-
exports.isObject = isObject;
|
|
871
870
|
exports.logger = logger;
|
|
872
871
|
exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2;
|
|
873
872
|
exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3;
|
|
874
873
|
exports.monkeyPatchForSupportingCustomUnit = monkeyPatchForSupportingCustomUnit;
|
|
875
|
-
exports.requireResolve = requireResolve;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "patch tailwindcss for exposing context and extract classes",
|
|
5
5
|
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,13 @@
|
|
|
29
29
|
"bin",
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "unbuild --sourcemap",
|
|
34
|
+
"build": "unbuild",
|
|
35
|
+
"test": "vitest run --coverage.enabled",
|
|
36
|
+
"test:dev": "vitest",
|
|
37
|
+
"patch": "node bin/tw-patch.js install"
|
|
38
|
+
},
|
|
32
39
|
"publishConfig": {
|
|
33
40
|
"access": "public",
|
|
34
41
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -46,6 +53,7 @@
|
|
|
46
53
|
"@babel/parser": "^7.24.8",
|
|
47
54
|
"@babel/traverse": "^7.24.8",
|
|
48
55
|
"@babel/types": "^7.24.9",
|
|
56
|
+
"@tailwindcss-mangle/config": "workspace:^",
|
|
49
57
|
"cac": "^6.7.14",
|
|
50
58
|
"consola": "^3.2.3",
|
|
51
59
|
"fs-extra": "^11.2.0",
|
|
@@ -53,27 +61,6 @@
|
|
|
53
61
|
"lilconfig": "^3.1.2",
|
|
54
62
|
"postcss": "^8.4.39",
|
|
55
63
|
"resolve": "^1.22.8",
|
|
56
|
-
"semver": "^7.6.3"
|
|
57
|
-
"@tailwindcss-mangle/config": "^3.0.0"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@types/babel__generator": "^7.6.8",
|
|
61
|
-
"@types/babel__traverse": "^7.20.6",
|
|
62
|
-
"@types/resolve": "^1.20.6",
|
|
63
|
-
"@types/semver": "^7.5.8",
|
|
64
|
-
"pkg-types": "^1.1.3",
|
|
65
|
-
"postcss7": "npm:postcss@7",
|
|
66
|
-
"tailwindcss": "^3.4.6",
|
|
67
|
-
"tailwindcss2": "npm:@tailwindcss/postcss7-compat@^2.2.17"
|
|
68
|
-
},
|
|
69
|
-
"directories": {
|
|
70
|
-
"test": "test"
|
|
71
|
-
},
|
|
72
|
-
"scripts": {
|
|
73
|
-
"dev": "unbuild --sourcemap",
|
|
74
|
-
"build": "unbuild",
|
|
75
|
-
"test": "vitest run --coverage.enabled",
|
|
76
|
-
"test:dev": "vitest",
|
|
77
|
-
"patch": "node bin/tw-patch.js install"
|
|
64
|
+
"semver": "^7.6.3"
|
|
78
65
|
}
|
|
79
|
-
}
|
|
66
|
+
}
|