next.js
624a0140 - [turbopack] Add support for debug_ids (#84319)

Commit
111 days ago
[turbopack] Add support for debug_ids (#84319) ## What? Add a new feature to turbopack for generating debug_ids based on the [TC39 Debug ID proposal](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md) If a user sets `turbopack.debugIds = true` then we will * register the debug id with the global `_debugIds` object * this object is keyed by a stack trace for the script. This enables associating debug ids with stack frames when reporting errors. * add a ` //# debugId=XXX` comment at the end of the generated code * add a `"debugId": "XXX"` property to the source map json file The debug id value is a hash of the file contents using the `xxhash3_128` hash algorithm represented as a UUID hyphentated string. One oddity is Indexed source maps. Turbopack uses indexed source maps for simple performance and 'incremental execution' reasons, but the debug id spec says that debugIds only apply to non-indexed source maps. Reading between the lines (thanks @bgw! ), this appears to be a simple spec issue related to older versions of the indexed-source maps specification. Adding the debugId to the indexed map is unlikely to be harmful and the authors agree this should be covered ([see issue](https://github.com/tc39/ecma426/issues/203)). ## Why? Debug Ids make javascript source files and source maps self identifying without relying on URLs. This improves the ability for offline processes to ensure a proper association regardless of how sources our source maps are served. ## How? * thread the `debug_ids` bit from the next config down to the chunking context and finally to the `Code` structs * implement a uuid generator that can content address the code to generate the id - neither content addressing nor even determinism are _required_ by the spec but this is the simplest approach. We could use a simple 128 bit random number, but this is chaotic and goes against our own natural desires for determinism. * compute the debug id in a turbotask on the `Code` struct and embed when generating chunks and source maps. * add a few tiny snapshot tests to demonstrate the feature. Fixes PACK-417 --------- Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Author
Parents
Loading