-
Notifications
You must be signed in to change notification settings - Fork 21
fix: allow invocation from webpack/bin/webpack.js #30
Conversation
Use lib/cli.js as the package.json "main" field so that webpack-command can be invoked via webpack/bin/webpack.js
To repro this issue using pnpm, you can run these commands:
|
Thanks for the PR/Issue 🍺 This is where I start to really dog on alternative package managers that start to redefine the rules. Shouldn't this be something that the As for |
I just tested webpack-command and I think we're affected in our setup as well. This is the way we invoke webpack: node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js --env.production --config config/webpack.prod.js --bail with webpack-command it doesn't print anything :( |
@dhardtke you're kind of off-topic here, and I dare say you're using that in an unintended manner. use the webpack-command bin directly with |
I believe this isn't an issue with pnpm or npm necessarily, although it is a little annoying that neither emits a warning when there are multiple npm install webpack-command
npm install webpack
./node_modules/.bin/webpack --version
# no output I agree that having
Or, another approach could be to rename webpack-command's bin to |
This thread is raising some good points. I was never a fan of webpack's approach to the "things have moved to..." approach. I hope that's removed for webpack v5, and the cli modules can take it from there. I think there's another approach that could be useful; a no-conflict approach. That's something that could be introduced in webpack has a |
That's an interesting idea. Although it doesn't quite feel like something that a well-behaved npm package would do, since you would expect that only npm itself would be changing the contents of |
Not typically, no. |
Rather than require()-ing the "main" module in webpack-cli/ webpack-command, require() the "bin" module. This avoids the issue described in webpack-contrib/webpack-command#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
To summarize the options we've discussed so far:
I have an implementation of option 4 here: webpack/webpack#7534 |
reversible? |
@Legends I'm sure it is. @elliottsj given that you've opened a PR with |
Rather than require()-ing the "main" module in webpack-cli/ webpack-command, require() the "bin" module. This avoids the issue described in webpack-contrib/webpack-command#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
Rather than require()-ing the "main" module in webpack-cli/ webpack-command, require() the "bin" module. This avoids the issue described in webpack-contrib/webpack-command#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
Rather than require()-ing the "main" module in webpack-cli/ webpack-command, require() the "bin" module. This avoids the issue described in webpack-contrib/webpack-command#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 PR contains a:
Motivation / Use-Case
Because both webpack and webpack-command define a
"bin"
called "webpack" in their respective package.json manifests, there is ambiguity over which one will be linked atnode_modules/.bin/webpack
. When using pnpm, it turns out webpack's binary is linked rather than webpack-command's. So whennode_modules/.bin/webpack
is invoked, this is called:This currently causes the command to output nothing because webpack-command's "main" module lib/index.js does not launch the CLI.
Changing the "main" field to reference
lib/cli.js
fixes this issue, the same as how it works for webpack-cli.Breaking Changes
This breaks any consumers of webpack-command which expect
require('webpack-command')
to return the exports oflib/index.js
. To avoid this breaking change, I can think of two approaches:"main": "lib/index.js"
, but do some detection at the module scope oflib/index.js
to detect whether it's being invoked as a CLI. I'm not too sure what this would look like though.webpack/bin/webpack.js
's implementation to import and execute some function exported by webpack-command, instead of relying on the side effects ofrequire(installedClis[0].package);
. This would introduce some inconsistency with how webpack-cli is invoked, so maybe some changes should be made over in webpack-cli too.