Strip rollup-plugin prefix to find named plugin exports, throw when export cannot be found#3647
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via or load it into the REPL: |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
|
||
| function getCamelizedPluginBaseName(pluginText: string): string { | ||
| return pluginText | ||
| .match(/^(@rollup\/plugin-|rollup-plugin-)?(.*)$/)![2] |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Makes sense. I will add some changes.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #3646
Description
This will improve how Rollup handles exports of plugins passed via the
--pluginoption to detect a potential named export (if no "default" export is available):rollup-plugin-or@rollup/plugin-prefix it will be stripped\or/., it will only take the part before the first.my-plugin-name) to camel case (myPluginName)E.g.
rollup-plugin-terser: Checkterser@rollup/plugin-node-resolve: ChecknodeResolve./path/to/my-awesome-plugin: CheckmyAwesomePlugin./path/to/my-awesome-plugin.js: CheckmyAwesomePluginFurthermore if no sensible export can be found, it now throws an error indicating exactly which exports were tried.