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
Migration of the infamous triplet
to next level, Nodenext support
#4349
Comments
Is the new system backward compatible? @fox1t you had an old testbed repo for these. Should we update it for the new testcase/problem? |
Yes, it support all the previous use case. |
What do we do with fastify-plugin? |
It's becomes a tools only for providing metadata and exclude encapsulation. |
@mcollina yes, this was the playground that allowed us to discover that triplet https://github.com/fox1t/modules-playground |
@mcollina and @climba03003 I've updated the playground https://github.com/fox1t/modules-playground We have the winner, the "infamous triplet with namespace types". fastify.fastify = fastify;
fastify.default = fastify;
module.exports = fastify declare namespace fastify {
export { fastify };
export { fastify as default };
}
declare function fastify(): string
export = fastify; This combination is usable in every possible context, without any issues. It is also the most compatible one (even better than TS compiled to CJS that lacks of namespace callable import O_o) |
Are we rolling this out across all org? |
Certainly YES, it also be a good chance for the contribution. |
do we have this issue in the respective repos that require this change? |
It's a hard work. There are too many repo and creating issue one by one use more time than just sending the fix. |
I think I will just pick a repo and work on it 😄 Could you say briefly looking at https://github.com/fastify/fastify-multipart/blob/master/index.d.ts and confirm the need for this export update? |
Orange - Internal Types
|
please review fastify/fastify-multipart#396 |
https://github.com/fastify/fastify-helmet/blob/master/types/index.d.ts also needs the same kind of update, right? @climba03003 |
the infamous triplet
to next levelthe infamous triplet
to next level, Nodenext support
The minimal approach to make the typings nodenext compatible is I think done with #4438 If we want to improve chaining and other stuff, then we need to invest more time. |
I checked your claim on twitter regarding esModuleInterop. It seems to work without issues. |
@Uzlopak, which claim? |
That |
This is the case you are referring to: https://github.com/fox1t/modules-playground/blob/master/modules/ts-es-module-interop-false/cjs-namespace.ts As far as I can see there are no fail cases: |
Just need to know the import default from 'package'
// import.js
// const default = require('package').default
// export.js
// module.exports.default = package
import * as namespace from 'package'
// import.js
// const namespace = require('package')
// export.js
// module.exports = namespace
import { default as package } from 'package'
// import.js
// const { default: package } = require('package').default
// export.js
// module.exports = package
// module.exports.default = package // we recursively adding .default |
So there are now about 10 PRs regarding various plugins. It takes about 10 minutes to convert typings for nodenext. Sometimes it takes more time, because some packages can be optimized in a "drive-by". I guess we can first process the open PRs and then I can provide another batch. |
I think these are repos we have to make nodenext compatible:
|
We are imho nearly done. The typescript ones i wont touch. But on the other hand avvio, fluent-json-schema and co are kind of hard to transform. |
Just wanted to say good job and thanks for smashing all of these @Uzlopak! I've started using TypeScript to type check JS projects and the types being all up to date for these has been great. |
still need help? I want to make my first contribution it's a great chance for me @mcollina @fox1t @Uzlopak @Fdawgs @climba03003 |
I think the work is maily done reading this comment: #4349 (comment) we should check if the missing ✅ are expected or not |
I started to rewrite the typings for avvio few weeks ago, but it is very hard to implement them properly. |
@Uzlopak, it is truly a complex task. GL & HF. |
Hi there! Thanks for the god-like work! 🙏 I faced an error with Node16, it seems it's not taking my tsconfig.json "paths" into consideration and can't resolve things like
which I took into consideration to choose "Node16". However, I now realize that Node16 ~= NodeNext, and fastify is not yet fully compatible with it either. Thanks again for the awesome work! |
I believe all the plugins works are done. |
Prerequisites
Issue
Currently, we aim to support different way of
import
andTypeScript
environment which is great for developer experience.However, the tech is growing and the current architect of
the infamous triplet
facing some limitation.ESM
forJavaScript
. expose named export fastify-cors#231TypeScript
support includingNodeNext
andIDE
typings. make type definitons"module": "nodenext"
compatible fastify-cookie#184Solution
Here is the summary on a proper approach that should be done inside the organization packages.
explicit module.exports
.The reason behind is that
node
itself are usingstatic analysis
onCommonJS
. Which leads to the problem,dynamic generation
of named export byfastify-plugin
will only be recognize byTypeScript
but notNode
.typings
and usenamespace
The current typings is relay on the
TypeScript
to do module resolution and which will break theNodeNext
moduleResolution
.The text was updated successfully, but these errors were encountered: