Skip to content

Migrate JS/TS templates to @cartesi/rollup, pnpm and node 24 - #89

Open
tuler wants to merge 7 commits into
prerelease/sdk-12from
claude/cartesi-rollup-templates-k6ajdh
Open

Migrate JS/TS templates to @cartesi/rollup, pnpm and node 24#89
tuler wants to merge 7 commits into
prerelease/sdk-12from
claude/cartesi-rollup-templates-k6ajdh

Conversation

@tuler

@tuler tuler commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

Migrates the JavaScript and TypeScript templates from the rollup HTTP server to the @cartesi/rollup package, which talks directly to the rollup device of the Cartesi Machine, and refreshes the toolchain around it.

Key Changes

Source code

  • Replaced the HTTP polling loop with rollup.run(), whose handlers receive typed request objects: msgSender, index, blockTimestamp, and payload as a Buffer
  • Updated handler signatures: advance handlers return boolean (true accepts the input, false rejects it) instead of a status string, and inspect handlers answer with reports
  • Removed the OpenAPI schema generation: the schema.ts codegen script is gone, along with openapi-fetch, openapi-typescript and viem, since the package ships its own types
  • Both templates are ESM now, bundled to dist/index.mjs

Docker

  • The entrypoint is node itself, with index.mjs as the command. rollup-init only execs rollup-http-server, which bridges the rollup device to HTTP, and the application now talks to the device directly
  • Added a riscv64 dependencies stage: @cartesi/rollup is a native addon, and its installation selects the prebuilt binary of the platform it runs on. The build stage still bundles the application code on the build platform, with the dependencies left external
  • Removed ROLLUP_HTTP_SERVER_URL, and dropped /opt/cartesi/bin from PATH, as the machine guest tools are installed in /usr/bin
  • Bumped node to 24.17.0, on both the riscv64 base and the build stage

Toolchain

  • pnpm replaces yarn, pinned by the packageManager field of package.json and installed with corepack
  • Added pnpm-workspace.yaml, which allows the build script of @cartesi/rollup and exempts it from the minimum release age, so that a freshly published pre-release can be installed. The build script of esbuild, which comes in as a dependency of tsx, is denied, as tsx runs without it
  • rolldown replaces esbuild, configured in rolldown.config.js and rolldown.config.ts
  • TypeScript template: typescript 7, tsx in place of ts-node, tsc only type checks, and vitest is dropped, as the template has no tests

Documentation

  • Updated READMEs: the package, the pnpm setup, and running on the development host with the mock driver through CMT_INPUTS, with a pointer to @cartesi/codec for encoding advance inputs

Notable Implementation Details

  • @cartesi/rollup is a pre-release, published under the alpha npm tag
  • The same application code runs in both environments: on the development host the package uses a mock driver, which reads the inputs listed in CMT_INPUTS from files and writes the outputs next to them, and inside the Cartesi Machine it talks to the real rollup device
  • The native addon is the reason the dependencies are installed for riscv64 and kept out of the bundle, instead of being bundled with the application code

https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r

claude added 2 commits August 13, 2026 19:11
Replace the ROLLUP_HTTP_SERVER_URL polling loop of the JavaScript and
TypeScript templates with the @cartesi/rollup package, which talks
directly to the rollup device of the Cartesi Machine.

The package is a native addon, so the runtime dependencies are now
installed in a new riscv64 stage, where the matching prebuilt binary is
selected, and the application code is bundled with the dependencies kept
external. Both templates are ESM now, and the bundle is emitted as
index.mjs.

The TypeScript template no longer generates types from the rollup OpenAPI
spec, since the package ships its own, dropping the schema.ts codegen and
the openapi-fetch, openapi-typescript and viem dependencies. Its runtime
stage was also missing the APT_UPDATE_SNAPSHOT argument, which made the
apt snapshot pin empty.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
Replace yarn with pnpm on the JavaScript and TypeScript templates. The
version is pinned by the packageManager field of package.json and
installed with corepack, which is bundled with the node images.

The pnpm-workspace.yaml file allows the build scripts of @cartesi/rollup
and esbuild, which pnpm blocks by default, and exempts @cartesi/rollup
from the minimum release age, so that a freshly published pre-release can
be installed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
@tuler
tuler marked this pull request as draft August 13, 2026 20:21
claude added 5 commits August 13, 2026 20:34
The esbuild command line grew past what is comfortable in a package.json
script, so the options move to a build.js/build.ts file using the esbuild
JavaScript API, which is also where an application is likely to extend
them.

The image entrypoint is now node itself. rollup-init only execs
rollup-http-server, which bridges the rollup device to HTTP, and the
application talks to the device directly through @cartesi/rollup.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
The machine guest tools are installed in /usr/bin, and nothing else
creates /opt/cartesi/bin, so the directory does not exist in the image.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
The bundler options move from a build script to a rolldown.config file,
read by the rolldown CLI, which is the configuration format of the
bundler.

esbuild is still installed on the TypeScript template as a dependency of
tsx, but its install script is not needed, and is denied.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
The template has no tests, and the JavaScript one does not carry a test
runner either, so vitest goes away. typescript is bumped to 7, which
type checks the template with the existing configuration, and tsx to its
latest release.

@types/node is bumped within the 22 line, the node version of the
application image, so that the types describe the runtime the application
actually runs on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
Both the riscv64 base and the build stage move to node 24.17.0, and
@types/node follows the same line on the TypeScript template.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQk8hkw6zUJe38hM7LNd4r
@tuler

tuler commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

We should wait for Cartesi CLI version with cartesi-machine 0.21 support, but this is pretty much ready for review.

@tuler
tuler marked this pull request as ready for review August 14, 2026 01:52
@tuler tuler changed the title Migrate to @cartesi/rollup package and pnpm Migrate JS/TS templates to @cartesi/rollup, pnpm and node 24 Aug 14, 2026
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