-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[@types/node] correct ResolveFnOutput.format (can be intermediary)
#71493
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
[@types/node] correct ResolveFnOutput.format (can be intermediary)
#71493
Conversation
…y value) `format` can be any string, it does not have to be one of the final values. It was designed that way so it can signal to its partner `load` hook that the current module is relevant. ex resolve's `format` can be `typescript`, and then `load` checks `format === 'typescript` to know whether it do anything. Only `LoadFnOutput.format` is restricted to `ModuleFormat`.
|
@JakobJingleheimer Thank you for submitting this PR! This is a live comment that I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 71493,
"author": "JakobJingleheimer",
"headCommitOid": "9adb1adbfbf8a57798af14df4b6293e7913111d1",
"mergeBaseOid": "1880268063b4c3a1e06c661c544790fa312c5120",
"lastPushDate": "2024-12-23T22:23:18.000Z",
"lastActivityDate": "2025-03-03T17:40:02.000Z",
"mergeOfferDate": "2025-03-03T17:38:45.000Z",
"mergeRequestDate": "2025-03-03T17:40:02.000Z",
"mergeRequestUser": "JakobJingleheimer",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "node",
"kind": "edit",
"files": [
{
"path": "types/node/module.d.ts",
"kind": "definition"
},
{
"path": "types/node/test/module.ts",
"kind": "test"
}
],
"owners": [
"Microsoft",
"jkomyno",
"alvis",
"r3nya",
"btoueg",
"smac89",
"touffy",
"DeividasBakanas",
"eyqs",
"Hannes-Magnusson-CK",
"hoo29",
"kjin",
"ajafff",
"islishude",
"mwiktorczyk",
"mohsen1",
"galkin",
"parambirs",
"eps1lon",
"ThomasdenH",
"WilcoBakker",
"wwwy3y3",
"samuela",
"kuehlein",
"bhongy",
"chyzwar",
"trivikr",
"yoursunny",
"qwelias",
"ExE-Boss",
"peterblazejewicz",
"addaleax",
"victorperin",
"NodeJS",
"LinusU",
"wafuwafu13",
"mcollina",
"Semigradsky"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "gabritto",
"date": "2025-03-03T17:38:07.000Z",
"isMaintainer": true
},
{
"type": "stale",
"reviewer": "Renegade334",
"date": "2025-01-03T00:00:47.000Z",
"abbrOid": "b03feaa"
},
{
"type": "stale",
"reviewer": "Semigradsky",
"date": "2024-12-26T13:03:41.000Z",
"abbrOid": "100e34e"
}
],
"mainBotCommentID": 2560377613,
"ciResult": "pass"
} |
|
🔔 @microsoft @jkomyno @alvis @r3nya @btoueg @smac89 @Touffy @DeividasBakanas @eyqs @Hannes-Magnusson-CK @hoo29 @kjin @ajafff @islishude @mwiktorczyk @mohsen1 @galkin @parambirs @eps1lon @ThomasdenH @WilcoBakker @wwwy3y3 @samuela @kuehlein @bhongy @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @nodejs @LinusU @wafuwafu13 @mcollina @Semigradsky — please review this PR in the next few days. Be sure to explicitly select |
|
@JakobJingleheimer The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review. |
|
The test failure for LoadHook is because it's too naive: |
|
@Semigradsky could you please advise? |
types/node/module.d.ts
Outdated
| interface ResolveFnOutput { | ||
| /** | ||
| * A hint to the load hook (it might be ignored) | ||
| * A hint to the load hook (it might be ignored); can be an intermediary value. | ||
| */ | ||
| format?: ModuleFormat | null | undefined; | ||
| format?: string | ModuleFormat | null | undefined; |
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.
Obviously you're the authoritative source, but can this be partnered with an upstream doc patch to make this behaviour clearer? The existing docblock is taken from the upstream documentation in module.md, which states this this value should be a valid module format string.
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.
Ah, true. I usually look at the jsdoc in the code. Yes, I'll update the markdown docs (I'm not sure how they became incorrect—they didn't use to specify that).
| interface ResolveFnOutput { | ||
| /** | ||
| * A hint to the load hook (it might be ignored) | ||
| * A hint to the load hook (it might be ignored); can be an intermediary value. |
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.
Not entirely clear to the uninitiated what "intermediary" should mean in this context? YMMV, but I'd say this line could be left as-is.
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.
| * A hint to the load hook (it might be ignored); can be an intermediary value. | |
| * A hint to the load hook (it might be ignored); can be an arbitrary value to be changed at a later stage (eg `css` → `json`). |
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.
@Renegade334 thoughts on this updated comment wording?
types/node/module.d.ts
Outdated
| * The format optionally supplied by the `resolve` hook chain (can be an intermediary value). | ||
| */ | ||
| format: ModuleFormat; | ||
| format: string | ModuleFormat; |
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.
Ditto.
| format: string | ModuleFormat; | |
| format: string; |
| conditions: string[]; | ||
| /** | ||
| * The format optionally supplied by the `resolve` hook chain | ||
| * The format optionally supplied by the `resolve` hook chain (can be an intermediary value). |
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.
Ditto.
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.
Will apply the suggestion above here too if it's acceptable.
This example is derived from the docs example in module.md, which may itself need addressing given what's being discussed here. Shouldn't be any problem with adjusting it. const load: Module.LoadHook = async (url, context, nextLoad) => {
if (Math.random() > 0.5) {
return {
format: "commonjs",
shortCircuit: true,
source: "...",
};
}
return nextLoad(url);
}; |
Co-authored-by: René <[email protected]>
|
@JakobJingleheimer The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review. |
|
@Renegade334 it would probably make your lives much easier to consume the jsdocs from the node source-code (ex The markdown docs use some extremely limited subset and parser¹, which tie my wrist to my foot in terms of what I can provide. For instance, in the markdown docs, there is no way to specify that the ¹ I already proposed fixing it, and that's apparently a very political decision. |
|
Upstream fix: nodejs/node#56454 |
|
@JakobJingleheimer Unfortunately, this pull request currently has a merge conflict 😥. Please update your PR branch to be up-to-date with respect to master. Have a nice day! |
|
@JakobJingleheimer I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Feb 2nd (in a week) if the issues aren't addressed. |
|
This is not abandoned |
|
@JakobJingleheimer The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review. |
|
@JakobJingleheimer The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review. |
|
@JakobJingleheimer How about 6bb9ba5? (The test suite is never executed, so it doesn't necessarily need to be comprehensive, it just needs to give the compiler an adequate example to test assignability.) |
OH! Sure, thanks! P.S. Not needing to be robust is rather unintuitive though 😅 |
|
@Renegade334, @Semigradsky Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
|
@Renegade334 nudge 👀 |
|
@JakobJingleheimer: Everything looks good here. I am ready to merge this PR (at 9adb1ad) on your behalf whenever you think it's ready. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@microsoft, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @galkin, @parambirs, @eps1lon, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @nodejs, @LinusU, @wafuwafu13, @mcollina, @Semigradsky: you can do this too.) |
|
Ready to merge |
A `LoadHook` accepts a `LoadHookContext` object having a `format` of `string | null | undefined`. `LookHook` implementors often want to pass this value through ([example from docs](https://nodejs.org/api/module.html\#asynchronous-version), which suggests to me that a) it can be falsy, and b) it should be a looser type as established for `ResolveFnOutput` in DefinitelyTyped#71493). A consequence of this is that `ModuleFormat` is no longer referenced anywhere; it can be removed.
A `LoadHook` accepts a `LoadHookContext` object having a `format` of `string | null | undefined`. `LookHook` implementors often want to pass this value through ([example from docs](https://nodejs.org/api/module.html\#asynchronous-version), which suggests to me that a) it can be falsy, and b) it should be a looser type as established for `ResolveFnOutput` in DefinitelyTyped#71493).
A `LoadHook` accepts a `LoadHookContext` object having a `format` of `string | null | undefined`. `LookHook` implementors often want to pass this value through ([example from docs](https://nodejs.org/api/module.html\#asynchronous-version), which suggests to me that a) it can be falsy, and b) it should be a looser type as established for `ResolveFnOutput` in DefinitelyTyped#71493).
formatcan be any string, it does not have to be one of the final values. It was designed that way so it can signal to its partnerloadhook that the current module is relevant. ex resolve'sformatcan betypescript, and thenloadchecksformat === 'typescriptto know whether it do anything.Only
LoadFnOutput.formatis restricted toModuleFormat.Please fill in this template.
pnpm test <package to test>.If changing an existing definition: