Skip to content

Commit

Permalink
fix(no-missing-import): Ignore node builtins in package.json imports (
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood authored Oct 9, 2024
1 parent 6cd7954 commit 148e47e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/util/import-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ const { resolve } = require("path")
const { isBuiltin } = require("node:module")
const resolver = require("enhanced-resolve")

const {
NodeBuiltinModules,
} = require("../unsupported-features/node-builtins.js")
const isTypescript = require("./is-typescript")
const { getTSConfigForContext } = require("./get-tsconfig.js")
const getTypescriptExtensionMap = require("./get-typescript-extension-map")

const nodeBuiltinFallback = Object.keys(NodeBuiltinModules).map(
name => /** @type {const} */ ({ name, alias: false })
)

/**
* @overload
* @param {string[]} input
Expand Down Expand Up @@ -304,6 +311,8 @@ module.exports = class ImportTarget {

extensionAlias,
alias,

fallback: nodeBuiltinFallback,
}

const requireResolve = resolver.create.sync(this.resolverConfig)
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/no-missing/issue-285/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"imports": {
"#is-ip": {
"node": "net",
"browser": "is-ip"
}
}
}
6 changes: 6 additions & 0 deletions tests/lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ ruleTester.run("no-missing-import", rule, {
code: "import plugin from 'eslint-plugin-n';",
},

// imports alias
{
filename: fixture("issue-285/test.js"),
code: "import isIp from '#is-ip';",
},

// import()
...(DynamicImportSupported
? [
Expand Down

0 comments on commit 148e47e

Please sign in to comment.