Skip to content

Commit

Permalink
Reduce max hash size to 21 (#5723)
Browse files Browse the repository at this point in the history
In certain cases, the maximum length was actually 21, resulting in unexpected
file names and off-by-one-sourcemaps.
  • Loading branch information
lukastaegert authored Nov 15, 2024
1 parent a9acb57 commit 50697b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/migration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,7 @@ Rollup now includes native code that is automatically installed (and removed) as

The browser build (`@rollup/browser` on NPM) now relies on a WASM artifact that needs to be provided as well. If you are using the browser build with Vite, you'll need to add `"@rollup/browser"` to `optimizeDeps.exclude`, otherwise `npm run dev` fails with an invalid path to the `.wasm` file (see also [vitejs #14609](https://github.com/vitejs/vite/issues/14609)). Otherwise it should work without any specific intervention.

Otherwise, an obvious change is that Rollup now uses url-safe base64 hashes in file names instead of the older base16 hashes. This provides more hash safety but means that hash length is now limited to at most 22 characters for technical reasons.
Otherwise, an obvious change is that Rollup now uses url-safe base64 hashes in file names instead of the older base16 hashes. This provides more hash safety but means that hash length is now limited to at most 21 characters for technical reasons.

When bundling CLI apps, Rollup will now automatically preserve shebang comments in entry files if the output [`format`](../configuration-options/index.md#output-format) is `es` or `cjs`. Previously, you would have needed to add the comment via a plugin.

Expand Down
2 changes: 1 addition & 1 deletion src/utils/hashPlaceholders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ const hashPlaceholderRight = '}~';
const hashPlaceholderOverhead = hashPlaceholderLeft.length hashPlaceholderRight.length;

// This is the size of a 128-bits xxhash with base64url encoding
const MAX_HASH_SIZE = 22;
const MAX_HASH_SIZE = 21;
export const DEFAULT_HASH_SIZE = 8;

export type HashPlaceholderGenerator = (optionName: string, hashSize: number) => string;
Expand Down
4 changes: 2 additions & 2 deletions test/function/samples/hashing/maximum-hash-size/_config.js
Original file line number Diff line number Diff line change
@@ -1,9 1,9 @@
module.exports = defineTest({
description: 'throws when the maximum hash size is exceeded',
options: { output: { chunkFileNames: '[hash:23].js' } },
options: { output: { chunkFileNames: '[hash:22].js' } },
generateError: {
code: 'VALIDATION_ERROR',
message:
'Hashes cannot be longer than 22 characters, received 23. Check the "output.chunkFileNames" option.'
'Hashes cannot be longer than 21 characters, received 22. Check the "output.chunkFileNames" option.'
}
});

0 comments on commit 50697b8

Please sign in to comment.