Skip to content

Commit

Permalink
feat(node/rollup-compat): add properties used by Vite to `NormalizedO…
Browse files Browse the repository at this point in the history
…utputOptions` (#2907)

<!-- Thank you for contributing! -->

### Description

refs #2867, #2906

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
  • Loading branch information
sapphi-red authored Nov 25, 2024
1 parent 87f7277 commit 62a9ed2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 48 deletions.
21 changes: 21 additions & 0 deletions crates/rolldown_binding/src/types/binding_normalized_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ impl BindingNormalizedOptions {
}
}

#[napi(getter)]
pub fn dir(&self) -> Option<String> {
// NOTE: rollup returns undefined when `dir` is not set
Some(self.inner.dir.clone())
}

// For `Fn` variant, we can't convert it to JS, so we just return `None`.
#[napi(getter)]
pub fn entry_filenames(&self) -> Option<String> {
Expand All @@ -65,4 +71,19 @@ impl BindingNormalizedOptions {
rolldown::OutputFormat::Umd => "umd".to_string(),
}
}

#[napi(getter)]
pub fn inline_dynamic_imports(&self) -> bool {
self.inner.inline_dynamic_imports
}

#[napi(getter, ts_return_type = "boolean | 'inline' | 'hidden'")]
pub fn sourcemap(&self) -> Either<bool, String> {
match self.inner.sourcemap {
Some(rolldown::SourceMapType::File) => Either::A(true),
Some(rolldown::SourceMapType::Hidden) => Either::B("hidden".to_string()),
Some(rolldown::SourceMapType::Inline) => Either::B("inline".to_string()),
None => Either::A(false),
}
}
}
3 changes: 3 additions & 0 deletions packages/rolldown/src/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export declare class BindingModuleInfo {
export declare class BindingNormalizedOptions {
get shimMissingExports(): boolean
get input(): Array<string> | Record<string, string>
get dir(): string | null
get entryFilenames(): string | null
get format(): 'es' | 'cjs' | 'app' | 'iife' | 'umd'
get inlineDynamicImports(): boolean
get sourcemap(): boolean | 'inline' | 'hidden'
}

export declare class BindingOutputAsset {
Expand Down
15 changes: 15 additions & 0 deletions packages/rolldown/src/options/normalized-output-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { ChunkFileNamesFunction } from './output-options'
export type InternalModuleFormat = 'es' | 'cjs' | 'iife' | 'umd' | 'app'

export interface NormalizedOutputOptions {
dir: string | undefined
entryFileNames: string | ChunkFileNamesFunction
format: InternalModuleFormat
inlineDynamicImports: boolean
sourcemap: boolean | 'inline' | 'hidden'
}

// TODO: I guess we make these getters enumerable so it act more like a plain object
Expand All @@ -16,6 +19,10 @@ export class NormalizedOutputOptionsImpl implements NormalizedOutputOptions {
this.inner = inner
}

get dir() {
return this.inner.dir ?? undefined
}

get entryFileNames() {
return (
this.inner.entryFilenames ||
Expand All @@ -28,4 +35,12 @@ export class NormalizedOutputOptionsImpl implements NormalizedOutputOptions {
get format() {
return this.inner.format
}

get inlineDynamicImports() {
return this.inner.inlineDynamicImports
}

get sourcemap() {
return this.inner.sourcemap
}
}
48 changes: 24 additions & 24 deletions packages/rolldown/src/rolldown-binding.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,30 @@ function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__BindingModuleInfo_struct_81']?.()
__napiInstance.exports['__napi_register__BindingModuleInfo_impl_83']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_struct_84']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_impl_89']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_struct_90']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_impl_95']?.()
__napiInstance.exports['__napi_register__JsOutputAsset_struct_96']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_struct_97']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_impl_112']?.()
__napiInstance.exports['__napi_register__JsOutputChunk_struct_113']?.()
__napiInstance.exports['__napi_register__BindingOutputs_struct_114']?.()
__napiInstance.exports['__napi_register__BindingOutputs_impl_118']?.()
__napiInstance.exports['__napi_register__JsChangedOutputs_struct_119']?.()
__napiInstance.exports['__napi_register__PreRenderedChunk_struct_120']?.()
__napiInstance.exports['__napi_register__RenderedChunk_struct_121']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_struct_122']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_impl_124']?.()
__napiInstance.exports['__napi_register__AliasItem_struct_125']?.()
__napiInstance.exports['__napi_register__ExtensionAliasItem_struct_126']?.()
__napiInstance.exports['__napi_register__BindingSourcemap_struct_127']?.()
__napiInstance.exports['__napi_register__BindingJsonSourcemap_struct_128']?.()
__napiInstance.exports['__napi_register__BindingWatcher_struct_129']?.()
__napiInstance.exports['__napi_register__BindingWatcher_impl_132']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_struct_133']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_impl_139']?.()
__napiInstance.exports['__napi_register__BindingWatcherChangeData_struct_140']?.()
__napiInstance.exports['__napi_register__BindingBundleEndEventData_struct_141']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_impl_92']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_struct_93']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_impl_98']?.()
__napiInstance.exports['__napi_register__JsOutputAsset_struct_99']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_struct_100']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_impl_115']?.()
__napiInstance.exports['__napi_register__JsOutputChunk_struct_116']?.()
__napiInstance.exports['__napi_register__BindingOutputs_struct_117']?.()
__napiInstance.exports['__napi_register__BindingOutputs_impl_121']?.()
__napiInstance.exports['__napi_register__JsChangedOutputs_struct_122']?.()
__napiInstance.exports['__napi_register__PreRenderedChunk_struct_123']?.()
__napiInstance.exports['__napi_register__RenderedChunk_struct_124']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_struct_125']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_impl_127']?.()
__napiInstance.exports['__napi_register__AliasItem_struct_128']?.()
__napiInstance.exports['__napi_register__ExtensionAliasItem_struct_129']?.()
__napiInstance.exports['__napi_register__BindingSourcemap_struct_130']?.()
__napiInstance.exports['__napi_register__BindingJsonSourcemap_struct_131']?.()
__napiInstance.exports['__napi_register__BindingWatcher_struct_132']?.()
__napiInstance.exports['__napi_register__BindingWatcher_impl_135']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_struct_136']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_impl_142']?.()
__napiInstance.exports['__napi_register__BindingWatcherChangeData_struct_143']?.()
__napiInstance.exports['__napi_register__BindingBundleEndEventData_struct_144']?.()
}
export const BindingBundleEndEventData = __napiModule.exports.BindingBundleEndEventData
export const BindingCallableBuiltinPlugin = __napiModule.exports.BindingCallableBuiltinPlugin
Expand Down
48 changes: 24 additions & 24 deletions packages/rolldown/src/rolldown-binding.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,30 @@ function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__BindingModuleInfo_struct_81']?.()
__napiInstance.exports['__napi_register__BindingModuleInfo_impl_83']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_struct_84']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_impl_89']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_struct_90']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_impl_95']?.()
__napiInstance.exports['__napi_register__JsOutputAsset_struct_96']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_struct_97']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_impl_112']?.()
__napiInstance.exports['__napi_register__JsOutputChunk_struct_113']?.()
__napiInstance.exports['__napi_register__BindingOutputs_struct_114']?.()
__napiInstance.exports['__napi_register__BindingOutputs_impl_118']?.()
__napiInstance.exports['__napi_register__JsChangedOutputs_struct_119']?.()
__napiInstance.exports['__napi_register__PreRenderedChunk_struct_120']?.()
__napiInstance.exports['__napi_register__RenderedChunk_struct_121']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_struct_122']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_impl_124']?.()
__napiInstance.exports['__napi_register__AliasItem_struct_125']?.()
__napiInstance.exports['__napi_register__ExtensionAliasItem_struct_126']?.()
__napiInstance.exports['__napi_register__BindingSourcemap_struct_127']?.()
__napiInstance.exports['__napi_register__BindingJsonSourcemap_struct_128']?.()
__napiInstance.exports['__napi_register__BindingWatcher_struct_129']?.()
__napiInstance.exports['__napi_register__BindingWatcher_impl_132']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_struct_133']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_impl_139']?.()
__napiInstance.exports['__napi_register__BindingWatcherChangeData_struct_140']?.()
__napiInstance.exports['__napi_register__BindingBundleEndEventData_struct_141']?.()
__napiInstance.exports['__napi_register__BindingNormalizedOptions_impl_92']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_struct_93']?.()
__napiInstance.exports['__napi_register__BindingOutputAsset_impl_98']?.()
__napiInstance.exports['__napi_register__JsOutputAsset_struct_99']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_struct_100']?.()
__napiInstance.exports['__napi_register__BindingOutputChunk_impl_115']?.()
__napiInstance.exports['__napi_register__JsOutputChunk_struct_116']?.()
__napiInstance.exports['__napi_register__BindingOutputs_struct_117']?.()
__napiInstance.exports['__napi_register__BindingOutputs_impl_121']?.()
__napiInstance.exports['__napi_register__JsChangedOutputs_struct_122']?.()
__napiInstance.exports['__napi_register__PreRenderedChunk_struct_123']?.()
__napiInstance.exports['__napi_register__RenderedChunk_struct_124']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_struct_125']?.()
__napiInstance.exports['__napi_register__BindingRenderedModule_impl_127']?.()
__napiInstance.exports['__napi_register__AliasItem_struct_128']?.()
__napiInstance.exports['__napi_register__ExtensionAliasItem_struct_129']?.()
__napiInstance.exports['__napi_register__BindingSourcemap_struct_130']?.()
__napiInstance.exports['__napi_register__BindingJsonSourcemap_struct_131']?.()
__napiInstance.exports['__napi_register__BindingWatcher_struct_132']?.()
__napiInstance.exports['__napi_register__BindingWatcher_impl_135']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_struct_136']?.()
__napiInstance.exports['__napi_register__BindingWatcherEvent_impl_142']?.()
__napiInstance.exports['__napi_register__BindingWatcherChangeData_struct_143']?.()
__napiInstance.exports['__napi_register__BindingBundleEndEventData_struct_144']?.()
}
module.exports.BindingBundleEndEventData = __napiModule.exports.BindingBundleEndEventData
module.exports.BindingCallableBuiltinPlugin = __napiModule.exports.BindingCallableBuiltinPlugin
Expand Down

0 comments on commit 62a9ed2

Please sign in to comment.