Skip to content

Commit 9e4283f

Browse files
committed
feat: support output.sourcemapExcludeSources option
1 parent 47ab703 commit 9e4283f

File tree

20 files changed

+85
-3
lines changed

20 files changed

+85
-3
lines changed

crates/rolldown/src/utils/prepare_build_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ pub fn prepare_build_context(
401401
sourcemap_ignore_list: raw_options.sourcemap_ignore_list,
402402
sourcemap_path_transform: raw_options.sourcemap_path_transform,
403403
sourcemap_debug_ids: raw_options.sourcemap_debug_ids.unwrap_or(false),
404+
sourcemap_exclude_sources: raw_options.sourcemap_exclude_sources.unwrap_or(false),
404405
shim_missing_exports: raw_options.shim_missing_exports.unwrap_or(false),
405406
module_types,
406407
experimental,

crates/rolldown/src/utils/process_code_and_sourcemap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub async fn process_code_and_sourcemap(
2424
let file_base_name = Path::new(filename).file_name().expect("should have file name");
2525
map.set_file(file_base_name.to_string_lossy().as_ref());
2626

27+
if options.sourcemap_exclude_sources {
28+
map.set_source_contents(vec![]);
29+
}
30+
2731
let map_filename = format!("{filename}.map");
2832
let map_path = file_dir.join(&map_filename);
2933

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"config": {
3+
"entryFilenames": "assets/[name].js",
4+
"sourcemap": "File",
5+
"sourcemapExcludeSources": true
6+
},
7+
"expectExecuted": false
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from 'node:fs';
2+
import assert from 'node:assert';
3+
import path from 'node:path';
4+
5+
const sourceMap = JSON.parse(
6+
fs.readFileSync(path.resolve(import.meta.dirname, 'dist/assets/main.js.map'), 'utf8'),
7+
);
8+
assert.ok(
9+
!sourceMap.sourcesContent || sourceMap.sourcesContent.length === 0,
10+
'sourcesContent should be empty or absent',
11+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/rolldown_testing/src/integration_test.rs
3+
---
4+
# Assets
5+
6+
## assets/main.js
7+
8+
```js
9+
//#region main.js
10+
console.log(1);
11+
//#endregion
12+
13+
//# sourceMappingURL=main.js.map
14+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(1);

crates/rolldown_binding/src/options/binding_output_options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct BindingOutputOptions<'env> {
132132
#[debug(skip)]
133133
#[napi(ts_type = "(source: string, sourcemapPath: string) => string")]
134134
pub sourcemap_path_transform: Option<JsCallback<FnArgs<(String, String)>, String>>,
135-
// sourcemapExcludeSources: boolean;
135+
pub sourcemap_exclude_sources: Option<bool>,
136136
// sourcemapFile: string | undefined;
137137
#[napi(ts_type = "boolean | 'auto'")]
138138
pub strict: Option<Either<bool, String>>,

crates/rolldown_binding/src/types/binding_normalized_options.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ impl BindingNormalizedOptions {
250250
self.inner.sourcemap_debug_ids
251251
}
252252

253+
#[napi(getter)]
254+
pub fn sourcemap_exclude_sources(&self) -> bool {
255+
self.inner.sourcemap_exclude_sources
256+
}
257+
253258
#[napi(getter)]
254259
pub fn polyfill_require(&self) -> bool {
255260
self.inner.polyfill_require

crates/rolldown_binding/src/utils/normalize_binding_options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ pub fn normalize_binding_options(
349349
sourcemap_ignore_list,
350350
sourcemap_path_transform,
351351
sourcemap_debug_ids: output_options.sourcemap_debug_ids,
352+
sourcemap_exclude_sources: output_options.sourcemap_exclude_sources,
352353
exports: output_options
353354
.exports
354355
.map(|format_str| {

crates/rolldown_common/src/inner_bundler_options/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub struct BundlerOptions {
161161
)]
162162
pub sourcemap_path_transform: Option<SourceMapPathTransform>,
163163
pub sourcemap_debug_ids: Option<bool>,
164+
pub sourcemap_exclude_sources: Option<bool>,
164165

165166
/// Key is the file extension. The extension should start with a `.`. E.g. `".txt"`.
166167
pub module_types: Option<FxHashMap<String, ModuleType>>,

0 commit comments

Comments
 (0)