npm: publishable packages, prebuilt addons per platform, a release workflow #12
Loading…
Reference in a new issue
No description provided.
Delete branch "npm-packages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
.tsfiles, and Node won't strip types insidenode_modules.require("../safe-ts-native/index.cjs"), and the peer ranges were"*".safe-ts.nodefromnpm run build.files,repositoryorpublishConfig, and the transform had no types forvite.config.ts.What changed
scripts/build-packages.mjswrites 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.Ztag doesn't match.q/matchitself), then tsc (NodeNext, the package's own strict options) writes.js+.d.ts. The generatedpackage.jsonhasexportslike{ types: ./dist/x.d.ts, default: ./dist/x.js }..tssources and its workflow is unchanged: tests, the demo, docs and the checker all still usesrc/.@evobug/safe-ts-native-{linux-x64-gnu, linux-arm64-gnu, darwin-x64, darwin-arm64, win32-x64-msvc}, each withos/cpu/libc. They are listed inpackages/safe-ts-native/platforms.cjsand become optional dependencies of@evobug/safe-ts-nativein the published manifest.index.cjsloads, in order:SAFE_TS_NATIVE_PATH, the local./safe-ts.node(the repo build), then the platform package.--omit=optional, npm/cli#4828) and the exactnpm installcommand to fix it. Platforms with no prebuilt addon (musl, other CPUs) get a build-from-source hint.scripts/build-native.mjscross-compiles all five on Linux: Linux and macOS with cargo-zigbuild (Linux against glibc 2.17), Windows with cargo-xwin.scripts/stage-native.mjsputs each binary into its platform package;--checkfails if any is missing.license: MIT OR Apache-2.0,repository(withdirectory),bugs,filesandpublishConfig.access: public.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 >=1.90.0, exportsrecommended.json.^0.1.0instead of*.scripts/verify-packages.mjs(for CI) runsnpm packon every package and checks the contents: licenses, README, everyexports/main/typestarget present, no.tssources, the addon present. It then installs the tarballs into a new project under/tmp, usingoverridesso internal dependencies also come from the tarballs, and checks:skipLibCheck: false, no@types/node) accepts the published declarations;q,matchandparseJson<T>(with aSafeIntfield) withcheck: "error". The bundle runs with the expected output, has no leftover "not compiled" stubs or runtimematch, andmatchbecame aswitch;.tsfile, and the prelude (no imports) works under the loader and tsc;./node_modules/@evobug/oxlint-plugin-safe-ts/recommended.json: the sources pass, and a file withthrowgetssafe-ts(no-throw)..forgejo/workflows/release.yml(same runner style as pages.yml) runs only onpush: 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.npm publish --dry-run), which is useful for testing the pipeline before the first tag.oxlintadded 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
@evobug. Create the npm organizationevobug, 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 fivesafe-ts-native-<platform>,oxlint-plugin-safe-ts,safe-ts-prelude,safe-ts-feature-{node,browser,zod,vue-router}.NPM_TOKENin Forgejo (Settings → Actions → Secrets). Use a granular access token with read/write on the@evobugpackages (or an automation token). If the org enforces 2FA for publishing, the token must be allowed to skip it.v<version>, e.g.v0.1.0. It must equal theversionin everypackages/*/package.json; the workflow refuses a mismatch. Bump all of them together, merge, thengit tag v0.1.0 && git push origin v0.1.0.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.node scripts/build-native.mjs --allbuilt all five targets here.fileshows Mach-O arm64/x86_64, ELF aarch64/x86-64 and a PE32+ DLL.GLIBC_2.17, and it loads and transforms in Node.npm run test:vitepasses.npm run test:docspasses (docs typecheck, wasm build, VitePress build).npm run typecheckpasses.npm run test:std: 115/116. The failure isevery Node callable is mapped exactly once(feature-node's inventory compared against this machine's Node 26.13 API list). It reads onlynode-api.jsonand the Node runtime, which this PR doesn't touch.cargo nextest run: 94/95. The failure isfixtures_match_annotations, fixturefeatures, an unexpectedcreateDecipherivdiagnostic at main.ts:55. Its inputs (crates/, and feature-node's and feature-zod'ssafe-ts.json/node-api.json) are byte-identical tomain, so it is pre-existing. There are no Rust changes here.npm run lintexits 1 on the demo's deliberate problems, same as before.Left out / uncertain
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 fordlopenby path. The first real check will be someone running the dry run's tarballs on a Mac.ubuntu-latesthas 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.node_modules, so std isn't analysed. It knows std's key functions by name. For a sample usingunsafe,parseJson,qand a Result-returning function, the diagnostics were identical with std symlinked and with std in node_modules. I didn't audit every rule.safe-tsCLI. The docs'safe-ts check|emit|explainstill need a build from source.shell: trueon Windows.🤖 Generated with Claude Code