Skip to content

fix(cli): make scaffolded projects start cleanly under pnpm#1669

Merged
os-zhuang merged 2 commits into
mainfrom
fix/cli-init-pnpm-build-scripts
Jun 9, 2026
Merged

fix(cli): make scaffolded projects start cleanly under pnpm#1669
os-zhuang merged 2 commits into
mainfrom
fix/cli-init-pnpm-build-scripts

Conversation

@baozhoutao

Copy link
Copy Markdown
Contributor

Problem

npx @objectstack/cli initpnpm installpnpm start failed for a freshly scaffolded app project, in two independent ways:

  1. better-sqlite3 native binding missing. It's pulled in transitively by the default standalone SQLite store (via knex). pnpm 10+ blocks dependency build scripts by default, so the native module shipped uncompiled and objectstack serve crashed at runtime with:

    Could not locate the bindings file ... better_sqlite3.node
    
  2. pnpm start failed before any build. The scaffold's start script was objectstack serve (production mode), which boots from the compiled dist/objectstack.json. That artifact doesn't exist right after pnpm install, so serve errored out (surfacing as a cryptic Service 'manifest' is async).

Fix

Both changes are in the init app template only.

  1. Generate pnpm-workspace.yaml allowlisting the native build deps:

    onlyBuiltDependencies:
      - better-sqlite3
      - esbuild

    The allowlist must live in pnpm-workspace.yaml — current pnpm (10.33) ignores the pnpm field in package.json and emits a deprecation warning. This mirrors how this repo configures itself. npm/yarn/bun ignore the file and build native modules by default, so it's harmless for them.

  2. start now runs objectstack compile && objectstack serve, so it works straight after pnpm install without a separate build step.

Verification (pnpm v10.33.0)

  • A/B: without pnpm-workspace.yaml → binding missing (bug reproduced); with it → binding compiled automatically.
  • Real init --package-manager pnpm: generates pnpm-workspace.yaml, no pnpm field in package.json, better_sqlite3.node built.
  • init → install → pnpm start (no manual build): auto-compiles, reaches ✓ Server is ready (HTTP 302).
  • pnpm dev works out of the box (SqlDriver(better-sqlite3)).
  • init.test.ts: 28/28 passing (added coverage for the rendered pnpm-workspace.yaml and that the allowlist is not in package.json).

Note (out of scope)

Discovered a separate, deeper bug: objectstack serve booting directly from config (no prebuilt artifact) throws Service 'manifest' is async (packages/core/src/kernel.ts:106). This PR sidesteps it via compile-before-serve rather than changing the kernel/serve boot ordering. Worth a follow-up.

`npx @objectstack/cli init` followed by `pnpm install` && `pnpm start`
failed in two ways:

1. better-sqlite3 (pulled in transitively by the default standalone
   SQLite store, via knex) shipped uncompiled because pnpm 10+ blocks
   dependency build scripts by default, so `serve` crashed with
   "Could not locate the bindings file". The allowlist must live in
   `pnpm-workspace.yaml` — current pnpm ignores the `pnpm` field in
   package.json — so init now generates one listing better-sqlite3 and
   esbuild (mirrors how this repo configures itself). npm/yarn/bun
   ignore the file and build native modules by default.

2. `start` ran `objectstack serve` (production, boots from the compiled
   dist/objectstack.json), which does not exist right after install, so
   `pnpm start` failed before any build. The start script now runs
   `objectstack compile && objectstack serve` so it works straight after
   `pnpm install`.

Verified end-to-end with pnpm v10.33.0: init -> install -> pnpm start
auto-compiles and reaches "Server is ready" (HTTP 302), with the
better-sqlite3 binding compiled. Added unit coverage for the generated
pnpm-workspace.yaml and that the allowlist is not placed in package.json.
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 9, 2026 6:32am

Request Review

Comment thread packages/cli/src/commands/init.ts Fixed
CodeQL flagged the exists()-then-writeFileSync pattern as a file-system
race. Use an exclusive write (flag: 'wx') and ignore EEXIST so the
"don't clobber an existing file" decision is atomic.
@os-zhuang os-zhuang merged commit 2c3c0cd into main Jun 9, 2026
12 checks passed
@os-zhuang os-zhuang deleted the fix/cli-init-pnpm-build-scripts branch June 9, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants