Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce CLI --plugin support (#3379)
* introduce CLI --plugin support - provide plugin prefixes as required - support new and old styles of plugin naming Examples: --plugin rollup-plugin-buble --plugin @rollup/plugin-buble --plugin buble -p "@rollup/plugin-replace={DBG:true}" -p node-resolve,commonjs -p "terser={output:{beautify:true}}" -p "/absolute/path/to/plugin={A:1}" -p "../relative/path/to/plugin={B:2}" * Add documentation, fix error handling * Fix markdown formatting * Remove trailing slash * Fix examples in documentation Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
1b5f505
commit 07223eb
Showing
26 changed files
with
286 additions
and
26 deletions.
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
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
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,5 @@ | ||
module.exports = { | ||
description: 'CLI --plugin /absolute/path', | ||
skipIfWindows: true, | ||
command: `echo 'console.log(VALUE);' | rollup -p "\`pwd\`/my-plugin={VALUE: 'absolute', ZZZ: 1}"` | ||
}; |
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("absolute"); |
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,14 @@ | ||
module.exports = function(options) { | ||
if (options === void 0) options = {}; | ||
return { | ||
transform(code) { | ||
// dumb search and replace for test purposes | ||
for (var key in options) { | ||
const rx = new RegExp(key, 'g'); | ||
const value = JSON.stringify(options[key]); | ||
code = code.replace(rx, value); | ||
} | ||
return code; | ||
} | ||
}; | ||
}; |
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: 'advanced CLI --plugin functionality with rollup config', | ||
skipIfWindows: true, | ||
command: `rollup -c -p node-resolve,commonjs -p "terser={output: {beautify: true, indent_level: 2}}"` | ||
}; |
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 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
|
||
var t = function() { | ||
function t(t) { | ||
this.x = t; | ||
} | ||
return t.prototype.output = function() { | ||
var t; | ||
t = this.x, console.log(t); | ||
}, t; | ||
}(); | ||
|
||
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,13 @@ | ||
var t = function() { | ||
function t(t) { | ||
this.x = t; | ||
} | ||
return t.prototype.output = function() { | ||
var t; | ||
t = this.x, console.log(t); | ||
}, t; | ||
}(); | ||
|
||
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,4 @@ | ||
import {Foo} from "foo"; | ||
var foo = new Foo(123); | ||
foo.output(); | ||
export {Foo as Bar}; |
10 changes: 10 additions & 0 deletions
10
test/cli/samples/plugin/advanced/node_modules/foo/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 @@ | ||
module.exports = { | ||
description: 'basic CLI --plugin functionality', | ||
command: `rollup main.js -f cjs --plugin rollup-plugin-buble` | ||
}; |
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,14 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var Bar = function Bar(x) { | ||
this.x = value; | ||
}; | ||
Bar.prototype.value = function value () { | ||
return this.x; | ||
}; | ||
var bar = new Bar(123); | ||
console.log(bar.value()); | ||
|
||
exports.Bar = 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,10 @@ | ||
export class Bar { | ||
constructor(x) { | ||
this.x = value; | ||
} | ||
value() { | ||
return this.x; | ||
} | ||
} | ||
var bar = new Bar(123); | ||
console.log(bar.value()); |
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,10 @@ | ||
const { assertStderrIncludes } = require('../../../../utils.js'); | ||
|
||
module.exports = { | ||
description: 'unknown CLI --plugin results in an error', | ||
skipIfWindows: true, | ||
command: `echo "console.log(123);" | rollup --plugin foobar`, | ||
error(err) { | ||
assertStderrIncludes(err.message, '[!] Error: Cannot load plugin "foobar"'); | ||
} | ||
}; |
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,10 @@ | ||
const { assertStderrIncludes } = require('../../../../utils.js'); | ||
|
||
module.exports = { | ||
description: 'invalid CLI --plugin argument format', | ||
skipIfWindows: true, | ||
command: `echo "console.log(123);" | rollup --plugin 'foo bar'`, | ||
error(err) { | ||
assertStderrIncludes(err.message, '[!] Error: Invalid --plugin argument format: "foo 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,5 @@ | ||
module.exports = { | ||
description: 'CLI --plugin object', | ||
skipIfWindows: true, | ||
command: `echo 'console.log(42);' | rollup -f cjs -p '{transform: c => c + String.fromCharCode(10) + c}'` | ||
}; |
Oops, something went wrong.