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: deduplicate assets with buffer source #4712
Merged
lukastaegert
merged 11 commits into
rollup:master
from
patak-dev:feat/deduplicate-assets-when-using-buffer
Nov 12, 2022
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8b248a7
feat: deduplicate binary assets option
patak-dev 670cdf7
docs: deduplicateBinaryAssets option
patak-dev 22f9af6
test: fix previous tests after new option
patak-dev 131b6b2
test: sample using deduplicateBinaryAssets
patak-dev 7ad10a9
chore: remove option and simplify code
patak-dev 12ad13a
docs: update emitFile deduplication note
patak-dev bacaf62
chore: remove missplaced test case
patak-dev 9dbffe1
test: extend chunking-form deduplicate-assets
patak-dev aa9a4e1
chore: simplify sourceHash generation
patak-dev 7e41f02
refactor: precompute hash then slice
patak-dev c8484d6
Merge branch 'master' into feat/deduplicate-assets-when-using-buffer
lukastaegert File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...unking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/buffer-d0ca8c2a.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...g-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/otherBuffer-e8d9b528.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
otherBuffer |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/named/buffer.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...unking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/buffer-d0ca8c2a.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...g-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/otherBuffer-e8d9b528.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
otherBuffer |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/named/buffer.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...hunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/buffer-d0ca8c2a.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...ng-form/samples/emit-file/deduplicate-assets/_expected/es/assets/otherBuffer-e8d9b528.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
otherBuffer |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/named/buffer.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...ing-form/samples/emit-file/deduplicate-assets/_expected/system/assets/buffer-d0ca8c2a.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
1 change: 1 addition & 0 deletions
1
...orm/samples/emit-file/deduplicate-assets/_expected/system/assets/otherBuffer-e8d9b528.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
otherBuffer |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/named/buffer.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 42; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought: Why not just
const sourceHash = getSourceHash(source)
at the top? But then I noticed that we allow specifying a hash size. Now this raises a problem, though an extremely edge case one: If for some reason with a dynamic asset file name function two assets with the same source are given file names with different hash length, they are not recognized as identical.Going even deeper, why would we even be calling the
assetFileNames
function twice in such a situation? What we actually want is that we first calculate the hash, then compare the hash, and only if it does not match we call the function for the name. For this to work reliably, the first hash needs to have the maximum hash length (e.g. by passingInfinity
as the size, which means we do not slice). Then during the actual file name generation we can slice the hash to the required size. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the contortions in the code were because of trying to reuse the dynamic hash size.
Your idea is great, implemented it in refactor: precompute hash then slice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot easier to directly check the final changelog, as the code is now a lot closer to the original https://github.com/rollup/rollup/pull/4712/files