Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make auto-import pages support .tsx files. #1651

Merged
merged 6 commits into from
Jan 21, 2021
Merged

Conversation

peterp
Copy link
Contributor

@peterp peterp commented Jan 17, 2021

require.resolve did not support .tsx extensions. So, now we're using glob instead. Fast, not recursive. Nice!

TODO:

  • Use fixtures directory for tests.
  • Remove recursion.
  • Make sure consts names are PascalCase.

@dac09 Probably helpful for your work on pre-rendering.

@github-actions
Copy link

github-actions bot commented Jan 17, 2021

@Tobbe
Copy link
Member

Tobbe commented Jan 17, 2021

require.resolve did not support .tsx extensions.

Because we're using node's resolver, and not TS's, right?

Anyway, this is great stuff! Now we don't have to wrap our tsx pages in a .js wrapper just to auto-load them with the router!

@peterp peterp force-pushed the pp-fix-auto-import-pages branch 3 times, most recently from 8fd92cf to 9f92af6 Compare January 17, 2021 13:12
@peterp
Copy link
Contributor Author

peterp commented Jan 17, 2021

@Tobbe

Because we're using node's resolver, and not TS's, right?

I think this has something to do with require.extensions (which is deprecated), for awhile .ts and .tsx were available, but I'm not sure when they got removed.

I figured that babel's TS module would have registered those in nodejs.

https://nodejs.org/api/modules.html#modules_require_extensions

@dac09
Copy link
Collaborator

dac09 commented Jan 17, 2021

@peterp this looks great.

Just to check in case there's a simpler way, did you try adding extensions to the Babel preset file? I noticed in my pre-render script that typescript files weren't being loaded until I added the line

extensions: ['.tsx', '.ts', '.jsx', '.js'],

As part of the Babel config.

@peterp
Copy link
Contributor Author

peterp commented Jan 17, 2021

@dac09 Crazy. I would be very surprised if that's actually something that works. It's something that we've always wanted... because otherwise it has to be specified via the CLI, which is super annoying.

I can't seem to find it in the docs and I found a bunch of issues and an un-merged PR.

If that does work, awesome, but I think this is a better solution, since I removed the recursion and opted for glob instead.

@peterp peterp merged commit ea327a0 into main Jan 21, 2021
@peterp peterp deleted the pp-fix-auto-import-pages branch January 21, 2021 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants