Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip rollup-plugin prefix to find named plugin exports, throw when export cannot be found #3647

Merged
merged 5 commits into from Jun 26, 2020

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
Resolves #3646

Description

This will improve how Rollup handles exports of plugins passed via the --plugin option to detect a potential named export (if no "default" export is available):

  • If there is a rollup-plugin- or @rollup/plugin- prefix it will be stripped
  • If there is a path, it will only take the part after the last \ or /
  • If there is a ., it will only take the part before the first .
  • The remaining part will be converted from kebab (my-plugin-name) to camel case (myPluginName)

E.g.

  • rollup-plugin-terser: Check terser
  • @rollup/plugin-node-resolve: Check nodeResolve
  • ./path/to/my-awesome-plugin: Check myAwesomePlugin
  • ./path/to/my-awesome-plugin.js: Check myAwesomePlugin

Furthermore if no sensible export can be found, it now throws an error indicating exactly which exports were tried.

@rollup-bot
Copy link
Collaborator

rollup-bot commented Jun 22, 2020

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-3646-handle-plugin-export-not-found

or load it into the REPL:
https://rollupjs.org/repl/?circleci=12132

@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #3647 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3647   +/-   ##
=======================================
  Coverage   96.70%   96.70%           
=======================================
  Files         183      183           
  Lines        6278     6282    +4     
  Branches     1829     1831    +2     
=======================================
+ Hits         6071     6075    +4     
  Misses        105      105           
  Partials      102      102           
Impacted Files Coverage Δ
cli/run/commandPlugins.ts 97.36% <100.00%> (+0.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 981b11c...048fd13. Read the comment docs.


function getCamelizedPluginBaseName(pluginText: string): string {
return pluginText
.match(/^(@rollup\/plugin-|rollup-plugin-)?(.*)$/)![2]
Copy link
Contributor

@kzc kzc Jun 22, 2020

Choose a reason for hiding this comment

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

If the ^ is removed from the regex then paths such as the following could be correctly handled:

./node_modules/@rollup/plugin-node-resolve
/absolute/dir/rollup-plugin-node-resolve

Also, replacing (.*) with (.+) would be better to handle the zero length name case. Or perhaps even ([-\w]+) - has at least one word character with optional dashes. This would exclude slashes such as in rollup-plugin-foo/bar.

(Edited comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather leave filesystem resolution up to node. if we assert a package name, users could alias that package to their file system using package.json

Copy link
Contributor

@kzc kzc Jun 22, 2020

Choose a reason for hiding this comment

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

Ignore the node_modules and node-resolve in the examples - they could be anything. My comment is unrelated to node file resolution. It is solely a --plugin parameter named export entry point parsing issue. The CLI plugin parameter already supports relative and absolute path arguments. Look at the tests for examples.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I will add some changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm

@lukastaegert lukastaegert merged commit b8013f8 into master Jun 26, 2020
@lukastaegert lukastaegert deleted the gh-3646-handle-plugin-export-not-found branch June 26, 2020 19:38
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.

Rollup does not error when full plugin name is passed onto the command line
4 participants