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

feat: support native type stripping for Node >= v23 #442

Merged

Conversation

jean-michelet
Copy link
Contributor

#441

My editor has reformatted the code a bit, but eslint seems ok with some of the changes.
I think the PR is still readable and it improves readability a bit, let me know if I should revert.


t.test('independent of module support', function (t) {
t.plan(8)
t.plan(typeStrippingEnabled ? 7 : 8)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed when #440 is merged.

@mcollina
Copy link
Member

Can you add something in the README?

@Eomm
Copy link
Member

Eomm commented Jan 26, 2025

My editor has reformatted the code a bit, but eslint seems ok with some of the changes.
I think the PR is still readable and it improves readability a bit, let me know if I should revert.

If you run npm run lint:fix, does the change reverse itself?

@jean-michelet
Copy link
Contributor Author

If you run npm run lint:fix, does the change reverse itself?

Not the indentation, but remove semi-colons, use single-quotes etc.

@Eomm
Copy link
Member

Eomm commented Jan 26, 2025

If you run npm run lint:fix, does the change reverse itself?

Not the indentation, but remove semi-colons, use single-quotes etc.

mmm so how does npm run lint passes? cc @voxpelli

@jean-michelet
Copy link
Contributor Author

Probably because it doesn't enforce certain formatting rules, like trailing coma for example: https://github.com/fastify/fastify-autoload/pull/442/files#diff-93d89c5bddae92725a3ce7b3a38a424edb3d4f4de3b403e34af97dadee0d583eR11

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing in a block until I can properly review.

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much stylistics changes.

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As has been said, the stylistic changes need to be reverted as it's hard to see what functionality has actually changed.

README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still possible to use non-native-typestripping on node 23 and newer?

If not, it needs to be ensured that you can use other typescript loaders for potentially not supported features...

@@ -1,4 +1,4 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From API docs:

Due to the nature of type stripping, the type keyword is necessary to correctly strip type imports.

const t = require('tap')
const fastify = require('fastify')

const basicApp = require('./basic/app.ts')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensions seems mandatory for ts file too.

@jean-michelet
Copy link
Contributor Author

jean-michelet commented Jan 27, 2025

Is it still possible to use non-native-typestripping on node 23 and newer?

Yes for Node 23, don't know in the future.

The flag --no-experimental-strip-types prevents Node.js from running TypeScript files.

Edit, if you mean is it possible to use other loaders such as tsx, swc etc, the tests with third-party loaders are green.

@jean-michelet
Copy link
Contributor Author

it needs to be ensured that you can use other typescript loaders for potentially not supported features...

We already have tests for loaders in scripts folder. Is it what you were suggesting?

README.md Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@voxpelli
Copy link

Probably because it doesn't enforce certain formatting rules, like trailing coma for example: https://github.com/fastify/fastify-autoload/pull/442/files#diff-93d89c5bddae92725a3ce7b3a38a424edb3d4f4de3b403e34af97dadee0d583eR11

@jean-michelet @Eomm We deactivated trailing comma rules a while ago as there's no clear consensus on whether it should be enforced or banned (many existing code bases ban them, many new wants to enforce them) neostandard/neostandard#143

@Uzlopak
Copy link
Contributor

Uzlopak commented Jan 29, 2025

is it ensured, that if you use other typescript engines, that it will use them in node 23 and not just use the type stripping?

So technically this should be possible in other engines
https://www.totaltypescript.com/erasable-syntax-only#what-does-erasablesyntaxonly-do
but fail in node23

@jean-michelet
Copy link
Contributor Author

They aren't engines but JIT-compiler TS -> JS, so Node will execute JS files when leveraged by these tools.

@jean-michelet jean-michelet requested a review from Fdawgs January 29, 2025 13:58
@Fdawgs Fdawgs removed their request for review January 29, 2025 14:02
@Uzlopak Uzlopak dismissed their stale review January 30, 2025 08:18

no strong feelings

@jean-michelet
Copy link
Contributor Author

Can you plz merge the PR if you're ok with changes @climba03003 @Uzlopak?

@jean-michelet
Copy link
Contributor Author

I merge it, so the changes can be integrated in #440

@jean-michelet jean-michelet merged commit 2b3a6ec into fastify:master Jan 31, 2025
11 checks passed
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.

7 participants