-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
base: master
Are you sure you want to change the base?
[@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
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. InactiveThis PR has been inactive for 17 days. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 71493,
"author": "JakobJingleheimer",
"headCommitOid": "58a5b711ad38c5d03950a26f95583abc53ae5813",
"mergeBaseOid": "374a4c6dd7415cc64eb30c834f798f6553fefa06",
"lastPushDate": "2024-12-23T22:23:18.000Z",
"lastActivityDate": "2025-01-26T18:50:15.000Z",
"hasMergeConflict": true,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "node",
"kind": "edit",
"files": [
{
"path": "types/node/module.d.ts",
"kind": "definition"
}
],
"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": "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": "fail",
"ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/58a5b711ad38c5d03950a26f95583abc53ae5813/checks?check_suite_id=32653467752"
} |
Hey @JakobJingleheimer, 😒 Your PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Please consider adding tests to cover the change you're making. Including tests allows this PR to be merged by yourself and the owners of this module. This can potentially save days of time for you! |
🔔 @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: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/test/module.ts#L92-L104 |
@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).
@@ -165,9 +165,9 @@ declare module "module" { | |||
} | |||
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.
*/ | ||
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; |
@@ -205,9 +205,9 @@ declare module "module" { | |||
*/ | |||
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.
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é <contact.9a5d6388@renegade334.me.uk>
@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 |
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 partnerload
hook that the current module is relevant. ex resolve'sformat
can betypescript
, and thenload
checksformat === 'typescript
to know whether it do anything.Only
LoadFnOutput.format
is restricted toModuleFormat
.Please fill in this template.
pnpm test <package to test>
.If changing an existing definition: