From 0f4676d9316a6eb4ec6715097d4d47455e9937ef Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 9 Nov 2024 07:40:22 +0100 Subject: [PATCH 1/3] Use a less surprising base-16 encoding (#5719) While not important to many, this makes it possible to recreate hashes. --- rust/xxhash/src/lib.rs | 2 +- .../amd/{dep-829e49d80e8138.js => dep-9748f597e7f841.js} | 0 .../samples/hashing/base-16/_expected/amd/main1-32c81258.js | 5 +++++ .../samples/hashing/base-16/_expected/amd/main1-c7c1549b.js | 5 ----- .../samples/hashing/base-16/_expected/amd/main2-b28d1351.js | 5 ----- .../samples/hashing/base-16/_expected/amd/main2-fe4f34dc.js | 5 +++++ ...st-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} | 0 .../cjs/{dep-56610f0f1f4a63.js => dep-8e72f6a548dc1a.js} | 0 .../_expected/cjs/{main1-f180bb4c.js => main1-2af756cb.js} | 2 +- .../_expected/cjs/{main2-d4907d4b.js => main2-e8d99f43.js} | 2 +- ...st-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} | 0 .../es/{dep-319d615e3e266e.js => dep-ea4271148a0859.js} | 0 .../samples/hashing/base-16/_expected/es/main1-2ba5365c.js | 3 --- .../samples/hashing/base-16/_expected/es/main1-e88c4e75.js | 3 +++ .../samples/hashing/base-16/_expected/es/main2-11f6fea7.js | 3 +++ .../samples/hashing/base-16/_expected/es/main2-c2fcf802.js | 3 --- ...st-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} | 0 .../system/{dep-bacfaa81397007.js => dep-fc1ce55215e47e.js} | 0 .../system/{main1-0b232646.js => main1-9428b54c.js} | 2 +- .../system/{main2-83b1318a.js => main2-bae4f47a.js} | 2 +- ...st-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} | 0 21 files changed, 21 insertions(+), 21 deletions(-) rename test/chunking-form/samples/hashing/base-16/_expected/amd/{dep-829e49d80e8138.js => dep-9748f597e7f841.js} (100%) create mode 100644 test/chunking-form/samples/hashing/base-16/_expected/amd/main1-32c81258.js delete mode 100644 test/chunking-form/samples/hashing/base-16/_expected/amd/main1-c7c1549b.js delete mode 100644 test/chunking-form/samples/hashing/base-16/_expected/amd/main2-b28d1351.js create mode 100644 test/chunking-form/samples/hashing/base-16/_expected/amd/main2-fe4f34dc.js rename test/chunking-form/samples/hashing/base-16/_expected/amd/{test-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} (100%) rename test/chunking-form/samples/hashing/base-16/_expected/cjs/{dep-56610f0f1f4a63.js => dep-8e72f6a548dc1a.js} (100%) rename test/chunking-form/samples/hashing/base-16/_expected/cjs/{main1-f180bb4c.js => main1-2af756cb.js} (51%) rename test/chunking-form/samples/hashing/base-16/_expected/cjs/{main2-d4907d4b.js => main2-e8d99f43.js} (51%) rename test/chunking-form/samples/hashing/base-16/_expected/cjs/{test-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} (100%) rename test/chunking-form/samples/hashing/base-16/_expected/es/{dep-319d615e3e266e.js => dep-ea4271148a0859.js} (100%) delete mode 100644 test/chunking-form/samples/hashing/base-16/_expected/es/main1-2ba5365c.js create mode 100644 test/chunking-form/samples/hashing/base-16/_expected/es/main1-e88c4e75.js create mode 100644 test/chunking-form/samples/hashing/base-16/_expected/es/main2-11f6fea7.js delete mode 100644 test/chunking-form/samples/hashing/base-16/_expected/es/main2-c2fcf802.js rename test/chunking-form/samples/hashing/base-16/_expected/es/{test-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} (100%) rename test/chunking-form/samples/hashing/base-16/_expected/system/{dep-bacfaa81397007.js => dep-fc1ce55215e47e.js} (100%) rename test/chunking-form/samples/hashing/base-16/_expected/system/{main1-0b232646.js => main1-9428b54c.js} (64%) rename test/chunking-form/samples/hashing/base-16/_expected/system/{main2-83b1318a.js => main2-bae4f47a.js} (64%) rename test/chunking-form/samples/hashing/base-16/_expected/system/{test-52f952ec201fb87af2.txt => test-b85fb84286751ed058.txt} (100%) diff --git a/rust/xxhash/src/lib.rs b/rust/xxhash/src/lib.rs index 1c64d4856..6dc938a76 100644 --- a/rust/xxhash/src/lib.rs +++ b/rust/xxhash/src/lib.rs @@ -6,7 +6,7 @@ const CHARACTERS_BASE64: &[u8; 64] = const CHARACTERS_BASE36: &[u8; 36] = b"abcdefghijklmnopqrstuvwxyz0123456789"; -const CHARACTERS_BASE16: &[u8; 16] = b"abcdef0123456789"; +const CHARACTERS_BASE16: &[u8; 16] = b"0123456789abcdef"; pub fn xxhash_base64_url(input: &[u8]) -> String { to_string(&xxh3_128(input).to_le_bytes(), 64, CHARACTERS_BASE64).unwrap() diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/dep-829e49d80e8138.js b/test/chunking-form/samples/hashing/base-16/_expected/amd/dep-9748f597e7f841.js similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/amd/dep-829e49d80e8138.js rename to test/chunking-form/samples/hashing/base-16/_expected/amd/dep-9748f597e7f841.js diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-32c81258.js b/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-32c81258.js new file mode 100644 index 000000000..374fe9446 --- /dev/null +++ b/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-32c81258.js @@ -0,0 +1,5 @@ +define(['./dep-9748f597e7f841'], (function (dep) { 'use strict'; + + console.log('main1'); + +})); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-c7c1549b.js b/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-c7c1549b.js deleted file mode 100644 index 50580b32c..000000000 --- a/test/chunking-form/samples/hashing/base-16/_expected/amd/main1-c7c1549b.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./dep-829e49d80e8138'], (function (dep) { 'use strict'; - - console.log('main1'); - -})); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-b28d1351.js b/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-b28d1351.js deleted file mode 100644 index 32414ff47..000000000 --- a/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-b28d1351.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./dep-829e49d80e8138'], (function (dep) { 'use strict'; - - console.log('main2'); - -})); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-fe4f34dc.js b/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-fe4f34dc.js new file mode 100644 index 000000000..bf78a4dec --- /dev/null +++ b/test/chunking-form/samples/hashing/base-16/_expected/amd/main2-fe4f34dc.js @@ -0,0 +1,5 @@ +define(['./dep-9748f597e7f841'], (function (dep) { 'use strict'; + + console.log('main2'); + +})); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/amd/test-52f952ec201fb87af2.txt b/test/chunking-form/samples/hashing/base-16/_expected/amd/test-b85fb84286751ed058.txt similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/amd/test-52f952ec201fb87af2.txt rename to test/chunking-form/samples/hashing/base-16/_expected/amd/test-b85fb84286751ed058.txt diff --git a/test/chunking-form/samples/hashing/base-16/_expected/cjs/dep-56610f0f1f4a63.js b/test/chunking-form/samples/hashing/base-16/_expected/cjs/dep-8e72f6a548dc1a.js similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/cjs/dep-56610f0f1f4a63.js rename to test/chunking-form/samples/hashing/base-16/_expected/cjs/dep-8e72f6a548dc1a.js diff --git a/test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-f180bb4c.js b/test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-2af756cb.js similarity index 51% rename from test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-f180bb4c.js rename to test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-2af756cb.js index 0fe155a99..46a720ce4 100644 --- a/test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-f180bb4c.js +++ b/test/chunking-form/samples/hashing/base-16/_expected/cjs/main1-2af756cb.js @@ -1,5 +1,5 @@ 'use strict'; -require('./dep-56610f0f1f4a63.js'); +require('./dep-8e72f6a548dc1a.js'); console.log('main1'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-d4907d4b.js b/test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-e8d99f43.js similarity index 51% rename from test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-d4907d4b.js rename to test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-e8d99f43.js index 5a53c37f9..ac7092b32 100644 --- a/test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-d4907d4b.js +++ b/test/chunking-form/samples/hashing/base-16/_expected/cjs/main2-e8d99f43.js @@ -1,5 +1,5 @@ 'use strict'; -require('./dep-56610f0f1f4a63.js'); +require('./dep-8e72f6a548dc1a.js'); console.log('main2'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/cjs/test-52f952ec201fb87af2.txt b/test/chunking-form/samples/hashing/base-16/_expected/cjs/test-b85fb84286751ed058.txt similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/cjs/test-52f952ec201fb87af2.txt rename to test/chunking-form/samples/hashing/base-16/_expected/cjs/test-b85fb84286751ed058.txt diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/dep-319d615e3e266e.js b/test/chunking-form/samples/hashing/base-16/_expected/es/dep-ea4271148a0859.js similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/es/dep-319d615e3e266e.js rename to test/chunking-form/samples/hashing/base-16/_expected/es/dep-ea4271148a0859.js diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/main1-2ba5365c.js b/test/chunking-form/samples/hashing/base-16/_expected/es/main1-2ba5365c.js deleted file mode 100644 index 167695748..000000000 --- a/test/chunking-form/samples/hashing/base-16/_expected/es/main1-2ba5365c.js +++ /dev/null @@ -1,3 +0,0 @@ -import './dep-319d615e3e266e.js'; - -console.log('main1'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/main1-e88c4e75.js b/test/chunking-form/samples/hashing/base-16/_expected/es/main1-e88c4e75.js new file mode 100644 index 000000000..f1f2c901a --- /dev/null +++ b/test/chunking-form/samples/hashing/base-16/_expected/es/main1-e88c4e75.js @@ -0,0 +1,3 @@ +import './dep-ea4271148a0859.js'; + +console.log('main1'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/main2-11f6fea7.js b/test/chunking-form/samples/hashing/base-16/_expected/es/main2-11f6fea7.js new file mode 100644 index 000000000..f479817a7 --- /dev/null +++ b/test/chunking-form/samples/hashing/base-16/_expected/es/main2-11f6fea7.js @@ -0,0 +1,3 @@ +import './dep-ea4271148a0859.js'; + +console.log('main2'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/main2-c2fcf802.js b/test/chunking-form/samples/hashing/base-16/_expected/es/main2-c2fcf802.js deleted file mode 100644 index a55c5d667..000000000 --- a/test/chunking-form/samples/hashing/base-16/_expected/es/main2-c2fcf802.js +++ /dev/null @@ -1,3 +0,0 @@ -import './dep-319d615e3e266e.js'; - -console.log('main2'); diff --git a/test/chunking-form/samples/hashing/base-16/_expected/es/test-52f952ec201fb87af2.txt b/test/chunking-form/samples/hashing/base-16/_expected/es/test-b85fb84286751ed058.txt similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/es/test-52f952ec201fb87af2.txt rename to test/chunking-form/samples/hashing/base-16/_expected/es/test-b85fb84286751ed058.txt diff --git a/test/chunking-form/samples/hashing/base-16/_expected/system/dep-bacfaa81397007.js b/test/chunking-form/samples/hashing/base-16/_expected/system/dep-fc1ce55215e47e.js similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/system/dep-bacfaa81397007.js rename to test/chunking-form/samples/hashing/base-16/_expected/system/dep-fc1ce55215e47e.js diff --git a/test/chunking-form/samples/hashing/base-16/_expected/system/main1-0b232646.js b/test/chunking-form/samples/hashing/base-16/_expected/system/main1-9428b54c.js similarity index 64% rename from test/chunking-form/samples/hashing/base-16/_expected/system/main1-0b232646.js rename to test/chunking-form/samples/hashing/base-16/_expected/system/main1-9428b54c.js index 8b374a2d3..1f213fefb 100644 --- a/test/chunking-form/samples/hashing/base-16/_expected/system/main1-0b232646.js +++ b/test/chunking-form/samples/hashing/base-16/_expected/system/main1-9428b54c.js @@ -1,4 +1,4 @@ -System.register(['./dep-bacfaa81397007.js'], (function () { +System.register(['./dep-fc1ce55215e47e.js'], (function () { 'use strict'; return { setters: [null], diff --git a/test/chunking-form/samples/hashing/base-16/_expected/system/main2-83b1318a.js b/test/chunking-form/samples/hashing/base-16/_expected/system/main2-bae4f47a.js similarity index 64% rename from test/chunking-form/samples/hashing/base-16/_expected/system/main2-83b1318a.js rename to test/chunking-form/samples/hashing/base-16/_expected/system/main2-bae4f47a.js index f0506cfd1..72d741153 100644 --- a/test/chunking-form/samples/hashing/base-16/_expected/system/main2-83b1318a.js +++ b/test/chunking-form/samples/hashing/base-16/_expected/system/main2-bae4f47a.js @@ -1,4 +1,4 @@ -System.register(['./dep-bacfaa81397007.js'], (function () { +System.register(['./dep-fc1ce55215e47e.js'], (function () { 'use strict'; return { setters: [null], diff --git a/test/chunking-form/samples/hashing/base-16/_expected/system/test-52f952ec201fb87af2.txt b/test/chunking-form/samples/hashing/base-16/_expected/system/test-b85fb84286751ed058.txt similarity index 100% rename from test/chunking-form/samples/hashing/base-16/_expected/system/test-52f952ec201fb87af2.txt rename to test/chunking-form/samples/hashing/base-16/_expected/system/test-b85fb84286751ed058.txt From d0935a8f2b2ea7a8bd6c5863c7ea37f7b39fffed Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Sat, 9 Nov 2024 07:41:17 +0100 Subject: [PATCH 2/3] feat: Add support for injecting Debug IDs (#5712) * feat: Add support for injecting Debug IDs * Add docs * PR review changes and full coverage --- cli/help.md | 1 + docs/command-line-interface/index.md | 2 ++ docs/configuration-options/index.md | 10 +++++++++ docs/javascript-api/index.md | 1 + src/rollup/types.d.ts | 2 ++ src/utils/options/mergeOptions.ts | 1 + src/utils/options/normalizeOutputOptions.ts | 1 + src/utils/renderChunks.ts | 21 ++++++++++++++++++ .../samples/output-options-hook/_config.js | 1 + test/misc/optionList.js | 4 ++-- .../debug-ids-with-placeholder/_config.js | 22 +++++++++++++++++++ .../samples/debug-ids-with-placeholder/bar.js | 1 + .../samples/debug-ids-with-placeholder/foo.js | 5 +++++ .../debug-ids-with-placeholder/main.js | 1 + test/sourcemaps/samples/debug-ids/_config.js | 21 ++++++++++++++++++ test/sourcemaps/samples/debug-ids/bar.js | 1 + test/sourcemaps/samples/debug-ids/foo.js | 5 +++++ test/sourcemaps/samples/debug-ids/main.js | 1 + 18 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 test/sourcemaps/samples/debug-ids-with-placeholder/_config.js create mode 100644 test/sourcemaps/samples/debug-ids-with-placeholder/bar.js create mode 100644 test/sourcemaps/samples/debug-ids-with-placeholder/foo.js create mode 100644 test/sourcemaps/samples/debug-ids-with-placeholder/main.js create mode 100644 test/sourcemaps/samples/debug-ids/_config.js create mode 100644 test/sourcemaps/samples/debug-ids/bar.js create mode 100644 test/sourcemaps/samples/debug-ids/foo.js create mode 100644 test/sourcemaps/samples/debug-ids/main.js diff --git a/cli/help.md b/cli/help.md index c0048b559..7a49dd45d 100644 --- a/cli/help.md +++ b/cli/help.md @@ -71,6 +71,7 @@ Basic options: --shimMissingExports Create shim variables for missing exports --silent Don't print warnings --sourcemapBaseUrl Emit absolute sourcemap URLs with given base +--sourcemapDebugIds Emit unique debug ids in source and sourcemaps --sourcemapExcludeSources Do not include source code in source maps --sourcemapFile Specify bundle position for source maps --sourcemapFileNames Name pattern for emitted sourcemaps diff --git a/docs/command-line-interface/index.md b/docs/command-line-interface/index.md index bcca39060..be0de7546 100755 --- a/docs/command-line-interface/index.md +++ b/docs/command-line-interface/index.md @@ -109,6 +109,7 @@ export default { preserveModulesRoot, sourcemap, sourcemapBaseUrl, + sourcemapDebugIds, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, @@ -439,6 +440,7 @@ Many options have command line equivalents. In those cases, any arguments passed --shimMissingExports Create shim variables for missing exports --silent Don't print warnings --sourcemapBaseUrl Emit absolute sourcemap URLs with given base +--sourcemapDebugIds Emit unique debug ids in source and sourcemaps --sourcemapExcludeSources Do not include source code in source maps --sourcemapFile Specify bundle position for source maps --sourcemapFileNames Name pattern for emitted sourcemaps diff --git a/docs/configuration-options/index.md b/docs/configuration-options/index.md index 16adb70d3..04638220a 100755 --- a/docs/configuration-options/index.md +++ b/docs/configuration-options/index.md @@ -1744,6 +1744,16 @@ If `true`, a separate sourcemap file will be created. If `"inline"`, the sourcem By default, sourcemap files generated by Rollup uses relative URLs to reference the files they describe. By providing an absolute base URL, e.g. `https://example.com`, sourcemaps will use absolute URLs instead. +### output.sourcemapDebugIds + +| | | +| -------: | :--------------------------------------------- | +| Type: | `boolean` | +| CLI: | `--sourcemapDebugIds`/`--no-sourcemapDebugIds` | +| Default: | `false` | + +if `true`, unique ids will be emitted in source and sourcemaps which streamlines identifying sourcemaps across different builds. See the [TC39 sourcemap debug ID proposal](https://github.com/tc39/source-map/blob/main/proposals/debug-id.md) for more details. + ### output.sourcemapExcludeSources | | | diff --git a/docs/javascript-api/index.md b/docs/javascript-api/index.md index 7567b25c9..22db217ee 100755 --- a/docs/javascript-api/index.md +++ b/docs/javascript-api/index.md @@ -208,6 +208,7 @@ const outputOptions = { preserveModulesRoot, sourcemap, sourcemapBaseUrl, + sourcemapDebugIds, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 48668c047..df450c491 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -782,6 +782,7 @@ export interface OutputOptions { sourcemapFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption; sourcemapPathTransform?: SourcemapPathTransformOption; + sourcemapDebugIds?: boolean; strict?: boolean; systemNullSetters?: boolean; validate?: boolean; @@ -836,6 +837,7 @@ export interface NormalizedOutputOptions { sourcemapFileNames: string | ((chunkInfo: PreRenderedChunk) => string) | undefined; sourcemapIgnoreList: SourcemapIgnoreListOption; sourcemapPathTransform: SourcemapPathTransformOption | undefined; + sourcemapDebugIds: boolean; strict: boolean; systemNullSetters: boolean; validate: boolean; diff --git a/src/utils/options/mergeOptions.ts b/src/utils/options/mergeOptions.ts index 29d7ff0e8..29eac4703 100644 --- a/src/utils/options/mergeOptions.ts +++ b/src/utils/options/mergeOptions.ts @@ -279,6 +279,7 @@ async function mergeOutputOptions( sanitizeFileName: getOption('sanitizeFileName'), sourcemap: getOption('sourcemap'), sourcemapBaseUrl: getOption('sourcemapBaseUrl'), + sourcemapDebugIds: getOption('sourcemapDebugIds'), sourcemapExcludeSources: getOption('sourcemapExcludeSources'), sourcemapFile: getOption('sourcemapFile'), sourcemapFileNames: getOption('sourcemapFileNames'), diff --git a/src/utils/options/normalizeOutputOptions.ts b/src/utils/options/normalizeOutputOptions.ts index 41a32f92b..027883e19 100644 --- a/src/utils/options/normalizeOutputOptions.ts +++ b/src/utils/options/normalizeOutputOptions.ts @@ -94,6 +94,7 @@ export async function normalizeOutputOptions( : defaultSanitizeFileName, sourcemap: config.sourcemap || false, sourcemapBaseUrl: getSourcemapBaseUrl(config), + sourcemapDebugIds: config.sourcemapDebugIds || false, sourcemapExcludeSources: config.sourcemapExcludeSources || false, sourcemapFile: config.sourcemapFile, sourcemapFileNames: getSourcemapFileNames(config, unsetOptions), diff --git a/src/utils/renderChunks.ts b/src/utils/renderChunks.ts index e92a8a48f..1b407fa14 100644 --- a/src/utils/renderChunks.ts +++ b/src/utils/renderChunks.ts @@ -347,6 +347,9 @@ function addChunksToBundle( const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder); let finalSourcemapFileName = null; if (map) { + if (options.sourcemapDebugIds) { + updatedCode += calculateDebugIdAndGetComment(updatedCode, map); + } finalSourcemapFileName = sourcemapFileName ? replacePlaceholders(sourcemapFileName, hashesByPlaceholder) : `${finalFileName}.map`; @@ -365,6 +368,9 @@ function addChunksToBundle( hashesByPlaceholder.size > 0 ? replacePlaceholders(code, hashesByPlaceholder) : code; let finalSourcemapFileName = null; if (map) { + if (options.sourcemapDebugIds) { + updatedCode += calculateDebugIdAndGetComment(updatedCode, map); + } finalSourcemapFileName = sourcemapFileName ? replacePlaceholders(sourcemapFileName, hashesByPlaceholder) : `${fileName}.map`; @@ -402,3 +408,18 @@ function emitSourceMapAndGetComment( } return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`; } + +function calculateDebugIdAndGetComment(code: string, map: SourceMap & { debugId?: string }) { + const hash = hasherByType.hex(code); + const debugId = [ + hash.slice(0, 8), + hash.slice(8, 12), + '4' + hash.slice(12, 15), + ((parseInt(hash.slice(15, 16), 16) & 3) | 8).toString(16) + hash.slice(17, 20), + hash.slice(20, 32) + ].join('-'); + + map.debugId = debugId; + + return '//# debugId=' + debugId + '\n'; +} diff --git a/test/function/samples/output-options-hook/_config.js b/test/function/samples/output-options-hook/_config.js index 30c2de9c1..c1e2e3843 100644 --- a/test/function/samples/output-options-hook/_config.js +++ b/test/function/samples/output-options-hook/_config.js @@ -57,6 +57,7 @@ module.exports = defineTest({ preserveModules: false, reexportProtoFromExternal: true, sourcemap: false, + sourcemapDebugIds: false, sourcemapExcludeSources: false, strict: true, systemNullSetters: true, diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 72caf132d..ece6d1cb1 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,6 +1,6 @@ exports.input = 'cache, context, experimentalCacheExpiry, experimentalLogSideEffects, external, input, jsx, logLevel, makeAbsoluteExternalsRelative, maxParallelFileOps, moduleContext, onLog, onwarn, perf, plugins, preserveEntrySignatures, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch'; exports.flags = - 'amd, assetFileNames, banner, bundleConfigAsCjs, c, cache, chunkFileNames, compact, config, configPlugin, context, d, dir, dynamicImportInCjs, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalLogSideEffects, experimentalMinChunkSize, exports, extend, external, externalImportAssertions, externalImportAttributes, externalLiveBindings, f, failAfterWarnings, file, filterLogs, footer, forceExit, format, freeze, g, generatedCode, globals, h, hashCharacters, hoistTransitiveImports, i, importAttributesKey, indent, inlineDynamicImports, input, interop, intro, jsx, logLevel, m, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, minifyInternalExports, moduleContext, n, name, noConflict, o, onLog, onwarn, outro, p, paths, perf, plugin, plugins, preserveEntrySignatures, preserveModules, preserveModulesRoot, preserveSymlinks, reexportProtoFromExternal, sanitizeFileName, shimMissingExports, silent, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, stdin, strict, strictDeprecations, systemNullSetters, treeshake, v, validate, virtualDirname, w, waitForBundleInput, watch'; + 'amd, assetFileNames, banner, bundleConfigAsCjs, c, cache, chunkFileNames, compact, config, configPlugin, context, d, dir, dynamicImportInCjs, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalLogSideEffects, experimentalMinChunkSize, exports, extend, external, externalImportAssertions, externalImportAttributes, externalLiveBindings, f, failAfterWarnings, file, filterLogs, footer, forceExit, format, freeze, g, generatedCode, globals, h, hashCharacters, hoistTransitiveImports, i, importAttributesKey, indent, inlineDynamicImports, input, interop, intro, jsx, logLevel, m, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, minifyInternalExports, moduleContext, n, name, noConflict, o, onLog, onwarn, outro, p, paths, perf, plugin, plugins, preserveEntrySignatures, preserveModules, preserveModulesRoot, preserveSymlinks, reexportProtoFromExternal, sanitizeFileName, shimMissingExports, silent, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, stdin, strict, strictDeprecations, systemNullSetters, treeshake, v, validate, virtualDirname, w, waitForBundleInput, watch'; exports.output = - 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportInCjs, entryFileNames, esModule, experimentalMinChunkSize, exports, extend, externalImportAssertions, externalImportAttributes, externalLiveBindings, file, footer, format, freeze, generatedCode, globals, hashCharacters, hoistTransitiveImports, importAttributesKey, indent, inlineDynamicImports, interop, intro, manualChunks, minifyInternalExports, name, noConflict, outro, paths, plugins, preserveModules, preserveModulesRoot, reexportProtoFromExternal, sanitizeFileName, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, sourcemapIgnoreList, sourcemapPathTransform, strict, systemNullSetters, validate, virtualDirname'; + 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportInCjs, entryFileNames, esModule, experimentalMinChunkSize, exports, extend, externalImportAssertions, externalImportAttributes, externalLiveBindings, file, footer, format, freeze, generatedCode, globals, hashCharacters, hoistTransitiveImports, importAttributesKey, indent, inlineDynamicImports, interop, intro, manualChunks, minifyInternalExports, name, noConflict, outro, paths, plugins, preserveModules, preserveModulesRoot, reexportProtoFromExternal, sanitizeFileName, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapExcludeSources, sourcemapFile, sourcemapFileNames, sourcemapIgnoreList, sourcemapPathTransform, strict, systemNullSetters, validate, virtualDirname'; diff --git a/test/sourcemaps/samples/debug-ids-with-placeholder/_config.js b/test/sourcemaps/samples/debug-ids-with-placeholder/_config.js new file mode 100644 index 000000000..1ae276c6f --- /dev/null +++ b/test/sourcemaps/samples/debug-ids-with-placeholder/_config.js @@ -0,0 +1,22 @@ +const assert = require('node:assert'); + +module.exports = defineTest({ + description: 'are injected into the source and sourcemaps when using placeholders', + options: { + output: { + name: 'myModule', + sourcemapDebugIds: true, + entryFileNames: '[name]-[hash].js' + } + }, + async test(code, map) { + const match = code.match(/\/\/# debugId=([a-fA-F0-9-]+)/); + assert.ok(match, 'Could not find debugId in source'); + const sourceDebugId = match[1]; + assert.equal( + map.debugId, + sourceDebugId, + "debugId in source doesn't match debugId in sourcemap" + ); + } +}); diff --git a/test/sourcemaps/samples/debug-ids-with-placeholder/bar.js b/test/sourcemaps/samples/debug-ids-with-placeholder/bar.js new file mode 100644 index 000000000..b074af8a4 --- /dev/null +++ b/test/sourcemaps/samples/debug-ids-with-placeholder/bar.js @@ -0,0 +1 @@ +export default function Foo () {} diff --git a/test/sourcemaps/samples/debug-ids-with-placeholder/foo.js b/test/sourcemaps/samples/debug-ids-with-placeholder/foo.js new file mode 100644 index 000000000..82616f39f --- /dev/null +++ b/test/sourcemaps/samples/debug-ids-with-placeholder/foo.js @@ -0,0 +1,5 @@ +import Bar from './bar'; + +export default function Foo () {} + +Foo.prototype = Object.create( Bar.prototype ); diff --git a/test/sourcemaps/samples/debug-ids-with-placeholder/main.js b/test/sourcemaps/samples/debug-ids-with-placeholder/main.js new file mode 100644 index 000000000..a03af9723 --- /dev/null +++ b/test/sourcemaps/samples/debug-ids-with-placeholder/main.js @@ -0,0 +1 @@ +export { default as Foo } from './foo'; diff --git a/test/sourcemaps/samples/debug-ids/_config.js b/test/sourcemaps/samples/debug-ids/_config.js new file mode 100644 index 000000000..9f6b3944d --- /dev/null +++ b/test/sourcemaps/samples/debug-ids/_config.js @@ -0,0 +1,21 @@ +const assert = require('node:assert'); + +module.exports = defineTest({ + description: 'are injected into the source and sourcemaps', + options: { + output: { + name: 'myModule', + sourcemapDebugIds: true + } + }, + async test(code, map) { + const match = code.match(/\/\/# debugId=([a-fA-F0-9-]+)/); + assert.ok(match, 'Could not find debugId in source'); + const sourceDebugId = match[1]; + assert.equal( + map.debugId, + sourceDebugId, + "debugId in source doesn't match debugId in sourcemap" + ); + } +}); diff --git a/test/sourcemaps/samples/debug-ids/bar.js b/test/sourcemaps/samples/debug-ids/bar.js new file mode 100644 index 000000000..b074af8a4 --- /dev/null +++ b/test/sourcemaps/samples/debug-ids/bar.js @@ -0,0 +1 @@ +export default function Foo () {} diff --git a/test/sourcemaps/samples/debug-ids/foo.js b/test/sourcemaps/samples/debug-ids/foo.js new file mode 100644 index 000000000..82616f39f --- /dev/null +++ b/test/sourcemaps/samples/debug-ids/foo.js @@ -0,0 +1,5 @@ +import Bar from './bar'; + +export default function Foo () {} + +Foo.prototype = Object.create( Bar.prototype ); diff --git a/test/sourcemaps/samples/debug-ids/main.js b/test/sourcemaps/samples/debug-ids/main.js new file mode 100644 index 000000000..a03af9723 --- /dev/null +++ b/test/sourcemaps/samples/debug-ids/main.js @@ -0,0 +1 @@ +export { default as Foo } from './foo'; From 42e587e0e37bc0661aa39fe7ad6f1d7fd33f825c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 9 Nov 2024 07:45:52 +0100 Subject: [PATCH 3/3] 4.25.0 --- CHANGELOG.md | 19 +++++++++++++++++++ browser/package.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a6943d59..4dabd1e77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # rollup changelog +## 4.25.0 + +_2024-11-09_ + +### Features + +- Add `output.sourcemapDebugIds` option to add matching debug ids to sourcemaps and code for tools like Sentry or Rollbar (#5712) + +### Bug Fixes + +- Make it easier to manually reproduce base16 hashes by using a more standard base16 conversion algorithm (#5719) + +### Pull Requests + +- [#5712](https://github.com/rollup/rollup/pull/5712): feat: Add support for injecting Debug IDs (@timfish) +- [#5717](https://github.com/rollup/rollup/pull/5717): fix(deps): update swc monorepo (major) (@renovate[bot]) +- [#5718](https://github.com/rollup/rollup/pull/5718): chore(deps): lock file maintenance minor/patch updates (@renovate[bot]) +- [#5719](https://github.com/rollup/rollup/pull/5719): Use a less surprising base-16 encoding (@lukastaegert) + ## 4.24.4 _2024-11-04_ diff --git a/browser/package.json b/browser/package.json index 84f5b8f6c..5819c749b 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/browser", - "version": "4.24.4", + "version": "4.25.0", "description": "Next-generation ES module bundler browser build", "main": "dist/rollup.browser.js", "module": "dist/es/rollup.browser.js", diff --git a/package-lock.json b/package-lock.json index 8010e3514..a19eb449c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup", - "version": "4.24.4", + "version": "4.25.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rollup", - "version": "4.24.4", + "version": "4.25.0", "license": "MIT", "dependencies": { "@types/estree": "1.0.6" diff --git a/package.json b/package.json index 70e11ef37..c24d24560 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "4.24.4", + "version": "4.25.0", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/es/rollup.js",