Skip to content

Commit

Permalink
Fix possible crash on --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 29, 2023
1 parent 14a6d12 commit 2850f77
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @typedef {import('./parse-argv.js').State} State
*/

import assert from 'node:assert/strict'
import process from 'node:process'
import stream from 'node:stream'
import {fileURLToPath} from 'node:url'
Expand Down Expand Up @@ -144,10 +143,14 @@ export function args(options) {
? fileURLToPath(state.engine.cwd)
: state.engine.cwd

assert(typeof cwd === 'string', '`cwd` is defined')

watcher = chokidar
.watch(urls, {cwd, ignoreInitial: true})
.watch(
urls,
// @ts-expect-error: chokidar types are wrong w/
// `exactOptionalPropertyTypes`,
// `cwd` can be `undefined`.
{cwd, ignoreInitial: true}
)
.on('error', done)
.on('change', function (filePath) {
state.engine.files = [filePath]
Expand Down

0 comments on commit 2850f77

Please sign in to comment.