diff --git a/src/core/importType.js b/src/core/importType.js index e0941b46b..a554aae96 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -21,10 +21,11 @@ export function isAbsolute(name) { return name.indexOf('/') === 0 } -export function isBuiltIn(name, settings) { +export function isBuiltIn(name, settings, path) { const base = baseModule(name) const extras = (settings && settings['import/core-modules']) || [] - return builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1 + const isInternal = isInternalModule(name, settings, path) + return !isInternal && (builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1) } function isExternalPath(path, name, settings) { diff --git a/tests/files/constants/foo.js b/tests/files/constants/foo.js new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index abf9b9522..bdc409bea 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -41,6 +41,11 @@ describe('importType(name)', function () { expect(importType('importType', pathContext)).to.equal('internal') }) + it("should return 'internal' for files resolved outside of node_modules that share a name with a builtin", function () { + const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } }) + expect(importType('constants/foo', pathContext)).to.equal('internal') + }) + it("should return 'parent' for internal modules that go through the parent", function() { expect(importType('../foo', context)).to.equal('parent') expect(importType('../../foo', context)).to.equal('parent')