mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 12:57:46 +00:00
In some rare cases, `npm bin` exits with code 7, but still outputs the right bin path.
To reproduce, try:
```
npm init -y
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
vc
# enter "echo build" for the build command, leave the other configuration as default
```
The build will fail with `Error: Command exited with 7` because `npm bin` fails with code 7, for some reason.
In this PR, we do 2 things:
(1) Ignore exit codes from `npm bin`. It still outputs the right path when it exits with code 7 so we just read the output and check if it's a valid path.
(2) Throw a more specific error message when `npm bin` fails to give us the bin path. The current error was hard to debug because it looked like it was coming from the install commmand. We can do better by emitting a custom error.
Alternative considered for (2): Do not throw errors. If `npm bin` fails, emit a warning and let the build continue.
Related Issues:
- https://github.com/vercel/customer-issues/issues/585 (internal)
22 lines
737 B
TypeScript
Vendored
22 lines
737 B
TypeScript
Vendored
import { spawnAsync, NowBuildError } from '../src';
|
|
|
|
it('should execute a command', async () => {
|
|
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
|
await expect(spawnAsync('echo', ['hello'])).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('should throw if the command exits with non-0 code', async () => {
|
|
await expect(spawnAsync('find', ['unknown-file'])).rejects.toBeInstanceOf(
|
|
NowBuildError
|
|
);
|
|
});
|
|
|
|
it('should return if the command exits with non-0 code and ignoreNon0Exit=true', async () => {
|
|
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
|
await expect(
|
|
spawnAsync('find', ['unknown-file'], {
|
|
ignoreNon0Exit: true,
|
|
})
|
|
).resolves.toBeUndefined();
|
|
});
|