router icon indicating copy to clipboard operation
router copied to clipboard

Source code for route file getting modified by the CLI

Open phuoccss opened this issue 2 years ago • 8 comments

Describe the bug

In my app I'm using double quote by default. Running tsr watch/tsr generate will update the code to use single quote. Is there a way to work around this?

export const Route = new FileRoute("/")

becomes

export const Route = new FileRoute('/')

Your Example Website or App

any of the file-base routing examples

Steps to Reproduce the Bug or Issue

NA

Expected behavior

NA

Screenshots or Videos

No response

Platform

NA

Additional context

No response

phuoccss avatar Dec 26 '23 16:12 phuoccss

Currently it's hardcoded:

https://github.com/TanStack/router/blob/beta/packages/router-cli/src/generator.ts#L186-L189

But could be made configurable...

schiller-manuel avatar Dec 26 '23 17:12 schiller-manuel

An easy solution for this use-case would be to use prettier and configure a script to run prettier immediately following tsr generate in package.json:

"scripts": {
  "generate-and-format": "tsr generate && prettier --write 'src/[yourRoutesDirectory]/*.{js,jsx,ts,tsx}'"
}

Then any time you'd run tsr generate you can instead run npm run generate-and-format to achieve the desired formatting.

EDIT: this might be unnecessary advice. Looking at the source code schiller-manuel linked, it looks like prettier config is already honored.

bswan0002 avatar Dec 26 '23 18:12 bswan0002

why is it necessary to pass path to FileRoute when path is computed from the route file path?

phuoccss avatar Dec 27 '23 04:12 phuoccss

TypeScript has no idea what file you’re in, or at least doesn’t expose it for use as a type.

tannerlinsley avatar Dec 27 '23 05:12 tannerlinsley

I see. I was under the impression that the type inference would come from the generated routeTree file, rather than the path that gets passed to FileRoute.

phuoccss avatar Dec 27 '23 06:12 phuoccss

It needs both. The path in the type is the key to getting the routes parent types.

tannerlinsley avatar Dec 27 '23 20:12 tannerlinsley

#894 (released in v1.0.6) adds a configuration option for the quote style.

schiller-manuel avatar Dec 29 '23 20:12 schiller-manuel

appreciate your fast response on this

phuoccss avatar Dec 31 '23 08:12 phuoccss