Repository navigation
feat: add helpful error messages for removed plugins - #6416
Conversation
TheLarkInn
left a comment
There was a problem hiding this comment.
Will let @ooflorent get a look at this too.
@kingdaro let's:
- Get an issue into GitHub.com/webpack/webpack.js.org that tracks this change. That way when complete, we'll merge those docs, AND then add an issue back to here to update the error message to link back to the docs.
| configurable: false, | ||
| enumerable: true, | ||
| get() { | ||
| throw new Error(errorMessage); |
There was a problem hiding this comment.
throw new Error(`RemovedPluginError: ${errorMessage}`);
ooflorent
left a comment
There was a problem hiding this comment.
Looks good but webpack must be compatible with node 6
| }); | ||
| }; | ||
|
|
||
| defineMissingPluginError( |
There was a problem hiding this comment.
Could you add the following comment before each call?
// TODO remove in webpack 5| }); | ||
|
|
||
| const defineMissingPluginError = (pluginName, errorMessage) => { | ||
| Reflect.defineProperty(exports.optimize, pluginName, { |
There was a problem hiding this comment.
Not available in node 6. Could you use Object.defineProperty instead?
There was a problem hiding this comment.
Reflect actually does appear to be in node 6. I used NVM to test:
PS C:\Users\kingd> nvm install 6.0.0
Downloading node.js version 6.0.0 (64-bit)...
Complete
Creating C:\ProgramData\nvm\temp
Downloading npm version 3.8.6... Complete
Installing npm v3.8.6...
Installation complete. If you want to use this version, type
nvm use 6.0.0
PS C:\Users\kingd> nvm use 6.0.0
Now using node v6.0.0 (64-bit)
PS C:\Users\kingd> node -v
v6.0.0
PS C:\Users\kingd> node
> Reflect
Reflect
{}
> Reflect.defineProperty
[Function: defineProperty]
There was a problem hiding this comment.
Reflect is preferred since it doesn't throw like Object.defineProperty does.
There was a problem hiding this comment.
Nevermind. When zoomed in, node.green table is messed up.
| }; | ||
|
|
||
| // TODO remove in webpack 5 | ||
| defineMissingPluginError( |
There was a problem hiding this comment.
pass exports.optimize as first argument, so we could define missing plugins for other categories too.
| configurable: false, | ||
| enumerable: true, | ||
| get() { | ||
| throw new Error(`RemovedPluginError: ${errorMessage}`); |
There was a problem hiding this comment.
Make it a Error class: RemovedPluginError
There was a problem hiding this comment.
Should I write that inline here, or put it in a separate file somewhere?
EDIT: I see there're a bunch of other error classes as well, so I'll just make a top-level file for it in lib like the rest.
|
@kingdaro Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
webpack test suite is not really straightforward to work with 😅 |
| @@ -0,0 +1,3 @@ | |||
| "use strict"; | |||
|
|
|||
| module.exports = class RemovedPluginError extends Error {}; | |||
There was a problem hiding this comment.
inherit from WebpackError, take a look on how the other errors do that
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
|
It looks like this Pull Request doesn't include enough test cases (based on Code Coverage analysis of the PR diff). A PR need to be covered by tests if you add a new feature (we want to make sure that your feature is working) or if you fix a bug (we want to make sure that we don't run into a regression in future). @kingdaro Please check if this is appliable to your PR and if you can add more test cases. Read the test readme for details how to write test cases. |
|
Thanks |
|
Congrats on your first webpack contribution!!!!!! 🎉🎉🎉🎉🎉 |
What kind of change does this PR introduce?
Gives helpful error messages when accessing removed plugins from v3.
TODO:
Include links to relevant documentationWill create an issue on webpack.js.org repo to track thisDid you add tests for your changes?
Yes
Summary
The current behavior will produce an error like "TypeError: webpack.optimize.UglifyJsPlugin is not a constructor". This PR gives a more appropriate message to point the user in the right direction.
See #6409 (comment)
Does this PR introduce a breaking change?
No