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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
766228e
Strip rollup-plugin prefix to find named plugin exports, throw when e…
lukastaegert 60d28d1
Also ignore anything after the first "."
lukastaegert 476a7ba
Update dependencies
lukastaegert 6b9b2eb
Cover more cases
lukastaegert 048fd13
Merge branch 'master' into gh-3646-handle-plugin-export-not-found
lukastaegert File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { assertIncludes } = require('../../../../utils.js'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: 'Throws when the plugin export cannot be found', | ||
skipIfWindows: true, | ||
command: `echo 'console.log("ignored");' | rollup -p "./my-missing-plugin"`, | ||
error(err) { | ||
assertIncludes( | ||
err.message, | ||
`[!] Error: Cannot find entry for plugin "${path.join( | ||
__dirname, | ||
'my-missing-plugin' | ||
)}". The plugin needs to export a function either as "default" or "myMissingPlugin" for Rollup to recognize it.` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('transformed'); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
description: 'supports stripping "rollup-config" prefix to find named plugin export', | ||
skipIfWindows: true, | ||
command: `rollup -c -p rollup-plugin-terser` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t){this.x=t};t.prototype.output=function(){console.log(this.x)},new t(123).output(),exports.Bar=t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var t=function(t){this.x=t};t.prototype.output=function(){console.log(this.x)},new t(123).output();export{t as Bar}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Foo { | ||
constructor(x) { | ||
this.x = x; | ||
} | ||
output() { | ||
console.log(this.x); | ||
} | ||
} | ||
|
||
const foo = new Foo(123); | ||
foo.output(); | ||
export { Foo as Bar }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const buble = require('@rollup/plugin-buble'); | ||
|
||
export default { | ||
input: 'main.js', | ||
plugins: [ | ||
buble() | ||
], | ||
output: [ | ||
{ | ||
file: '_actual/cjs.js', | ||
format: 'cjs' | ||
}, | ||
{ | ||
file: '_actual/es.js', | ||
format: 'esm' | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
description: 'handles plugins where the export name is the camelized file name', | ||
skipIfWindows: true, | ||
command: `echo 'console.log("ignored");' | rollup -p "./nested/my-super-plugin.js"` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('transformed'); |
5 changes: 5 additions & 0 deletions
5
test/cli/samples/plugin/relative-camelized/nested/my-super-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.mySuperPlugin = () => ({ | ||
transform() { | ||
return "console.log('transformed')"; | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: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 inrollup-plugin-foo/bar
.(Edited comment)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore the
node_modules
andnode-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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm