Skip to content

Use package.json gitHead in postinstall ref lookup#46

Merged
namthor9 merged 5 commits into
mainfrom
maxr/testfix
May 22, 2026
Merged

Use package.json gitHead in postinstall ref lookup#46
namthor9 merged 5 commits into
mainfrom
maxr/testfix

Conversation

@namthor9
Copy link
Copy Markdown
Contributor

When installing a git dep (npm install git://...#), npm strips the .git dir from its install cache, so the postinstall script's HAS_GIT check fails and the fallback uses the v$version tag — which doesn't exist for PR commits or any pre-release branch. That's why the test-install CI jobs have been failing on every version-bump PR.

npm writes the resolved SHA into the installed package.json as a gitHead field. Insert a new rung between the existing git-HEAD and v$version paths that reads gitHead and uses it as the lookup ref. v$version stays as the final fallback for post-release tarball installs.

namthor9 added 5 commits May 21, 2026 16:35
When installing a git dep (npm install git://...#<sha>), npm strips the
.git dir from its install cache, so the postinstall script's HAS_GIT
check fails and the fallback uses the v$version tag — which doesn't
exist for PR commits or any pre-release branch. That's why the
test-install CI jobs have been failing on every version-bump PR.

npm writes the resolved SHA into the installed package.json as a
`gitHead` field. Insert a new rung between the existing git-HEAD and
v$version paths that reads gitHead and uses it as the lookup ref.
v$version stays as the final fallback for post-release tarball installs.
The previous rung used package.json gitHead, which works for downstream
consumers of an already-installed package but not for npm's own pacote
prepare phase: by the time postinstall runs, the .git dir has been moved
away (so HAS_GIT is false) but the gitHead field has not yet been
injected into package.json. That left no signal to identify the SHA and
sent us back to the v$version tag fallback.

npm sets $npm_package_resolved during install lifecycle scripts. For a
git dep it's `git+ssh://...#<sha>`. Parse the SHA from the URL fragment
and use it as the lookup ref, gated on a length+hex check so a
registry-style resolved URL with no fragment doesn't slip through.
These jobs install via `npm install git://...#<sha>`, which puts the
postinstall script in pacote's prepare phase. In that phase pacote
strips .git from its install cache and doesn't expose the commit SHA
via any env var or injected package.json field, so postinstall.sh has
no signal to identify which synapse-api submodule SHA to download and
falls through to the v$version tag lookup. The tag doesn't exist for
PR commits (it's created post-merge by release-please), so the jobs
404 on every PR that bumps the version.

What these jobs actually validate is "can a released version of this
package install cleanly," which is a post-tag concern. Gate them on
`github.event_name != 'pull_request'` so they run on push to main and
workflow_dispatch only — matching their actual purpose.
@namthor9 namthor9 merged commit 8c1b104 into main May 22, 2026
4 checks passed
@namthor9 namthor9 deleted the maxr/testfix branch May 22, 2026 00:01
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