Skip to content

Commit 445c21d

Browse files
committed
feat: commit patches
1 parent ff8785f commit 445c21d

File tree

10 files changed

+22
-78
lines changed

10 files changed

+22
-78
lines changed

packages/tailwindcss-patch/src/core/postcss.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ import path from 'node:path'
22
import process from 'node:process'
33
import postcss from 'postcss'
44
import { lilconfig } from 'lilconfig'
5-
import createJiti from 'jiti'
6-
import { requireResolve } from '@/utils'
5+
import { jiti } from '@/jiti'
6+
import { defu, requireResolve } from '@/utils'
77

8-
const jiti = createJiti(__filename)
8+
export interface ProcessTailwindcssOptions {
9+
cwd?: string
10+
config?: string
11+
}
912

10-
export async function processTailwindcss(options: { cwd?: string, config?: string }) {
11-
options.cwd = options.cwd ?? process.cwd()
12-
let config = options.config
13+
export async function processTailwindcss(options: ProcessTailwindcssOptions) {
14+
const { config: userConfig, cwd } = defu<ProcessTailwindcssOptions, ProcessTailwindcssOptions[]>(options, {
15+
cwd: process.cwd(),
16+
})
17+
let config = userConfig
1318
// 没有具体指定的话,就走下面的分支
14-
if (!(typeof options.config === 'string' && path.isAbsolute(options.config))) {
19+
if (!(typeof config === 'string' && path.isAbsolute(config))) {
1520
const moduleName = 'tailwind'
1621
const result = await lilconfig('tailwindcss', {
1722
searchPlaces: [
@@ -31,14 +36,14 @@ export async function processTailwindcss(options: { cwd?: string, config?: strin
3136
'.cts': jiti,
3237
'.mts': jiti,
3338
},
34-
}).search(options.cwd)
39+
}).search(cwd)
3540
if (!result) {
36-
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`)
41+
throw new Error(`No TailwindCSS Config found in: ${cwd}`)
3742
}
3843
config = result.filepath
3944
}
4045
const id = requireResolve('tailwindcss', {
41-
basedir: options.cwd,
46+
basedir: cwd,
4247
})
4348
return await postcss([
4449
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports

packages/tailwindcss-patch/src/defaults.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export function getDefaultPatchOptions(): DeepRequired<PatchOptions> {
1212
}
1313
}
1414

15-
export function getPatchOptions(options: PatchOptions = {}) {
16-
return defu(
15+
export function getPatchOptions(options?: PatchOptions) {
16+
return defu<InternalPatchOptions, Partial<InternalPatchOptions>[]>(
1717
options,
1818
{
1919
basedir: process.cwd(),
2020
},
2121
getDefaultPatchOptions(),
22-
) as InternalPatchOptions
22+
)
2323
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import createJiti from 'jiti'
2+
3+
export const jiti = createJiti(__filename)

packages/tailwindcss-patch/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface PatchOptions {
2727
basedir?: string
2828
applyPatches?: {
2929
exportContext?: boolean
30-
extendLengthUnits?: boolean
30+
extendLengthUnits?: boolean | ILengthUnitsPatchOptions
3131
}
3232
}
3333

packages/tailwindcss-patch/test/context.test.ts

-47
This file was deleted.

packages/tailwindcss-patch/test/runtime-patcher.test.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)