-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support output plugins (#2916)
<!-- Thank you for contributing! --> ### Description <!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
- Loading branch information
Showing
12 changed files
with
89 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { asyncFlatten } from './async-flatten' | ||
import type { RolldownPlugin } from '../plugin' | ||
import type { RolldownPlugin, RolldownOutputPlugin } from '../plugin' | ||
import type { InputOptions } from '../options/input-options' | ||
import type { OutputOptions, OutputPlugin } from '../rollup-types' | ||
import type { OutputOptions } from '../options/output-options' | ||
|
||
export const normalizePluginOption: { | ||
(plugins: InputOptions['plugins']): Promise<RolldownPlugin[]> | ||
(plugins: OutputOptions['plugins']): Promise<OutputPlugin[]> | ||
(plugins: OutputOptions['plugins']): Promise<RolldownOutputPlugin[]> | ||
(plugins: unknown): Promise<any[]> | ||
} = async (plugins: any) => (await asyncFlatten([plugins])).filter(Boolean) |
32 changes: 32 additions & 0 deletions
32
packages/rolldown/tests/fixtures/plugin/output-plugins/_config.ts
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,32 @@ | ||
import { defineTest } from '@tests' | ||
import { getOutputChunk } from '@tests/utils' | ||
import { expect, vi } from 'vitest' | ||
|
||
const fn = vi.fn() | ||
const renderStartFn = vi.fn() | ||
|
||
export default defineTest({ | ||
skipComposingJsPlugin: true, // Here mutate the test config at non-skipComposingJsPlugin test will be next skipComposingJsPlugin test failed. | ||
config: { | ||
output: { | ||
plugins: [ | ||
{ | ||
name: 'test-plugin', | ||
outputOptions: function (options) { | ||
expect(options.banner).toBeUndefined() | ||
options.banner = '/* banner */' | ||
fn() | ||
return options | ||
}, | ||
renderStart: renderStartFn, | ||
}, | ||
], | ||
}, | ||
}, | ||
afterTest: (output) => { | ||
expect(renderStartFn).toHaveBeenCalledTimes(1) | ||
expect(fn).toHaveBeenCalledTimes(1) | ||
const chunk = getOutputChunk(output)[0] | ||
expect(chunk.code.includes('banner')).toBe(true) | ||
}, | ||
}) |
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
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