Skip to content

Commit

Permalink
feat(napi): update the doc and type for tsconfig references (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Dec 14, 2023
1 parent 65ae704 commit 852240d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ export interface TsconfigOptions {
configFile: string
/**
* Support for Typescript Project References.
* For the type TsconfigReferences
*
* * `'auto'`: use the `references` field from tsconfig of `config_file`.
* * `string[]`: manually provided relative or absolute path.
*/
references: 'disabled'| 'auto' | 'Array<string>'
references?: 'auto' | string[]
}
export interface ResolveResult {
path?: string
Expand Down
20 changes: 10 additions & 10 deletions napi/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ pub struct TsconfigOptions {
/// * a relative path to the configuration file. It will be resolved relative to cwd.
/// * an absolute path to the configuration file.
pub config_file: String,

/// Support for Typescript Project References.
/// alias type for [oxc_resolver::TsconfigReferences], cause napi does't support structured
/// enum
#[napi(ts_type = "'disabled'| 'auto' | 'Array<string>'")]
pub references: Either<String, Vec<String>>,
///
/// * `'auto'`: use the `references` field from tsconfig of `config_file`.
/// * `string[]`: manually provided relative or absolute path.
#[napi(ts_type = "'auto' | string[]")]
pub references: Option<Either<String, Vec<String>>>,
}

impl Into<oxc_resolver::Restriction> for Restriction {
Expand Down Expand Up @@ -218,18 +220,16 @@ impl Into<oxc_resolver::TsconfigOptions> for TsconfigOptions {
oxc_resolver::TsconfigOptions {
config_file: PathBuf::from(self.config_file),
references: match self.references {
Either::A(string) if string.as_str() == "disabled" => {
oxc_resolver::TsconfigReferences::Disabled
}
Either::A(string) if string.as_str() == "auto" => {
Some(Either::A(string)) if string.as_str() == "auto" => {
oxc_resolver::TsconfigReferences::Auto
}
Either::A(opt) => {
Some(Either::A(opt)) => {
panic!("`{}` is not a valid option for tsconfig references", opt)
}
Either::B(paths) => oxc_resolver::TsconfigReferences::Paths(
Some(Either::B(paths)) => oxc_resolver::TsconfigReferences::Paths(
paths.into_iter().map(PathBuf::from).collect::<Vec<_>>(),
),
None => oxc_resolver::TsconfigReferences::Disabled,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub struct TsconfigOptions {
#[derive(Debug, Clone)]
pub enum TsconfigReferences {
Disabled,
/// Use the `references` field from tsconfig read from `config_file`.
/// Use the `references` field from tsconfig of `config_file`.
Auto,
/// Manually provided relative or absolute path.
Paths(Vec<PathBuf>),
Expand Down

0 comments on commit 852240d

Please sign in to comment.