require() webpack-cli/webpack-command's bin module

Rather than require()-ing the "main" module in webpack-cli/
webpack-command, require() the "bin" module.

This avoids the issue described in
https://github.com/webpack-contrib/webpack-command/pull/30
where installing packages in this order results in no output from
./node_modules/.bin/webpack:

    $ npm install webpack-command
    $ npm install webpack
    $ ./node_modules/.bin/webpack
    # exit 0 with no output
This commit is contained in:
Spencer Elliott 2018-06-14 11:39:42 -07:00
parent 02a955b433
commit 2b4ed3d942
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