Skip to content

Commit b09e7f8

Browse files
committed
Add support for debug_ids
1 parent d2b8fb7 commit b09e7f8

40 files changed

+3025
-108
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ ringmap = "0.1.3"
414414
roaring = "0.10.10"
415415
rstest = "0.16.0"
416416
rustc-hash = "2.1.1"
417-
twox-hash = { version = "2.0.1", features = ["xxhash64"] }
417+
twox-hash = { version = "2.1.0", features = ["xxhash64", "xxhash3_128"] }
418418
semver = "1.0.16"
419419
serde = { version = "1.0.217", features = ["derive"] }
420420
serde_json = "1.0.138"
@@ -443,6 +443,7 @@ triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable
443443
unsize = "1.1.0"
444444
url = "2.2.2"
445445
urlencoding = "2.1.2"
446+
uuid = "1.18.1"
446447
vergen = { version = "9.0.6", features = ["cargo"] }
447448
vergen-gitcl = { version = "1.0.8", features = ["cargo"] }
448449
webbrowser = "0.8.7"

crates/next-api/src/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@ impl Project {
10481048
source_maps: self.next_config().client_source_maps(self.next_mode()),
10491049
no_mangling: self.no_mangling(),
10501050
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
1051+
debug_ids: self.next_config().turbopack_debug_ids(),
10511052
}))
10521053
}
10531054

crates/next-core/src/next_client/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ pub struct ClientChunkingContextOptions {
421421
pub source_maps: Vc<bool>,
422422
pub no_mangling: Vc<bool>,
423423
pub scope_hoisting: Vc<bool>,
424+
pub debug_ids: Vc<bool>,
424425
}
425426

426427
#[turbo_tasks::function]
@@ -441,6 +442,7 @@ pub async fn get_client_chunking_context(
441442
source_maps,
442443
no_mangling,
443444
scope_hoisting,
445+
debug_ids,
444446
} = options;
445447

446448
let next_mode = mode.await?;
@@ -473,7 +475,8 @@ pub async fn get_client_chunking_context(
473475
.asset_base_path(asset_prefix)
474476
.current_chunk_method(CurrentChunkMethod::DocumentCurrentScript)
475477
.export_usage(*export_usage.await?)
476-
.module_id_strategy(module_id_strategy.to_resolved().await?);
478+
.module_id_strategy(module_id_strategy.to_resolved().await?)
479+
.debug_ids(*debug_ids.await?);
477480

478481
if next_mode.is_development() {
479482
builder = builder

crates/next-core/src/next_config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ pub struct TurbopackConfig {
561561
pub rules: Option<FxIndexMap<RcStr, RuleConfigCollection>>,
562562
pub resolve_alias: Option<FxIndexMap<RcStr, JsonValue>>,
563563
pub resolve_extensions: Option<Vec<RcStr>>,
564+
pub debug_ids: Option<bool>,
564565
}
565566

566567
#[derive(
@@ -1855,6 +1856,16 @@ impl NextConfig {
18551856
Ok(Vc::cell(source_maps.unwrap_or(true)))
18561857
}
18571858

1859+
#[turbo_tasks::function]
1860+
pub fn turbopack_debug_ids(&self) -> Vc<bool> {
1861+
Vc::cell(
1862+
self.turbopack
1863+
.as_ref()
1864+
.and_then(|turbopack| turbopack.debug_ids)
1865+
.unwrap_or(false),
1866+
)
1867+
}
1868+
18581869
#[turbo_tasks::function]
18591870
pub fn typescript_tsconfig_path(&self) -> Result<Vc<Option<RcStr>>> {
18601871
Ok(Vc::cell(

crates/next-core/src/raw_ecmascript_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl EcmascriptChunkItem for RawEcmascriptChunkItem {
271271

272272
let code = code.build();
273273
let source_map = if code.has_source_map() {
274-
let source_map = code.generate_source_map_ref()?;
274+
let source_map = code.generate_source_map_ref(None);
275275

276276
static SECTIONS_REGEX: Lazy<Regex> =
277277
Lazy::new(|| Regex::new(r#"sections"[\s\n]*:"#).unwrap());

packages/next/src/server/config-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const zTurbopackConfig: zod.ZodType<TurbopackOptions> = z.strictObject({
159159
.optional(),
160160
resolveExtensions: z.array(z.string()).optional(),
161161
root: z.string().optional(),
162+
debugIds: z.boolean().optional(),
162163
})
163164

164165
export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>

packages/next/src/server/config-shared.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ export interface TurbopackOptions {
172172
* directory can be resolved by turbopack.
173173
*/
174174
root?: string
175+
176+
/**
177+
* Enables generation of debug IDs in JavaScript bundles and source maps.
178+
* These debug IDs help with debugging and error tracking by providing stable identifiers.
179+
*
180+
* @see https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md TC39 Debug ID Proposal
181+
*/
182+
debugIds?: boolean
175183
}
176184

177185
export interface WebpackConfigContext {

turbopack/crates/turbo-tasks-fs/src/rope.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ impl AsyncRead for RopeReader {
760760
}
761761

762762
impl BufRead for RopeReader {
763+
/// Never returns an error.
763764
fn fill_buf(&mut self) -> IoResult<&[u8]> {
764765
// Returns the full buffer without coping any data. The same bytes will
765766
// continue to be returned until [consume] is called.

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ impl BrowserChunkingContextBuilder {
168168
self
169169
}
170170

171+
pub fn debug_ids(mut self, debug_ids: bool) -> Self {
172+
self.chunking_context.debug_ids = debug_ids;
173+
self
174+
}
175+
171176
pub fn chunking_config<T>(mut self, ty: ResolvedVc<T>, chunking_config: ChunkingConfig) -> Self
172177
where
173178
T: Upcast<Box<dyn ChunkType>>,
@@ -229,6 +234,8 @@ pub struct BrowserChunkingContext {
229234
enable_module_merging: bool,
230235
/// Enable dynamic chunk content loading.
231236
enable_dynamic_chunk_content_loading: bool,
237+
/// Enable debug IDs for chunks and source maps.
238+
debug_ids: bool,
232239
/// The environment chunks will be evaluated in.
233240
environment: ResolvedVc<Environment>,
234241
/// The kind of runtime to include in the output.
@@ -279,6 +286,7 @@ impl BrowserChunkingContext {
279286
enable_tracing: false,
280287
enable_module_merging: false,
281288
enable_dynamic_chunk_content_loading: false,
289+
debug_ids: false,
282290
environment,
283291
runtime_type,
284292
minify_type: MinifyType::NoMinify,
@@ -780,4 +788,9 @@ impl ChunkingContext for BrowserChunkingContext {
780788
Ok(ModuleExportUsage::all())
781789
}
782790
}
791+
792+
#[turbo_tasks::function]
793+
async fn debug_ids_enabled(self: Vc<Self>) -> Result<Vc<bool>> {
794+
Ok(Vc::cell(self.await?.debug_ids))
795+
}
783796
}

0 commit comments

Comments
 (0)