Skip to content

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 passed
  • ✅ Most recent commit is approved by a DT maintainer

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

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

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

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
* 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`).

Copy link
Contributor Author

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?

* The format optionally supplied by the `resolve` hook chain (can be an intermediary value).
*/
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;

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.

Copy link
Contributor Author

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.

@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);
    };

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

@typescript-bot typescript-bot added Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. The CI failed When GH Actions fails and removed The CI failed When GH Actions fails Untested Change This PR does not touch tests Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Feb 15, 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.

@Renegade334
Copy link
Contributor

Renegade334 commented Feb 15, 2025

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

@JakobJingleheimer
Copy link
Contributor Author

JakobJingleheimer commented Feb 16, 2025

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

@typescript-bot typescript-bot added Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. and removed The CI failed When GH Actions fails labels Feb 16, 2025
@DangerBotOSS
Copy link

Formatting

The following files are not formatted:

  1. types/node/test/module.ts

Consider running pnpm dprint fmt on these files to make review easier.

Generated by 🚫 dangerJS against 9adb1ad

@typescript-bot
Copy link
Contributor

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

@JakobJingleheimer
Copy link
Contributor Author

@Renegade334 nudge 👀

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Mar 3, 2025
@typescript-bot
Copy link
Contributor

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

Ready to merge

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

@typescript-bot typescript-bot moved this from Needs Maintainer Action to Waiting for Author to Merge in Pull Request Status Board Mar 3, 2025
@JakobJingleheimer
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in Pull Request Status Board Mar 3, 2025
@typescript-bot typescript-bot merged commit eda5d24 into DefinitelyTyped:master Mar 3, 2025
15 checks passed
boneskull added a commit to boneskull/DefinitelyTyped that referenced this pull request Apr 23, 2025
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.
boneskull added a commit to boneskull/DefinitelyTyped that referenced this pull request Apr 24, 2025
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).
boneskull added a commit to boneskull/DefinitelyTyped that referenced this pull request May 22, 2025
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants