Skip to content

add allowNumericOnlyHash option for asset/resource #17903

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
add allowNumericOnlyHash test
  • Loading branch information
makaria committed Dec 28, 2023
commit a0eca572ae0c5bbf5b5586ab15a8736757b0ca6d
13 changes: 13 additions & 0 deletions test/__snapshots__/Cli.basictest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,19 @@ Object {
"multiple": false,
"simpleType": "string",
},
"module-generator-asset-resource-allow-numeric-only-hash": Object {
"configs": Array [
Object {
"description": "Hash may not contain any non-numeric characters when true. Hash may prefixed with character 'a' when false.",
"multiple": false,
"path": "module.generator.asset/resource.allowNumericOnlyHash",
"type": "boolean",
},
],
"description": "Hash may not contain any non-numeric characters when true. Hash may prefixed with character 'a' when false.",
"multiple": false,
"simpleType": "boolean",
},
"module-generator-asset-resource-emit": Object {
"configs": Array [
Object {
Expand Down
24 changes: 24 additions & 0 deletions test/configCases/asset-modules/allow-numeric-only-hash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import url from "../_images/file.png";
import url2 from "../_images/file_copy.png";

it("should import asset with module.generator.asset.allowNumericOnlyHash", () => {
expect(url).toMatch(/images\/file\.[a-f0-9]{6}\.png$/);
expect(url2).toMatch(/images\/file_copy\.[a-f0-9]{6}\.png$/);
const assetInfo1 = __STATS__.assets.find(
a => a.info.sourceFilename === "../_images/file.png"
).info;
const assetInfo2 = __STATS__.assets.find(
a => a.info.sourceFilename === "../_images/file_copy.png"
).info;

expect(assetInfo1.contenthash.length).toBe(2);
expect(assetInfo1.contenthash[0].length).toBe(6);
expect(assetInfo1.contenthash[1].length).toBe(6);
expect(assetInfo2.contenthash.length).toBe(2);
expect(assetInfo2.contenthash[0].length).toBe(6);
expect(assetInfo2.contenthash[1].length).toBe(6);

expect(assetInfo1.fullhash).toBe(assetInfo2.fullhash);
expect(assetInfo1.contenthash[0]).not.toEqual(assetInfo2.contenthash[0]);
expect(assetInfo1.contenthash[0].slice(1)).toEqual(assetInfo2.contenthash[0].slice(1));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
output: {
hashDigestLength: 6
},
module: {
rules: [
{
test: /file.png$/,
type: "asset/resource",
generator: {
emit: false,
filename: "[name].[contenthash:6][ext]",
allowNumericOnlyHash: false
}
},
{
test: /file_copy.png$/,
type: "asset/resource",
generator: {
emit: false,
filename: "[name].[contenthash:6][ext]",
allowNumericOnlyHash: true
}
}
]
}
};