Skip to content

Stop 'spacetime init' copying a broken generate script into TypeScript projects - #6709

Open
krisajenkins wants to merge 1 commit into
masterfrom
kris/init-drop-gen-bindings-script
Open

krisajenkins wants to merge 1 commit into
masterfrom
kris/init-drop-gen-bindings-script

Conversation

@krisajenkins

Copy link
Copy Markdown
Contributor

Description of Changes

Projects scaffolded with spacetime init from any of the twelve TypeScript client templates no longer get a generate script that cannot run.

Each template's package.json has a generate script that calls cargo run -p gen-bindings:

"generate": "pnpm --dir spacetimedb install && cargo run -p gen-bindings -- --out-dir src/module_bindings --module-path spacetimedb && prettier --write src/module_bindings"

gen-bindings is a crate in this repo's Cargo workspace, which the templates use to regenerate their checked-in bindings (and which CI calls through this script). Outside the monorepo there is no such crate, and usually no Cargo at all, so a user who runs npm run generate after changing their module gets a failure. The script that works for them, spacetime:generate, sits a line below it, but the broken one has the name people reach for.

It went unnoticed because it works for everyone who maintains the templates. spacetime init copies each package.json unchanged apart from the name and the spacetimedb version, and the template smoketests only install and publish.

Renaming the script in every template would mean changing the repo's CI and SDK scripts that call it. Instead, update_package_json, which already rewrites each template's package.json during init, now drops any script that invokes gen-bindings. The monorepo keeps its workflow, and scaffolded projects get only scripts that can run.

API and ABI breaking changes

None.

Rollback safety impact

n/a

Expected complexity level and risk

1

Testing

Added one test covering the following behaviors:

  • update_package_json removes gen-bindings scripts from every embedded template. Removing the new filter made the test fail, naming money-exchange-react-ts. The same test covers:
    • Every other script is kept unchanged.
    • At least one template still uses gen-bindings, so the check can't go stale silently.

Scaffolding svelte-ts with the rebuilt CLI produced a package.json without generate and with its other scripts intact.

…t projects.

Say you scaffold a project with 'spacetime init --template react-ts' (or
any of the twelve TypeScript client templates), change your module, and
want fresh bindings. package.json has an obvious-looking 'generate'
script, so you run 'npm run generate'. It fails:

    "generate": "pnpm --dir spacetimedb install && cargo run -p gen-bindings -- --out-dir src/module_bindings --module-path spacetimedb && prettier --write src/module_bindings"

gen-bindings is a tool in the SpacetimeDB repository's Cargo workspace.
The templates use it to regenerate their checked-in bindings, and the
repo's own CI calls it through this script ('pnpm generate' in
chat-react-ts, and in react-ts via bindings-typescript). Outside the repo
there is no such crate, and usually no Cargo at all. The script that
actually works for users, 'spacetime:generate', sits a line below it, but
the broken one has the name people reach for.

Nobody caught it because it works for everyone who maintains the
templates: inside the monorepo the script runs fine. 'spacetime init'
copies each template's package.json unchanged apart from the name and the
spacetimedb version, and the template smoketests only install and publish.

Renaming the script in every template would mean changing the repo's CI
and SDK scripts that call it. Instead, update_package_json, which already
rewrites each template's package.json during init, now drops any script
that invokes gen-bindings. The monorepo keeps its workflow, and scaffolded
projects get only scripts that can run.

A new test runs update_package_json over every embedded template's
package.json. It checks that each gen-bindings script is removed and
every other script is kept unchanged. It also fails if no template uses
gen-bindings any more, so the marker can't go stale silently. Removing the
call makes it fail, naming money-exchange-react-ts. Scaffolding svelte-ts
with the rebuilt CLI produces a package.json without 'generate' and with
its other scripts intact.
@krisajenkins
krisajenkins force-pushed the kris/init-drop-gen-bindings-script branch from 9723c25 to 30d0f13 Compare November 26, 2026 16:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants