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

Expose full SHA256 hash in file name placeholders #2770

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Chunk.ts
Expand Up @@ -208,13 +208,16 @@ export default class Chunk {
options: OutputOptions,
existingNames: Record<string, true>
) {
const hash = () => this.computeContentHashWithDependencies(addons, options);
this.id = makeUnique(
renderNamePattern(pattern, patternName, type => {
switch (type) {
case 'format':
return options.format === 'es' ? 'esm' : options.format;
case 'hash':
return this.computeContentHashWithDependencies(addons, options);
return hash().substr(0, 8);
case 'fullhash':
return hash();
case 'name':
return this.getChunkName();
}
Expand Down Expand Up @@ -765,7 +768,7 @@ export default class Chunk {
else hash.update(dep.getRenderedHash());
});

return hash.digest('hex').substr(0, 8);
return hash.digest('hex');
}

private finaliseDynamicImports() {
Expand Down
16 changes: 11 additions & 5 deletions src/utils/assetHooks.ts
Expand Up @@ -22,13 +22,19 @@ export function getAssetFileName(

return makeUnique(
renderNamePattern(assetFileNames, 'assetFileNames', name => {
function computeHash() {
const hash = sha256();
hash.update(name);
hash.update(':');
hash.update(asset.source);
return hash.digest('hex');
}

switch (name) {
case 'hash':
const hash = sha256();
hash.update(name);
hash.update(':');
hash.update(asset.source);
return hash.digest('hex').substr(0, 8);
return computeHash().substr(0, 8);
case 'fullhash':
return computeHash();
case 'name':
return asset.name.substr(0, asset.name.length - extname(asset.name).length);
case 'extname':
Expand Down