Skip to content

Commit

Permalink
fix: actually trigger rebuild when watched files change
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jul 25, 2022
1 parent 8dbb97d commit 135ff39
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/index.ts
Expand Up @@ -28,9 +28,9 @@ export const defineConfig = (
| Options
| Options[]
| ((
/** The options derived from CLI flags */
overrideOptions: Options
) => MaybePromise<Options | Options[]>)
/** The options derived from CLI flags */
overrideOptions: Options
) => MaybePromise<Options | Options[]>)
) => options

const killProcess = ({
Expand Down Expand Up @@ -67,8 +67,8 @@ const normalizeOptions = async (
? {}
: undefined
: typeof _options.dts === 'string'
? { entry: _options.dts }
: _options.dts,
? { entry: _options.dts }
: _options.dts,
}

setSilent(options.silent)
Expand Down Expand Up @@ -120,9 +120,9 @@ export async function build(_options: Options) {
_options.config === false
? {}
: await loadTsupConfig(
process.cwd(),
_options.config === true ? undefined : _options.config
)
process.cwd(),
_options.config === true ? undefined : _options.config
)

const configData =
typeof config.data === 'function'
Expand Down Expand Up @@ -272,16 +272,17 @@ export async function build(_options: Options) {
typeof options.watch === 'boolean'
? '.'
: Array.isArray(options.watch)
? options.watch.filter(
? options.watch.filter(
(path): path is string => typeof path === 'string'
)
: options.watch
: options.watch

logger.info(
'CLI',
`Watching for changes in ${Array.isArray(watchPaths)
? watchPaths.map((v) => '"' + v + '"').join(' | ')
: '"' + watchPaths + '"'
`Watching for changes in ${
Array.isArray(watchPaths)
? watchPaths.map((v) => '"' + v + '"').join(' | ')
: '"' + watchPaths + '"'
}`
)
logger.info(
Expand All @@ -298,8 +299,12 @@ export async function build(_options: Options) {
})
watcher.on('all', (type, file) => {
file = slash(file)
if (!buildDependencies.has(file)) return

// By default we only rebuild when imported files change
// If you specify custom `watch`, a string or multiple strings
// We rebuild when those files change
if (options.watch === true && !buildDependencies.has(file)) {
return
}
logger.info('CLI', `Change detected: ${type} ${file}`)
debouncedBuildAll()
})
Expand Down

0 comments on commit 135ff39

Please sign in to comment.