Skip to content

feat: add helpful error messages for removed plugins - #6416

Merged
sokra merged 13 commits into
webpack:nextfrom
itsMapleLeaf:removed-plugin-errors
Feb 5, 2018
Merged

sokra merged 13 commits into
webpack:nextfrom
itsMapleLeaf:removed-plugin-errors

Conversation

@itsMapleLeaf

@itsMapleLeaf itsMapleLeaf commented Jan 30, 2018 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Gives helpful error messages when accessing removed plugins from v3.

TODO:

  • Tests
  • Include links to relevant documentation Will create an issue on webpack.js.org repo to track this

Did 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

@TheLarkInn TheLarkInn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/webpack.js Outdated
configurable: false,
enumerable: true,
get() {
throw new Error(errorMessage);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new Error(`RemovedPluginError: ${errorMessage}`);

@ooflorent ooflorent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but webpack must be compatible with node 6

Comment thread lib/webpack.js
});
};

defineMissingPluginError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the following comment before each call?

// TODO remove in webpack 5

Comment thread lib/webpack.js Outdated
});

const defineMissingPluginError = (pluginName, errorMessage) => {
Reflect.defineProperty(exports.optimize, pluginName, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not available in node 6. Could you use Object.defineProperty instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect is preferred since it doesn't throw like Object.defineProperty does.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. When zoomed in, node.green table is messed up.

Comment thread lib/webpack.js
};

// TODO remove in webpack 5
defineMissingPluginError(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass exports.optimize as first argument, so we could define missing plugins for other categories too.

Comment thread lib/webpack.js Outdated
configurable: false,
enumerable: true,
get() {
throw new Error(`RemovedPluginError: ${errorMessage}`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a Error class: RemovedPluginError

@itsMapleLeaf itsMapleLeaf Jan 30, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@webpack-bot

Copy link
Copy Markdown
Contributor

@kingdaro Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@ooflorent

Copy link
Copy Markdown
Contributor

I initially misunderstood where it was supposed to go.

webpack test suite is not really straightforward to work with 😅

@sokra sokra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, small change

Comment thread lib/RemovedPluginError.js Outdated
@@ -0,0 +1,3 @@
"use strict";

module.exports = class RemovedPluginError extends Error {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit from WebpackError, take a look on how the other errors do that

@webpack-bot

Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@webpack-bot

Copy link
Copy Markdown
Contributor

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.

@sokra
sokra merged commit 1de3d48 into webpack:next Feb 5, 2018
@sokra

sokra commented Feb 5, 2018

Copy link
Copy Markdown
Member

Thanks

@TheLarkInn

Copy link
Copy Markdown
Member

Congrats on your first webpack contribution!!!!!! 🎉🎉🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants