Skip to content

Conversation

calebeby
Copy link
Member

@calebeby calebeby commented Jun 6, 2022

From the changeset:

Enforce using the node: protocol for imports to node built-in modules (prefer-node-protocol).

require('fs') → ✅ require('node:fs')
import * as fs from 'fs' → ✅ import * as fs from 'node:fs'

The import form is supported in node v14.13.1+.
The require form is supported in node v14.18.0+.

It is auto-fixable.

Previously we disabled the rule because it hadn't yet been backported to being supported in require()s in node 14 yet, but now it has been. Also, Jest supports it now.

Why this rule:

It makes it easy to distinguish between builtin modules and modules from npm. There are over 40 builtin modules and it is hard to keep track of them. If you see code like require('inspector') you might look for the documentation on npm before realizing that you are actually referencing the node builtin module.

The node: prefix makes it unambiguous which modules are node's builtin modules.

@changeset-bot
Copy link

changeset-bot bot commented Jun 6, 2022

🦋 Changeset detected

Latest commit: 2b3d0cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudfour/eslint-plugin Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

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

Sweet!

@calebeby calebeby merged commit 4545d67 into main Jun 6, 2022
@calebeby calebeby deleted the imports-node-protocol branch June 6, 2022 17:22
@github-actions github-actions bot mentioned this pull request Jun 6, 2022
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.

2 participants