GeezerVison is showing github.com — test: update ESM loader hooks to allow ambiguous format by avivkeller · Pull Request #52990 · nodejs/node
Conversation
avivkeller
commented
May 14, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
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
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
avivkeller
commented
May 14, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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")
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
avivkeller
commented
May 14, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
You can use this PR to land the variable renaming if you want
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
avivkeller
commented
May 15, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
@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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
aduh95
aduh95 requested 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.
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.
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.
|