router
router copied to clipboard
Preserve whitespace and trailing comma during cli path replacement
Formatters such as Prettier and Biome break the path to a new line as soon as the line length exceeds X characters:
export const Route = new FileRoute(
'/dashboard/invoices/$invoiceId',
).createRoute({
However, the router CLI expects the path to be on the same line with no trailing comma:
export const Route = new FileRoute('/dashboard/invoices/$invoiceId').createRoute({
Example: Try saving src/routes/dashboard.invoices.$invoiceId.tsx in the kitchen-sink-file-based example. First, Prettier formats the file, and then the formatted file is overwritten by the router CLI.
This fix maintains the whitespace and the trailing comma (if present) within the constructor parentheses of FileRoute during the string replacement. I've also replaced [^)]* with a non-greedy any character match .*?.