diff --git a/deployment/idunn/recipe.toml b/deployment/idunn/recipe.toml index 7af9fc2..8f0de73 100644 --- a/deployment/idunn/recipe.toml +++ b/deployment/idunn/recipe.toml @@ -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" }, ] diff --git a/package.json b/package.json index 4ad2147..675bc6d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ef04033..d037c3c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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