Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand allowed removeKeyHash length from exactly 32 to 16-32 #248

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 'removeKeyHashCustomLength')
},
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 @@ -6,6 +6,24 @@ Generated by [AVA](https://avajs.dev).

## removeKeyHash

> 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',
}

## removeKeyHash, custom hash length

> Snapshot 1

{
Expand Down
Binary file modified test/unit/snapshots/options.js.snap
Binary file not shown.