Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 10e353d

Browse files
Fix execution of hooks outside of process
In case you need a hook to be executed outside of process, you should place correct shebang at the beginning of the file and CLI should spawn it. However, this is not working at the moment, as when CLI detects that the hook should be spawned, it just does nothing. The code is incorrectly placed inside the `if` for in process execution. This causes another issue - in case a hook returns a function, which returns falsey value, we decide the hook should be executed outside of process and spawn a new Node.js process to execute the hook. So we execute it twice. Fix the if-else logic, so the hooks will work correctly.
1 parent 7e6dbe9 commit 10e353d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

services/hooks-service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,15 @@ export class HooksService implements IHooksService {
139139
}
140140

141141
this.$logger.trace('Hook completed');
142-
} else {
143-
const environment = this.prepareEnvironment(hook.fullPath);
144-
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
142+
}
143+
} else {
144+
const environment = this.prepareEnvironment(hook.fullPath);
145+
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
145146

146-
const output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
147-
if (output.exitCode !== 0) {
148-
throw new Error(output.stdout + output.stderr);
149-
}
147+
const output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
148+
149+
if (output.exitCode !== 0) {
150+
throw new Error(output.stdout + output.stderr);
150151
}
151152
}
152153
}

0 commit comments

Comments
 (0)