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

fix: teach precinct about node:-prefixed modules introduced in Node 18 #108

Closed
wants to merge 6 commits into from

Conversation

Skn0tt
Copy link
Contributor

@Skn0tt Skn0tt commented Apr 21, 2022

Node v18 was released a couple days ago, and it ships a new node:test builtin. Interestingly (and different from existing builtins), it can only be imported using the node: prefix:

Screenshot 2022-04-21 at 14 58 55

Thus, precinct.paperwork should not exclude require("test") when includeCore: true is set.

index.js Outdated
return false
}

if (["test"].includes(dep)) { // some builtins can only be access via node: prefix
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this condition? It seems like we want require("node:test") to be excluded but require("test") to be included, which would already happen if you remove this condition.

I might not be following the nuance of the test builtin.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you includeCore = true, then we wouldn't run this filtering, which means require("node:test") would be returned as a dependency no?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be excluded, because it's part of the natives object. The "weird" thing about the new test builtin is that, although it's included in process.binding("natives") as "test", it can only be required as "node:test".

So this condition is necessary, yes.

test/index.js Outdated Show resolved Hide resolved
const deps = precinct.paperwork(path.join(__dirname, 'fixtures', 'requiretest.js'), {
includeCore: false
});
assert.deepEqual(deps, ['test']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect this to be true even without the changes to the filtering code. Was that not true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't on Node 18, because it was filtered out by includeCore: false. That's the reason I opened this PR.

@mrjoelkemp
Copy link
Collaborator

Can we add Node 18 to to CI https://github.com/dependents/node-precinct/blob/main/.github/workflows/ci.yml#L19 to ensure that the fix works in that environment?

@Skn0tt
Copy link
Contributor Author

Skn0tt commented May 2, 2022

Can we add Node 18 to to CI

sure thing, done in f9d2c48

index.js Outdated Show resolved Hide resolved
@mrjoelkemp
Copy link
Collaborator

mrjoelkemp commented May 8, 2022

Thanks for the fix and extra context @Skn0tt. I merged this locally after testing on node 18 to better understand what was happening. I cut a new patch with your changes.

Your PR didn't auto-close because I forgot to add a "closes gh-108" annotation. I also could have merged then layered on any changes. My fault, but your contributions still have your name as author. Thanks again for contributing.

Merged via 8cd6d47 and f9d2c48

@mrjoelkemp mrjoelkemp closed this May 8, 2022
@Skn0tt
Copy link
Contributor Author

Skn0tt commented May 9, 2022

No worries! Thanks for merging this + maintaining the project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants