Skip to content

Commit

Permalink
fix: use appropriate exit codes (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 19, 2020
1 parent 08aaff3 commit 83f73b0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions README.md
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
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
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
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
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
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
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

0 comments on commit 83f73b0

Please sign in to comment.