Skip to content

Commit 9333cc1

Browse files
feat: expand allowed removeKeyHash length from exactly 32 to 16-32 (#248)
1 parent 9f408f6 commit 9333cc1

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const defaults = {
1414
generate: void 0,
1515
map: null,
1616
publicPath: null,
17-
removeKeyHash: /([a-f0-9]{32}\.?)/gi,
17+
removeKeyHash: /([a-f0-9]{16,32}\.?)/gi,
1818
// seed must be reset for each compilation. let the code initialize it to {}
1919
seed: void 0,
2020
serialize(manifest) {

test/unit/options.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const outputPath = join(__dirname, '../output/options');
1010

1111
test.after(() => del(outputPath));
1212

13-
const clean = (what) => what.replace(/([a-f0-9]{20,32})/gi, '[test-hash]');
13+
const clean = (what) => what.replace(/([a-f0-9]{16,32})/gi, '[test-hash]');
1414

1515
test('removeKeyHash', async (t) => {
1616
const config = {
@@ -49,6 +49,44 @@ test('removeKeyHash', async (t) => {
4949
t.snapshot(manifest);
5050
});
5151

52+
test('removeKeyHash, custom hash length', async (t) => {
53+
const config = {
54+
context: __dirname,
55+
entry: '../fixtures/file.js',
56+
output: {
57+
hashDigestLength: 16,
58+
filename: '[contenthash].removeKeyHash.js',
59+
path: join(outputPath, 'removeKeyHashCustomLength')
60+
},
61+
plugins: [
62+
new CopyPlugin({
63+
patterns: [
64+
{ from: '../fixtures/*.css', to: '[name].[contenthash].[ext]' },
65+
{ from: '../fixtures/*.txt', to: '[contenthash].[name].[ext]' }
66+
]
67+
})
68+
]
69+
};
70+
71+
let { manifest } = await compile(config, t);
72+
73+
manifest = Object.keys(manifest).reduce((prev, key) => {
74+
prev[clean(key)] = clean(manifest[key]);
75+
return prev;
76+
}, {});
77+
78+
t.snapshot(manifest);
79+
80+
({ manifest } = await compile(config, t, { removeKeyHash: false }));
81+
82+
manifest = Object.keys(manifest).reduce((prev, key) => {
83+
prev[clean(key)] = clean(manifest[key]);
84+
return prev;
85+
}, {});
86+
87+
t.snapshot(manifest);
88+
});
89+
5290
test('useEntryKeys', async (t) => {
5391
const config = {
5492
context: __dirname,

test/unit/snapshots/options.js.md

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ Generated by [AVA](https://avajs.dev).
66

77
## removeKeyHash
88

9+
> Snapshot 1
10+
11+
{
12+
'file.txt': '[test-hash].file.txt',
13+
'main.js': '[test-hash].removeKeyHash.js',
14+
'style.css': 'style.[test-hash].css',
15+
}
16+
17+
> Snapshot 2
18+
19+
{
20+
'[test-hash].file.txt': '[test-hash].file.txt',
21+
'main.js': '[test-hash].removeKeyHash.js',
22+
'style.[test-hash].css': 'style.[test-hash].css',
23+
}
24+
25+
## removeKeyHash, custom hash length
26+
927
> Snapshot 1
1028
1129
{

test/unit/snapshots/options.js.snap

36 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)