Bundle the service; ship one executable instead of a dependency tree

Idunn refuses to seal a release containing a symlink with parent traversal,
and pnpm's node_modules is exactly that -- a forest of relative links into
.pnpm. Negotiating with that layout failed twice: --node-linker=hoisted was
silently ignored (staging trees still had .pnpm), and pnpm 10's
--config.node-linker=hoisted did not resolve it either.

Bundling removes the question. `pnpm bundle` runs esbuild over src/index.ts
into a single 2.5 MB dist/heimdall with a shebang and a createRequire shim
for the CJS dependencies, pg-native left external as the optional native
binding it is. node_modules is now a build input rather than an artifact.

That also fixes a defect the seal had not reached yet: launch_command does
`ensure!(executable.is_file())` and execs the artifact directly, so the old
recipe -- executable_artifact pointing at the dist *directory*, with
"dist/src/index.js" as the first argument -- would have failed there too.
The service is now one file that is genuinely executable, and its only
arguments are the state root Idunn assigns.

Shipping a dependency tree to run a service was the larger liability
anyway; this deletes it rather than making it sealable.

Recipe validates; 54 pass, 1 skipped, tsc clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-06 16:51:59 +02:00
commit c931775ad1
3 changed files with 23 additions and 16 deletions

View file

@ -78,29 +78,31 @@ runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "build"]
# The release is one self-contained executable. node_modules is a build
# input, not an artifact: pnpm lays it out as symlinks into .pnpm, which
# Idunn refuses to seal, and shipping a dependency tree to run a service is
# a larger liability than bundling it.
[[steps]]
id = "bundle-heimdall"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "bundle"]
# The unit runs dist/src/index.js, and Node resolves its imports at runtime, so
# the release is the compiled output plus the production dependency tree. These
# are the two artifacts; nothing else from the build tree is installed.
[[artifacts]]
id = "heimdall-dist"
id = "heimdall"
source_kind = "runner-output"
runner = "node-build"
source = "dist"
destination = "dist"
executable = false
[[artifacts]]
id = "heimdall-node-modules"
source_kind = "runner-output"
runner = "node-build"
source = "node_modules"
destination = "node_modules"
executable = false
source = "dist/heimdall"
destination = "heimdall"
executable = true
[service]
executable_artifact = "heimdall-dist"
executable_artifact = "heimdall"
arguments = [
{ kind = "literal", value = "dist/src/index.js" },
{ kind = "literal", value = "--state-root" },
{ kind = "binding", name = "state_root" },
]

View file

@ -13,7 +13,8 @@
"test": "vitest run --config vitest.config.ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
"export:provider-health-public-key": "tsx src/export-provider-health-public-key.ts",
"export:provider-advertisement": "tsx src/export-provider-advertisement.ts --pretty"
"export:provider-advertisement": "tsx src/export-provider-advertisement.ts --pretty",
"bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node24 --outfile=dist/heimdall --external:pg-native --banner:js=\"#!/usr/bin/env node\nimport{createRequire}from'node:module';const require=createRequire(import.meta.url);\""
},
"dependencies": {
"@fastify/cors": "^11.2.0",
@ -31,7 +32,8 @@
"pg-mem": "^3.0.14",
"tsx": "^4.21.0",
"typescript": "^6.0.3",
"vitest": "^4.1.5"
"vitest": "^4.1.5",
"esbuild": "^0.27.7"
},
"pnpm": {
"overrides": {

3
pnpm-lock.yaml generated
View file

@ -43,6 +43,9 @@ importers:
'@types/pg':
specifier: ^8.20.0
version: 8.20.0
esbuild:
specifier: ^0.27.7
version: 0.27.7
pg-mem:
specifier: ^3.0.14
version: 3.0.14