Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions packages/package-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"@types/cross-spawn": "6.0.1"
},
"peerDependenciesMeta": {
"webpack": {
"optional": true
},
"@webpack-cli/info": {
"optional": true
},
Expand Down
14 changes: 11 additions & 3 deletions packages/webpack-cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
require('v8-compile-cache');
const importLocal = require('import-local');
const runCLI = require('../lib/bootstrap');
const { yellow } = require('colorette');
const { packageExists, promptInstallation } = require('@webpack-cli/package-utils');
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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')) {
const [, , ...rawArgs] = process.argv;
runCLI(rawArgs);
} else {
promptInstallation('webpack', () => {
console.error(`It looks like ${yellow('webpack')} is not installed.`);
});
return;
}
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/Compiler.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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