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

module: prevent format from being set to null internaly #53015

Closed
wants to merge 5 commits into from

Conversation

RedYetiDev
Copy link
Member

@RedYetiDev RedYetiDev commented May 15, 2024

With all the changes and backtraces my PR's have caused regarding changes similar to this, @GeoffreyBooth and I agreed that preventing format from being set to null internaly would at least be a step in the right direction.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@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. labels May 15, 2024
@RedYetiDev RedYetiDev changed the title module: prevent format from being null module: prevent format from being set to null internaly May 15, 2024
Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

The reason for this is to simplify tests. The format value might be null or it might be undefined based on arbitrary things like which code path is followed. Our internal code is careful to do loose tests like format == null to account for format being either null or undefined, but not all the tests are so loose. Eliminating null from the potential possibilities means that our tests can remain precise while not breaking as we refactor code paths. The internal conditions will remain loose so that user hooks can still set format: null.

@GeoffreyBooth
Copy link
Member

https://github.com/nodejs/node/blob/main/doc/api/module.md needs updating too, the various lines like this:

  * `format` {string|null|undefined} The format optionally supplied by the
    `resolve` hook chain

To remove null from the list.

doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
@aduh95
Copy link
Contributor

aduh95 commented May 16, 2024

IIUC, before this change, defaultResolve would set format to null when it can't find a better value (and load would still accept undefined nonetheless in case that's what a user hook returned). With this change, it will now be undefined (and load would still accept null nonetheless in case that's what a user hook returned). How does that make tests more precise? It seems to me it's just switching a value for another, that seems rather pointless.

@dygabo
Copy link
Member

dygabo commented May 17, 2024

I accidentally found this PR and looked a bit into the details (might still miss something). But iiuc the goal of the module detection is to allow .js files to be either CJS or ESM as opposed to current behaviour without the --experimental-detect-module that is .js are assumed to be CJS if not otherwise specified with --experimental-default-type command line option. Is this correct?

I can have a look and open a PR if I find a solution. I agree that null or undefined have equivalent explanatory value.

cc: @aduh95, @GeoffreyBooth

@RedYetiDev
Copy link
Member Author

RedYetiDev commented May 17, 2024

I accidentally found this PR and looked a bit into the details (might still miss something). But iiuc the goal of the module detection is to allow .js files to be either CJS or ESM as opposed to current behaviour without the --experimental-detect-module that is .js are assumed to be CJS if not otherwise specified with --experimental-default-type command line option. Is this correct?

#53016 has some more information, but essentially, in the end, we want it to default to CJS, but it defaults to null / undefined

@H4ad H4ad added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jun 8, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

I disagree this simplifies anything, let's not land this – it'd be a small breaking change, but still a breaking change, and we should have some justification for breaking things

@RedYetiDev
Copy link
Member Author

I was actually planning on closing this favor of another PR (I need to find it then I'll link it)

@RedYetiDev RedYetiDev closed this Jun 8, 2024
@RedYetiDev RedYetiDev deleted the never-null-format branch June 8, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants