Skip to content

Commit 51effe6

Browse files
committed
Merge branch 'main' into storage
2 parents 7fe28ba + 0ef8d6d commit 51effe6

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ To get started, install Wayfinder via the Composer package manager:
1515
composer require laravel/wayfinder
1616
```
1717

18-
If you would like to automatically watch your files for changes, you should also install the `vite-plugin-run` npm package:
18+
We also recommend installing and configuring [`vite-plugin-run`](https://github.com/innocenzi/vite-plugin-run) to ensure that your routes are generated during Vite's build step and also whenever your files change while running the Vite's dev server.
19+
20+
First, install the plugin via NPM:
1921

2022
```
2123
npm i -D vite-plugin-run

build.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { execSync } from "node:child_process";
22
import path from "node:path";
33

4-
export default function setup() {
4+
const testbenchDir = path.join(__dirname, "vendor", "bin", "testbench");
5+
6+
const artisan = (command: string): void => console.error(execSync(`${testbenchDir} ${command}`).toString('utf8'))
7+
8+
export function setup(): void {
59
try {
6-
const testbenchDir = path.join(__dirname, "vendor", "bin", "testbench");
10+
process.env.WAYFINDER_CACHE_ROUTES
11+
? artisan('route:cache')
12+
: artisan('route:clear')
713

8-
execSync(
9-
`${testbenchDir} wayfinder:generate --path=workbench/resources/js --with-form`,
10-
);
14+
artisan('wayfinder:generate --path=workbench/resources/js --with-form')
1115
} catch (error) {
12-
console.error(
13-
`Wayfinder build error.\n----------${error.output}\n----------`,
14-
);
16+
console.error(`Wayfinder build error\n----------${error.output}\n----------`);
17+
1518
process.exit(1);
1619
}
1720
}
21+
22+
export function teardown(): void {
23+
artisan('route:clear')
24+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"type": "module",
33
"scripts": {
4-
"test": "vitest run"
4+
"test": "vitest run && npm run test-routes-cached",
5+
"test-routes-cached": "WAYFINDER_CACHE_ROUTES=1 vitest run"
56
},
67
"devDependencies": {
78
"@types/node": "^22.7.5",

src/Route.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Laravel\Wayfinder;
44

5+
use Closure;
56
use Illuminate\Contracts\Routing\UrlRoutable;
67
use Illuminate\Routing\Route as BaseRoute;
8+
use Illuminate\Routing\RouteAction;
79
use Illuminate\Support\Collection;
810
use Illuminate\Support\Str;
911
use Laravel\SerializableClosure\Support\ReflectionClosure;
@@ -127,7 +129,7 @@ public function controllerPath(): string
127129
$controller = $this->controller();
128130

129131
if ($controller === '\\Closure') {
130-
return $this->relativePath((new ReflectionClosure($this->base->getAction()['uses']))->getFileName());
132+
return $this->relativePath((new ReflectionClosure($this->closure()))->getFileName());
131133
}
132134

133135
if (! class_exists($controller)) {
@@ -142,7 +144,7 @@ public function controllerMethodLineNumber(): int
142144
$controller = $this->controller();
143145

144146
if ($controller === '\\Closure') {
145-
return (new ReflectionClosure($this->base->getAction()['uses']))->getStartLine();
147+
return (new ReflectionClosure($this->closure()))->getStartLine();
146148
}
147149

148150
if (! class_exists($controller)) {
@@ -167,4 +169,11 @@ private function relativePath(string $path)
167169
{
168170
return ltrim(str_replace(base_path(), '', $path), DIRECTORY_SEPARATOR);
169171
}
172+
173+
private function closure(): Closure
174+
{
175+
return RouteAction::containsSerializedClosure($this->base->getAction())
176+
? unserialize($this->base->getAction('uses'))->getClosure()
177+
: $this->base->getAction('uses');
178+
}
170179
}

0 commit comments

Comments
 (0)