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

Commit 6918147

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 df4b878 commit 6918147

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

services/hooks-service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ export class HooksService implements IHooksService {
143143
}
144144

145145
this.$logger.trace('Hook completed');
146-
} else {
147-
const environment = this.prepareEnvironment(hook.fullPath);
148-
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
146+
}
147+
} else {
148+
const environment = this.prepareEnvironment(hook.fullPath);
149+
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
149150

150-
const output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
151-
results.push(output);
151+
const output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
152+
results.push(output);
152153

153-
if (output.exitCode !== 0) {
154-
throw new Error(output.stdout + output.stderr);
155-
}
154+
if (output.exitCode !== 0) {
155+
throw new Error(output.stdout + output.stderr);
156156
}
157157
}
158158
}

0 commit comments

Comments
 (0)