Skip to content

Commit f15cdc7

Browse files
authored
Merge branch 'main' into docs/add-external-icon
2 parents d5f4ff4 + 7d7ec52 commit f15cdc7

File tree

22 files changed

+271
-306
lines changed

22 files changed

+271
-306
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ styl = "styl"
4040

4141
[default.extend-identifiers]
4242
IIFEs = "IIFEs"
43+
PnP = "PnP"

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rolldown/src/utils/prepare_build_context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ pub fn prepare_build_context(
269269
}
270270

271271
let tsconfig = raw_options.tsconfig.map(|tsconfig| tsconfig.with_base(&cwd)).unwrap_or_default();
272-
let fs = OsFileSystem::new(raw_resolve.yarn_pnp.is_some_and(|b| b));
272+
let yarn_pnp = raw_resolve.yarn_pnp.unwrap_or(false);
273+
let fs = OsFileSystem::new(yarn_pnp);
273274
let resolver = Arc::new(Resolver::new(fs.clone(), cwd.clone(), platform, &tsconfig, raw_resolve));
274275

275276
let transform_options = {
@@ -339,7 +340,7 @@ pub fn prepare_build_context(
339340
)
340341
} else {
341342
TransformOptions::new_raw(
342-
RawTransformOptions::new(raw_transform_options, v.clone()),
343+
RawTransformOptions::new(raw_transform_options, v.clone(), yarn_pnp),
343344
target,
344345
jsx_preset,
345346
)
@@ -350,7 +351,7 @@ pub fn prepare_build_context(
350351
// Auto mode: Create Raw mode TransformOptions
351352
// Each file will find its nearest tsconfig during compilation
352353
TransformOptions::new_raw(
353-
RawTransformOptions::new(raw_transform_options, v),
354+
RawTransformOptions::new(raw_transform_options, v, yarn_pnp),
354355
target,
355356
jsx_preset,
356357
)

crates/rolldown_binding/src/transform.rs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn enhanced_transform_internal(
4444
source_text: &str,
4545
options: Option<BindingEnhancedTransformOptions>,
4646
cache: Option<&TsconfigCache>,
47+
yarn_pnp: bool,
4748
) -> napi::Result<BindingEnhancedTransformResult> {
4849
let options = options.unwrap_or_default();
4950
let cwd = options
@@ -59,7 +60,7 @@ fn enhanced_transform_internal(
5960
));
6061
}
6162

62-
let result = core_enhanced_transform(filename, source_text, transform_options);
63+
let result = core_enhanced_transform(filename, source_text, transform_options, yarn_pnp);
6364
Ok(BindingEnhancedTransformResult::from_enhanced_transform_result(result, cwd))
6465
}
6566

@@ -68,6 +69,7 @@ pub struct EnhancedTransformTask<'a> {
6869
source_text: String,
6970
options: Option<BindingEnhancedTransformOptions>,
7071
cache: Option<&'a TsconfigCache>,
72+
yarn_pnp: bool,
7173
}
7274

7375
#[napi]
@@ -76,71 +78,49 @@ impl Task for EnhancedTransformTask<'_> {
7678
type Output = BindingEnhancedTransformResult;
7779

7880
fn compute(&mut self) -> napi::Result<Self::Output> {
79-
enhanced_transform_internal(&self.filename, &self.source_text, self.options.take(), self.cache)
81+
enhanced_transform_internal(
82+
&self.filename,
83+
&self.source_text,
84+
self.options.take(),
85+
self.cache,
86+
self.yarn_pnp,
87+
)
8088
}
8189

8290
fn resolve(&mut self, _env: napi::Env, output: Self::Output) -> napi::Result<Self::JsValue> {
8391
Ok(output)
8492
}
8593
}
8694

87-
/// Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
88-
///
89-
/// Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
90-
///
91-
/// @param filename The name of the file being transformed. If this is a
92-
/// relative path, consider setting the {@link TransformOptions#cwd} option.
93-
/// @param sourceText The source code to transform.
94-
/// @param options The transform options including tsconfig and inputMap. See {@link
95-
/// BindingEnhancedTransformOptions} for more information.
96-
/// @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
97-
/// Only used when tsconfig auto-discovery is enabled.
98-
///
99-
/// @returns a promise that resolves to an object containing the transformed code,
100-
/// source maps, and any errors that occurred during parsing or transformation.
101-
///
102-
/// @experimental
10395
#[napi]
10496
pub fn enhanced_transform(
10597
filename: String,
10698
source_text: String,
10799
options: Option<BindingEnhancedTransformOptions>,
108100
cache: Option<&TsconfigCache>,
101+
yarn_pnp: bool,
109102
) -> AsyncTask<EnhancedTransformTask<'_>> {
110-
AsyncTask::new(EnhancedTransformTask { filename, source_text, options, cache })
103+
AsyncTask::new(EnhancedTransformTask { filename, source_text, options, cache, yarn_pnp })
111104
}
112105

113-
/// Transpile a JavaScript or TypeScript into a target ECMAScript version.
114-
///
115-
/// @param filename The name of the file being transformed. If this is a
116-
/// relative path, consider setting the {@link TransformOptions#cwd} option.
117-
/// @param sourceText The source code to transform.
118-
/// @param options The transform options including tsconfig and inputMap. See {@link
119-
/// BindingEnhancedTransformOptions} for more information.
120-
/// @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
121-
/// Only used when tsconfig auto-discovery is enabled.
122-
///
123-
/// @returns an object containing the transformed code, source maps, and any errors
124-
/// that occurred during parsing or transformation.
125-
///
126-
/// @experimental
127106
#[napi]
128107
pub fn enhanced_transform_sync(
129108
filename: String,
130109
source_text: String,
131110
options: Option<BindingEnhancedTransformOptions>,
132111
cache: Option<&TsconfigCache>,
112+
yarn_pnp: bool,
133113
) -> napi::Result<BindingEnhancedTransformResult> {
134-
enhanced_transform_internal(&filename, &source_text, options, cache)
114+
enhanced_transform_internal(&filename, &source_text, options, cache, yarn_pnp)
135115
}
136116

137-
/// @hidden This is only expected to be used by Vite
138117
#[napi]
139118
pub fn resolve_tsconfig(
140119
filename: String,
141120
cache: Option<&TsconfigCache>,
121+
yarn_pnp: bool,
142122
) -> napi::Result<Option<BindingTsconfigResult>> {
143-
let tsconfig_cache = if let Some(cache) = cache { cache } else { &TsconfigCache::new() };
123+
let tsconfig_cache = if let Some(cache) = cache { cache } else { &TsconfigCache::new(yarn_pnp) };
144124

145125
match tsconfig_cache.find_tsconfig(Path::new(&filename)) {
146126
Ok(Some(tsconfig)) => Ok(Some(tsconfig.as_ref().clone().into())),

crates/rolldown_binding/src/transform_cache.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ use napi_derive::napi;
88
use oxc_resolver::{ResolveError, ResolveOptions, Resolver, TsConfig, TsconfigDiscovery};
99
use rolldown_utils::dashmap::FxDashMap;
1010

11-
/// Cache for tsconfig resolution to avoid redundant file system operations.
12-
///
13-
/// The cache stores resolved tsconfig configurations keyed by their file paths.
14-
/// When transforming multiple files in the same project, tsconfig lookups are
15-
/// deduplicated, improving performance.
16-
///
17-
/// @category Utilities
18-
/// @experimental
1911
#[napi]
2012
pub struct TsconfigCache {
2113
resolver: Arc<Resolver>,
@@ -26,10 +18,11 @@ pub struct TsconfigCache {
2618
impl TsconfigCache {
2719
/// Create a new transform cache with auto tsconfig discovery enabled.
2820
#[napi(constructor)]
29-
pub fn new() -> Self {
21+
pub fn new(yarn_pnp: bool) -> Self {
3022
Self {
3123
resolver: Arc::new(Resolver::new(ResolveOptions {
3224
tsconfig: Some(TsconfigDiscovery::Auto),
25+
yarn_pnp,
3326
..Default::default()
3427
})),
3528
cache: FxDashMap::default(),
@@ -51,12 +44,6 @@ impl TsconfigCache {
5144
}
5245
}
5346

54-
impl Default for TsconfigCache {
55-
fn default() -> Self {
56-
Self::new()
57-
}
58-
}
59-
6047
impl TsconfigCache {
6148
/// Get the resolver instance.
6249
pub fn resolver(&self) -> &Resolver {
@@ -91,13 +78,13 @@ mod tests {
9178

9279
#[test]
9380
fn test_cache_creation() {
94-
let cache = TsconfigCache::new();
81+
let cache = TsconfigCache::new(false);
9582
assert_eq!(cache.size(), 0);
9683
}
9784

9885
#[test]
9986
fn test_cache_clear() {
100-
let cache = TsconfigCache::new();
87+
let cache = TsconfigCache::new(false);
10188
cache.clear();
10289
assert_eq!(cache.size(), 0);
10390
}

crates/rolldown_common/src/inner_bundler_options/types/transform_options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct RawTransformOptions {
3434
}
3535

3636
impl RawTransformOptions {
37-
pub fn new(base_options: BundlerTransformOptions, tsconfig: TsConfig) -> Self {
37+
pub fn new(base_options: BundlerTransformOptions, tsconfig: TsConfig, yarn_pnp: bool) -> Self {
3838
Self {
3939
base_options: Arc::new(base_options),
4040
cache: FxDashMap::default(),
@@ -46,6 +46,7 @@ impl RawTransformOptions {
4646
references: oxc_resolver::TsconfigReferences::Auto,
4747
})),
4848
},
49+
yarn_pnp,
4950
..Default::default()
5051
})),
5152
}

crates/rolldown_common/src/utils/enhanced_transform.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ fn build_inject_config(
256256
/// * `filename` - The filename (used for source type detection and error reporting)
257257
/// * `source_text` - The source code to transform
258258
/// * `transform_options` - Transform options including tsconfig and sourcemap settings
259+
/// * `yarn_pnp` - Whether to enable Yarn PnP support when resolving tsconfig
259260
pub fn enhanced_transform(
260261
filename: &str,
261262
source_text: &str,
262263
transform_options: EnhancedTransformOptions,
264+
yarn_pnp: bool,
263265
) -> EnhancedTransformResult {
264266
let mut errors = Vec::new();
265267
let mut warnings = Vec::new();
@@ -273,6 +275,7 @@ pub fn enhanced_transform(
273275
let file_path = PathBuf::from(filename);
274276
let result = oxc_resolver::Resolver::new(oxc_resolver::ResolveOptions {
275277
tsconfig: Some(oxc_resolver::TsconfigDiscovery::Auto),
278+
yarn_pnp,
276279
..Default::default()
277280
})
278281
.find_tsconfig(file_path);

crates/rolldown_sourcemap/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ doctest = false
2222
memchr = { workspace = true }
2323
oxc = { workspace = true }
2424
oxc_sourcemap = { workspace = true }
25-
rolldown_utils = { workspace = true }
26-
rustc-hash = { workspace = true }
2725

2826
[dev-dependencies]
2927
criterion2 = { workspace = true, default-features = false }

crates/rolldown_sourcemap/src/lib.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod source_joiner;
44
use std::sync::Arc;
55

66
use oxc_sourcemap::Token;
7-
use rustc_hash::FxHashMap;
87

98
pub use oxc_sourcemap::{JSONSourceMap, SourceMap, SourceMapBuilder, SourcemapVisualizer};
109
pub use source_joiner::SourceJoiner;
@@ -45,10 +44,7 @@ pub fn adjust_sourcemap_dst_lines(sourcemap: SourceMap, lines: u32) -> SourceMap
4544
)
4645
}
4746

48-
use rolldown_utils::rustc_hash::FxHashMapExt;
49-
5047
// <https://github.com/rollup/rollup/blob/master/src/utils/collapseSourcemaps.ts>
51-
#[expect(clippy::cast_possible_truncation)]
5248
pub fn collapse_sourcemaps(sourcemap_chain: &[&SourceMap]) -> SourceMap {
5349
debug_assert!(sourcemap_chain.len() > 1);
5450
if sourcemap_chain.len() == 1 {
@@ -65,18 +61,8 @@ pub fn collapse_sourcemaps(sourcemap_chain: &[&SourceMap]) -> SourceMap {
6561
.map(|sourcemap| (sourcemap, sourcemap.generate_lookup_table()))
6662
.collect::<Vec<_>>();
6763

68-
let source_view_tokens = last_map.get_source_view_tokens();
69-
70-
let sources_map = first_map
71-
.get_sources()
72-
.enumerate()
73-
.map(|(i, source)| (source, i as u32))
74-
.collect::<FxHashMap<_, _>>();
75-
76-
// Avoid hashing the source text for every token.
77-
let mut sources_cache = FxHashMap::with_capacity(sources_map.len());
78-
79-
let tokens = source_view_tokens
64+
let tokens = last_map
65+
.get_source_view_tokens()
8066
.filter_map(|token| {
8167
let original_token = sourcemap_and_lookup_table.iter().rev().try_fold(
8268
token,
@@ -94,14 +80,7 @@ pub fn collapse_sourcemaps(sourcemap_chain: &[&SourceMap]) -> SourceMap {
9480
token.get_dst_col(),
9581
original_token.get_src_line(),
9682
original_token.get_src_col(),
97-
original_token.get_source_id().and_then(|source_id| {
98-
sources_cache
99-
.entry(source_id)
100-
.or_insert_with(|| {
101-
first_map.get_source(source_id).and_then(|source| sources_map.get(source))
102-
})
103-
.copied()
104-
}),
83+
original_token.get_source_id(),
10584
original_token.get_name_id(),
10685
)
10786
})

crates/rolldown_sourcemap/src/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Source for &Box<dyn Source + Send + Sync> {
8282
#[expect(clippy::cast_possible_truncation)]
8383
#[inline]
8484
fn lines_count(str: &str) -> u32 {
85-
memchr::memmem::find_iter(str.as_bytes(), "\n").count() as u32
85+
memchr::memchr_iter(b'\n', str.as_bytes()).count() as u32
8686
}
8787

8888
#[test]

0 commit comments

Comments
 (0)