Skip to content

Commit 8732c96

Browse files
feat(biome): Add watchPath option (#590)
1 parent 9d906eb commit 8732c96

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/checkers/biome.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Advanced object configuration table of `options.biome`
3131
| :------------ | --------------------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
3232
| command | `'check' \| 'lint' \| 'format' \| 'ci'` | `'lint'` in dev, `'check'` in build. | The command to execute biome with. |
3333
| flags | `string` | `''` | CLI flags to pass to the command. |
34+
| watchPath | `string \| string[]` | `undefined` | **(Only in dev mode)** Configure path to watch files for Biome. If not specified, will watch the entire project root. |
3435
| dev.logLevel | `('error' \| 'warning')[]` | `['error', 'warning']` | **(Only in dev mode)** Which level of Biome diagnostics should be emitted to terminal and overlay in dev mode. |
3536
| dev.command | `'check' \| 'lint' \| 'format' \| 'ci'` | `''` | Command to run in dev mode, it will override `command` config in dev mode. |
3637
| dev.flags | `string` | `''` | Flags to run in dev mode, it will override `flags` config in dev mode. |

packages/vite-plugin-checker/src/checkers/biome/main.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,16 @@ const createDiagnostic: CreateDiagnostic<'biome'> = (pluginConfig) => {
121121
dispatchDiagnostics()
122122

123123
// watch lint
124-
const watcher = chokidar.watch([], {
124+
let watchTarget: string | string[] = root
125+
if (typeof biomeConfig === 'object' && biomeConfig.watchPath) {
126+
if (Array.isArray(biomeConfig.watchPath)) {
127+
watchTarget = biomeConfig.watchPath.map((p) => path.resolve(root, p))
128+
} else {
129+
watchTarget = path.resolve(root, biomeConfig.watchPath)
130+
}
131+
}
132+
133+
const watcher = chokidar.watch(watchTarget, {
125134
cwd: root,
126135
ignored: (path: string) => path.includes('node_modules'),
127136
})
@@ -131,7 +140,6 @@ const createDiagnostic: CreateDiagnostic<'biome'> = (pluginConfig) => {
131140
watcher.on('unlink', async (filePath) => {
132141
handleFileChange(filePath, 'unlink')
133142
})
134-
watcher.add('.')
135143
},
136144
}
137145
}

packages/vite-plugin-checker/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export type BiomeConfig =
108108
* or `build.command` is set their mode.
109109
* */
110110
flags?: string
111+
/**
112+
* Configure path to watch files
113+
*/
114+
watchPath?: string | string[]
111115
dev?: Partial<{
112116
/** Command will be used in dev mode */
113117
command: BiomeCommand

0 commit comments

Comments
 (0)