Skip to content

Commit 7dc8bec

Browse files
committed
Add strawman proposal for 'sourcesHash'
1 parent e4dba00 commit 7dc8bec

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

proposals/sources-hash.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Proposal to add hashes for "sources"
2+
3+
## Current Status
4+
5+
Source maps proposal at stage 1 of the process, see [Our process document](https://github.com/tc39/source-map/blob/main/PROCESS.md)
6+
7+
## Author
8+
9+
Simon Zünd
10+
11+
12+
## Motivation
13+
14+
Modern debugging workflows frequently encounter scenarios where the same "original source" URL appears in multiple source maps. Determining whether these URLs refer to identical source files presents a challenge. When the optional `"sourcesContent"` field is present in both source maps, this comparison is straightforward. However, many source maps omit `"sourcesContent"` to reduce file size. In such cases, debuggers are forced to fetch the content of the original source file(s) to ascertain their identity, leading to unnecessary network requests and increased debugging overhead.
15+
16+
This issue is particularly prevalent in modern web development practices:
17+
18+
* With Code Splitting, common source files (e.g., `shared.ts`) can be included in multiple bundles. Debuggers need an efficient way to recognize that these instances refer to the same underlying file without redundant fetches.
19+
* With Hot Module Replacement (HMR), development servers often serve different versions of the same `"foo.ts"` file over time, even when referenced from the same source map. Debuggers could significantly optimize their behavior by skipping unnecessary processing when they can reliably determine that a source file's content has not changed across HMR updates.
20+
21+
For the *generated file*, a similar problem is addressed by the [Debug ID proposal](./debug-id.md), which provides a unique identifier for the generated code. A comparable mechanism would be advantageous original source files.
22+
23+
## Proposal
24+
25+
We propose the addition of a new optional field, `"sourcesHash"`, to the ECMA-426 Source Map specification. This field would be an array, where each entry corresponds to an entry in the `"sources"` array and contains an implementation-defined hash of the original source file's content.
26+
27+
The `"sourcesHash"` field would enable debuggers and other tooling to quickly and reliably determine if two "original source" URLs refer to the same file content without needing to fetch the actual source content, thereby improving debugging efficiency and reducing network load.
28+
29+
30+
### Example
31+
32+
```json
33+
{
34+
"version": 3,
35+
"file": "bundle.js",
36+
"sources": [
37+
"src/foo.ts",
38+
"src/bar.ts"
39+
],
40+
"sourcesHash": [
41+
"sha256-abc123...",
42+
"sha256-def456..."
43+
],
44+
"mappings": "...",
45+
"names": []
46+
}
47+
```
48+
49+
50+
## Considerations
51+
52+
* The specific hashing algorithm used should be implementation-defined to allow for flexibility and future-proofing. However, the specification could recommend or provide guidance on suitable algorithms (e.g., SHA-256) for interoperability.
53+
* The representation of the hash should be clearly defined. It could be an opaque string or the base64 encoded binary hash.

0 commit comments

Comments
 (0)