@@ -18,7 +18,7 @@ export function getInstalledPkgJsonPath(options: PatchOptions) {
18
18
19
19
const pkgJson = require ( tmpJsonPath ) as PackageJson
20
20
// https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin
21
-
21
+ // only tailwindcss version > 3.0.0
22
22
if ( gte ( pkgJson . version ! , '3.0.0' ) ) {
23
23
return tmpJsonPath
24
24
}
@@ -29,22 +29,23 @@ export function getInstalledPkgJsonPath(options: PatchOptions) {
29
29
}
30
30
}
31
31
32
- export function createPatch ( options : PatchOptions ) {
32
+ export function createPatch ( options : PatchOptions = { } ) {
33
33
const opt = defu ( options , defaultOptions ) as InternalPatchOptions
34
34
return ( ) => {
35
35
try {
36
- return internalPatch ( getInstalledPkgJsonPath ( options ) , opt )
36
+ const pkgJsonPath = getInstalledPkgJsonPath ( options )
37
+ return internalPatch ( pkgJsonPath , opt )
37
38
} catch ( error ) {
38
39
console . warn ( `patch tailwindcss failed:` + ( < Error > error ) . message )
39
40
}
40
41
}
41
42
}
42
43
43
- export function monkeyPatchForExposingContext ( rootDir : string , opt : InternalPatchOptions ) {
44
- const processTailwindFeaturesFilePath = path . resolve ( rootDir , 'lib/processTailwindFeatures.js' )
44
+ export function monkeyPatchForExposingContext ( twDir : string , opt : InternalPatchOptions ) {
45
+ const processTailwindFeaturesFilePath = path . resolve ( twDir , 'lib/processTailwindFeatures.js' )
45
46
46
47
const processTailwindFeaturesContent = ensureFileContent ( processTailwindFeaturesFilePath )
47
- const result : { processTailwindFeatures ?: string ; plugin ?: string } = { }
48
+ const result : { processTailwindFeatures ?: string ; plugin ?: string } & Record < string , any > = { }
48
49
if ( processTailwindFeaturesContent ) {
49
50
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext ( processTailwindFeaturesContent )
50
51
if ( ! hasPatched && opt . overwrite ) {
@@ -56,8 +57,8 @@ export function monkeyPatchForExposingContext(rootDir: string, opt: InternalPatc
56
57
result . processTailwindFeatures = code
57
58
}
58
59
59
- const pluginFilePath = path . resolve ( rootDir , 'lib/plugin.js' )
60
- const indexFilePath = path . resolve ( rootDir , 'lib/index.js' )
60
+ const pluginFilePath = path . resolve ( twDir , 'lib/plugin.js' )
61
+ const indexFilePath = path . resolve ( twDir , 'lib/index.js' )
61
62
const pluginContent = ensureFileContent ( [ pluginFilePath , indexFilePath ] )
62
63
if ( pluginContent ) {
63
64
const { code, hasPatched } = inspectPostcssPlugin ( pluginContent )
@@ -69,13 +70,15 @@ export function monkeyPatchForExposingContext(rootDir: string, opt: InternalPatc
69
70
}
70
71
result . plugin = code
71
72
}
73
+
74
+ opt . custom && typeof opt . custom === 'function' && opt . custom ( twDir , result )
72
75
return result
73
76
}
74
77
75
78
export function internalPatch ( pkgJsonPath : string | undefined , options : InternalPatchOptions ) : any | undefined {
76
79
if ( pkgJsonPath ) {
77
- const rootDir = path . dirname ( pkgJsonPath )
78
- const result = monkeyPatchForExposingContext ( rootDir , options )
80
+ const twDir = path . dirname ( pkgJsonPath )
81
+ const result = monkeyPatchForExposingContext ( twDir , options )
79
82
return result
80
83
}
81
84
}
0 commit comments