@@ -157,7 +157,7 @@ private function writeControllerFile(Collection $routes, string $namespace): voi
157
157
158
158
if ($ invokable ->isEmpty ()) {
159
159
$ exportedMethods = $ methods ->map (fn (Route $ route ) => $ route ->jsMethod ());
160
- $ reservedMethods = $ methods ->filter (fn (Route $ route ) => $ route ->originalJsMethod () !== $ route ->jsMethod ())->map (fn (Route $ route ) => $ route ->originalJsMethod ().': ' .$ route ->jsMethod ());
160
+ $ reservedMethods = $ methods ->filter (fn (Route $ route ) => $ route ->originalJsMethod () !== $ route ->jsMethod ())->map (fn (Route $ route ) => TypeScript:: quoteIfNeeded ( $ route ->originalJsMethod () ).': ' .$ route ->jsMethod ());
161
161
$ exportedMethods = $ exportedMethods ->merge ($ reservedMethods );
162
162
163
163
$ methodProps = "const {$ defaultExport } = { " ;
@@ -176,17 +176,20 @@ private function writeControllerFile(Collection $routes, string $namespace): voi
176
176
177
177
private function writeMultiRouteControllerMethodExport (Collection $ routes , string $ path ): void
178
178
{
179
+ $ isInvokable = $ routes ->first ()->hasInvokableController ();
180
+
179
181
$ this ->appendContent ($ path , $ this ->view ->make ('wayfinder::multi-method ' , [
180
182
'method ' => $ routes ->first ()->jsMethod (),
181
183
'original_method ' => $ routes ->first ()->originalJsMethod (),
182
184
'path ' => $ routes ->first ()->controllerPath (),
183
185
'line ' => $ routes ->first ()->controllerMethodLineNumber (),
184
186
'controller ' => $ routes ->first ()->controller (),
185
- 'isInvokable ' => $ routes ->first ()->hasInvokableController (),
187
+ 'isInvokable ' => $ isInvokable ,
188
+ 'shouldExport ' => ! $ isInvokable ,
186
189
'withForm ' => $ this ->option ('with-form ' ) ?? false ,
187
190
'routes ' => $ routes ->map (fn ($ r ) => [
188
191
'method ' => $ r ->jsMethod (),
189
- 'tempMethod ' => $ r ->jsMethod ().md5 ( $ r ->uri ()),
192
+ 'tempMethod ' => $ r ->jsMethod ().hash ( ' xxh128 ' , $ r ->uri ()),
190
193
'parameters ' => $ r ->parameters (),
191
194
'verbs ' => $ r ->verbs (),
192
195
'uri ' => $ r ->uri (),
@@ -201,6 +204,7 @@ private function writeControllerMethodExport(Route $route, string $path): void
201
204
'method ' => $ route ->jsMethod (),
202
205
'original_method ' => $ route ->originalJsMethod (),
203
206
'isInvokable ' => $ route ->hasInvokableController (),
207
+ 'shouldExport ' => ! $ route ->hasInvokableController (),
204
208
'path ' => $ route ->controllerPath (),
205
209
'line ' => $ route ->controllerMethodLineNumber (),
206
210
'parameters ' => $ route ->parameters (),
@@ -255,7 +259,8 @@ private function writeNamedMethodExport(Route $route, string $path): void
255
259
'controller ' => $ route ->controller (),
256
260
'method ' => $ route ->namedMethod (),
257
261
'original_method ' => $ route ->originalJsMethod (),
258
- 'isInvokable ' => false ,
262
+ 'isInvokable ' => $ route ->hasInvokableController (),
263
+ 'shouldExport ' => ! $ route ->hasInvokableController () || str_contains ($ route ->controller (), '\\Closure ' ),
259
264
'path ' => $ route ->controllerPath (),
260
265
'line ' => $ route ->controllerMethodLineNumber (),
261
266
'parameters ' => $ route ->parameters (),
@@ -273,14 +278,12 @@ private function writeBarrelFiles(array|Collection $children, string $parent): v
273
278
return ;
274
279
}
275
280
276
- $ normalizeToCamelCase = fn ($ value ) => str_contains ($ value , '- ' ) ? Str::camel ($ value ) : $ value ;
277
-
278
281
$ indexPath = join_paths ($ this ->base (), $ parent , 'index.ts ' );
279
282
280
283
$ childKeys = $ children ->keys ()->mapWithKeys (fn ($ child ) => [
281
284
$ child => [
282
- 'safe ' => TypeScript::safeMethod ($ normalizeToCamelCase ( $ child) , 'Method ' ),
283
- 'normalized ' => $ normalizeToCamelCase ($ child ),
285
+ 'safe ' => TypeScript::safeMethod ($ child , 'Method ' ),
286
+ 'normalized ' => str ($ child)-> whenContains ( ' - ' , fn ( $ s ) => $ s -> camel ())-> toString ( ),
284
287
],
285
288
]);
286
289
@@ -297,7 +300,7 @@ private function writeBarrelFiles(array|Collection $children, string $parent): v
297
300
298
301
$ keys = $ childKeys ->map (fn ($ alias , $ key ) => str_repeat (' ' , 4 ).implode (': ' , array_unique ([$ alias ['normalized ' ], $ alias ['safe ' ]])))->implode (', ' .PHP_EOL );
299
302
300
- $ varExport = $ normalizeToCamelCase (Str::afterLast ($ parent , DIRECTORY_SEPARATOR ));
303
+ $ varExport = TypeScript:: safeMethod (Str::afterLast ($ parent , DIRECTORY_SEPARATOR ), ' Method ' );
301
304
302
305
$ this ->appendContent ($ indexPath , <<<JAVASCRIPT
303
306
0 commit comments