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 CLI after webpack installation #1951

Merged
merged 1 commit into from Oct 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/webpack-cli/bin/cli.js
@@ -1,31 +1,39 @@
#!/usr/bin/env node

'use strict';

require('v8-compile-cache');

const importLocal = require('import-local');
const runCLI = require('../lib/bootstrap');
const { yellow } = require('colorette');
const { error, success } = require('../lib/utils/logger');
const { packageExists } = require('../lib/utils/package-exists');
const { promptInstallation } = require('../lib/utils/prompt-installation');

// Prefer the local installation of webpack-cli
// Prefer the local installation of `webpack-cli`
if (importLocal(__filename)) {
return;
}

process.title = 'webpack';

const [, , ...rawArgs] = process.argv;

if (packageExists('webpack')) {
const [, , ...rawArgs] = process.argv;
runCLI(rawArgs);
} else {
promptInstallation('webpack', () => {
promptInstallation('webpack -W', () => {
error(`It looks like ${yellow('webpack')} is not installed.`);
})
.then(() => success(`${yellow('webpack')} was installed sucessfully.`))
.then(() => {
success(`${yellow('webpack')} was installed sucessfully.`);

runCLI(rawArgs);
})
.catch(() => {
process.exitCode = 2;
error(`Action Interrupted, Please try once again or install ${yellow('webpack')} manually.`);

process.exit(2);
});
return;
}