A sidecar was a folder of its own
A sidecar has been its own kind of source folder: kosmo sidecar created it, its kosmo.config.ts named an entry and a run, and the two files sat at the folder root.
Putting one beside a web app worked, but only just, and the docs talked you out of it.
Now it is a block
A sidecar is a block of a source folder now, just like frontend and backend. Any folder can have one, beside pages and an API or on its own:
export default defineConfig({
frontend: {
// ...
},
backend: {
// ...
},
sidecar: {
serve: false,
},
});Its files live in the folder's sidecar/ directory, the way pages live in pages/ and API routes in api/:
src/app/
├── api/
├── pages/
└── sidecar/
├── entry.ts -> the service: defineService({ start, teardown })
└── run.ts -> the runner: starts it, stops it on a signalThe block names no files any more. sidecar/entry.ts and sidecar/run.ts are the convention, seeded when missing, like api/app.ts for a backend or entry/client.ts for a frontend. That leaves the block with options only: serve, test and viteConfig.
serve is required now, so every sidecar says whether the dev server runs it.
The build already wrote a sidecar into dist/<folder>/sidecar/, so the source and the output now have the same shape.
Whether a worker belongs in the app's folder, or in one of its own, is a judgement call now. Sidecars › weighs it up.
kosmo sidecar is gone
With a sidecar being a block, adding one is a line in kosmo.config.ts, not a command of its own:
export default defineConfig({
// ...
sidecar: {
serve: false,
},
});The next start seeds sidecar/entry.ts and sidecar/run.ts.
When creating a folder, kosmo folder can add the block for you: it asks about a sidecar in its dialog, after the frontend and the backend, or takes --sidecar. That is also the way to a sidecar on its own, in a folder with neither side:
pnpm folder --name mailer --sidecar--sidecar takes no value. Leave it out and the dialog asks about a sidecar, or, with no terminal to ask in, the folder gets none.
create kosmo does the same for a project's first folder: it takes --sidecar, and asks about a sidecar when the flag is missing.
No more --no-* flags
--no-frontend and --no-backend are gone. --frontend, --backend and --sidecar are each optional now, and at least one is required.
In a terminal, the dialog asks only for the ones you leave out. With no terminal to ask in, the folder goes without them:
pnpm folder --name svc --backend hono
pnpm folder --name docs --frontend mdx
pnpm folder --name mailer --sidecarGiving or choosing none of them is an error.
create kosmo works the same way.
Sidecars get tests
vitest.config.ts loads every source folder with testing enabled as a Vitest project: <folder>:api for the backend, <folder>:pages for the frontend.
Sidecars were not on that list, so a test beside a queue consumer or a mail listener never ran.
Now a sidecar can turn its tests on:
export default defineConfig({
sidecar: {
serve: false,
test: true,
},
});Every *.test.ts and *.spec.ts file under sidecar/ is then loaded, at any depth, as a project of its own named mailer:sidecar.
Not just index.{test,spec}.ts, as on frontend and backend, where tests follow the routes. A sidecar has no routes to follow, so service.test.ts and smtp/parser.spec.ts count alike.
And since they stay within sidecar/, as frontend tests stay within pages/, a folder with all three blocks has each test file in exactly one project.
Nothing is seeded, so the tests are yours to write. There is no harness to go through either: the entry is an ordinary module, so a test starts it the way the runner does, and stops it the same way.
To run just those:
pnpm test --project mailer:sidecarTesting is opt-in
frontend.test and backend.test seed a starter index.test.ts beside every route. That is a file in your source folder for every page and every endpoint, and the scaffolder used to write test: true into each new folder's config, so you got them without asking.
Now new folders are scaffolded without it, and testing is off until you turn it on. The same goes for sidecars, which is why sidecar.test is off by default too.
export default defineConfig({
frontend: {
// ...
test: true,
},
backend: {
// ...
test: true,
},
});Or test: { seed: false }, to get the harness without the seeded files.
.spec.ts loads too
Frontend and backend tests used to load only as index.test.ts. Now index.spec.ts loads as well, so either naming habit works.
Seeding still writes index.test.ts. To seed under another name, set seed.name; once it is set, that name is also the only one that loads.
Upgrading
Sidecar folders
Move the two files into sidecar/, drop entry and run from the block, and give it serve if it has none:
src/mailer/entry.ts -> src/mailer/sidecar/entry.ts
src/mailer/run.ts -> src/mailer/sidecar/run.tsexport default defineConfig({
sidecar: {
entry: "./entry.ts",
run: "./run.ts",
serve: false,
},
});Move them rather than delete: a missing file is seeded anew, and your code would be gone with the old one.
Scripts
pnpm sidecar becomes pnpm folder, and the sidecar script in package.json can go.
Drop --no-frontend and --no-backend wherever a script passes them: pnpm folder --name svc --no-frontend --backend hono becomes pnpm folder --name svc --backend hono.
Tests
Nothing to change. Existing folders keep the test: true the scaffolder wrote into their config, and their tests run as before. Sidecars without test stay out of Vitest, as before too.