From 63c8a12b2e7e6eaa0ac661342efec7e78bf1f794 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 14 Feb 2022 12:10:53 -0800 Subject: [PATCH] fix: close the config watcher so that Node can exit safely --- src/commands/base-command.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commands/base-command.js b/src/commands/base-command.js index 9532bee5d66..05f360619e7 100644 --- a/src/commands/base-command.js +++ b/src/commands/base-command.js @@ -121,6 +121,9 @@ class BaseCommand extends Command { await this.init(actionCommand) debug(`${name}:preAction`)('end') }) + .hook('postAction', async () => { + await this.configWatcherHandle.close() + }) ) } @@ -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 }) @@ -443,6 +446,9 @@ class BaseCommand extends Command { }, }) + // chokidar handler + this.configWatcherHandle = configWatcherHandle + actionCommand.netlify = { // api methods api: new NetlifyAPI(token || '', apiOpts),