Merge pull request #7534 from elliottsj/cli-bin-exec

require() webpack-cli/webpack-command's bin module
This commit is contained in:
Tobias Koppers 2018-06-27 12:56:19 +02:00 committed by GitHub
commit 408c4ca9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -47,6 +47,7 @@ const isInstalled = packageName => {
* @typedef {Object} CliOption
* @property {string} name display name
* @property {string} package npm package name
* @property {string} binName name of the executable file
* @property {string} alias shortcut for choice
* @property {boolean} installed currently installed?
* @property {string} url homepage
@ -58,6 +59,7 @@ const CLIs = [
{
name: "webpack-cli",
package: "webpack-cli",
binName: "webpack-cli",
alias: "cli",
installed: isInstalled("webpack-cli"),
url: "https://github.com/webpack/webpack-cli",
@ -66,6 +68,7 @@ const CLIs = [
{
name: "webpack-command",
package: "webpack-command",
binName: "webpack-command",
alias: "command",
installed: isInstalled("webpack-command"),
url: "https://github.com/webpack-contrib/webpack-command",
@ -154,7 +157,10 @@ if (installedClis.length === 0) {
});
});
} else if (installedClis.length === 1) {
require(installedClis[0].package); // eslint-disable-line
const path = require("path");
const pkgPath = require.resolve(`${installedClis[0].package}/package.json`);
const pkg = require(pkgPath); // eslint-disable-line
require(path.resolve(path.dirname(pkgPath), pkg.bin[installedClis[0].binName])); // eslint-disable-line
} else {
console.warn(
`You have installed ${installedClis