Skip to content

Commit

Permalink
feat: expand allowed removeKeyHash length from exactly 32 to 16-32
Browse files Browse the repository at this point in the history
  • Loading branch information
cascornelissen committed Feb 12, 2021
1 parent 9f408f6 commit 3eeac03
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaults = {
generate: void 0,
map: null,
publicPath: null,
removeKeyHash: /([a-f0-9]{32}\.?)/gi,
removeKeyHash: /([a-f0-9]{16,32}\.?)/gi,
// seed must be reset for each compilation. let the code initialize it to {}
seed: void 0,
serialize(manifest) {
Expand Down
40 changes: 39 additions & 1 deletion test/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const outputPath = join(__dirname, '../output/options');

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

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

test('removeKeyHash', async (t) => {
const config = {
Expand Down Expand Up @@ -49,6 +49,44 @@ test('removeKeyHash', async (t) => {
t.snapshot(manifest);
});

test('removeKeyHash, custom hash length', async (t) => {
const config = {
context: __dirname,
entry: '../fixtures/file.js',
output: {
hashDigestLength: 16,
filename: '[contenthash].removeKeyHash.js',
path: join(outputPath, 'removeKeyHash')
},
plugins: [
new CopyPlugin({
patterns: [
{ from: '../fixtures/*.css', to: '[name].[contenthash].[ext]' },
{ from: '../fixtures/*.txt', to: '[contenthash].[name].[ext]' }
]
})
]
};

let { manifest } = await compile(config, t);

manifest = Object.keys(manifest).reduce((prev, key) => {
prev[clean(key)] = clean(manifest[key]);
return prev;
}, {});

t.snapshot(manifest);

({ manifest } = await compile(config, t, { removeKeyHash: false }));

manifest = Object.keys(manifest).reduce((prev, key) => {
prev[clean(key)] = clean(manifest[key]);
return prev;
}, {});

t.snapshot(manifest);
});

test('useEntryKeys', async (t) => {
const config = {
context: __dirname,
Expand Down
18 changes: 18 additions & 0 deletions test/unit/snapshots/options.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ Generated by [AVA](https://avajs.dev).
main: 'main.js',
'main.js.map': 'main.js.map',
}

## removeKeyHash, custom hash length

> Snapshot 1
{
'file.txt': '[test-hash].file.txt',
'main.js': '[test-hash].removeKeyHash.js',
'style.css': 'style.[test-hash].css',
}

> Snapshot 2
{
'[test-hash].file.txt': '[test-hash].file.txt',
'main.js': '[test-hash].removeKeyHash.js',
'style.[test-hash].css': 'style.[test-hash].css',
}
Binary file modified test/unit/snapshots/options.js.snap
Binary file not shown.

0 comments on commit 3eeac03

Please sign in to comment.