Skip to content

Commit

Permalink
feat: Allow pass tsconfig to oxc-resolver via `InputOptions#resolve…
Browse files Browse the repository at this point in the history
…#tsconfigFilename` (#767)

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

### Description

<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
  • Loading branch information
hyf0 committed Apr 6, 2024
1 parent d743a01 commit c304a0d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct BindingResolveOptions {
pub main_files: Option<Vec<String>>,
pub modules: Option<Vec<String>>,
pub symlinks: Option<bool>,
pub tsconfig_filename: Option<String>,
}

impl From<BindingResolveOptions> for rolldown::ResolveOptions {
Expand All @@ -31,6 +32,7 @@ impl From<BindingResolveOptions> for rolldown::ResolveOptions {
main_files: value.main_files,
modules: value.modules,
symlinks: value.symlinks,
tsconfig_filename: value.tsconfig_filename,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pub struct ResolveOptions {
pub main_files: Option<Vec<String>>,
pub modules: Option<Vec<String>>,
pub symlinks: Option<bool>,
pub tsconfig_filename: Option<String>,
}
8 changes: 6 additions & 2 deletions crates/rolldown_resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::path::{Path, PathBuf};
use sugar_path::SugarPathBuf;

use oxc_resolver::{
EnforceExtension, Resolution, ResolveError, ResolveOptions as OxcResolverOptions, ResolverGeneric,
EnforceExtension, Resolution, ResolveError, ResolveOptions as OxcResolverOptions,
ResolverGeneric, TsconfigOptions,
};

#[derive(Debug)]
Expand Down Expand Up @@ -48,7 +49,10 @@ impl<F: FileSystem + Default> Resolver<F> {
});

let resolve_options_with_default_conditions = OxcResolverOptions {
tsconfig: None,
tsconfig: raw_resolve.tsconfig_filename.map(|p| TsconfigOptions {
config_file: p.into(),
references: oxc_resolver::TsconfigReferences::Disabled,
}),
alias: raw_resolve
.alias
.map(|alias| {
Expand Down
6 changes: 6 additions & 0 deletions crates/rolldown_testing/_test.scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@
"boolean",
"null"
]
},
"tsconfigPath": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down
47 changes: 47 additions & 0 deletions packages/bench/src/suites.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nodePath from 'node:path'
import * as esbuild from 'esbuild'
import { PROJECT_ROOT, REPO_ROOT } from './utils.js'
import _ from 'lodash'

Expand Down Expand Up @@ -40,8 +41,54 @@ export const suites = expandSuitesWithDerived([
tsconfig: nodePath.join(REPO_ROOT, './tmp/bench/rome/src/tsconfig.json'),
},
rolldownOptions: {
external: [
'crypto',
'net',
'fs',
'path',
'os',
'stream',
'buffer',
'tty',
'util',
'child_process',
'assert',
'http',
'https',
'url',
'vm',
'readline',
'module',
'zlib',
'inspector',
],
plugins: [
{
name: '@rolldown/plugin-esbuild',
async transform(code, id) {
const ext = nodePath.extname(id)
if (ext === '.ts' || ext === '.tsx') {
const ret = await esbuild.transform(code, {
platform: 'node',
loader: ext === '.tsx' ? 'tsx' : 'ts',
format: 'esm',
target: 'es2020',
sourcemap: true,
})

return {
code: ret.code,
}
}
},
},
],
resolve: {
extensions: ['.ts'],
tsconfigFilename: nodePath.join(
REPO_ROOT,
'./tmp/bench/rome/src/tsconfig.json',
),
},
},
disableBundler: ['rolldown', 'rollup'],
Expand Down
1 change: 1 addition & 0 deletions packages/rolldown/src/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface BindingResolveOptions {
mainFiles?: Array<string>
modules?: Array<string>
symlinks?: boolean
tsconfigFilename?: string
}

export interface RenderedChunk {
Expand Down

0 comments on commit c304a0d

Please sign in to comment.