npm: publishable packages, prebuilt addons per platform, a release workflow #12

Merged
sionzee merged 1 commit from npm-packages into main 2026-11-03 21:37:34 +01:00
Owner

Makes every package under packages/ publishable to npm as @evobug/*. Nothing is published by this PR, and it adds no tags or secrets.

What blocked publishing

  • TypeScript in node_modules. std, safe-ts-vue and feature-zod exported .ts files, and Node won't strip types inside node_modules.
  • Workspace-only paths. The transform and the oxlint plugin loaded the addon with require("../safe-ts-native/index.cjs"), and the peer ranges were "*".
  • No published addon. The native addon was only a local safe-ts.node from npm run build.
  • Missing metadata. Most manifests had no files, repository or publishConfig, and the transform had no types for vite.config.ts.

What changed

  • scripts/build-packages.mjs writes one publishable directory per package to .release/ (gitignored), all at one version. It refuses to run if the versions differ, or if a --check-version vX.Y.Z tag doesn't match.
    • std, safe-ts-vue and feature-zod are built: each file goes through the safe-ts transform (std uses q/match itself), then tsc (NodeNext, the package's own strict options) writes .js + .d.ts. The generated package.json has exports like { types: ./dist/x.d.ts, default: ./dist/x.js }.
    • The repository keeps the .ts sources and its workflow is unchanged: tests, the demo, docs and the checker all still use src/.
    • The other packages are copied as they are. Each package gets the two license files and a short README.
  • The native addon, the usual napi pattern. There are five platform packages: @evobug/safe-ts-native-{linux-x64-gnu, linux-arm64-gnu, darwin-x64, darwin-arm64, win32-x64-msvc}, each with os/cpu/libc. They are listed in packages/safe-ts-native/platforms.cjs and become optional dependencies of @evobug/safe-ts-native in the published manifest.
    • index.cjs loads, in order: SAFE_TS_NATIVE_PATH, the local ./safe-ts.node (the repo build), then the platform package.
    • If none loads, the error says which package is missing, why that happens (--omit=optional, npm/cli#4828) and the exact npm install command to fix it. Platforms with no prebuilt addon (musl, other CPUs) get a build-from-source hint.
  • scripts/build-native.mjs cross-compiles all five on Linux: Linux and macOS with cargo-zigbuild (Linux against glibc 2.17), Windows with cargo-xwin. scripts/stage-native.mjs puts each binary into its platform package; --check fails if any is missing.
  • Manifests. Every package now has license: MIT OR Apache-2.0, repository (with directory), bugs, files and publishConfig.access: public.
    • transform: types (index.d.ts), depends on @evobug/safe-ts-native (exact version), peer std ^0.1.0 (its output imports std's runtime helpers), optional peer vite, engines.node >=22.18.
    • oxlint plugin: depends on native, peer oxlint >=1.90.0, exports recommended.json.
    • vue, zod and prelude: peer std ^0.1.0 instead of *.
  • scripts/verify-packages.mjs (for CI) runs npm pack on every package and checks the contents: licenses, README, every exports/main/types target present, no .ts sources, the addon present. It then installs the tarballs into a new project under /tmp, using overrides so internal dependencies also come from the tarballs, and checks:
    • only this platform's addon package is installed;
    • std (every subpath), safe-ts-vue and feature-zod import and run as plain JS from node_modules;
    • tsc (strict, skipLibCheck: false, no @types/node) accepts the published declarations;
    • Vite builds an app using q, match and parseJson<T> (with a SafeInt field) with check: "error". The bundle runs with the expected output, has no leftover "not compiled" stubs or runtime match, and match became a switch;
    • the Node loader runs a .ts file, and the prelude (no imports) works under the loader and tsc;
    • the oxlint preset loads from ./node_modules/@evobug/oxlint-plugin-safe-ts/recommended.json: the sources pass, and a file with throw gets safe-ts(no-throw).
  • .forgejo/workflows/release.yml (same runner style as pages.yml) runs only on push: tags: ["v*"] or by hand, never on normal pushes. It installs clang/lld, zig 0.14.1 (sha256-checked) and cargo-zigbuild/cargo-xwin, builds and verifies everything, then publishes the platform packages first, then the rest.
    • A version that is already on npm is skipped, so a failed run can be re-run.
    • Started by hand, it is a dry run (npm publish --dry-run), which is useful for testing the pipeline before the first tag.
  • Docs. The README has a "Releasing" section. The install sections still say the packages aren't on npm yet. The npm commands shown now match what the packages need: oxlint added to the dev-dependency line (it's a peer of the plugin), and an install step for the prelude and feature packs.

Needed from the maintainer to publish

  1. The npm scope @evobug. Create the npm organization evobug, or confirm you own it; the packages are scoped public packages. These 15 names must be free in it: safe-ts-std, safe-ts-vue, safe-ts-transform, safe-ts-native, the five safe-ts-native-<platform>, oxlint-plugin-safe-ts, safe-ts-prelude, safe-ts-feature-{node,browser,zod,vue-router}.
  2. The token secret. Add a repository secret NPM_TOKEN in Forgejo (Settings → Actions → Secrets). Use a granular access token with read/write on the @evobug packages (or an automation token). If the org enforces 2FA for publishing, the token must be allowed to skip it.
  3. The tag format: v<version>, e.g. v0.1.0. It must equal the version in every packages/*/package.json; the workflow refuses a mismatch. Bump all of them together, merge, then git tag v0.1.0 && git push origin v0.1.0.
  4. Optional: run the Release workflow by hand once first (a dry run) to see that the runner can install the cross-compilers and build all five addons.

Testing

Done locally:

  • node scripts/verify-packages.mjs: all checks pass. They ran against the zig-built linux-x64 addon (glibc 2.17), with the other four platform packages carrying real binaries. npm skipped them on install, as intended.
  • Cross-builds: node scripts/build-native.mjs --all built all five targets here.
    • file shows Mach-O arm64/x86_64, ELF aarch64/x86-64 and a PE32+ DLL.
    • The linux-x64 build needs at most GLIBC_2.17, and it loads and transforms in Node.
  • Loader fallback: with the platform package removed, the error message is as described above.
  • Repo test suite:
    • npm run test:vite passes. npm run test:docs passes (docs typecheck, wasm build, VitePress build). npm run typecheck passes.
    • npm run test:std: 115/116. The failure is every Node callable is mapped exactly once (feature-node's inventory compared against this machine's Node 26.13 API list). It reads only node-api.json and the Node runtime, which this PR doesn't touch.
    • cargo nextest run: 94/95. The failure is fixtures_match_annotations, fixture features, an unexpected createDecipheriv diagnostic at main.ts:55. Its inputs (crates/, and feature-node's and feature-zod's safe-ts.json / node-api.json) are byte-identical to main, so it is pre-existing. There are no Rust changes here.
    • npm run lint exits 1 on the demo's deliberate problems, same as before.

Left out / uncertain

  • The macOS and arm64 binaries were not run. I could only build them. The macOS dylibs have no undefined napi_* symbols, which is expected because napi-sys loads them at runtime via libloading (the Linux build works the same way and runs). Their install name is an absolute build-dir path, which is harmless for dlopen by path. The first real check will be someone running the dry run's tarballs on a Mac.
  • The workflow hasn't run on the Forgejo runner yet. It assumes ubuntu-latest has apt, curl and network access to ziglang.org, crates.io and Microsoft's CRT download (for cargo-xwin). A dry run will show any problems.
  • When std comes from npm, the checker treats it as third-party code. It doesn't follow calls into node_modules, so std isn't analysed. It knows std's key functions by name. For a sample using unsafe, parseJson, q and a Result-returning function, the diagnostics were identical with std symlinked and with std in node_modules. I didn't audit every rule.
  • No npm package for the safe-ts CLI. The docs' safe-ts check|emit|explain still need a build from source.
  • The verify script is for Linux. It is written for Linux CI, and its npm calls would need shell: true on Windows.

🤖 Generated with Claude Code

Makes every package under `packages/` publishable to npm as `@evobug/*`. **Nothing is published by this PR**, and it adds no tags or secrets. ## What blocked publishing - **TypeScript in node_modules.** std, safe-ts-vue and feature-zod exported `.ts` files, and Node won't strip types inside `node_modules`. - **Workspace-only paths.** The transform and the oxlint plugin loaded the addon with `require("../safe-ts-native/index.cjs")`, and the peer ranges were `"*"`. - **No published addon.** The native addon was only a local `safe-ts.node` from `npm run build`. - **Missing metadata.** Most manifests had no `files`, `repository` or `publishConfig`, and the transform had no types for `vite.config.ts`. ## What changed - **`scripts/build-packages.mjs`** writes one publishable directory per package to `.release/` (gitignored), all at one version. It refuses to run if the versions differ, or if a `--check-version vX.Y.Z` tag doesn't match. - std, safe-ts-vue and feature-zod are built: each file goes through the safe-ts transform (std uses `q`/`match` itself), then tsc (NodeNext, the package's own strict options) writes `.js` + `.d.ts`. The generated `package.json` has `exports` like `{ types: ./dist/x.d.ts, default: ./dist/x.js }`. - The repository keeps the `.ts` sources and its workflow is unchanged: tests, the demo, docs and the checker all still use `src/`. - The other packages are copied as they are. Each package gets the two license files and a short README. - **The native addon, the usual napi pattern.** There are five platform packages: `@evobug/safe-ts-native-{linux-x64-gnu, linux-arm64-gnu, darwin-x64, darwin-arm64, win32-x64-msvc}`, each with `os`/`cpu`/`libc`. They are listed in `packages/safe-ts-native/platforms.cjs` and become optional dependencies of `@evobug/safe-ts-native` in the published manifest. - `index.cjs` loads, in order: `SAFE_TS_NATIVE_PATH`, the local `./safe-ts.node` (the repo build), then the platform package. - If none loads, the error says which package is missing, why that happens (`--omit=optional`, npm/cli#4828) and the exact `npm install` command to fix it. Platforms with no prebuilt addon (musl, other CPUs) get a build-from-source hint. - **`scripts/build-native.mjs`** cross-compiles all five on Linux: Linux and macOS with cargo-zigbuild (Linux against glibc 2.17), Windows with cargo-xwin. **`scripts/stage-native.mjs`** puts each binary into its platform package; `--check` fails if any is missing. - **Manifests.** Every package now has `license: MIT OR Apache-2.0`, `repository` (with `directory`), `bugs`, `files` and `publishConfig.access: public`. - transform: types (`index.d.ts`), depends on `@evobug/safe-ts-native` (exact version), peer std `^0.1.0` (its output imports std's runtime helpers), optional peer vite, `engines.node >=22.18`. - oxlint plugin: depends on native, peer `oxlint >=1.90.0`, exports `recommended.json`. - vue, zod and prelude: peer std `^0.1.0` instead of `*`. - **`scripts/verify-packages.mjs`** (for CI) runs `npm pack` on every package and checks the contents: licenses, README, every `exports`/`main`/`types` target present, no `.ts` sources, the addon present. It then installs the tarballs into a new project under `/tmp`, using `overrides` so internal dependencies also come from the tarballs, and checks: - only this platform's addon package is installed; - std (every subpath), safe-ts-vue and feature-zod import and run as plain JS from node_modules; - tsc (strict, `skipLibCheck: false`, no `@types/node`) accepts the published declarations; - **Vite** builds an app using `q`, `match` and `parseJson<T>` (with a `SafeInt` field) with `check: "error"`. The bundle runs with the expected output, has no leftover "not compiled" stubs or runtime `match`, and `match` became a `switch`; - the **Node loader** runs a `.ts` file, and the **prelude** (no imports) works under the loader and tsc; - the **oxlint preset** loads from `./node_modules/@evobug/oxlint-plugin-safe-ts/recommended.json`: the sources pass, and a file with `throw` gets `safe-ts(no-throw)`. - **`.forgejo/workflows/release.yml`** (same runner style as pages.yml) runs only on `push: tags: ["v*"]` or by hand, never on normal pushes. It installs clang/lld, zig 0.14.1 (sha256-checked) and cargo-zigbuild/cargo-xwin, builds and verifies everything, then publishes the platform packages first, then the rest. - A version that is already on npm is skipped, so a failed run can be re-run. - Started by hand, it is a dry run (`npm publish --dry-run`), which is useful for testing the pipeline before the first tag. - **Docs.** The README has a "Releasing" section. The install sections still say the packages aren't on npm yet. The npm commands shown now match what the packages need: `oxlint` added to the dev-dependency line (it's a peer of the plugin), and an install step for the prelude and feature packs. ## Needed from the maintainer to publish 1. **The npm scope `@evobug`.** Create the npm organization `evobug`, or confirm you own it; the packages are scoped public packages. These 15 names must be free in it: `safe-ts-std`, `safe-ts-vue`, `safe-ts-transform`, `safe-ts-native`, the five `safe-ts-native-<platform>`, `oxlint-plugin-safe-ts`, `safe-ts-prelude`, `safe-ts-feature-{node,browser,zod,vue-router}`. 2. **The token secret.** Add a repository secret **`NPM_TOKEN`** in Forgejo (Settings → Actions → Secrets). Use a granular access token with read/write on the `@evobug` packages (or an automation token). If the org enforces 2FA for publishing, the token must be allowed to skip it. 3. **The tag format: `v<version>`**, e.g. `v0.1.0`. It must equal the `version` in every `packages/*/package.json`; the workflow refuses a mismatch. Bump all of them together, merge, then `git tag v0.1.0 && git push origin v0.1.0`. 4. **Optional:** run the Release workflow by hand once first (a dry run) to see that the runner can install the cross-compilers and build all five addons. ## Testing Done locally: - **`node scripts/verify-packages.mjs`:** all checks pass. They ran against the zig-built linux-x64 addon (glibc 2.17), with the other four platform packages carrying real binaries. npm skipped them on install, as intended. - **Cross-builds:** `node scripts/build-native.mjs --all` built all five targets here. - `file` shows Mach-O arm64/x86_64, ELF aarch64/x86-64 and a PE32+ DLL. - The linux-x64 build needs at most `GLIBC_2.17`, and it loads and transforms in Node. - **Loader fallback:** with the platform package removed, the error message is as described above. - **Repo test suite:** - `npm run test:vite` passes. `npm run test:docs` passes (docs typecheck, wasm build, VitePress build). `npm run typecheck` passes. - `npm run test:std`: 115/116. The failure is `every Node callable is mapped exactly once` (feature-node's inventory compared against this machine's Node 26.13 API list). It reads only `node-api.json` and the Node runtime, which this PR doesn't touch. - `cargo nextest run`: 94/95. The failure is `fixtures_match_annotations`, fixture `features`, an unexpected `createDecipheriv` diagnostic at main.ts:55. Its inputs (`crates/`, and feature-node's and feature-zod's `safe-ts.json` / `node-api.json`) are byte-identical to `main`, so it is pre-existing. There are no Rust changes here. - `npm run lint` exits 1 on the demo's deliberate problems, same as before. ## Left out / uncertain - **The macOS and arm64 binaries were not run.** I could only build them. The macOS dylibs have no undefined `napi_*` symbols, which is expected because napi-sys loads them at runtime via libloading (the Linux build works the same way and runs). Their install name is an absolute build-dir path, which is harmless for `dlopen` by path. The first real check will be someone running the dry run's tarballs on a Mac. - **The workflow hasn't run on the Forgejo runner yet.** It assumes `ubuntu-latest` has apt, curl and network access to ziglang.org, crates.io and Microsoft's CRT download (for cargo-xwin). A dry run will show any problems. - **When std comes from npm, the checker treats it as third-party code.** It doesn't follow calls into `node_modules`, so std isn't analysed. It knows std's key functions by name. For a sample using `unsafe`, `parseJson`, `q` and a Result-returning function, the diagnostics were identical with std symlinked and with std in node_modules. I didn't audit every rule. - **No npm package for the `safe-ts` CLI.** The docs' `safe-ts check|emit|explain` still need a build from source. - **The verify script is for Linux.** It is written for Linux CI, and its npm calls would need `shell: true` on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Nothing could be installed from npm as it was: std, safe-ts-vue and feature-zod ship
TypeScript, which Node refuses to strip inside node_modules; the transform and the oxlint
plugin loaded the addon through a workspace-relative path; the addon existed only as a
local build; and several manifests had no files/repository/publishConfig.

scripts/build-packages.mjs now writes one publishable directory per package to .release/.
The TypeScript packages go through the safe-ts transform and tsc and ship .js + .d.ts,
while the repository keeps using the sources. The addon is published as five per-platform
packages (linux x64/arm64 gnu, darwin x64/arm64, win32 x64 msvc), optional dependencies of
@evobug/safe-ts-native, whose loader picks the right one and explains what to do when it is
missing. scripts/build-native.mjs cross-compiles all five on Linux (cargo-zigbuild,
cargo-xwin); scripts/verify-packages.mjs packs everything, installs the tarballs into a
new project under /tmp and uses them there. .forgejo/workflows/release.yml runs all of it
on a v* tag and publishes with NPM_TOKEN; started by hand it is a dry run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch npm-packages 2026-11-03 21:37:34 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!12
No description provided.