Skip to content

Commit

Permalink
fix: nested plugin in options stage (#4668)
Browse files Browse the repository at this point in the history
* fix: nested plugin in options stage

* chore: remove unused
  • Loading branch information
sxzz committed Oct 14, 2022
1 parent a1f9e4b commit 53de5b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/rollup/rollup.ts
Expand Up @@ -3,7 +3,6 @@ import Bundle from '../Bundle';
import Graph from '../Graph';
import type { PluginDriver } from '../utils/PluginDriver';
import { getSortedValidatedPlugins } from '../utils/PluginDriver';
import { ensureArray } from '../utils/ensureArray';
import {
error,
errorAlreadyClosed,
Expand All @@ -15,6 +14,7 @@ import { promises as fs } from '../utils/fs';
import { catchUnfinishedHookActions } from '../utils/hookActions';
import { normalizeInputOptions } from '../utils/options/normalizeInputOptions';
import { normalizeOutputOptions } from '../utils/options/normalizeOutputOptions';
import { normalizePluginOption } from '../utils/options/options';
import { dirname, resolve } from '../utils/path';
import { ANONYMOUS_OUTPUT_PLUGIN_PREFIX, ANONYMOUS_PLUGIN_PREFIX } from '../utils/pluginUtils';
import { getTimings, initialiseTimers, timeEnd, timeStart } from '../utils/timers';
Expand Down Expand Up @@ -111,7 +111,7 @@ async function getInputOptions(
}
const rawPlugins = getSortedValidatedPlugins(
'options',
ensureArray(rawInputOptions.plugins) as Plugin[]
normalizePluginOption(rawInputOptions.plugins)
);
const { options, unsetOptions } = normalizeInputOptions(
await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions))
Expand Down Expand Up @@ -188,7 +188,7 @@ function getOutputOptionsAndPluginDriver(
if (!rawOutputOptions) {
throw new Error('You must supply an options object');
}
const rawPlugins = ensureArray(rawOutputOptions.plugins) as Plugin[];
const rawPlugins = normalizePluginOption(rawOutputOptions.plugins);
normalizePlugins(rawPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX);
const outputPluginDriver = inputPluginDriver.createOutputPluginDriver(rawPlugins);

Expand Down
28 changes: 15 additions & 13 deletions test/function/samples/nested-plugin/_config.js
@@ -1,22 +1,24 @@
const plugin = [
{
name: 'nested-plugin-1',
transform(code) {
return code.replace('foo = 1', 'foo = 2');
}
const pluginA = {
name: 'nested-plugin-1',
options(options) {
options.plugins.push(pluginB);
},
{
name: 'nested-plugin-2',
transform(code) {
return code.replace('answer = 41', 'answer = 42');
}
transform(code) {
return code.replace('foo = 1', 'foo = 2');
}
];
};

const pluginB = {
name: 'nested-plugin-2',
transform(code) {
return code.replace('answer = 41', 'answer = 42');
}
};

module.exports = {
description: 'works when nested plugin',
options: {
// eslint-disable-next-line no-sparse-arrays
plugins: [plugin, [undefined, [null]], ,]
plugins: [[pluginA], [undefined, [null]], ,]
}
};

0 comments on commit 53de5b0

Please sign in to comment.