Skip to content

Commit c7dc5ce

Browse files
committed
feat: change the syntax for providing options from scratch
BREAKING CHANGE to provide configs for a plugin from scratch, pass false as the third input. Also deprecates passing extra plugins to `createPlugins`
1 parent e4b294f commit c7dc5ce

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,32 @@ terser (in production)
8888
replace (in production)
8989
```
9090

91-
### Override Default Options for the plugins `[name, overriddenOptions, true]`
91+
### Override Default Options for the plugins `[name, overriddenOptions]`
9292

93-
You can pass an input plugin with the overridden options using the `[name, overriddenOptions, true]` syntax.
93+
You can pass an input plugin with the overridden options using the `[name, overriddenOptions]` syntax.
9494

9595
```ts
96-
const plugins = createPlugins([
97-
["ts", { tsconfig: "./lib/tsconfig.json" }, true], // third element makes the config merge to and override the default options
98-
"js",
99-
])
96+
const plugins = createPlugins([["ts", { tsconfig: "./lib/tsconfig.json" }], "js"])
10097
```
10198

102-
The difference with the next syntax is that these are merged into the default options and if there is a config with the same name, they override it, but the next syntax completely replaces the default options.
99+
### Completely New Options for the plugins `[name, newOptions, false]`
103100

104-
### Completely New Options for the plugins `[name, newOptions]`
105-
106-
You can pass an input plugin with their supported option using the `[name, newOptions]` syntax:
101+
You can pass an input plugin with their supported option using the `[name, newOptions, false]` syntax:
107102

108103
```ts
109104
const plugins = createPlugins([
110-
["ts", { tsconfig: "./lib/tsconfig.json", noEmitOnError: false, module: "ESNext" }],
105+
["ts", { tsconfig: "./lib/tsconfig.json", noEmitOnError: false, module: "ESNext" }, false],
111106
"js",
112107
])
113108
```
114109

110+
Passing false as the third argument results in discarding the `rollup-config-atomic` built-in options.
111+
115112
### Adding New Extra Plugins
116113

117-
For adding extra plugins, you can pass them in array to the second argument
114+
For adding extra plugins, you can simply concatenate your plugins with the output of `createPlugins`
118115

119116
```ts
120117
import multyentry from "@rollup/plugin-multi-entry"
121-
createPlugins(["ts"], [multyentry()])
118+
const plugins = [...createPlugins(["ts"]), multyentry()]
122119
```

src/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ export function createPlugins(
132132

133133
// extra plugins
134134
if (extraPlugins !== undefined && typeof extraPlugins === "object" /*array*/) {
135+
console.warn(
136+
"Passing extra plugins to `createPlugins` is deprecated. Instead concatenate the output of `createPlugins` with your extra plugins."
137+
)
135138
try {
136139
plugins.push(...extraPlugins)
137140
} catch (e) {
@@ -225,7 +228,10 @@ export function createPlugins(
225228
if (typeof inputPluginsNames[index] === "string") {
226229
// plugin name only
227230
plugins.push(pluginFunction(pluginDefaultOptions))
228-
} else if (typeof inputPluginsNames[index][2] === "boolean" && inputPluginsNames[index][2] === true) {
231+
} else if (inputPluginsNames[index].length == 3 && inputPluginsNames[index][2] === false) {
232+
// plugin with options from scratch
233+
plugins.push(pluginFunction(inputPluginsNames[index][1]))
234+
} else {
229235
// plugin with options that override pluginDefaultOptions
230236
const pluginOptions = inputPluginsNames[index][1]
231237
plugins.push(
@@ -235,9 +241,6 @@ export function createPlugins(
235241
: { ...pluginDefaultOptions, pluginOptions }
236242
)
237243
)
238-
} else {
239-
// plugin with options
240-
plugins.push(pluginFunction(inputPluginsNames[index][1]))
241244
}
242245
} else if (includeByDefault) {
243246
const pluginFunction = getPluginFunction(require(moduleName), prop)

0 commit comments

Comments
 (0)