|
1 | 1 | import { getClassCacheSet, getContexts, getTailwindcssEntry } from './exposeContext'
|
2 |
| -import type { CacheOptions, PatchOptions, InternalCacheOptions } from './type' |
| 2 | +import type { CacheOptions, PatchOptions, InternalCacheOptions, InternalPatchOptions } from './type' |
3 | 3 | import { writeCache, readCache } from './cache'
|
4 |
| -import { createPatch } from './patcher' |
| 4 | +import { createPatch, getPatchOptions } from './patcher' |
5 | 5 |
|
6 | 6 | export interface TailwindcssPatcherOptions {
|
7 | 7 | cache?: CacheOptions
|
8 | 8 | patch?: PatchOptions
|
9 | 9 | }
|
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 | +} |
11 | 32 | export class TailwindcssPatcher {
|
12 | 33 | public rawOptions: TailwindcssPatcherOptions
|
13 | 34 | public cacheOptions: InternalCacheOptions
|
14 |
| - public patchOptions?: PatchOptions |
| 35 | + public patchOptions: InternalPatchOptions |
15 | 36 | public patch: () => void
|
16 | 37 | constructor(options: TailwindcssPatcherOptions = {}) {
|
17 | 38 | 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) |
40 | 42 | }
|
41 | 43 |
|
42 | 44 | getPkgEntry(basedir?: string) {
|
|
0 commit comments