diff --git a/.github/workflows/kits.yml b/.github/workflows/kits.yml index af9b215..a5cf3ad 100644 --- a/.github/workflows/kits.yml +++ b/.github/workflows/kits.yml @@ -91,14 +91,24 @@ jobs: npm test -w kits/tanstack-start npm run types:check -w kits/tanstack-start npm run build -w kits/tanstack-start + # Its tests run packages/ui-vue's too, and its typecheck the + # shared components it imports; vue-tsc checks the rest. + # test:build builds it, then checks what the built server sends. + - name: Nuxt kit + run: | + npm test -w kits/nuxt + npm run types:check -w kits/nuxt + npx vue-tsc --noEmit -p packages/ui-vue + npm run test:build -w kits/nuxt - run: composer ci:check # The Playwright suite (tests/e2e), screenshots included, against each - # kit: the Inertia app Laravel serves, and the TanStack kit with Laravel - # headless behind its proxy. Both compare against the same screenshots, - # made in this same image (the README's "Screenshots"), so the browser, - # its fonts and its libraries render them pixel for pixel. Its version is - # the @playwright/test in package-lock.json. + # kit: the Inertia app Laravel serves, and the TanStack and Nuxt kits + # with Laravel headless behind their proxies. All of them compare + # against the same screenshots, made in this same image (the README's + # "Screenshots"), so the browser, its fonts and its libraries render them + # pixel for pixel. Its version is the @playwright/test in + # package-lock.json. browser: name: Browser tests (${{ matrix.kit }}) runs-on: ubuntu-latest @@ -107,7 +117,7 @@ jobs: strategy: fail-fast: false matrix: - kit: [inertia-react, tanstack-start] + kit: [inertia-react, tanstack-start, nuxt] env: E2E_KIT: ${{ matrix.kit }} steps: diff --git a/.gitignore b/.gitignore index b93ab36..1f5acdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /.phpunit.cache /bootstrap/ssr -/node_modules +node_modules/ /public/build /public/fonts-manifest.dev.json /public/hot diff --git a/README.md b/README.md index 9de4f9d..0fe832c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Laravel starter kits with [Keyring](https://github.com/keyringphp/keyring) for s | ---------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------- | | `inertia-react` | Inertia and React, the app in this repository (`resources/js`) | `laravel new my-app --using=keyringphp/starter-inertia-react` | | `tanstack-start` | TanStack Start, talking to the backend headless (`kits/tanstack-start`) | `laravel new my-app --using=keyringphp/starter-tanstack-start` | -| `nuxt` | Nuxt, talking to the backend headless (coming, `kits/`) | | +| `nuxt` | Nuxt (Vue), talking to the backend headless (`kits/nuxt`) | `laravel new my-app --using=keyringphp/starter-nuxt` | ## Installing a kit @@ -18,11 +18,11 @@ cd my-app composer dev ``` -Without the installer, `composer create-project keyringphp/starter-inertia-react my-app` followed by `npm install && npm run build` does the same (for the TanStack kit, `npm install && npm ci --prefix frontend && npm run build`). Either way the new app gets its `.env` from `.env.example`, an app key and a migrated SQLite database, like Laravel's own starter kits. +Without the installer, `composer create-project keyringphp/starter-inertia-react my-app` followed by `npm install && npm run build` does the same (for a headless kit, the TanStack or Nuxt one, `npm install && npm ci --prefix frontend && npm run build`). Either way the new app gets its `.env` from `.env.example`, an app key and a migrated SQLite database, like Laravel's own starter kits. A kit is a clean starter, not this repository's demo: a plain welcome page and dashboard, every auth page, the settings pages (profile, security, appearance) and Keyring's emails, under the app's own name. `php artisan db:seed` adds one test user, as Laravel's kits do. The demo stays here, for keyringphp.com and the browser tests (see [The demo](#the-demo)). -`APP_URL` in `.env` has to be the address the app is opened at, because Keyring builds the passkey origin and every emailed link from it. For the Inertia kit, `laravel new my-app` sets it (to `http://my-app.test` under Herd or Valet, `http://localhost:8000` otherwise), and `composer create-project` sets `http://localhost:8000`, where `composer dev` serves. `laravel new .` leaves it at `http://localhost`, so set it yourself after that, or whenever you serve the app somewhere else. The TanStack kit's is the frontend's address, `http://localhost:3000`, where its `composer dev` serves. +`APP_URL` in `.env` has to be the address the app is opened at, because Keyring builds the passkey origin and every emailed link from it. For the Inertia kit, `laravel new my-app` sets it (to `http://my-app.test` under Herd or Valet, `http://localhost:8000` otherwise), and `composer create-project` sets `http://localhost:8000`, where `composer dev` serves. `laravel new .` leaves it at `http://localhost`, so set it yourself after that, or whenever you serve the app somewhere else. A headless kit's is the frontend's address, `http://localhost:3000`, where its `composer dev` serves. Each kit's repository (`keyringphp/starter-`) is read-only and built from this one on every release, so issues and pull requests come here. @@ -35,11 +35,13 @@ resources/js/ # inertia-react's frontend: its pages, and what only resources/css/app.css # inertia-react's stylesheet: the theme, then its @source lines packages/ ├── theme/ # @keyringjs/theme: Tailwind v4, the palette, shadcn tokens, dark mode, fonts -└── ui-react/ # @keyringjs/ui-react: the shadcn/ui primitives, and the app components, - # layouts and Keyring's settings components both React kits share +├── ui-react/ # @keyringjs/ui-react: the shadcn/ui primitives, and the app components, +│ # layouts and Keyring's settings components both React kits share +└── ui-vue/ # @keyringjs/ui-vue: the same, written for Vue (shadcn-vue), for the Vue kits kits/ ├── inertia-react/ # kit.json (how to export it) and the README its repository gets ├── tanstack-start/ # the TanStack Start frontend, headless: kit.json, its README and the app +├── nuxt/ # the Nuxt frontend, headless: kit.json, its README and the app └── / # a headless kit: kit.json and its frontend app bin/export-kit.mjs # builds one kit as a standalone Laravel app .github/workflows/kits.yml # checks the monorepo and every kit, and publishes them on release @@ -73,6 +75,8 @@ The ones that link, post or read the page's props do it through `@keyringjs/ui-r An exported kit gets the package back in its own source, with the imports rewritten. The Inertia kit's export gets the files where they were before they were shared (`resources/js/components`, `layouts`, `hooks` and `keyring`), and imports the adapter from `@inertiajs/react`, the routes from Wayfinder's `@/routes` and the types from `@/types`, so it has no adapter and reads as if the files had never moved. The TanStack kit's gets them in `frontend/src`. +`@keyringjs/ui-vue` is the same for Vue kits, the Nuxt kit's for now: `@keyringjs/ui-react`'s primitives, app components, layouts, Keyring's settings components and the challenge's factors, written for Vue with [shadcn-vue](https://www.shadcn-vue.com) on Reka UI, with the same markup and classes, so it matches the same screenshots. Its files have Vue's names, and are imported with their extension (`@keyringjs/ui-vue/components/InputError.vue`, `@keyringjs/ui-vue/composables/useAppearance`, `@keyringjs/ui-vue/button`). Its adapter, `@keyringjs/ui-vue/adapter`, is the part of Inertia's Vue API the components use (`Link`, `Form`, `usePage()`, `router`), which an app provides with `provideAdapter()`, and its components import Keyring's helpers from `@keyringjs/keyring/vue`, which the Nuxt kit points at its headless entry (see [its README](kits/nuxt/README.md#shared-components)). The Nuxt kit's export gets them in `frontend/app`. + What stays in the Inertia app: the pages, `pages.test.tsx`, the toaster (`resources/js/components/ui/sonner.tsx`, which shows Inertia's flashed toasts), `toUrl()` (`resources/js/lib/url.ts`), the header layout and its header, and the delete-account card. `components.json` (and the `paths` in `tsconfig.json`) point shadcn's CLI at the package, so `npx shadcn add ` writes new primitives to `packages/ui-react/src/components/ui`. An exported kit gets the usual `components.json` back, pointing at its own `resources/js/components/ui`. ## The demo @@ -90,7 +94,7 @@ The app here is also the demo keyringphp.com runs and the browser tests drive: a | `tests/Feature/Demo/` | the demo's tests | | `resources/emails/` | the Maizzle sources of the emails, which kits get built (see [Emails](#emails)) | -The browser tests build the app without the demo's pages, login extras and links (`VITE_DEMO=false`), so both kits show the same pages there. The app reaches the demo only through lines tagged `@monorepo-only`, which the export strips: the provider in `bootstrap/providers.php`, `require __DIR__.'/demo.php'` in `routes/web.php`, the `demoAccounts`, `demoSettings` and `demoLocation` props in `WelcomeController`, `DashboardController` and `HandleInertiaRequests`, the `demo` locator in `config/keyring.php` and `.env.example`, the emailed codes `KeyringServiceProvider` registers for it, the demo's extras on the login page and in the header and sidebar, and the page resolver in `resources/js/app.tsx`. That resolver, `resources/js/demo/pages.ts`, takes a page in `resources/js/demo/pages` over the one of the same name in `resources/js/pages`. The demo's welcome page and dashboard render the plain ones with their own content inside (as `children`), and get the plain page's `layout` when they don't set one, so the header, the alerts and the layout are written once. `resources/js/pages.test.tsx` renders the plain ones, as a kit has them. +The browser tests build the app without the demo's pages, login extras and links (`VITE_DEMO=false`), so every kit shows the same pages there. The app reaches the demo only through lines tagged `@monorepo-only`, which the export strips: the provider in `bootstrap/providers.php`, `require __DIR__.'/demo.php'` in `routes/web.php`, the `demoAccounts`, `demoSettings` and `demoLocation` props in `WelcomeController`, `DashboardController` and `HandleInertiaRequests`, the `demo` locator in `config/keyring.php` and `.env.example`, the emailed codes `KeyringServiceProvider` registers for it, the demo's extras on the login page and in the header and sidebar, and the page resolver in `resources/js/app.tsx`. That resolver, `resources/js/demo/pages.ts`, takes a page in `resources/js/demo/pages` over the one of the same name in `resources/js/pages`. The demo's welcome page and dashboard render the plain ones with their own content inside (as `children`), and get the plain page's `layout` when they don't set one, so the header, the alerts and the layout are written once. `resources/js/pages.test.tsx` renders the plain ones, as a kit has them. The manifest's `forbid` list then names `demo` and `Demo`, and the demo's classes, paths, routes and props, and the export stops if any exported file still has one in its text or its path. A new reference to the demo from shared code has to be tagged, or the export fails. @@ -126,6 +130,7 @@ node bin/export-kit.mjs inertia-react /tmp/starter-inertia-react --force # node bin/export-kit.mjs inertia-react /tmp/starter-inertia-react --skip-lock # leave the lockfiles as copied node bin/export-kit.mjs tanstack-start /tmp/starter-tanstack-start node bin/export-kit.mjs tanstack-start /tmp/starter-tanstack-start --allow-dirty # with uncommitted changes +node bin/export-kit.mjs nuxt /tmp/starter-nuxt ``` It refuses to run while a tracked file has changes that aren't committed, staged or not: it copies the working tree, so a Keyring checkout linked for local work (see [Working on Keyring Itself](#working-on-keyring-itself)), a path repository in `composer.json` and a `file:` dependency in `package.json`, would ship with the export. Export a clean worktree (`git worktree add /tmp/kit HEAD`), or pass `--allow-dirty` to take the working tree as it is. @@ -141,7 +146,7 @@ The output is what the kit's repository gets: a complete Laravel app with no wor 7. Stops with an error if any exported file still names a workspace package anywhere, in an import or not, or has anything in the kit's `forbid` list in its text or its path. 8. Updates `package-lock.json` and `composer.lock` to match, without moving any version: what the kit removed leaves the locks, and nothing else changes. A headless kit's `frontend/` gets a `package-lock.json` of its own, made from the monorepo's: what its workspace and the packages inlined into it have there, at the paths they'd have on their own, which `npm install --package-lock-only` then trims to what it uses. -Each kit has a manifest, `kits//kit.json` ([inertia-react's](kits/inertia-react/kit.json), [tanstack-start's](kits/tanstack-start/kit.json)). Paths are from the repository's root, and a trailing `/` means a directory and everything in it. +Each kit has a manifest, `kits//kit.json` ([inertia-react's](kits/inertia-react/kit.json), [tanstack-start's](kits/tanstack-start/kit.json), [nuxt's](kits/nuxt/kit.json)). Paths are from the repository's root, and a trailing `/` means a directory and everything in it. | Key | What it does | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -162,9 +167,11 @@ The inertia-react export leaves out the demo, the Maizzle sources of the emails, The tanstack-start export leaves out the same, and the Inertia frontend: `resources/js`, `resources/css`, the Vite and TypeScript config, and Wayfinder. The backend keeps its Inertia mode, which its tests cover (`config/inertia.php` only checks Inertia's page files where they are), but not that mode's frontend. The kit goes in `frontend/`, without `scripts/` (`npm run dev:tanstack`), with `@keyringjs/theme` in `frontend/src/theme` and `@keyringjs/ui-react` in `frontend/src` (its routes in `frontend/src/lib/routes`, apart from TanStack Router's), and `.npmrc`. The root's `package.json` keeps only `concurrently` and `@laravel/multiplex`, for `composer dev`, and scripts that run `frontend/`'s: `build`, `dev`, `test`, `check` and `types:check`. `composer dev` (`php artisan dev`) then runs Laravel's server on `127.0.0.1:8000` and the frontend's on `localhost:3000`, which is `APP_URL` and `FRONTEND_URL` in `.env.example`, with `APP_FRONTEND=headless`. The Laravel installer only runs `npm install` and `npm run build` at the root, so `composer.json`'s `extra.laravel.installer.post-create-project` hook runs `npm ci --prefix frontend` first (unless it was told `--no-node`), and fails the install when that does, and `composer setup` does the same. The kit is npm only, so `laravel new --pnpm`, `--bun` or `--yarn` aren't supported. In headless mode `composer dev` runs `artisan serve --tries=0`: Laravel's server takes its port or stops, rather than moving to the next free one while the frontend still proxies to the first. +The nuxt export is the tanstack-start one with the Nuxt app in `frontend/` instead (without `scripts/`, `npm run dev:nuxt`): `@keyringjs/theme` in `frontend/app/theme`, and `@keyringjs/ui-vue` in `frontend/app`, but for its layouts, which go in `frontend/app/components/layouts` (`app/layouts` is Nuxt's), and its routes, in `frontend/app/lib/routes`. Its root `package.json`, `.env.example`, installer hook and `composer dev` are the tanstack-start export's. + ## CI and releases -`.github/workflows/kits.yml` runs on pushes to `main` and on pull requests. It checks the monorepo, runs the browser tests against each React kit (see [Browser tests](#browser-tests)), then exports every kit in `kits/*/kit.json`, installs it (`composer install`, `post-root-package-install`, `key:generate`, `npm ci`, and `npm ci --prefix frontend` for a headless kit), builds it and runs its `npm test` and `composer ci:check`, which for the TanStack kit lint, typecheck and test `frontend/` too. It doesn't run `post-create-project-cmd` or the installer's own steps; those were checked by hand with the real installer against a local copy. +`.github/workflows/kits.yml` runs on pushes to `main` and on pull requests. It checks the monorepo, runs the browser tests against each kit (see [Browser tests](#browser-tests)), then exports every kit in `kits/*/kit.json`, installs it (`composer install`, `post-root-package-install`, `key:generate`, `npm ci`, and `npm ci --prefix frontend` for a headless kit), builds it and runs its `npm test` and `composer ci:check`, which for a headless kit lint, typecheck and test `frontend/` too. It doesn't run `post-create-project-cmd` or the installer's own steps; those were checked by hand with the real installer against a local copy. When a release is published (not a prerelease), each kit's tested export is pushed to its repository as one commit on `main`, tagged with the release's tag. The release job runs in the `release` environment. One-time setup: @@ -361,7 +368,7 @@ Headless mode needs Keyring 0.4 or later, and the headless kits `@keyringjs/keyr -The TanStack Start kit in `kits/tanstack-start` is the first of them. `npm run dev:tanstack` runs it with this backend in headless mode, on `http://localhost:3765`: see [its README](kits/tanstack-start/README.md). +The TanStack Start kit in `kits/tanstack-start` and the Nuxt kit in `kits/nuxt` are two of them. `npm run dev:tanstack` and `npm run dev:nuxt` run them with this backend in headless mode, on `http://localhost:3765` (one at a time, since they use the same ports): see [the TanStack kit's README](kits/tanstack-start/README.md) and [the Nuxt kit's](kits/nuxt/README.md). @@ -414,27 +421,29 @@ Two things in the demo aren't for a real app: it registers emailed codes, to sho ## Browser tests -`tests/e2e` drives the real pages in Chromium with Playwright, including passkeys and security keys through Chrome's virtual authenticator. The same specs run against each React kit, picked with `E2E_KIT`: +`tests/e2e` drives the real pages in Chromium with Playwright, including passkeys and security keys through Chrome's virtual authenticator. The same specs run against each kit, picked with `E2E_KIT`: ```bash npx playwright install chromium # once npm run test:browser # the Inertia kit (E2E_KIT=inertia-react) npm run test:browser:tanstack # the TanStack kit (E2E_KIT=tanstack-start) +npm run test:browser:nuxt # the Nuxt kit (E2E_KIT=nuxt) ``` -They build the assets and serve the app with a throwaway SQLite database (`database/e2e.sqlite`) and their own `.env.e2e` (`tests/e2e/serve.sh`): the Inertia kit on `http://localhost:8137`, or the TanStack kit's production server on `http://localhost:3765` with Laravel headless behind it on `127.0.0.1:8765`. Mail is written to `storage/logs/laravel.log`, where the tests read the links and codes it carries. Before starting, they check that the booted app really uses that database, so your dev database and server are left alone. Run one kit at a time: both use the same database. Each kit is its own Playwright project, named after it. +They build the assets and serve the app with a throwaway SQLite database (`database/e2e.sqlite`) and their own `.env.e2e` (`tests/e2e/serve.sh`): the Inertia kit on `http://localhost:8137`, or a headless kit's production server (its `npm start`) on `http://localhost:3765` with Laravel headless behind it on `127.0.0.1:8765`. Mail is written to `storage/logs/laravel.log`, where the tests read the links and codes it carries. Before starting, they check that the booted app really uses that database, so your dev database and server are left alone. Run one kit at a time: they all use the same database. Each kit is its own Playwright project, named after it. -The specs don't know which kit they drive: the paths, labels and words are the same. Two things really differ, and `tests/e2e/helpers.ts` says so once each: a page that needs a session sends a guest to `/login?redirect=...` in the TanStack kit, where Laravel keeps the page in the session (`sentToLogin`), and the TanStack kit's requests to Laravel go through `/backend` (`laravelPath()`). +The specs don't know which kit they drive: the paths, labels and words are the same. Two things really differ, and `tests/e2e/helpers.ts` says so once each: a page that needs a session sends a guest to `/login?redirect=...` in the headless kits, where Laravel keeps the page in the session (`sentToLogin`), and the headless kits' requests to Laravel go through `/backend` (`laravelPath()`). A spec only for the headless kits skips the Inertia kit with `headless`, from `tests/e2e/env.ts`. ### Screenshots -`tests/e2e/screenshots.spec.ts` shoots every page (the guest pages, the second step and step-up, the dashboard and the settings pages, a held user's security page, and the pages emailed links open), in light and dark, at a desktop's and a phone's width. Both kits compare against the same screenshots, in `tests/e2e/screenshots`, made from the Inertia kit, so a page that drifts from the other kit's fails. They're made with the browser in Playwright's Docker image (`mcr.microsoft.com/playwright:v-noble`), the one CI's browser job runs in, so they match to the pixel: no more than 50 pixels of a page may differ, which one missing control or changed word is far over. Only times and IP addresses are masked, each on its own (`components/keyring/details.tsx` puts them in a `