Two additions in v0.6.10, and two fixes. One addition changes the shape of function templates, so check the upgrade note.
$/: derived code of any folder
_/ reaches the derived code of the folder you are in. That is the right default, and it is also its limit: there was no clean way to reach another folder's derived code, or any folder's at all from a file at the project root.
So a root-level helper that needed the admin folder's base had to hardcode a path into var/lib/.
$/ resolves to var/lib/, wherever it is used:
// a helper at the project root
import { base } from "$/admin/core";
// the admin folder, reading the docs folder's routes
import { apiRouteMap } from "$/docs/core";Inside a folder, _/core and $/<this folder>/core point at the same file. Keep _/ for your own folder, and use $/ when the code belongs to another one.
Templates for layouts and use.ts
A template seeds a route's file by pattern: the page on the frontend, the route on the backend. But some source folders, an admin CRUD for example, want their layouts or use.ts files seeded consistently as well.
Rather than a second option with the same patterns repeated, the function form grew. It now receives the resolved entry, { kind, entry }, and returns the template, or undefined to keep the built-in one. It is called for routes and for layouts on the frontend, for routes and use.ts on the backend:
export default defineConfig({
frontend: {
stack: "react",
base: "/admin",
templates: {
"crud/**": ({ kind, entry }) => {
if (kind === "pageLayout") {
return adminLayout;
}
return adminPage(entry.name);
},
},
},
});One pattern, one place, so the page and its layout cannot drift apart. A plain string still works as before, and still seeds only the route file.
Upgrading: a function template used to receive the route itself. It now receives { kind, entry }, and is called for layouts or use.ts files too, so return undefined for the kinds it should leave alone:
// before
"admin/**": (route) => adminPage(route.name),
// after
"admin/**": ({ kind, entry }) => {
return kind === "pageRoute" ? adminPage(entry.name) : undefined;
},Fixes
basewasundefinedin folders without a frontend.
A folder with no frontend, or no base for it, got base set to undefined in _/core, which broke type checking for code that read it. The same happened to backendBase in folders without a backend. Both are strings now.
Vitest ran every test in both projects.
The backend and frontend test projects were given the same globs, so each one loaded the tests of both. Now each project loads only its own: api/ tests for the backend, pages/ tests for the frontend.