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

refactor: Use node: protocol for built-in Node.js modules #18434

Merged
merged 1 commit into from May 9, 2024

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

Updates all modules to use node: protocol when requiring built-in Node.js modules.

What changes did you make? (Give an overview)

  • Enabled n/prefer-node-protocol rule and let it autofix the whole project.
  • Updated a few tests that use proxyquire.
  • Updated webpack configuration to support node:.

Is there anything you'd like reviewers to focus on?

When testing whether the new @eslint/config-array package will work when used from eslint, I noticed that the webpack build (part of the browser test) fails with:

ERROR in node:path
Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

So, the first goal was to make the browser test (and eventually the Playground build on eslint.org) work. Then I switched to node: in a few places in eslint to additionally test the build, and in the end I decided to switch to node: in the entire project.

@mdjermanovic mdjermanovic requested a review from a team as a code owner May 8, 2024 14:45
@eslint-github-bot eslint-github-bot bot added the chore This change is not user-facing label May 8, 2024
@github-actions github-actions bot added cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features labels May 8, 2024
Copy link

netlify bot commented May 8, 2024

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 67500f3
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/663b900f6e4ad00008cbae00
😎 Deploy Preview https://deploy-preview-18434--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +49 to +54
new webpack.NormalModuleReplacementPlugin(
/^node:/u,
resource => {
resource.request = resource.request.replace(/^node:/u, "");
}
),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a solution recommended in webpack/webpack#13290

Copy link
Member

@kecrily kecrily left a comment

Choose a reason for hiding this comment

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

We can definitely use the n/prefer-node-protocol rule at eslint-config-eslint to force the use of the node protocol

@mdjermanovic
Copy link
Member Author

We can definitely use the n/prefer-node-protocol rule at eslint-config-eslint to force the use of the node protocol

Yeah, I enabled that rule in eslint-config-eslint in this PR.

https://github.com/eslint/eslint/pull/18434/files#diff-88a18842266c290a5fbf05c5d2829127c09c342d104e0dbf1ebc239a0a9e53b6

Copy link
Member

@kecrily kecrily left a comment

Choose a reason for hiding this comment

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

Sorry for missing it. LGTM

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open until tomorrow in case someone else wants to review.

@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 9, 2024
@aladdin-add aladdin-add merged commit a63ed72 into main May 9, 2024
20 checks passed
@aladdin-add aladdin-add deleted the node-protocol branch May 9, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion chore This change is not user-facing cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

4 participants