Skip to content

Commit

Permalink
fix: close the config watcher so that Node can exit safely
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Feb 14, 2022
1 parent fcb5ec5 commit 63c8a12
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/commands/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class BaseCommand extends Command {
await this.init(actionCommand)
debug(`${name}:preAction`)('end')
})
.hook('postAction', async () => {
await this.configWatcherHandle.close()
})
)
}

Expand Down Expand Up @@ -431,9 +434,9 @@ class BaseCommand extends Command {
const apiOpts = { ...apiUrlOpts, agent }
const globalConfig = await getGlobalConfig()
const { NetlifyAPI } = await jsClient
const configWatcher = new events.EventEmitter()

watchDebounced(configPath, {
const configWatcher = new events.EventEmitter()
const configWatcherHandle = await watchDebounced(configPath, {
depth: 1,
onChange: async () => {
const { config: newConfig } = await actionCommand.getConfig({ cwd, state, token, ...apiUrlOpts })
Expand All @@ -443,6 +446,9 @@ class BaseCommand extends Command {
},
})

// chokidar handler
this.configWatcherHandle = configWatcherHandle

actionCommand.netlify = {
// api methods
api: new NetlifyAPI(token || '', apiOpts),
Expand Down

0 comments on commit 63c8a12

Please sign in to comment.