Skip to content

fix: add lazy first-use install for npm RFC #868 compatibility - #5291

Merged
Lilian Kasem (liliankasem) merged 1 commit into
mainfrom
liliankasem/fix-npm-install-script-blocking
Jun 2, 2026
Merged

Lilian Kasem (liliankasem) merged 1 commit into
mainfrom
liliankasem/fix-npm-install-script-blocking

Conversation

@liliankasem

Copy link
Copy Markdown
Member

Summary

Fixes #5258.

npm RFC #868 will block postinstall scripts by default in a future npm release (already the behavior in pnpm, Yarn Berry, Bun, and Deno). This would cause silent install failures where func is unusable because the binary was never downloaded.

Changes

eng/tools/publish-tools/npm/lib/main.js

Added an installIfNeeded() function that runs before spawning func. It checks whether the platform binary (bin/func or bin/func.exe) exists, and if not, runs install.js synchronously via spawnSync so the binary is downloaded on first use.

README.md

Added a note in the npm install section explaining:

  • The new lazy first-use install behavior when postinstall is blocked
  • How to opt back in to install-time download with allowScripts for newer npm

Behavior

Scenario Before After
Older npm (postinstall allowed) Binary downloaded at npm install ✅ Binary downloaded at npm install ✅
Newer npm (postinstall blocked) Binary missing, confusing runtime error ❌ Binary downloaded on first func run ✅
User sets allowScripts N/A Binary downloaded at npm install ✅

When npm RFC #868 ships, postinstall scripts will be blocked by default.
This change adds a lazy install check in main.js so that if the func binary
is not present (because postinstall was blocked), it is downloaded
transparently on the first invocation of the func command.

The postinstall script is retained for backward compatibility with older
npm versions that still run it automatically.

README is updated to document the new behavior and the allowScripts opt-in
for users who prefer install-time download.

Fixes #5258

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@liliankasem
Lilian Kasem (liliankasem) requested a review from a team as a code owner June 2, 2026 21:18
@liliankasem
Lilian Kasem (liliankasem) merged commit 232fe30 into main Jun 2, 2026
42 checks passed
@liliankasem
Lilian Kasem (liliankasem) deleted the liliankasem/fix-npm-install-script-blocking branch June 2, 2026 23:32
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.

npm RFC #868 will block this package's install script by default

2 participants