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

[@types/node] correct ResolveFnOutput.format (can be intermediary) #71493

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JakobJingleheimer
Copy link
Contributor

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.

Please fill in this template.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: I am the author.

…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`.
@typescript-bot
Copy link
Contributor

typescript-bot commented Dec 23, 2024

@JakobJingleheimer Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because 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

  • ❌ No merge conflicts
  • ❌ Continuous integration tests have failed
  • 🕐 Only a DT maintainer can approve changes without tests

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This 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"
}

@typescript-bot typescript-bot added Critical package Untested Change This PR does not touch tests labels Dec 23, 2024
@typescript-bot
Copy link
Contributor

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!

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Dec 26, 2024
@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed Owner Approved A listed owner of this package signed off on the pull request. labels Dec 27, 2024
@typescript-bot
Copy link
Contributor

@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
Copy link
Contributor Author

The test failure for LoadHook is because it's too naive: LoadContext.format can be any value, but LoadFnOutput can be only ModuleFormat.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/test/module.ts#L92-L104

@JakobJingleheimer
Copy link
Contributor Author

@Semigradsky could you please advise?

types/node/module.d.ts Outdated Show resolved Hide resolved
Comment on lines 166 to 170
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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Suggested change
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).
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@Renegade334
Copy link
Contributor

The test failure for LoadHook is because it's too naive: LoadContext.format can be any value, but LoadFnOutput can be only ModuleFormat.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/test/module.ts#L92-L104

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>
@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Jan 3, 2025
@typescript-bot
Copy link
Contributor

@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
Copy link
Contributor Author

JakobJingleheimer commented Jan 3, 2025

@Renegade334 it would probably make your lives much easier to consume the jsdocs from the node source-code (ex ResolveHook & LoadHook from customization_hooks.js#L28-L34). These are the dogfood we eat, and they are fully TypeScript-compatible. Finding them may be difficult though.

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 ResolveContext argument passed to nextResolve is actually Partial<ResolveContext>.

¹ I already proposed fixing it, and that's apparently a very political decision.

@JakobJingleheimer
Copy link
Contributor Author

Upstream fix: nodejs/node#56454

@typescript-bot typescript-bot added the Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. label Jan 23, 2025
@typescript-bot
Copy link
Contributor

@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!

@typescript-bot
Copy link
Contributor

@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.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Jan 26, 2025
@JakobJingleheimer
Copy link
Contributor Author

This is not abandoned

@typescript-bot typescript-bot removed the Abandoned This PR had no activity for a long time, and is considered abandoned label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. The CI failed When GH Actions fails Untested Change This PR does not touch tests
Projects
Status: Needs Author Action
Development

Successfully merging this pull request may close these issues.

4 participants