Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(run): Preserve none zero exit code #6926

Merged
merged 12 commits into from Mar 14, 2019
24 changes: 24 additions & 0 deletions __tests__/integration.js
Expand Up @@ -450,6 +450,30 @@ test('yarn run <failing script>', async () => {
expect(stderr).toEqual('error Command failed with exit code 1.');
});

test('yarn run <failing script with custom exit code>', async () => {
const cwd = await makeTemp();

await fs.writeFile(
path.join(cwd, 'package.json'),
JSON.stringify({
license: 'MIT',
scripts: {false: 'exit 78'},
}),
);

let stderr = null;
let err = null;
try {
await runYarn(['run', 'false'], {cwd});
} catch (e) {
stderr = e.stderr.trim();
err = e.code;
}

expect(err).toEqual(78);
expect(stderr).toEqual('error Command failed with exit code 78.');
});

test('yarn run in path need escaping', async () => {
const cwd = await makeTemp('special (chars)');

Expand Down
7 changes: 6 additions & 1 deletion src/cli/index.js
Expand Up @@ -24,6 +24,7 @@ import {spawnp, forkp} from '../util/child.js';
import {version} from '../util/yarn-version.js';
import handleSignals from '../util/signal-handler.js';
import {boolify, boolifyWithDefault} from '../util/conversion.js';
import {ProcessTermError} from '../errors';

function findProjectRoot(base: string): string {
let prev = null;
Expand Down Expand Up @@ -583,7 +584,11 @@ export async function main({
reporter.info(command.getDocsInfo);
}

return exit(1);
if (err instanceof ProcessTermError) {
return exit(err.EXIT_CODE || 1);
}

zhigang1992 marked this conversation as resolved.
Show resolved Hide resolved
return exit((err.code && Number(err.code)) || 1);
zhigang1992 marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
1 change: 1 addition & 0 deletions src/util/execute-lifecycle-script.js
Expand Up @@ -366,6 +366,7 @@ export async function execCommand({
err.EXIT_SIGNAL
? reporter.lang('commandFailedWithSignal', err.EXIT_SIGNAL)
: reporter.lang('commandFailedWithCode', err.EXIT_CODE),
String(err.EXIT_CODE),
zhigang1992 marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
throw err;
Expand Down