Skip to content

Commit

Permalink
fix: not all commands will have configPath
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Feb 14, 2022
1 parent c3e3335 commit f00011d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/commands/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class BaseCommand extends Command {
debug(`${name}:preAction`)('end')
})
.hook('postAction', async () => {
await this.configWatcherHandle.close()
if (this.configWatcherHandle) {
await this.configWatcherHandle.close()
}
})
)
}
Expand Down Expand Up @@ -436,18 +438,22 @@ class BaseCommand extends Command {
const { NetlifyAPI } = await jsClient

const configWatcher = new events.EventEmitter()
const configWatcherHandle = await watchDebounced(configPath, {
depth: 1,
onChange: async () => {
const { config: newConfig } = await actionCommand.getConfig({ cwd, state, token, ...apiUrlOpts })

const normalizedNewConfig = normalizeConfig(newConfig)
configWatcher.emit('change', normalizedNewConfig)
},
})
// Only set up a watcher if we know the config path.
if (configPath) {
const configWatcherHandle = await watchDebounced(configPath, {
depth: 1,
onChange: async () => {
const { config: newConfig } = await actionCommand.getConfig({ cwd, state, token, ...apiUrlOpts })

const normalizedNewConfig = normalizeConfig(newConfig)
configWatcher.emit('change', normalizedNewConfig)
},
})

// chokidar handler
this.configWatcherHandle = configWatcherHandle
// chokidar handler
this.configWatcherHandle = configWatcherHandle
}

actionCommand.netlify = {
// api methods
Expand Down

0 comments on commit f00011d

Please sign in to comment.