Skip to content

Commit

Permalink
fix: check webpack installation before running cli (#1827)
Browse files Browse the repository at this point in the history
* fix: check webpack installation before running cli

* chore: rephrase message

* chore(package-utils): add webpack to peerDependenciesMeta

* refactor: cli import

* fix: lint

* chore: use logger

Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
  • Loading branch information
snitin315 and rishabh3112 committed Sep 25, 2020
1 parent 77ff99b commit be509fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
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');

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

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

runCLI(rawArgs);
if (packageExists('webpack')) {
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 BASIC_GROUP = 'basic';
Expand Down

0 comments on commit be509fa

Please sign in to comment.