fix(cli): make scaffolded projects start cleanly under pnpm#1669
Merged
Conversation
`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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
npx @objectstack/cli init→pnpm install→pnpm startfailed for a freshly scaffoldedappproject, in two independent ways:better-sqlite3native 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 andobjectstack servecrashed at runtime with:pnpm startfailed before any build. The scaffold'sstartscript wasobjectstack serve(production mode), which boots from the compileddist/objectstack.json. That artifact doesn't exist right afterpnpm install, soserveerrored out (surfacing as a crypticService 'manifest' is async).Fix
Both changes are in the
initapptemplate only.Generate
pnpm-workspace.yamlallowlisting the native build deps:The allowlist must live in
pnpm-workspace.yaml— current pnpm (10.33) ignores thepnpmfield inpackage.jsonand 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.startnow runsobjectstack compile && objectstack serve, so it works straight afterpnpm installwithout a separate build step.Verification (pnpm v10.33.0)
pnpm-workspace.yaml→ binding missing (bug reproduced); with it → binding compiled automatically.init --package-manager pnpm: generatespnpm-workspace.yaml, nopnpmfield inpackage.json,better_sqlite3.nodebuilt.init → install → pnpm start(no manual build): auto-compiles, reaches✓ Server is ready(HTTP 302).pnpm devworks out of the box (SqlDriver(better-sqlite3)).init.test.ts: 28/28 passing (added coverage for the renderedpnpm-workspace.yamland that the allowlist is not inpackage.json).Note (out of scope)
Discovered a separate, deeper bug:
objectstack servebooting directly from config (no prebuilt artifact) throwsService '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.