From 11a66fab6f3ee799eb064ba86eeed32fa7f2fe3b Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:25:10 +0000 Subject: [PATCH 1/5] feat: enhance Laravel Playwright module and tests for improved E2E environment setup --- .github/workflows/run-tests.yml | 17 +++-------------- .github/workflows/test-module.yml | 18 ++++-------------- src/Console/Commands/InstallCommand.php | 5 +++++ stubs/app/README.md | 2 +- stubs/app/playwright.config.ts | 13 ++++++++++--- stubs/stack/react/config/package.json | 2 +- stubs/stack/vue/config/package.json | 2 +- tests/Feature/InstallCommandTest.php | 18 +++++++++++++++++- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b9e840c..1bb53bd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -136,21 +136,10 @@ jobs: timeout-minutes: 2 run: ./node_modules/.bin/playwright install chromium --with-deps - - name: Start Laravel server + # Playwright serves .env.e2e itself (laravelServer() in playwright.config.ts). + - name: Prepare the E2E environment working-directory: app - run: php artisan serve --host=0.0.0.0 --port=8000 & - - - name: Wait for server - run: | - for _ in $(seq 15); do - if curl -fs localhost:8000 > /dev/null; then - echo "Server is ready!" - exit 0 - fi - echo 'Waiting for server...' - sleep 2 - done - exit 1 + run: php artisan playwright:env --url=http://localhost:8000 --force - name: Execute core's browser tests working-directory: app diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index 50b80dc..99d4683 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -178,9 +178,12 @@ jobs: E2E_SETUP: ${{ inputs.e2e_setup }} run: bash -euo pipefail -c "$E2E_SETUP" - - name: Start Laravel server + # After the variant's setup, which may write to .env: .env.e2e is a copy of it. + # Playwright then serves it itself (laravelServer() in playwright.config.ts). + - name: Prepare the E2E environment working-directory: app run: | + php artisan playwright:env --url="$APP_URL" --force # Ports below 1024 are privileged by default. Lower the threshold # rather than serving as root, so the app never writes root-owned # logs, sessions, or SQLite files. Already root (act, containers) @@ -188,19 +191,6 @@ jobs: if [ "$SERVE_PORT" -lt 1024 ] && [ "$(id -u)" -ne 0 ]; then sudo sysctl -w "net.ipv4.ip_unprivileged_port_start=$SERVE_PORT" fi - php artisan serve --host=0.0.0.0 --port="$SERVE_PORT" & - - - name: Wait for server - run: | - for _ in $(seq 15); do - if curl -fs "localhost:$SERVE_PORT" > /dev/null; then - echo "Server is ready!" - exit 0 - fi - echo 'Waiting for server...' - sleep 2 - done - exit 1 - name: Run E2E tests working-directory: app diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 28b3456..15da6f5 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -37,6 +37,11 @@ class InstallCommand extends Command '/bootstrap/ssr', '/playwright-report', '/test-results', + '/storage/framework/playwright', + // Every env file, the E2E suite's `.env.e2e` included, but the examples. + '.env.*', + '!.env.*.example', + '!.env.example', '/public/css/filament', '/public/js/filament', '/public/fonts/filament', diff --git a/stubs/app/README.md b/stubs/app/README.md index aea640b..d0d0318 100644 --- a/stubs/app/README.md +++ b/stubs/app/README.md @@ -40,7 +40,7 @@ php artisan test # PHPUnit npm run test:e2e # Playwright ``` -**`npm run test:e2e` resets the database in `.env`.** Run it on an app whose data you can lose. +**`npm run test:e2e` runs on its own server and database**, from `.env.e2e`, so your app's data stays untouched. Create the file once with `php artisan playwright:env` (a copy of `.env` with its own SQLite database and port). ## Learn more diff --git a/stubs/app/playwright.config.ts b/stubs/app/playwright.config.ts index 3a4a018..f219351 100644 --- a/stubs/app/playwright.config.ts +++ b/stubs/app/playwright.config.ts @@ -1,10 +1,14 @@ /// import { defineConfig, devices } from '@playwright/test'; -import type { LaravelOptions } from '@saucebase/laravel-playwright'; -import 'dotenv/config'; +import { laravelServer, type LaravelOptions } from '@saucebase/laravel-playwright'; +import { config } from 'dotenv'; import { saucebaseProjects } from './vendor/saucebase/core/resources/js/modules.ts'; -const BASE_URL = process.env.APP_URL ?? 'http://localhost'; +// The suite runs on its own server and database, never the app's: .env.e2e, written +// by `php artisan playwright:env`. Loading .env here instead would hand that server +// your database. +config({ path: '.env.e2e', quiet: true }); +const BASE_URL = process.env.APP_URL ?? 'http://localhost:8100'; async function createConfig() { // database.setup, every module's setups and projects, per device, in order. @@ -62,6 +66,9 @@ async function createConfig() { /* Configure projects for major browsers */ projects, + /* Migrates .env.e2e's database, then serves it on APP_URL's port. */ + webServer: laravelServer(), + /** * Tests run against built assets, the way CI does. * diff --git a/stubs/stack/react/config/package.json b/stubs/stack/react/config/package.json index 8a94fc5..509654b 100644 --- a/stubs/stack/react/config/package.json +++ b/stubs/stack/react/config/package.json @@ -36,7 +36,7 @@ "@inertiajs/react": "^3.9.1", "@inertiajs/vite": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@svgr/core": "^8.1.0", "@svgr/plugin-jsx": "^8.1.0", "@tailwindcss/forms": "^0.5.11", diff --git a/stubs/stack/vue/config/package.json b/stubs/stack/vue/config/package.json index e04dd78..f96d010 100644 --- a/stubs/stack/vue/config/package.json +++ b/stubs/stack/vue/config/package.json @@ -36,7 +36,7 @@ "@inertiajs/vite": "^3.9.1", "@inertiajs/vue3": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", "@tailwindcss/vite": "^4.3.3", diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index d8c26e7..7670b3b 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -294,11 +294,27 @@ public function test_it_ignores_the_files_saucebase_generates(): void // Laravel's own lines stay. $this->assertStringStartsWith("/vendor\n/public/build\n", $ignored); - foreach (['/bootstrap/ssr', '/playwright-report', '/test-results', '/public/css/filament', '/public/js/filament', '/public/fonts/filament'] as $path) { + foreach (['/bootstrap/ssr', '/playwright-report', '/test-results', '/storage/framework/playwright', '/public/css/filament', '/public/js/filament', '/public/fonts/filament'] as $path) { $this->assertStringContainsString("\n{$path}\n", $ignored); } } + /** `.env.e2e` (the E2E suite's own env) and any other env file, but never an example. */ + public function test_it_ignores_every_env_file_but_the_examples(): void + { + $this->files->put($this->appPath.'/.gitignore', "/vendor\n.env\n.env.backup\n"); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $ignored = $this->read('.gitignore'); + $envs = strpos($ignored, "\n.env.*\n"); + + $this->assertNotFalse($envs); + // Negations only work after the pattern they undo. + $this->assertGreaterThan($envs, strpos($ignored, "\n!.env.*.example\n")); + $this->assertGreaterThan($envs, strpos($ignored, "\n!.env.example\n")); + } + public function test_it_does_not_ignore_a_path_twice(): void { $this->files->put($this->appPath.'/.gitignore', "/vendor\n/bootstrap/ssr\n"); From 5fcae4b560d742b32148b1c645d85b6bef4aff8f Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:31:49 +0000 Subject: [PATCH 2/5] feat: update E2E environment setup and README assertions in tests --- .github/workflows/test-module.yml | 1 + tests/Feature/InstallCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index 99d4683..e2b628c 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -183,6 +183,7 @@ jobs: - name: Prepare the E2E environment working-directory: app run: | + # localhost inside the runner, and artisan serve has no TLS. php artisan playwright:env --url="$APP_URL" --force # Ports below 1024 are privileged by default. Lower the threshold # rather than serving as root, so the app never writes root-owned diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index 7670b3b..db3740c 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -57,7 +57,7 @@ public function test_it_replaces_laravels_readme_with_one_for_saucebase(): void $readme = $this->read('README.md'); $this->assertStringContainsString('php artisan saucebase:module-install', $readme); $this->assertStringContainsString('docker compose exec app php artisan', $readme); - $this->assertStringContainsString('resets the database', $readme); + $this->assertStringContainsString('php artisan playwright:env', $readme); } public function test_the_published_user_factory_never_repeats_an_email_across_requests(): void From 6f907ebf3389ffa9ba70f6af8d8d22f7938f2957 Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:34:17 +0000 Subject: [PATCH 3/5] feat: update Laravel Playwright module to version 2.1.0 and refactor configuration for improved environment handling --- stubs/app/playwright.config.ts | 8 +++++--- stubs/stack/react/config/package-lock.json | 8 ++++---- stubs/stack/vue/config/package-lock.json | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/stubs/app/playwright.config.ts b/stubs/app/playwright.config.ts index f219351..8e226af 100644 --- a/stubs/app/playwright.config.ts +++ b/stubs/app/playwright.config.ts @@ -7,8 +7,10 @@ import { saucebaseProjects } from './vendor/saucebase/core/resources/js/modules. // The suite runs on its own server and database, never the app's: .env.e2e, written // by `php artisan playwright:env`. Loading .env here instead would hand that server // your database. -config({ path: '.env.e2e', quiet: true }); -const BASE_URL = process.env.APP_URL ?? 'http://localhost:8100'; +const e2e = config({ path: '.env.e2e', quiet: true }).parsed ?? {}; +// From the file, not process.env: an APP_URL exported for the dev app would win there, +// and the suite would test it while laravelServer() serves .env.e2e's. +const BASE_URL = e2e.APP_URL ?? 'http://localhost:8100'; async function createConfig() { // database.setup, every module's setups and projects, per device, in order. @@ -60,7 +62,7 @@ async function createConfig() { /** Laravel Playwright integration */ laravelBaseUrl: `${BASE_URL}/playwright`, - laravelSecret: process.env.PLAYWRIGHT_SECRET, + laravelSecret: e2e.PLAYWRIGHT_SECRET, }, /* Configure projects for major browsers */ diff --git a/stubs/stack/react/config/package-lock.json b/stubs/stack/react/config/package-lock.json index 2f41479..dcd596b 100644 --- a/stubs/stack/react/config/package-lock.json +++ b/stubs/stack/react/config/package-lock.json @@ -35,7 +35,7 @@ "@inertiajs/react": "^3.9.1", "@inertiajs/vite": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@svgr/core": "^8.1.0", "@svgr/plugin-jsx": "^8.1.0", "@tailwindcss/forms": "^0.5.11", @@ -3998,9 +3998,9 @@ } }, "node_modules/@saucebase/laravel-playwright": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-1.0.0.tgz", - "integrity": "sha512-zMO31P4ssto7W7T0PaGyQMsQO0nFmEgHjBUJtetCu3kkTF9ZP438VzzWikEfn1x5EIiPMBrA6aTn63HXf5oMsw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-2.1.0.tgz", + "integrity": "sha512-4sK2sUIwbS8vKz7FaL+Xw5AeSUFz79WXJ4BdBNj4LJDxUMH1dCB85P+S61vrVn1FpEdSmOdyqqxbvsEZK5eVWw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/stubs/stack/vue/config/package-lock.json b/stubs/stack/vue/config/package-lock.json index f51f785..6297f5e 100644 --- a/stubs/stack/vue/config/package-lock.json +++ b/stubs/stack/vue/config/package-lock.json @@ -35,7 +35,7 @@ "@inertiajs/vite": "^3.9.1", "@inertiajs/vue3": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", "@tailwindcss/vite": "^4.3.3", @@ -2381,9 +2381,9 @@ } }, "node_modules/@saucebase/laravel-playwright": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-1.0.0.tgz", - "integrity": "sha512-zMO31P4ssto7W7T0PaGyQMsQO0nFmEgHjBUJtetCu3kkTF9ZP438VzzWikEfn1x5EIiPMBrA6aTn63HXf5oMsw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-2.1.0.tgz", + "integrity": "sha512-4sK2sUIwbS8vKz7FaL+Xw5AeSUFz79WXJ4BdBNj4LJDxUMH1dCB85P+S61vrVn1FpEdSmOdyqqxbvsEZK5eVWw==", "dev": true, "license": "MIT", "dependencies": { From b9a1dbea1f6a989b96e9a5692430ea3db6f4cabb Mon Sep 17 00:00:00 2001 From: roble Date: Wed, 28 Oct 2026 20:49:26 +0000 Subject: [PATCH 4/5] feat: CopyField, formatRelative and destructive confirm fix - CopyField (Vue and React) in components/ui/saucebase: a read-only value with a copy button. - formatRelative() in lib/dates: "yesterday", "in 3 weeks" through Intl.RelativeTimeFormat. - React DynamicDialog: pass the confirm variant through AlertDialogAction's prop, so a destructive confirm is red instead of keeping the default variant's classes. - Module development skill: event listeners are discovered from src/Listeners; never also register them with Event::listen(). - Ignore node_modules at the root (Vitest's cache). Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + .../saucebase-module-development/SKILL.md | 15 ++++- resources/js/lib/dates.test.ts | 29 +++++++- resources/js/lib/dates.ts | 36 ++++++++++ .../react/js/components/DynamicDialog.tsx | 11 ++-- .../js/components/ui/saucebase/CopyField.tsx | 66 +++++++++++++++++++ .../react/js/components/ui/saucebase/index.ts | 1 + .../js/components/ui/saucebase/CopyField.vue | 65 ++++++++++++++++++ .../vue/js/components/ui/saucebase/index.ts | 1 + 9 files changed, 214 insertions(+), 11 deletions(-) create mode 100644 stubs/stack/react/js/components/ui/saucebase/CopyField.tsx create mode 100644 stubs/stack/vue/js/components/ui/saucebase/CopyField.vue diff --git a/.gitignore b/.gitignore index b3846c8..095d774 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ .DS_Store /.phpstan.cache/ tests/Fixtures/modules/*/resources/js/ +/node_modules/ /resources/js/node_modules/ /stubs/stack/*/config/node_modules/ diff --git a/resources/boost/skills/saucebase-module-development/SKILL.md b/resources/boost/skills/saucebase-module-development/SKILL.md index 8e3ebe0..9cc491e 100644 --- a/resources/boost/skills/saucebase-module-development/SKILL.md +++ b/resources/boost/skills/saucebase-module-development/SKILL.md @@ -14,10 +14,10 @@ Ask one question at a time, and skip frontend questions for admin-only modules: 1. Does it have Inertia pages, or is it admin-only (Filament)? 2. Does it need models and migrations? 3. Does it need Filament resources? If yes, activate `saucebase-filament-development`. -4. *(frontend)* Does it have public pages that need SSR? +4. _(frontend)_ Does it have public pages that need SSR? 5. Does it need a seeder? -6. *(frontend, logged-in area)* Does it need navigation entries and breadcrumbs? -7. *(frontend)* Should it have E2E tests? +6. _(frontend, logged-in area)_ Does it need navigation entries and breadcrumbs? +7. _(frontend)_ Should it have E2E tests? Write each behavior's failing test before its implementation. @@ -65,6 +65,15 @@ List extra providers in `protected array $providers`. `replaceConfig($path, $key config key where `mergeConfigFrom` would merge numeric arrays wrongly. Call `parent::boot()` when overriding `boot()`. +## Event Listeners + +Put listeners in `src/Listeners/` with a `handle()` method typed to the event +(`handle(PasswordReset $event)`). The module loader discovers them, so never also call `Event::listen()` for +them in the provider: the listener would run twice. `php artisan event:list` shows each listener once. + +Discovery only covers dispatched events. Eloquent model events on a model the module doesn't own (the +app's `User`) are hooked in the provider's `boot()`: `$users::deleted(fn (Model $user) => ...)`. + ## Navigation Core loads `routes/navigation.php` from the app and from every installed module. diff --git a/resources/js/lib/dates.test.ts b/resources/js/lib/dates.test.ts index 06460c8..c3fa6a0 100644 --- a/resources/js/lib/dates.test.ts +++ b/resources/js/lib/dates.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { formatDate } from './dates'; +import { formatDate, formatRelative } from './dates'; describe('formatDate', () => { it('formats in the language it is given', () => { @@ -25,3 +25,30 @@ describe('formatDate', () => { expect(formatDate('', 'en')).toBe(''); }); }); + +describe('formatRelative', () => { + const now = new Date('2026-10-28T12:00:00Z'); + const at = (seconds: number) => + new Date(now.getTime() + seconds * 1000).toISOString(); + const day = 86_400; + + it('says how long ago, or how long until, in the largest whole unit', () => { + expect(formatRelative(at(-30), 'en', now)).toBe('now'); + expect(formatRelative(at(-5 * 60), 'en', now)).toBe('5 minutes ago'); + expect(formatRelative(at(-3 * 3600), 'en', now)).toBe('3 hours ago'); + expect(formatRelative(at(-day), 'en', now)).toBe('yesterday'); + expect(formatRelative(at(3 * day), 'en', now)).toBe('in 3 days'); + expect(formatRelative(at(21 * day), 'en', now)).toBe('in 3 weeks'); + expect(formatRelative(at(-62 * day), 'en', now)).toBe('2 months ago'); + expect(formatRelative(at(400 * day), 'en', now)).toBe('next year'); + }); + + it('speaks the language it is given', () => { + expect(formatRelative(at(-day), 'pt-BR', now)).toBe('ontem'); + }); + + it('returns an empty string when there is no date', () => { + expect(formatRelative(null, 'en', now)).toBe(''); + expect(formatRelative('', 'en', now)).toBe(''); + }); +}); diff --git a/resources/js/lib/dates.ts b/resources/js/lib/dates.ts index 066711f..8712277 100644 --- a/resources/js/lib/dates.ts +++ b/resources/js/lib/dates.ts @@ -52,3 +52,39 @@ export function formatDateTime( minute: '2-digit', }); } + +const RELATIVE_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [ + ['year', 365 * 86_400], + ['month', 30 * 86_400], + ['week', 7 * 86_400], + ['day', 86_400], + ['hour', 3_600], + ['minute', 60], +]; + +/** + * How long ago, or how long until, in the app's language: "yesterday", "in 3 weeks", + * "2 months ago". Under a minute is "now". + * + * Only for pages that never render on the server, like `formatDateTime()`: the + * server's "now" is not the reader's, so the text would change on hydration. + */ +export function formatRelative( + value: string | Date | null | undefined, + locale: string | undefined, + now: Date = new Date(), +): string { + if (!value) { + return ''; + } + + const seconds = (new Date(value).getTime() - now.getTime()) / 1000; + const format = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }); + const unit = RELATIVE_UNITS.find(([, size]) => Math.abs(seconds) >= size); + + if (!unit) { + return format.format(0, 'second'); + } + + return format.format(Math.round(seconds / unit[1]), unit[0]); +} diff --git a/stubs/stack/react/js/components/DynamicDialog.tsx b/stubs/stack/react/js/components/DynamicDialog.tsx index 64ac617..c621225 100644 --- a/stubs/stack/react/js/components/DynamicDialog.tsx +++ b/stubs/stack/react/js/components/DynamicDialog.tsx @@ -7,7 +7,6 @@ import { AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; -import { buttonVariants } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { useDialog } from '@saucebase/react/hooks/useDialog'; import { useT } from '@saucebase/react/i18n'; @@ -74,12 +73,10 @@ export default function DynamicDialog() { {options.cancelLabel ?? t('Cancel')} resolve(true)} > diff --git a/stubs/stack/react/js/components/ui/saucebase/CopyField.tsx b/stubs/stack/react/js/components/ui/saucebase/CopyField.tsx new file mode 100644 index 0000000..3fbf06f --- /dev/null +++ b/stubs/stack/react/js/components/ui/saucebase/CopyField.tsx @@ -0,0 +1,66 @@ +import { + InputGroup, + InputGroupAddon, + InputGroupButton, + InputGroupInput, +} from '@/components/ui/input-group'; +import { useT } from '@saucebase/react/i18n'; +import { Check, Copy } from 'lucide-react'; +import { useEffect, useRef, useState } from 'react'; +import { toast } from 'sonner'; + +interface CopyFieldProps { + value: string; + testId: string; + className?: string; +} + +export function CopyField({ value, testId, className }: CopyFieldProps) { + const t = useT(); + + // The tick is feedback the user can see without reading the toast, so it clears + // itself on a timer rather than waiting for something else to re-render. + const [copied, setCopied] = useState(false); + const copyTimerRef = useRef | null>(null); + + useEffect( + () => () => { + if (copyTimerRef.current) clearTimeout(copyTimerRef.current); + }, + [], + ); + + const copy = () => { + navigator.clipboard + .writeText(value) + .then(() => { + toast.success(t('Copied to clipboard')); + if (copyTimerRef.current) clearTimeout(copyTimerRef.current); + setCopied(true); + copyTimerRef.current = setTimeout(() => setCopied(false), 2000); + }) + .catch(() => toast.error(t('Failed to copy'))); + }; + + return ( + + e.target.select()} + /> + + + {copied ? : } + + + + ); +} diff --git a/stubs/stack/react/js/components/ui/saucebase/index.ts b/stubs/stack/react/js/components/ui/saucebase/index.ts index 2945b78..c39a6c1 100644 --- a/stubs/stack/react/js/components/ui/saucebase/index.ts +++ b/stubs/stack/react/js/components/ui/saucebase/index.ts @@ -242,3 +242,4 @@ export const modules: Module[] = [ export { ModuleCard } from './ModuleCard'; export { ModuleModal } from './ModuleModal'; export { default as PageHero } from './PageHero'; +export { CopyField } from './CopyField'; diff --git a/stubs/stack/vue/js/components/ui/saucebase/CopyField.vue b/stubs/stack/vue/js/components/ui/saucebase/CopyField.vue new file mode 100644 index 0000000..f0df7e4 --- /dev/null +++ b/stubs/stack/vue/js/components/ui/saucebase/CopyField.vue @@ -0,0 +1,65 @@ + + + diff --git a/stubs/stack/vue/js/components/ui/saucebase/index.ts b/stubs/stack/vue/js/components/ui/saucebase/index.ts index de007d9..b27fd7f 100644 --- a/stubs/stack/vue/js/components/ui/saucebase/index.ts +++ b/stubs/stack/vue/js/components/ui/saucebase/index.ts @@ -287,3 +287,4 @@ export type Module = ReturnType['value'][number]; export { default as ModuleCard } from './ModuleCard.vue'; export { default as ModuleModal } from './ModuleModal.vue'; export { default as PageHero } from './PageHero.vue'; +export { default as CopyField } from './CopyField.vue'; From c3688b24f3de4cf71358740e1ddeae400849f764 Mon Sep 17 00:00:00 2001 From: roble Date: Wed, 28 Oct 2026 21:02:03 +0000 Subject: [PATCH 5/5] fix: address review on relative dates, gitignore rules and listener docs - formatRelative(): an unreadable date returns '' instead of "now", and past and future round alike (90 minutes is "2 hours" either way). - Installer: a new .gitignore also ignores `.env`, and when `.env.*` is appended its exceptions follow it, even ones the file already had. - Module skill: listener discovery depends on event discovery being on; the model-event example defines the user model it uses. Co-Authored-By: Claude Opus 5.5 --- .../saucebase-module-development/SKILL.md | 11 +++++++-- resources/js/lib/dates.test.ts | 9 +++++++ resources/js/lib/dates.ts | 9 ++++++- src/Console/Commands/InstallCommand.php | 13 +++++++++- tests/Feature/InstallCommandTest.php | 24 +++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/resources/boost/skills/saucebase-module-development/SKILL.md b/resources/boost/skills/saucebase-module-development/SKILL.md index 9cc491e..b04d435 100644 --- a/resources/boost/skills/saucebase-module-development/SKILL.md +++ b/resources/boost/skills/saucebase-module-development/SKILL.md @@ -68,11 +68,18 @@ overriding `boot()`. ## Event Listeners Put listeners in `src/Listeners/` with a `handle()` method typed to the event -(`handle(PasswordReset $event)`). The module loader discovers them, so never also call `Event::listen()` for +(`handle(PasswordReset $event)`). The module loader discovers them while event discovery is on, which is +Laravel's default (`app-modules.should_discover_events` overrides it). Never also call `Event::listen()` for them in the provider: the listener would run twice. `php artisan event:list` shows each listener once. Discovery only covers dispatched events. Eloquent model events on a model the module doesn't own (the -app's `User`) are hooked in the provider's `boot()`: `$users::deleted(fn (Model $user) => ...)`. +app's `User`) are hooked in the provider's `boot()`: + +```php +$users = config('auth.providers.users.model'); + +$users::deleted(fn (Model $user) => ...); +``` ## Navigation diff --git a/resources/js/lib/dates.test.ts b/resources/js/lib/dates.test.ts index c3fa6a0..a49a45c 100644 --- a/resources/js/lib/dates.test.ts +++ b/resources/js/lib/dates.test.ts @@ -43,6 +43,15 @@ describe('formatRelative', () => { expect(formatRelative(at(400 * day), 'en', now)).toBe('next year'); }); + it('rounds past and future alike', () => { + expect(formatRelative(at(-90 * 60), 'en', now)).toBe('2 hours ago'); + expect(formatRelative(at(90 * 60), 'en', now)).toBe('in 2 hours'); + }); + + it('returns an empty string for a date it cannot read', () => { + expect(formatRelative('not-a-date', 'en', now)).toBe(''); + }); + it('speaks the language it is given', () => { expect(formatRelative(at(-day), 'pt-BR', now)).toBe('ontem'); }); diff --git a/resources/js/lib/dates.ts b/resources/js/lib/dates.ts index 8712277..67e69e7 100644 --- a/resources/js/lib/dates.ts +++ b/resources/js/lib/dates.ts @@ -79,6 +79,10 @@ export function formatRelative( } const seconds = (new Date(value).getTime() - now.getTime()) / 1000; + + if (Number.isNaN(seconds)) { + return ''; + } const format = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }); const unit = RELATIVE_UNITS.find(([, size]) => Math.abs(seconds) >= size); @@ -86,5 +90,8 @@ export function formatRelative( return format.format(0, 'second'); } - return format.format(Math.round(seconds / unit[1]), unit[0]); + // Rounded by size, then signed, so 90 minutes is "2 hours" either way. + const amount = Math.round(Math.abs(seconds) / unit[1]); + + return format.format(seconds < 0 ? -amount : amount, unit[0]); } diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 15da6f5..640f6a8 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -39,6 +39,7 @@ class InstallCommand extends Command '/test-results', '/storage/framework/playwright', // Every env file, the E2E suite's `.env.e2e` included, but the examples. + '.env', '.env.*', '!.env.*.example', '!.env.example', @@ -98,7 +99,17 @@ private function ignoreGeneratedFiles(Filesystem $files): void { $path = $this->laravel->basePath('.gitignore'); $current = $files->exists($path) ? $files->get($path) : ''; - $missing = array_diff(self::GENERATED, array_map(trim(...), explode("\n", $current))); + $present = array_map(trim(...), explode("\n", $current)); + $missing = array_diff(self::GENERATED, $present); + + // A negation only works after the pattern it undoes, so a `.env.*` appended now + // brings its exceptions along, even ones the file already has. + if (in_array('.env.*', $missing, true)) { + $missing = array_filter( + self::GENERATED, + fn (string $line) => in_array($line, $missing, true) || str_starts_with($line, '!.env'), + ); + } if ($missing !== []) { $files->put($path, ($current === '' ? '' : rtrim($current, "\n")."\n\n")."# Saucebase\n".implode("\n", $missing)."\n"); diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index db3740c..c403947 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -315,6 +315,30 @@ public function test_it_ignores_every_env_file_but_the_examples(): void $this->assertGreaterThan($envs, strpos($ignored, "\n!.env.example\n")); } + public function test_a_new_gitignore_ignores_the_env_file(): void + { + $this->files->delete($this->appPath.'/.gitignore'); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $this->assertContains('.env', explode("\n", $this->read('.gitignore'))); + } + + /** Exceptions already in the file still have to follow the pattern they undo. */ + public function test_existing_env_exceptions_still_follow_the_pattern(): void + { + $this->files->put($this->appPath.'/.gitignore', "/vendor\n.env\n!.env.*.example\n!.env.example\n"); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $ignored = $this->read('.gitignore'); + $envs = strrpos($ignored, "\n.env.*\n"); + + $this->assertNotFalse($envs); + $this->assertGreaterThan($envs, strrpos($ignored, "\n!.env.*.example\n")); + $this->assertGreaterThan($envs, strrpos($ignored, "\n!.env.example\n")); + } + public function test_it_does_not_ignore_a_path_twice(): void { $this->files->put($this->appPath.'/.gitignore', "/vendor\n/bootstrap/ssr\n");