Closed Markyiptw closed 5 months ago
As I understand it, the main issue is related to test environment. So maybe we should just add support for tsx
files that will be JIT compiled by ts-node
.
But I need confirmation from other maintainers.
If they agree, can you send a PR with unit tests? Perhaps you should also document the behavior in the documentation.
@climba03003
Can you take a look plz?
Accepted scripts are here: https://github.com/fastify/fastify-autoload/blob/aded7b5a43059590fa89fcc1b945f5ec15e69d92/index.js#L12
But the issue is that it should work with @swc/register
(deprecated but we still support it for now), @swc-node/register
and others. You can see the tests in the scripts
folder.
One can always change the pattern, although it is not documented.
I don't think we should support tsx
or jsx
by default because we have no mechanism to transpile those file.
You should change the options and fit your needs.
Setting scriptPattern
works for me so I'm closing the issue. Thank you for the quick response!
Prerequisites
🚀 Feature Proposal
Currently the plugin only register route / plugins written in .js / .ts files, but not those in .jsx and .tsx, I hope them to be supported as well.
Motivation
With fastify-html-plugin, one can write a fastify app with jsx syntax.
With a tsc setup, a
"include": ["src/**/*"]
line intsconfig.json
would compile.tsx
files to.js
files, so the the compiled app can run normally.However in a testing environment, the files are not compiled, but instead being run with ts-node (at least that's the configuration from
fastify-cli
's typescript template), and the plugin won't register route files ending withtsx
, causing tests failed with route not found error.Example
I'm not sure whether tsx file should be hardcoded to be loaded or an extra option should be provided.