Skip to content

Commit 57277bf

Browse files
authored
Implement "output.hashCharacters" option to define character set for file hashes (#5371)
* Add documentation * Add new hashing functions and update hashes The hashes changed due to how they are now encoded * Add new hashing functions in JavaScript * Implement new output.hashCharacters option
1 parent 63a91a6 commit 57277bf

476 files changed

Lines changed: 852 additions & 440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

browser/src/wasm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line import/no-unresolved
2-
export { parse, xxhashBase64Url } from '../../wasm/bindings_wasm.js';
2+
export { parse, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../wasm/bindings_wasm.js';
33

44
// eslint-disable-next-line import/no-unresolved
55
import { parse } from '../../wasm/bindings_wasm.js';

cli/help.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Basic options:
4848
--generatedCode.objectShorthand Use shorthand properties in generated code
4949
--no-generatedCode.reservedNamesAsProps Always quote reserved names as props
5050
--generatedCode.symbols Use symbols in generated code
51+
--hashCharacters <name> Use the specified character set for file hashes
5152
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
5253
--no-indent Don't indent result
5354
--inlineDynamicImports Create single bundle when using dynamic imports

docs/command-line-interface/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default {
9090
externalImportAttributes,
9191
footer,
9292
generatedCode,
93+
hashCharacters,
9394
hoistTransitiveImports,
9495
inlineDynamicImports,
9596
interop,
@@ -398,6 +399,7 @@ Many options have command line equivalents. In those cases, any arguments passed
398399
--generatedCode.objectShorthand Use shorthand properties in generated code
399400
--no-generatedCode.reservedNamesAsProps Always quote reserved names as props
400401
--generatedCode.symbols Use symbols in generated code
402+
--hashCharacters <name> Use the specified character set for file hashes
401403
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
402404
--no-indent Don't indent result
403405
--inlineDynamicImports Create single bundle when using dynamic imports

docs/configuration-options/index.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ The pattern to use for naming custom emitted assets to include in the build outp
539539
540540
- `[extname]`: The file extension of the asset including a leading dot, e.g. `.css`.
541541
- `[ext]`: The file extension without a leading dot, e.g. `css`.
542-
- `[hash]`: A hash based on the content of the asset. You can also set a specific hash length via e.g. `[hash:10]`.
542+
- `[hash]`: A hash based on the content of the asset. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character sets, see [`output.hashCharacters`](#output-hashcharacters)
543543
- `[name]`: The file name of the asset excluding any extension.
544544
545545
Forward slashes `/` can be used to place files in sub-directories. When using a function, `assetInfo` is a reduced version of the one in [`generateBundle`](../plugin-development/index.md#generatebundle) without the `fileName`. See also [`output.chunkFileNames`](#output-chunkfilenames), [`output.entryFileNames`](#output-entryfilenames).
@@ -585,7 +585,7 @@ See also [`output.intro/output.outro`](#output-intro-output-outro).
585585
The pattern to use for naming shared chunks created when code-splitting, or a function that is called per chunk to return such a pattern. Patterns support the following placeholders:
586586
587587
- `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
588-
- `[hash]`: A hash based only on the content of the final generated chunk, including transformations in [`renderChunk`](../plugin-development/index.md#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`.
588+
- `[hash]`: A hash based only on the content of the final generated chunk, including transformations in [`renderChunk`](../plugin-development/index.md#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character sets, see [`output.hashCharacters`](#output-hashcharacters)
589589
- `[name]`: The name of the chunk. This can be explicitly set via the [`output.manualChunks`](#output-manualchunks) option or when the chunk is created by a plugin via [`this.emitFile`](../plugin-development/index.md#this-emitfile). Otherwise, it will be derived from the chunk contents.
590590
591591
Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](../plugin-development/index.md#generatebundle) without properties that depend on file names and no information about the rendered modules as rendering only happens after file names have been generated. You can however access a list of included `moduleIds`. See also [`output.assetFileNames`](#output-assetfilenames), [`output.entryFileNames`](#output-entryfilenames).
@@ -661,7 +661,7 @@ Promise.resolve()
661661
The pattern to use for chunks created from entry points, or a function that is called per entry chunk to return such a pattern. Patterns support the following placeholders:
662662
663663
- `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
664-
- `[hash]`: A hash based only on the content of the final generated entry chunk, including transformations in [`renderChunk`](../plugin-development/index.md#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`.
664+
- `[hash]`: A hash based only on the content of the final generated entry chunk, including transformations in [`renderChunk`](../plugin-development/index.md#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character sets, see [`output.hashCharacters`](#output-hashcharacters)
665665
- `[name]`: The file name (without extension) of the entry point, unless the object form of input was used to define a different name.
666666
667667
Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](../plugin-development/index.md#generatebundle) without properties that depend on file names and no information about the rendered modules as rendering only happens after file names have been generated. You can however access a list of included `moduleIds`. See also [`output.assetFileNames`](#output-assetfilenames), [`output.chunkFileNames`](#output-chunkfilenames).
@@ -863,6 +863,20 @@ const foo = 42;
863863
exports.foo = foo;
864864
```
865865
866+
### output.hashCharacters
867+
868+
| | |
869+
| -------: | :------------------------------ |
870+
| Type: | `"base64" \| "base32" \| "hex"` |
871+
| CLI: | `--hashCharacters <name>` |
872+
| Default: | `"base64"` |
873+
874+
This determines the character set that Rollup is allowed to use in file hashes.
875+
876+
- the default `"base64"` will use url-safe base-64 hashes with potential characters `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`.
877+
- `"base36"` will only use lower-case letters and numbers `abcdefghijklmnopqrstuvwxyz0123456789`.
878+
- `"hex"` will create hexadecimal hashes with characters `abcdef0123456789`.
879+
866880
### output.hoistTransitiveImports
867881
868882
| | |
@@ -1480,7 +1494,7 @@ The location of the generated bundle. If this is an absolute path, all the `sour
14801494
The pattern to use for sourcemaps, or a function that is called per sourcemap to return such a pattern. Patterns support the following placeholders:
14811495

14821496
- `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
1483-
- `[hash]`: A hash based only on the content of the final generated sourcemap. You can also set a specific hash length via e.g. `[hash:10]`.
1497+
- `[hash]`: A hash based only on the content of the final generated sourcemap. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character sets, see [`output.hashCharacters`](#output-hashcharacters)
14841498
- `[chunkhash]`: The same hash as the one used for the corresponding generated chunk (if any).
14851499
- `[name]`: The file name (without extension) of the entry point, unless the object form of input was used to define a different name.
14861500

docs/javascript-api/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ const outputOptions = {
165165
externalImportAttributes,
166166
footer,
167167
generatedCode,
168+
hashCharacters,
168169
hoistTransitiveImports,
169170
inlineDynamicImports,
170171
interop,

docs/repl/stores/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ export const useOptions = defineStore('options2', () => {
242242
name: 'output.globals',
243243
required: () => true
244244
});
245+
const optionOutputHashCharacters = getSelect({
246+
defaultValue: 'base64',
247+
name: 'output.hashCharacters',
248+
options: () => ['base64', 'base36', 'hex']
249+
});
245250
const optionOutputHoistTransitiveImports = getBoolean({
246251
available: alwaysTrue,
247252
defaultValue: true,
@@ -432,6 +437,7 @@ export const useOptions = defineStore('options2', () => {
432437
optionOutputGeneratedCodeReservedNamesAsProperties,
433438
optionOutputGeneratedCodeSymbols,
434439
optionOutputGlobals,
440+
optionOutputHashCharacters,
435441
optionOutputHoistTransitiveImports,
436442
optionOutputIndent,
437443
optionOutputInlineDynamicImports,

native.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
export function parse(code: string, allowReturnOutsideFunction: boolean): Buffer
77
export function parseAsync(code: string, allowReturnOutsideFunction: boolean, signal?: AbortSignal | undefined | null): Promise<Buffer>
88
export function xxhashBase64Url(input: Uint8Array): string
9+
export function xxhashBase36(input: Uint8Array): string
10+
export function xxhashBase16(input: Uint8Array): string

native.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ const requireWithFriendlyError = id => {
9393
}
9494
};
9595

96-
const { parse, parseAsync, xxhashBase64Url } = requireWithFriendlyError(
96+
const { parse, parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } = requireWithFriendlyError(
9797
existsSync(join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
9898
);
9999

100100
module.exports.parse = parse;
101101
module.exports.parseAsync = parseAsync;
102102
module.exports.xxhashBase64Url = xxhashBase64Url;
103+
module.exports.xxhashBase36 = xxhashBase36;
104+
module.exports.xxhashBase16 = xxhashBase16;

native.wasm.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
const { parse, xxhashBase64Url } = require('./wasm-node/bindings_wasm.js');
1+
const {
2+
parse,
3+
xxhashBase64Url,
4+
xxhashBase36,
5+
xxhashBase16
6+
} = require('./wasm-node/bindings_wasm.js');
27

38
exports.parse = parse;
49
exports.parseAsync = async (code, allowReturnOutsideFunction, _signal) =>
510
parse(code, allowReturnOutsideFunction);
611
exports.xxhashBase64Url = xxhashBase64Url;
12+
exports.xxhashBase36 = xxhashBase36;
13+
exports.xxhashBase16 = xxhashBase16;

rust/Cargo.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)