From 301c59536888bf0632c301d2f98f83695da1dc2a Mon Sep 17 00:00:00 2001 From: Cas Cornelissen Date: Fri, 5 Feb 2021 22:28:04 +0100 Subject: [PATCH] feat: expand allowed removeKeyHash length from exactly 32 to 16-32 --- lib/index.js | 2 +- test/unit/options.js | 40 +++++++++++++++++++++++++++- test/unit/snapshots/options.js.md | 18 +++++++++++++ test/unit/snapshots/options.js.snap | Bin 325 -> 361 bytes 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 189266b..0a12f17 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { diff --git a/test/unit/options.js b/test/unit/options.js index 507addf..0907b80 100644 --- a/test/unit/options.js +++ b/test/unit/options.js @@ -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 = { @@ -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, diff --git a/test/unit/snapshots/options.js.md b/test/unit/snapshots/options.js.md index 6089cce..086ca0a 100644 --- a/test/unit/snapshots/options.js.md +++ b/test/unit/snapshots/options.js.md @@ -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 { diff --git a/test/unit/snapshots/options.js.snap b/test/unit/snapshots/options.js.snap index 7505ae7de0e2b5f79743166fd9c41efd2b27aa72..24445cbafd66e159f8d6faf9f5a6ecad0639d3f5 100644 GIT binary patch delta 346 zcmV-g0j2)M0_g&OK~_N^Q*L2!b7*gLAa*he0s!J+TBfB5=N_4EhVk&jP;HBRX7Q(vsa$N&P}K%8*GW$71rWyou`nZ>AS0W9QdVkm2_qw%DIg%gz{tzM$i$JM z8h>bNxS_&&xrqhX#E_iAqz9x;2s?w37-t}v%VGwkZGgBCh}RM}pBc@3jaYn2jOcG5K%pEYk46>f0)ZF~CRPWSE4uJk(r4{sWB`E(AQpM`^at0Gk57U%PU!DbU#!Fk z7JUrF6W+X5x}4JxYkisPccV#X5))YTI3olfW&)YZ4mO7(k%N&*4@jE;u`nZ>AS0W9 zQdVkm2_qw%DIg%gz{tzM$jFhw8h=RUG8+MD3m}dmY&H`yW}~U$h6?NDCKg~5Lvjj> z8IZOC;zA%^OV~NgXjXBgW#**nl~k0#1Vo}sQj1G;GZKq4V)bB>XqsTohVf;P^%SM% z=9i^