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

Refactor createAssetPackage to use happo.io's deterministicArchive #68

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

lencioni
Copy link
Contributor

This is how we create archives elsewhere, so we might as well build on top of it.

One improvement with this method is it enables zlib compression at level 6, which in my tests seems to reduce the size of asset packages by about 14%. That is one reach the package hash in the tests changed.

This is how we create archives elsewhere, so we might as well build on
top of it.

One improvement with this method is it enables zlib compression at level
6, which in my tests seems to reduce the size of asset packages by about
14%. That is one reach the package hash in the tests changed.
@lencioni lencioni requested a review from trotzig February 18, 2025 20:57
// Get all of the archive items in parallel first. Then add them to the
// archive serially afterwards to ensure that packages are created
// deterministically.
await Promise.all(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use p-all here, to ensure the concurrency isn't too high.


seenUrls.add(name);

if (/\.happo-tmp\/_inlined/.test(name)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use string.includes instead of a regex test.

@@ -45,13 +45,18 @@ describe('createAssetPackage', () => {
},
]);

assert.equal(pkg.hash, '898862aad00d429b73f57256332a6ee1');
assert.equal(pkg.hash, '8cdd63709442c4f37034425715630055');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash is different because the determinsticArchive function uses zlib compression level of 6 (archiver's default seems to be 1, which is not great compression). I think the entries in the zip are also ordered differently now, which would also change the hash.

@lencioni lencioni merged commit 0fb3b67 into main Feb 18, 2025
5 checks passed
@lencioni lencioni deleted the deterministic-archive branch February 18, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant