You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Everytime I run this command (without changing anything in distribution), the checksum (a priori containing some file modification timestamps) will be different.
However paradoxically, extension stores, like the Firefox store, will ask developers to provide steps to build the extension package and require it to produce the exact same checksum as the ZIP that you submitted.
How can I build a ZIP for my extension that would always produce the exact same ZIP?
When I use xxd I see that the sizes are identical but the contents are different, possibly a different ordering.
When I use zipinfo on the generated zip files, I can see inconsistent orderings, confirming my suspicion.
The package itself is relatively light, the actual zip generation is done by jszip (https://www.npmjs.com/package/jszip).
That library has not been updated for 6 years. We should cut out this middle man, and implement a deterministic file reading logic ourselves, and directly use jszip.
@kylekatarnls Do you want to submit a patch to implement this?
I took a look but apparently it's not just about file order, all of the points below must match:
date of files
date of folders (automatically created from file paths but with current timestamp by default)
order of the structure (due to the way zipBuffer is made, i.e. using recursion, it has to be changed so it first do the listing recursively without starting to queue with zip.file(), then apply all the zip.file() in a second step after listing)
I took a look but apparently it's not just about file order, all of the points below must match:
date of files
date of folders (automatically created from file paths but with current timestamp by default)
If timestamps of the files don't change, running the same command twice will generate the same output.
order of the structure (due to the way zipBuffer is made, i.e. using recursion, it has to be changed so it first do the listing recursively without starting to queue with zip.file(), then apply all the zip.file() in a second step after listing)
Yep, that is the issue here. I provided pointers to the relevant implementation details at #3613 (comment). Are you interested in contributing a patch? If not, I will make this issue available to other interested contributors.
If timestamps of the files don't change, running the same command twice will generate the same output.
File timestamps use the one from the actual file, but folder timestamps use current timestamp. So even if you have only 1 file in a folder, such as folder/index.html, then on first run you get:
Length Date Time Name
--------- ---------- ----- ----
0 2026-02-16 19:19 folder/
295 2026-02-10 12:10 folder/index.html
And running it again later the folder date-time will change even if was not touched:
Length Date Time Name
--------- ---------- ----- ----
0 2026-02-16 19:20 folder/
295 2026-02-10 12:10 folder/index.html
I was considering the option createFolder: false but it might have an impact for those having empty folders in their package, I don't know if it's a thing that really needs to be supported though.
I'm taking a look and trying to make in in 2 steps, but it won't just touch the part of the code you mentioned, it will probably end up with a rather significant rewriting of zip-dir.js I don't promise to finish that soon.
Listing files, then sorting before zipping them should be fine.
But now there is also the zipping phase that happen in parallel and you can start zipping A before B and get B zipped bytes ready before A ones.
So this means we have to save the result for B in a variable and wait for A content to be ready and appended to the result file, before we actually write the content for B.
As a result writing a deterministic ZIP will consume a bit more memory and take a bit more time than the current version.
The current implementation in web-ext already keeps the generated zip in memory before writing to disk, opposed to streaming the zip.
I don't think that memory efficiency is a problem yet; keep in mind that the resulting file should be sufficiently reasonably sized to be loaded by users in a web browser.
The original zip-dir library did not limit the size of the files either, only the number of concurrently open files.
Thanks @kylekatarnls and @Rob--W for the original investigation. Trying to have a stab at it. Opening a PR #3709 using JSZip directly with sorted entries, a fixed default timestamp (1980-01-01) with an override parameter.
Activity
Rob--W commentedon Feb 12, 2026
I tried it myself with an extension containing many files, at https://addons.mozilla.org/firefox/downloads/file/4207386/crxviewer-1.7.0.xpi
When I use
xxdI see that the sizes are identical but the contents are different, possibly a different ordering.When I use
zipinfoon the generated zip files, I can see inconsistent orderings, confirming my suspicion.We should use a consistent ordering.
Rob--W commentedon Feb 12, 2026
We call
zipDiratweb-ext/src/cmd/build.js
Lines 134 to 136 in 2adf895
zipDir is the
zip-dirlibrary, which is essentially a single file implementation at https://github.com/jsantell/node-zip-dir/blob/master/index.jsThe package itself is relatively light, the actual zip generation is done by jszip (https://www.npmjs.com/package/jszip).
That library has not been updated for 6 years. We should cut out this middle man, and implement a deterministic file reading logic ourselves, and directly use jszip.
@kylekatarnls Do you want to submit a patch to implement this?
kylekatarnls commentedon Feb 16, 2026
I took a look but apparently it's not just about file order, all of the points below must match:
zip.file(), then apply all thezip.file()in a second step after listing)Rob--W commentedon Feb 16, 2026
If timestamps of the files don't change, running the same command twice will generate the same output.
Yep, that is the issue here. I provided pointers to the relevant implementation details at #3613 (comment). Are you interested in contributing a patch? If not, I will make this issue available to other interested contributors.
kylekatarnls commentedon Feb 16, 2026
File timestamps use the one from the actual file, but folder timestamps use current timestamp. So even if you have only 1 file in a folder, such as
folder/index.html, then on first run you get:And running it again later the folder date-time will change even if was not touched:
I was considering the option
createFolder: falsebut it might have an impact for those having empty folders in their package, I don't know if it's a thing that really needs to be supported though.I'm taking a look and trying to make in in 2 steps, but it won't just touch the part of the code you mentioned, it will probably end up with a rather significant rewriting of
zip-dir.jsI don't promise to finish that soon.Rob--W commentedon Feb 16, 2026
The
.filemethod can also be used to create a directory: https://stuk.github.io/jszip/documentation/api_jszip/file_data.html#argumentsSo you can use that to "create" the directory before adding the file, and use
createFolders: falseon the files for clarity.kylekatarnls commentedon Feb 20, 2026
Hello, I have another question/concern:
Listing files, then sorting before zipping them should be fine.
But now there is also the zipping phase that happen in parallel and you can start zipping A before B and get B zipped bytes ready before A ones.
So this means we have to save the result for B in a variable and wait for A content to be ready and appended to the result file, before we actually write the content for B.
As a result writing a deterministic ZIP will consume a bit more memory and take a bit more time than the current version.
Should it be then an option, so users can decide?
E.g.
zipMode: 'fast' | 'deterministic'Rob--W commentedon Feb 20, 2026
The current implementation in web-ext already keeps the generated zip in memory before writing to disk, opposed to streaming the zip.
I don't think that memory efficiency is a problem yet; keep in mind that the resulting file should be sufficiently reasonably sized to be loaded by users in a web browser.
The original zip-dir library did not limit the size of the files either, only the number of concurrently open files.
Gueupo commentedon May 5, 2026
Thanks @kylekatarnls and @Rob--W for the original investigation. Trying to have a stab at it. Opening a PR #3709 using JSZip directly with sorted entries, a fixed default timestamp (1980-01-01) with an override parameter.
3692189725im-bit commentedon Oct 24, 2026