-
Notifications
You must be signed in to change notification settings - Fork 449
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
Add gentypeconfig.moduleResolution
options: node16
and bundler
for better interop with TS+ESM projects
#6182
Conversation
gentypeconfig.moduleResolution
options: node16
and bundler
for better interop with TS
gentypeconfig.moduleResolution
options: node16
and bundler
for better interop with TSgentypeconfig.moduleResolution
options: node16
and bundler
for better interop with TS+ESM projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a first quick look, and everything looks fine. Will read in more detail later.
There are questions about adding new tests.
Also, the changelog needs updating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round of complete review.
Left some comments, but it all seems good.
Todo still remove the additional projects unless they bring some value in which case they can stay.
CHANGELOG.md
Outdated
@@ -15,6 +15,10 @@ | |||
#### :rocket: Main New Feature | |||
|
|||
- Add support for Dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/5703 | |||
- GenType: Add `moduleResolution` option to customize extensions on emitted import statements. This helps to adjust output compatibility with TypeScript projects using ESM. https://github.com/rescript-lang/rescript-compiler/pull/6182 | |||
- `node` (default): Drop extensions. | |||
- `node16`: Use TS output's extensions (e.g. `.gen.js`). Make it ESM-compatible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ".e.g"? Isn't it exactly .gen.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhh if I'm guessing right, the output of GenType is always .gen.ts
or .gen.tsx
and can't be customized with a different extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let inputFileSuffix ~(config : Config.t) =
match config.generatedFileExtension with
| Some s when Filename.extension s <> "" (* double extension *) -> s
| _ -> generatedFilesExtension ~config ^ ".tsx"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this code, I don't understand the naming of the functions:
let generatedModuleExtension ~(config : Config.t) =
match config.moduleResolution with
| Node -> generatedFilesExtension ~config
| Node16 -> outputFileSuffix ~config
| Bundler -> inputFileSuffix ~config
One is "input" one is "output" etc. Seems confusing.
Is there a more intuitive renaming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a multiplication of concepts here:
- node, node16, bundler
- input, output
- .js, .tsx
Feels like one has to keep all those in their head to understand what this does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the "e.g." I think it should be removed. If it's not always exactly that, say what config determines the extension and how, instead of "e.g.".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have the right sentences to use for the documentation website already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note:
TS bundler
moduleResolution means "hybrid". Whether it has no extension, .ts
or .js
, its resolution depends on the user's build tool (bundler)
Compatible with most bundlers, the most naive way to implement this is to specify the input filename exactly. Therefore, no implicit extension inference takes place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is, the behaviour of genType should be specified precisely. That's all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ready to merge.
Anything missing?
Ready to merge |
Fantastic. |
Thank you for the detailed review 😁 |
Resolves #6003
This introduces a new gentype option
moduleResolution
. This makes it able to customize the artifacts module imports strategy customizable, so it provides compatibility with thecompilerOptions.moduleResolution
setting in TypeScript projects.With
moduleResolution
:node
(default): Drop extensions in import paths. This doesn't change any behavior.node16
: Use TS output's extension. This provides compatibility with projects usingmoduleResolution: node16
and ESM.bundler
: Use TS input's extension. This provides compatibility with projects usingmoduleResolution: bundler
and ESM. This also requires TS v5.0+ andcompilerOptions.allowImportingTsExtensions
totrue