Skip to content

Commit 511e7e5

Browse files
committed
chore: type fix and createPatch change
1 parent d85bce3 commit 511e7e5

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

packages/tailwindcss-patch/src/class.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
import { getClassCacheSet, getContexts, getTailwindcssEntry } from './exposeContext'
2-
import type { CacheOptions, PatchOptions, InternalCacheOptions } from './type'
2+
import type { CacheOptions, PatchOptions, InternalCacheOptions, InternalPatchOptions } from './type'
33
import { writeCache, readCache } from './cache'
4-
import { createPatch } from './patcher'
4+
import { createPatch, getPatchOptions } from './patcher'
55

66
export interface TailwindcssPatcherOptions {
77
cache?: CacheOptions
88
patch?: PatchOptions
99
}
10-
10+
export function getCacheOptions(options?: CacheOptions) {
11+
let cache: InternalCacheOptions
12+
switch (typeof options) {
13+
case 'undefined': {
14+
cache = {
15+
enable: false
16+
}
17+
break
18+
}
19+
case 'boolean': {
20+
cache = {
21+
enable: options
22+
}
23+
break
24+
}
25+
case 'object': {
26+
cache = { ...options, enable: true }
27+
break
28+
}
29+
}
30+
return cache
31+
}
1132
export class TailwindcssPatcher {
1233
public rawOptions: TailwindcssPatcherOptions
1334
public cacheOptions: InternalCacheOptions
14-
public patchOptions?: PatchOptions
35+
public patchOptions: InternalPatchOptions
1536
public patch: () => void
1637
constructor(options: TailwindcssPatcherOptions = {}) {
1738
this.rawOptions = options
18-
let cache: InternalCacheOptions
19-
switch (typeof options.cache) {
20-
case 'undefined': {
21-
cache = {
22-
enable: false
23-
}
24-
break
25-
}
26-
case 'boolean': {
27-
cache = {
28-
enable: options.cache
29-
}
30-
break
31-
}
32-
case 'object': {
33-
cache = { ...options.cache, enable: true }
34-
break
35-
}
36-
}
37-
this.cacheOptions = cache
38-
this.patchOptions = options.patch
39-
this.patch = createPatch(options.patch)
39+
this.cacheOptions = getCacheOptions(options.cache)
40+
this.patchOptions = getPatchOptions(options.patch)
41+
this.patch = createPatch(this.patchOptions)
4042
}
4143

4244
getPkgEntry(basedir?: string) {

packages/tailwindcss-patch/src/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import { createPatch } from './patcher'
2-
const patch = createPatch()
1+
import { createPatch, getPatchOptions } from './patcher'
2+
const opt = getPatchOptions()
3+
const patch = createPatch(opt)
34
patch()

packages/tailwindcss-patch/src/patcher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ export function getInstalledPkgJsonPath(options: PatchOptions = {}) {
2626
}
2727
}
2828

29-
export function createPatch(options: PatchOptions = {}) {
30-
const opt = defu(
29+
export function getPatchOptions(options: PatchOptions = {}) {
30+
return defu(
3131
options,
3232
{
3333
basedir: process.cwd()
3434
},
3535
defaultOptions
3636
) as InternalPatchOptions
37+
}
38+
39+
export function createPatch(opt: InternalPatchOptions) {
3740
return () => {
3841
try {
3942
const pkgJsonPath = getInstalledPkgJsonPath(opt)

0 commit comments

Comments
 (0)