Skip to content

fix: wait for the zip module to load before traversing in folders:download --zip - #719

Closed
dgilman-perplexity wants to merge 1 commit into
box:mainfrom
dgilman-perplexity:fix/folders-download-zip-await-archiver
Closed

fix: wait for the zip module to load before traversing in folders:download --zip#719
dgilman-perplexity wants to merge 1 commit into
box:mainfrom
dgilman-perplexity:fix/folders-download-zip-await-archiver

Conversation

@dgilman-perplexity

Copy link
Copy Markdown
Contributor

Fixes #718

What

folders:download --zip regressed in v4.10.0: the archive is left empty (or the command hangs) and the files are written loose to the destination. #686 switched to the ESM-only archiver 8 and made _setupZip() async to await import('archiver'), but run() does not wait for it, so this.zip is still undefined when the first items are processed and they take the non-zip code path.

This change:

  • adds _loadZipArchive(), awaited in run() before traversal starts, so the archiver module is loaded up front;
  • makes _setupZip() synchronous again, so this.zip is assigned before _getItems() yields the first item (the returned promise still resolves when the output stream closes, as before).

Awaiting _setupZip() itself would deadlock, since its promise only resolves after finalize().

Tests

  • New test should initialize the zip archive before traversing the folder: stubs _getItems() and asserts this.zip is already set when it is first called. Fails on main (first --zip download in the process races the dynamic import), passes with this change.
  • The existing --zip test now verifies the archive: it lists the central-directory entries (small helper, no new dependency) and checks that nothing was written next to the .zip. This resolves the 2018 @TODO there.
  • npm test: 1191 passing, 9 pending. eslint and prettier clean on the touched files.

Reproduced manually on Node 20.20.1 with a mock API: 4.10.0 gives a 0-byte zip plus loose files 5/5; with this patch applied to 4.10.0, 5/5 valid archives. box files:zip is unaffected.

Since the archiver 8 upgrade, _setupZip() awaits a dynamic import before assigning this.zip, but run() started folder traversal without waiting for it. When the first folder listing returned before the module loaded, items took the non-zip path, the archive was never finalized and the .zip was left empty (or the command hung).

Load the module up front and keep _setupZip() synchronous so this.zip exists before the first item is processed. Add a regression test that asserts the archive is initialized before _getItems() runs, and verify the entries of the produced archive in the existing --zip test.
@CLAassistant

CLAassistant commented Sep 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dgilman-perplexity
dgilman-perplexity marked this pull request as ready for review September 10, 2026 16:35
@dgilman-perplexity
dgilman-perplexity requested a review from a team September 10, 2026 16:35
@dgilman-perplexity dgilman-perplexity changed the title fix: await archiver import before traversing in folders:download --zip fix: wait for the zip module to load before traversing in folders:download --zip Sep 10, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 34503039201

Coverage at 84.916% (no base build to compare)

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 6061
Covered Lines: 5396
Line Coverage: 89.03%
Relevant Branches: 2153
Covered Branches: 1579
Branch Coverage: 73.34%
Branches in Coverage %: Yes
Coverage Strength: 642.63 hits per line

💛 - Coveralls

@arjankowski

Copy link
Copy Markdown
Contributor

Thanks for the fix, @dgilman-perplexity!
I've cherry-picked your commit into #721 from an internal branch so that all CI checks (including the FOSSA license scan) can run — fork PRs don't have access to repository secrets, which caused FOSSA to fail here.

Closing this in favor of #721

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.

folders:download --zip produces an empty archive (or hangs) since v4.10.0: this.zip is assigned after traversal starts

4 participants