Skip to content

feat: replace download-lib.js with per-platform npm packages - #119

Open
jdsika wants to merge 1 commit into
matrix-org:mainfrom
reachhaven:feat/per-platform-packages
Open

jdsika wants to merge 1 commit into
matrix-org:mainfrom
reachhaven:feat/per-platform-packages

Conversation

@jdsika

@jdsika jdsika commented Nov 15, 2026

Copy link
Copy Markdown

Replaces download-lib.js with per-platform npm packages that contain the prebuilt library, as asked in #113. It follows the pattern of matrix-org/seshat#184, using the commands @napi-rs/cli (v2, already a dev dependency) has for this instead of custom scripts.

How it works

  • npm/<platform>/ holds one package per release target, @matrix-org/matrix-sdk-crypto-nodejs-<platform>, generated by napi create-npm-dir -t . from napi.triples in package.json, which now lists the 13 targets release.yml builds. Each sets os, cpu and, on Linux, libc, so package managers install only the matching one. The platform names are the ones download-lib.js used (linux-x64-gnu, win32-arm64-msvc, ...).
  • The published main package lists them as optionalDependencies at its own version. napi prepublish writes them into package.json when publishing, as seshat's publish job does with npm pkg set, so the lockfile never refers to versions that are not published yet.
  • index.js does not change: the file napi build --platform generates already loads ./matrix-sdk-crypto.<platform>.node if present (a local build) and otherwise requires @matrix-org/matrix-sdk-crypto-nodejs-<platform>.
  • A version script runs napi version, so pnpm version (step 3 of RELEASING.md) bumps npm/*/package.json in the same commit.
  • download-lib.js, the postinstall hook, node-downloader-helper and https-proxy-agent are removed, and so is --ignore-scripts, which only kept download-lib.js from running (as the comment in ci.yml said). No dependency in the lockfile has an install script.

Release workflow

  • Each build job still uploads its .node to the draft GitHub release, as seshat kept doing, and now also uploads it as the workflow artifact bindings-<target>.
  • The publish job downloads the artifacts, copies each into its npm/<platform> directory with napi artifacts, and publishes those 13 packages with napi prepublish --skip-gh-release (npm publish with NPM_CONFIG_ACCESS=public and NPM_CONFIG_PROVENANCE=true, matching the existing --access public --provenance). It then packs, uploads and publishes the main package as before.

Before the first release with this change, the maintainers need to own the 13 new names on npmjs.com. The workflow publishes them like the main package, with npm trusted publishing and no token, so each needs release.yml of this repository as its trusted publisher. npm only accepts that for a package that exists, so each name needs one publish by hand first (a placeholder version is enough), then the trusted publisher setting on npmjs.com or with npm trust github. The names are @matrix-org/matrix-sdk-crypto-nodejs- followed by darwin-arm64, darwin-x64, linux-arm-gnueabihf, linux-arm64-gnu, linux-arm64-musl, linux-ia32-gnu, linux-riscv64-gnu, linux-s390x-gnu, linux-x64-gnu, linux-x64-musl, win32-arm64-msvc, win32-ia32-msvc and win32-x64-msvc.

Differences from seshat (matrix-org/seshat#184)

  • Names follow napi-rs's <platform>-<arch>[-<abi>] instead of <os>-<cpu>, because the generated index.js requires them and Linux has both gnu and musl builds.
  • The platform package.json files are committed, as napi-rs lays them out, instead of being written by the workflow.
  • index.js tries a local build before the platform package (napi-rs's order; seshat tries the package first), so a local build such as one with tracing still wins under npm link.
  • Publishing still happens on the tag push, as today; seshat publishes when the draft release is published.
  • One step publishes all platform packages, where seshat runs a job per package. If it fails part way, a re-run stops at the first package already published, and the rest has to be published by hand.

Testing

  • pnpm lint, and pnpm test (9 suites, 67 tests) against a local pnpm release-build on Linux x64. Its index.js and index.d.ts are byte-identical to the ones in the published 0.7.0 tarball.
  • The publish job's commands in a scratch copy, with npm replaced by a stub: napi artifacts placed all 13 binaries, and napi prepublish ran npm publish once in each of the 13 directories with both settings and wrote the 13 optionalDependencies. pnpm pack of the main package then contains index.js, index.d.ts and those dependencies, and no download-lib.js, npm/ or .node. pnpm pack of npm/linux-x64-gnu contains the binary, package.json and README.md.
  • npm install --offline of both tarballs into an empty project loads the binary from the platform package. With the binary next to index.js instead, it loads that; with neither, it fails with Cannot find module '@matrix-org/matrix-sdk-crypto-nodejs-linux-x64-gnu'.
  • pnpm version 0.8.0 -m "v%s" in a scratch repository commits package.json and all 13 npm/*/package.json at 0.8.0.
  • zizmor (pedantic) reports the same findings as on main. The release workflow itself has not run.

The generated index.js has no case for Linux on ia32, so the linux-ia32-gnu build cannot be loaded through it. That is the same today and is not changed here.

Resolves #113.

Publish each prebuilt library of a release as its own package,
`@matrix-org/matrix-sdk-crypto-nodejs-<platform>`, laid out in `npm/`
by `napi create-npm-dir`. Each release build now also uploads its
library as a workflow artifact; the publish job copies them into those
packages with `napi artifacts` and publishes them with
`napi prepublish`, which also lists them as `optionalDependencies` of
the main package. The `index.js` that `napi build --platform`
generates already loads the library from that package when there is
no local build next to it.

Remove `download-lib.js`, its `postinstall` hook, the dependencies it
used, and the `--ignore-scripts` flags that only kept it from running.

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
@jdsika
jdsika force-pushed the feat/per-platform-packages branch from ba0aacf to 7bde151 Compare November 15, 2026 09:17

This branch has not been deployed

No deployments
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.

Replace download-lib with per-platform packages which include a binary

1 participant