Skip to content

Commit

Permalink
fix: using vec to keep input options order (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Nov 10, 2023
1 parent e878c3b commit 4e4f20a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
6 changes: 5 additions & 1 deletion crates/rolldown_binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export interface ResolveIdResult {
export interface SourceResult {
code: string
}
export interface InputItem {
name?: string
import: string
}
export interface InputOptions {
input: Record<string, string>
input: Array<InputItem>
plugins: Array<PluginOptions>
cwd: string
}
Expand Down
26 changes: 17 additions & 9 deletions crates/rolldown_binding/src/options/input_options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;
mod plugin;
mod plugin_adapter;
use napi_derive::napi;
Expand All @@ -9,6 +9,20 @@ use crate::options::input_options::plugin_adapter::JsAdapterPlugin;

use self::plugin::PluginOptions;

#[napi(object)]
#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct InputItem {
pub name: Option<String>,
pub import: String,
}

impl From<InputItem> for rolldown::InputItem {
fn from(value: InputItem) -> Self {
Self { name: value.name, import: value.import }
}
}

#[napi(object)]
#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
Expand All @@ -23,7 +37,7 @@ pub struct InputOptions {
// context?: string;sssssssssss
// experimentalCacheExpiry?: number;
// pub external: ExternalOption,
pub input: HashMap<String, String>,
pub input: Vec<InputItem>,
// makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
// /** @deprecated Use the "manualChunks" output option instead. */
// manualChunks?: ManualChunksOption;
Expand Down Expand Up @@ -59,13 +73,7 @@ pub fn resolve_input_options(

Ok((
rolldown::InputOptions {
input: Some(
opts
.input
.into_iter()
.map(|(name, import)| rolldown::InputItem { name: Some(name), import })
.collect::<Vec<_>>(),
),
input: Some(opts.input.into_iter().map(Into::into).collect::<Vec<_>>()),
cwd: Some(cwd),
},
plugins,
Expand Down
17 changes: 10 additions & 7 deletions packages/rolldown-core/src/options/input-options-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ function normalizeInput(
input: NormalizedInputOptions['input'],
): BindingInputOptions['input'] {
if (Array.isArray(input)) {
return Object.fromEntries(
input.map((src) => {
const name = path.parse(src).name
return [name, src]
}),
)
return input.map((src) => {
const name = path.parse(src).name
return {
name,
import: src,
}
})
} else {
return input
return Object.entries(input).map((value) => {
return { name: value[0], import: value[1] }
})
}
}

0 comments on commit 4e4f20a

Please sign in to comment.