Skip to content

Commit 52cfbca

Browse files
committed
chore: release 1.0.2
1 parent 28cf27e commit 52cfbca

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

packages/tailwindcss-patch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailwindcss-patch",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "patch tailwindcss for exposing context",
55
"main": "dist/index.js",
66
"types": "dist/types/index.d.ts",

packages/tailwindcss-patch/src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { createPatch } from './patcher'
2-
const patch = createPatch({})
2+
const patch = createPatch()
33
patch()
+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from './exposeContext'
22
export * from './inspector'
33
export * from './patcher'
4+
export * from './utils'
5+
export * from './type'

packages/tailwindcss-patch/src/patcher.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function getInstalledPkgJsonPath(options: PatchOptions) {
1818

1919
const pkgJson = require(tmpJsonPath) as PackageJson
2020
// https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin
21-
21+
// only tailwindcss version > 3.0.0
2222
if (gte(pkgJson.version!, '3.0.0')) {
2323
return tmpJsonPath
2424
}
@@ -29,22 +29,23 @@ export function getInstalledPkgJsonPath(options: PatchOptions) {
2929
}
3030
}
3131

32-
export function createPatch(options: PatchOptions) {
32+
export function createPatch(options: PatchOptions = {}) {
3333
const opt = defu(options, defaultOptions) as InternalPatchOptions
3434
return () => {
3535
try {
36-
return internalPatch(getInstalledPkgJsonPath(options), opt)
36+
const pkgJsonPath = getInstalledPkgJsonPath(options)
37+
return internalPatch(pkgJsonPath, opt)
3738
} catch (error) {
3839
console.warn(`patch tailwindcss failed:` + (<Error>error).message)
3940
}
4041
}
4142
}
4243

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')
4546

4647
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath)
47-
const result: { processTailwindFeatures?: string; plugin?: string } = {}
48+
const result: { processTailwindFeatures?: string; plugin?: string } & Record<string, any> = {}
4849
if (processTailwindFeaturesContent) {
4950
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent)
5051
if (!hasPatched && opt.overwrite) {
@@ -56,8 +57,8 @@ export function monkeyPatchForExposingContext(rootDir: string, opt: InternalPatc
5657
result.processTailwindFeatures = code
5758
}
5859

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')
6162
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath])
6263
if (pluginContent) {
6364
const { code, hasPatched } = inspectPostcssPlugin(pluginContent)
@@ -69,13 +70,15 @@ export function monkeyPatchForExposingContext(rootDir: string, opt: InternalPatc
6970
}
7071
result.plugin = code
7172
}
73+
74+
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result)
7275
return result
7376
}
7477

7578
export function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined {
7679
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)
7982
return result
8083
}
8184
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export interface PatchOptions {
22
overwrite?: boolean
33
paths?: string[]
4-
basedir?: string
4+
basedir?: string,
5+
custom?: (dir: string, ctx: Record<string, any>) => void
56
}
67

78
export interface InternalPatchOptions {
89
overwrite: boolean
910
paths?: string[]
1011
basedir?: string
12+
custom?: (dir: string, ctx: Record<string, any>) => void
1113
}

0 commit comments

Comments
 (0)