GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: update ESM loader hooks to allow ambiguous format by avivkeller · Pull Request #52990 · nodejs/node

Conversation

@avivkeller

@avivkeller avivkeller commented May 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Pull request #50314 added support for a null format value in addition to the existing commonjs or module. However, the test for ESM hooks relied on the default value of commonjs, causing it to fail when run with the --experimental-detect-module flag. This PR enables the test to detect null formats, ensuring it runs successfully with experimental detection enabled.

Sidenote: While @GeoffreyBooth and I were debugging this behavior, the single-character function arguments made it very difficult to understand, so this PR also expands them into the full names.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@avivkeller
test: update ESM loader hooks to allow ambiguous format
c686371
@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure. labels May 14, 2024
@avivkeller avivkeller added the loaders Issues and PRs related to ES module loaders. label May 14, 2024
GeoffreyBooth
GeoffreyBooth approved these changes May 14, 2024
View reviewed changes

@GeoffreyBooth GeoffreyBooth left a comment

Copy link
Copy Markdown
Member

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.

But is there a purpose behind Node’s internal resolve hook sometimes returning format: null as opposed to the key being missing? If not, maybe our internal hooks should always either set format if it has a truthy value, or don’t define it at all (or set format: undefined) and leave null out of it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@GeoffreyBooth

GeoffreyBooth commented May 14, 2024

Copy link
Copy Markdown
Member

@nodejs/loaders

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller

avivkeller commented May 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

But is there a purpose behind Node’s internal resolve hook sometimes returning format: null as opposed to the key being missing? If not, maybe our internal hooks should always either set format if it has a truthy value, or don’t define it at all (or set format: undefined) and leave null out of it.

I don't think there is a purpose of setting it to null rather than undefined, but IIRC @aduh95 added the change, so maybe he has a reason?

That being said, in this case, the null vs undefined could be seen asa "was the format even checked?":
Yes, the resolver tried (null)
No, the resolver didn't even check (undefined)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@GeoffreyBooth

GeoffreyBooth commented May 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Unless there’s a good reason we need null, I think we should first land this and then reopen #52988 and update it so that format is either a string or undefined (at least as set by Node internals).

That being said, in this case, the null vs undefined could be seen asa “was the format even checked?”:

I’m not sure that this is a good reason. If this is data that we want to preserve, it could be its own property on context, like formatWasChecked: true, and therefore it would be explicit and not mysterious.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JakobJingleheimer

JakobJingleheimer commented May 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

IIR, the historical reason (advocated by Antoine) was that null vs undefined was immaterial/unimportant and the historical precedent was nil.

Splitting hairs: undefined means "idk" and null means "empty" (where empty is "i explicitly acknowledged this exists and there is nothing here" whereas undefined means 🤷‍♂️ or "ignore me")

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@GeoffreyBooth

GeoffreyBooth commented May 14, 2024

Copy link
Copy Markdown
Member

In this case, the different is very material—some tests fail with null but not with undefined. This is a footgun for hooks authors, to need to handle an unexpected extra potential return value. Unless we need null for some reason, I think we should toss it and stick to just strings and undefined.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller

avivkeller commented May 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Just for sake of discussion, what value would be put in place for an unknown format module?

(But maybe this is a discussion for another time)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@GeoffreyBooth

GeoffreyBooth commented May 15, 2024

Copy link
Copy Markdown
Member

Just for sake of discussion, what value would be put in place for an unknown format module?

Without custom hooks registered, Node throws on unknown formats.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JakobJingleheimer
JakobJingleheimer approved these changes May 15, 2024
View reviewed changes
aduh95
aduh95 requested changes May 15, 2024
View reviewed changes

@aduh95 aduh95 left a comment

Copy link
Copy Markdown
Contributor

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.

Changing the test should happen in the same commit that changes the code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aduh95

aduh95 commented May 15, 2024

Copy link
Copy Markdown
Contributor

You can use this PR to land the variable renaming if you want

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller

avivkeller commented May 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Changing the test should happen in the same commit that changes the code

Unlike the other test changes for --experimental-detect-module, I think this one deserves its own PR, as IMO it should have been updated in #50314 to account for the new return value (but there was really no way to tell that this would happen).

WDYT @GeoffreyBooth

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@GeoffreyBooth

GeoffreyBooth commented May 15, 2024

Copy link
Copy Markdown
Member

@redyetidev I think reopen #52988 and have it undo the part of #50314 that returned null instead of undefined; and update the tests accordingly. Unless @aduh95 can point to a reason that sometimes returning null is desirable, it seems to me that the returning of null was an unintended change in #50314 that had no documentation or explanation, and we should just undo that part.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller

avivkeller commented May 15, 2024

Copy link
Copy Markdown
Member Author

@redyetidev I think reopen #52988 and have it undo the part of #50314 that returned null instead of undefined; and update the tests accordingly. Unless @aduh95 can point to a reason that sometimes returning null is desirable, it seems to me that the returning of null was an unintended change in #50314 that had no documentation or explanation, and we should just undo that part.

Sure, it'll take some work because it seems that certain infrastructure rely on that behavior, but I'll work on it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller avivkeller closed this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aduh95 aduh95 aduh95 requested changes
@GeoffreyBooth GeoffreyBooth GeoffreyBooth approved these changes
@JakobJingleheimer JakobJingleheimer JakobJingleheimer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders. needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@avivkeller @GeoffreyBooth @JakobJingleheimer @aduh95 @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.