Rook in an existing project
Rook does not need a project of its own: it comes into an existing one a module at a time, and it can leave the same way.
The task board can join an existing Vite app one piece at a time: start with a typed task module, then expose a custom element or move the request-rendered page to Rook. The rest of the app does not have to migrate with it.
A module in a Vite project. With npm install rooklang and the plugin in the config of Vite, a .rk module is imported from JS and TS like any other:
import { defineConfig } from "vite" import { rook } from "rooklang/vite" export default defineConfig({ plugins: [rook()] })
export func divide(a, b number) (number, error) { if b == 0 { return 0, error("division by zero") } return a / b, null }
import { divide } from "./math.rk" // Several results are an array in JS const [ratio, err] = divide(6, 3)
Type errors in .rk modules stop the build. Under Vite, TypeScript does not see their types yet: a line declare module "*.rk" in a .d.ts of the project lets it import them as any. rook build, without Vite, writes a .d.ts next to each module, here divide(a: number, b: number): [number, null] | [null, Error].
A component in a React app. A component with @html-tag is a custom element, so React, Vue and Svelte use it as any tag (Web components). Markup is off unless the project turns it on, with "rook": { "markup": true } in its package.json:
// A button that counts its clicks, as the custom element <click-counter> @html-tag("click-counter") comp ClickCounter(label string, start number = 0) { state count = start return <button onClick={count++}>{label}: {count}</button> }
import "./counter.rk" // defines <click-counter> export function Toolbar() { return <click-counter label="Clicks" start={3} /> }
React 19 sets start={3} as a property of the element, so the component gets a number; an attribute, as in plain HTML, is converted by the type of the property.
Leaving Rook. The output of the compiler is readable JS with the names and the structure of the source, so a project can build its modules once and go on without Rook:
npx rook build src # .js, .d.ts and .js.map next to each .rk rm src/*.rk
- Imports of
./math.rkin JS and TS files become./math.js; imports between the built modules already are. - The code that uses channels, goroutines or markup imports
rooklang/runtime, plain JS under the MIT license. The package stays a dependency, or its foldersrc/runtimeis copied into the project and an alias of the bundler pointsrooklang/runtimeto the copy. - The comments of the source are not in the output yet.
What is missing for a production project, and when it comes, is on the roadmap.