Skip to content

Commit 64ca4c4

Browse files
committed
feat: don't normalize options on js side - part2
1 parent 0d4ac61 commit 64ca4c4

File tree

5 files changed

+42
-104
lines changed

5 files changed

+42
-104
lines changed

packages/rolldown/src/options/bindingify-output-options.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export function bindingifyOutputOptions(
3535
exports,
3636
hashCharacters,
3737
sourcemap: bindingifySourcemap(sourcemap),
38-
sourcemapIgnoreList,
38+
sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
3939
sourcemapPathTransform,
40-
banner,
41-
footer,
42-
intro,
43-
outro,
40+
banner: bindingifyAddon(banner),
41+
footer: bindingifyAddon(footer),
42+
intro: bindingifyAddon(intro),
43+
outro: bindingifyAddon(outro),
4444
extend: outputOptions.extend,
4545
globals,
4646
esModule,
@@ -59,6 +59,19 @@ export function bindingifyOutputOptions(
5959
}
6060
}
6161

62+
type AddonKeys = 'banner' | 'footer' | 'intro' | 'outro'
63+
64+
function bindingifyAddon(
65+
configAddon: NormalizedOutputOptions[AddonKeys],
66+
): BindingOutputOptions[AddonKeys] {
67+
return async (chunk) => {
68+
if (typeof configAddon === 'function') {
69+
return configAddon(chunk)
70+
}
71+
return configAddon || ''
72+
}
73+
}
74+
6275
function bindingifyFormat(
6376
format: NormalizedOutputOptions['format'],
6477
): BindingOutputOptions['format'] {
@@ -101,3 +114,14 @@ function bindingifySourcemap(
101114
throw new Error(`unknown sourcemap: ${sourcemap}`)
102115
}
103116
}
117+
118+
function bindingifySourcemapIgnoreList(
119+
sourcemapIgnoreList: NormalizedOutputOptions['sourcemapIgnoreList'],
120+
): BindingOutputOptions['sourcemapIgnoreList'] {
121+
return typeof sourcemapIgnoreList === 'function'
122+
? sourcemapIgnoreList
123+
: sourcemapIgnoreList === false
124+
? () => false
125+
: (relativeSourcePath: string, _sourcemapPath: string) =>
126+
relativeSourcePath.includes('node_modules')
127+
}
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import type { SourcemapIgnoreListOption } from '../rollup'
2-
import type { AddonFunction, OutputOptions } from '../types/output-options'
3-
import type { RolldownPlugin } from '../plugin'
1+
import type { OutputOptions } from '../types/output-options'
42

53
export type InternalModuleFormat = 'es' | 'cjs' | 'iife' | 'umd'
64

7-
export interface NormalizedOutputOptions extends OutputOptions {
8-
plugins: RolldownPlugin[]
9-
sourcemapIgnoreList: SourcemapIgnoreListOption
10-
banner: AddonFunction
11-
footer: AddonFunction
12-
intro: AddonFunction
13-
outro: AddonFunction
14-
}
5+
export interface NormalizedOutputOptions extends OutputOptions {}

packages/rolldown/src/plugin/plugin-driver.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { getLogHandler, normalizeLog } from '../log/logHandler'
22
import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN } from '../log/logging'
33
import { Plugin, RolldownPluginRec } from './'
44
import { error, logPluginError } from '../log/logs'
5-
import { NormalizedInputOptions } from '../options/normalized-input-options'
65
import { RollupError } from '../rollup'
76
import { normalizeHook } from '../utils/normalize-hook'
8-
import { InputOptions, OutputOptions, VERSION } from '..'
7+
import { InputOptions, OutputOptions, RolldownPlugin, VERSION } from '..'
98
import { getLogger, getOnLog } from '../log/logger'
109
import { BuiltinPlugin } from './builtin-plugin'
1110

@@ -73,15 +72,15 @@ export class PluginDriver {
7372
}
7473

7574
public callOutputOptionsHook(
76-
inputOptions: NormalizedInputOptions,
75+
rawPlugins: RolldownPlugin[],
7776
outputOptions: OutputOptions,
7877
): OutputOptions {
79-
const plugins = getSortedPlugins(
78+
const sortedPlugins = getSortedPlugins(
8079
'outputOptions',
81-
getObjectPlugins(inputOptions.plugins),
80+
getObjectPlugins(rawPlugins),
8281
)
8382

84-
for (const plugin of plugins) {
83+
for (const plugin of sortedPlugins) {
8584
const options = plugin.outputOptions
8685
if (options) {
8786
const { handler } = normalizeHook(options)

packages/rolldown/src/utils/create-bundler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { bindingifyInputOptions } from '../options/bindingify-input-options'
22
import { Bundler } from '../binding'
33
import { initializeParallelPlugins } from './initialize-parallel-plugins'
44
import { normalizeInputOptions } from './normalize-input-options'
5-
import { normalizeOutputOptions } from './normalize-output-options'
65
import { bindingifyOutputOptions } from '../options/bindingify-output-options'
76
import { PluginDriver } from '../plugin/plugin-driver'
87
import type { InputOptions } from '../types/input-options'
@@ -27,21 +26,23 @@ export async function createBundler(
2726

2827
try {
2928
outputOptions = pluginDriver.callOutputOptionsHook(
30-
normalizedInputOptions,
29+
normalizedInputOptions.plugins,
3130
outputOptions,
3231
)
33-
const normalizedOutputOptions = normalizeOutputOptions(outputOptions)
3432

3533
// Convert `NormalizedInputOptions` to `BindingInputOptions`
3634
const bindingInputOptions = bindingifyInputOptions(
3735
normalizedInputOptions,
38-
normalizedOutputOptions,
36+
outputOptions,
3937
)
4038

39+
// Convert `NormalizedOutputOptions` to `BindingInputOptions`
40+
const bindingOutputOptions = bindingifyOutputOptions(outputOptions)
41+
4142
return {
4243
bundler: new Bundler(
4344
bindingInputOptions,
44-
bindingifyOutputOptions(normalizedOutputOptions),
45+
bindingOutputOptions,
4546
parallelPluginInitResult?.registry,
4647
),
4748
stopWorkers: parallelPluginInitResult?.stopWorkers,

packages/rolldown/src/utils/normalize-output-options.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)