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: check webpack installation before running cli #1827

Merged
merged 8 commits into from Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions packages/package-utils/package.json
Expand Up @@ -44,6 +44,9 @@
"@types/cross-spawn": "6.0.1"
},
"peerDependenciesMeta": {
"webpack": {
"optional": true
},
"@webpack-cli/info": {
"optional": true
},
Expand Down
15 changes: 12 additions & 3 deletions packages/webpack-cli/bin/cli.js
Expand Up @@ -4,13 +4,22 @@
require('v8-compile-cache');
const importLocal = require('import-local');
const runCLI = require('../lib/bootstrap');
const { yellow } = require('colorette');
const { error } = require('../lib/utils/logger');
const { packageExists, promptInstallation } = require('@webpack-cli/package-utils');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we add package-utils in deps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Already present.

"@webpack-cli/package-utils": "^1.0.1-rc.0",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these utils are only being used by webpack-cli, So we can safely move it from package-utils to utils. Let's do this in separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1822 will solve this


// Prefer the local installation of webpack-cli
if (importLocal(__filename)) {
return;
}
process.title = 'webpack';

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

runCLI(rawArgs);
if (packageExists('webpack')) {
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
const [, , ...rawArgs] = process.argv;
runCLI(rawArgs);
} else {
promptInstallation('webpack', () => {
error(`It looks like ${yellow('webpack')} is not installed.`);
});
return;
}
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/Compiler.js
@@ -1,4 +1,5 @@
const webpack = require('webpack');
const { packageExists } = require('@webpack-cli/package-utils');
const webpack = packageExists('webpack') ? require('webpack') : undefined;
const logger = require('./logger');
const bailAndWatchWarning = require('./warnings/bailAndWatchWarning');
const { CompilerOutput } = require('./CompilerOutput');
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
@@ -1,4 +1,5 @@
const { cli } = require('webpack');
const { packageExists } = require('@webpack-cli/package-utils');
const cli = packageExists('webpack') ? require('webpack').cli : undefined;

const HELP_GROUP = 'help';
const CONFIG_GROUP = 'config';
Expand Down