Skip to content

fix(prelude): extract compressed files into the native addon cache dir - #309

Merged
robertsLando merged 1 commit into
mainfrom
fix/bootstrap-homedir-import
Oct 23, 2026
Merged

robertsLando merged 1 commit into
mainfrom
fix/bootstrap-homedir-import

Conversation

@robertsLando

@robertsLando robertsLando commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #316. That PR fixed the missing homedir import from #166, but kept #166's temp location, ~/.pkg-cache.

Problem

At runtime, deflateSync extracts compressed snapshot files into ~/.pkg-cache/tmp-*. That gives a packaged binary a second on-disk location next to ~/.cache/pkg, where native addons already go. The second location:

  • is not documented anywhere (docs-site/architecture.md only mentions ~/.cache/pkg)
  • ignores PKG_NATIVE_CACHE_PATH, so a host with a read-only home folder can move the addon cache but compressed files still fail
  • shares its name with pkg-fetch's build-time download cache (places.js, and lib/sea.ts)

Fix

A new pkgCacheDir() in bootstrap-shared.js returns ~/.cache/pkg, or PKG_NATIVE_CACHE_PATH/pkg when that variable is set. Both patchDlopen and deflateSync use it, and deflateSync creates the folder before calling mkdtemp.

The homedir import that #316 added to bootstrap.js is removed because nothing in that file uses it any more.

Nothing depends on ~/.pkg-cache at runtime: #166 never ran successfully and has not been released. The build-time cache in lib/sea.ts is a separate thing and is unchanged.

Verified

  • test-80-compression-various-file-access, test-50-native-addon and test-50-native-addon-2 (node22) pass with HOME pointed at an empty folder. The temp folder is created under ~/.cache/pkg.
  • With PKG_NATIVE_CACHE_PATH set, the temp folder goes under that path instead.
  • yarn lint is clean.

deflateSync wrote to ~/.pkg-cache, a second runtime location that is
undocumented, not overridable, and shares its name with pkg-fetch's
build-time download cache. Use the dir patchDlopen already extracts
native addons into (~/.cache/pkg, or PKG_NATIVE_CACHE_PATH) via a shared
pkgCacheDir(), so read-only-home hosts can redirect both.
@robertsLando
robertsLando force-pushed the fix/bootstrap-homedir-import branch from 91a5f38 to a1a34ab Compare October 23, 2026 07:21
@robertsLando robertsLando changed the title fix(prelude): import the cache dir that deflateSync extracts into fix(prelude): extract compressed files into the native addon cache dir Oct 23, 2026
@robertsLando
robertsLando merged commit c819e37 into main Oct 23, 2026
27 of 28 checks passed
@robertsLando
robertsLando deleted the fix/bootstrap-homedir-import branch October 23, 2026 07:23
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