Skip to content

Commit

Permalink
Merge pull request #7534 from elliottsj/cli-bin-exec
Browse files Browse the repository at this point in the history
require() webpack-cli/webpack-command's bin module
  • Loading branch information
sokra committed Jun 27, 2018
2 parents c384c3f + 2b4ed3d commit 408c4ca
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 408c4ca

Please sign in to comment.