Skip to content

fix(windows): run vcpkg only when the prebuilt binary is unavailable - #52

Merged
aborovsky merged 2 commits into
developfrom
fix/windows-skip-vcpkg-when-prebuilt
Nov 26, 2026
Merged

aborovsky merged 2 commits into
developfrom
fix/windows-skip-vcpkg-when-prebuilt

Conversation

@aborovsky

@aborovsky aborovsky commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

npm install @brightsec/node-libcurl on Windows takes 20-30 minutes. The preinstall hook runs scripts/vcpkg-setup.js unconditionally on win32: it clones vcpkg and builds curl, OpenSSL, libssh2, ngtcp2, nghttp3, nghttp2, gsasl, brotli and c-ares from source (each twice, -dbg and -rel). Only then does install (node-pre-gyp install --fallback-to-build) download the prebuilt Windows binary, which is published for every release (for example node_libcurl-v5.1.6-node-v137-win32-x64-unknown.tar.gz) and makes that build unnecessary. Consumers also need git and Visual Studio installed for an install that ends up using the prebuilt binary anyway.

In bright-cli this costs about 20 minutes in each Windows job of the release pipeline: npm ci took 20m33s while building the Windows executable, and 23-29 minutes in every Windows smoke/e2e job.

Change

scripts/install.js replaces the preinstall and install hooks:

  • Windows, regular install: try node-pre-gyp install download-only. If it succeeds, stop. If not, run vcpkg-setup.js and then node-pre-gyp install --build-from-source. A source rebuild deletes lib/binding first, so a partial binary left by a failed extraction is never accepted as installed.
  • Windows, npm_config_build_from_source=true (or the package name), or a git checkout: run vcpkg first, as before. CI builds (build.ps1, thread-sanitizer, the Electron consumer job) set the flag, and local pnpm pregyp rebuild in a checkout still finds vcpkg ready.
  • Other platforms: unchanged, node-pre-gyp install --fallback-to-build.

The download-only attempt drops npm_config_fallback_to_build from its env, because node-pre-gyp lets npm_config_* override argv and a build without vcpkg would fail.

Verification

  • test/scripts/install.spec.ts covers each branch above.

  • New windows-consumer-install / npm-prebuilt-install job: packs the branch, installs it with npm into a fresh project on windows-latest, loads the addon, and fails if %LOCALAPPDATA%\node-libcurl-vcpkg exists or the job takes over 15 minutes. It needs Windows prebuilts for the version in package.json, so it fails on a version that has not finished publishing binaries yet.

  • Local (macOS): packed the branch as 5.1.6 and installed it with npm; scripts/install.js downloaded the prebuilt binary and the addon loaded.

  • windows-latest (run): npm install of the packed branch finished in 7s using the v5.2.0-1 prebuilt, with no vcpkg directory created. An earlier run of the same job, started before the v5.2.0-1 Windows binaries were published, got a 404 for the prebuilt, printed the fallback message and started vcpkg, which confirms the fallback path.

Comment thread scripts/install.js Resolved
The preinstall hook ran scripts/vcpkg-setup.js unconditionally on Windows,
so every npm install built curl and nine dependencies from source (20-30
minutes, needs git and Visual Studio) before node-pre-gyp downloaded the
prebuilt binary that made that build unnecessary.

scripts/install.js replaces the preinstall and install hooks. On Windows it
tries the prebuilt download first and runs vcpkg plus the fallback build only
when the download fails. Explicit source builds (npm_config_build_from_source)
and git checkouts still set up vcpkg first, so CI builds and local
`pnpm pregyp rebuild` keep working. Other platforms are unchanged.

A new windows-consumer-install job installs the packed tarball with npm and
fails if vcpkg ran or the install takes longer than 15 minutes.
A failed extraction can leave a partial lib/binding/node_libcurl.node.
A second `node-pre-gyp install` treats any file at that path as installed
and skips the build, so npm could finish with a corrupt addon. Use
--build-from-source, whose rebuild deletes module_path before compiling.
@aborovsky
aborovsky force-pushed the fix/windows-skip-vcpkg-when-prebuilt branch from a8486cb to 72895dd Compare November 26, 2026 20:50
@aborovsky
aborovsky merged commit 91eab4b into develop Nov 26, 2026
71 of 72 checks passed
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