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: use appropriate exit codes #1755

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [Utilities](#utilities)
- [Getting started](#getting-started)
- [webpack CLI Scaffolds](#webpack-cli-scaffolds)
- [Exit codes and their meanings](#exit-codes-and-their-meanings)
- [Contributing and Internal Documentation](#contributing-and-internal-documentation)
- [Open Collective](#open-collective)

Expand Down Expand Up @@ -96,6 +97,14 @@ With v3 of webpack CLI, we introduced scaffolding as an integral part of the CLI

You can read more about [Scaffolding](https://webpack.js.org/guides/scaffolding), learn [How to compose a webpack-scaffold?](https://webpack.js.org/contribute/writing-a-scaffold) or generate one with [webpack-scaffold-starter](https://github.com/rishabh3112/webpack-scaffold-starter).

## Exit codes and their meanings

| Exit Code | Description |
| --------- | -------------------------------------------------- |
| `0` | Success |
| `1` | Warnings/Errors from webpack |
| `2` | Configuration/options problem or an internal error |

## Contributing and Internal Documentation

The webpack family welcomes any contributor, small or big. We are happy to elaborate, guide you through the source code and find issues you might want to work on! To get started have a look at our [documentation on contributing](./.github/CONTRIBUTING.md).
Expand Down
2 changes: 1 addition & 1 deletion packages/package-utils/__tests__/packageUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('packageUtils', () => {
// runCommand should not be called, because the installation is not confirmed
expect((runCommand as jest.Mock).mock.calls.length).toEqual(0);
expect((prompt as jest.Mock).mock.calls[0][0][0].message).toMatch(/Would you like to install test-package\?/);
expect(process.exitCode).toEqual(-1);
expect(process.exitCode).toEqual(2);
});
});
});
2 changes: 1 addition & 1 deletion packages/package-utils/src/packageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ export async function promptInstallation(packageName: string, preMessage?: Funct
return exports.packageExists(packageName);
}
// eslint-disable-next-line require-atomic-updates
process.exitCode = -1;
process.exitCode = 2;
}
6 changes: 3 additions & 3 deletions packages/utils/src/modify-config-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function modifyHelperUtil(
} catch (err) {
console.error(red('\nYour package.json was incorrectly formatted.\n'));
Error.stackTraceLimit = 0;
process.exitCode = -1;
process.exitCode = 2;
}

env.registerStub(generator, generatorName);
Expand All @@ -108,7 +108,7 @@ export function modifyHelperUtil(
red("\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n"),
);
Error.stackTraceLimit = 0;
process.exitCode = -1;
process.exitCode = 2;
}
try {
// the configuration stored in .yo-rc.json should already be in the correct
Expand All @@ -126,7 +126,7 @@ export function modifyHelperUtil(
red('\nYour yeoman configuration file (.yo-rc.json) was incorrectly formatted. Deleting it may fix the problem.\n'),
);
Error.stackTraceLimit = 0;
process.exitCode = -1;
process.exitCode = 2;
}

const transformConfig = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/npm-packages-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function npmPackagesExists(pkg: string[]): void {
.catch((err: Error): void => {
console.error(err.stack || err);
// eslint-disable-next-line no-process-exit
process.exit(0);
process.exit(2);
})
.then(resolvePackagesIfReady);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-cli/lib/groups/HelpGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class HelpGroup {
}
} catch (e) {
logger.error('Error: External package not found.');
process.exitCode = 1;
process.exit(2);
}
}

if (commandsUsed.length > 1) {
logger.error('You provided multiple commands. Please use only one command at a time.\n');
process.exit(1);
process.exit(2);
}

if (invalidArgs.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/process-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const logger = require('./logger');

function logErrorAndExit(error) {
if (error && error.stack) logger.error(error.stack);
process.exit(1);
process.exit(error.exitCode);
}

process.on('uncaughtException', (error) => {
Expand Down