diff --git a/src/core/importType.js b/src/core/importType.js index 23bc6350d0..cc97de0d3f 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -8,13 +8,23 @@ function constant(value) { return () => value } +function baseModule(name) { + if (isScoped(name)) { + const [scope, pkg] = name.split('/') + return `${scope}/${pkg}` + } + const [pkg] = name.split('/') + return pkg +} + export function isAbsolute(name) { return name.indexOf('/') === 0 } export function isBuiltIn(name, settings) { + const base = baseModule(name) const extras = (settings && settings['import/core-modules']) || [] - return builtinModules.indexOf(name) !== -1 || extras.indexOf(name) > -1 + return builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1 } function isExternalPath(path, name, settings) { diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 5b63910af1..1a4816d1a7 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -69,9 +69,21 @@ describe('importType(name)', function () { it("should return 'builtin' for additional core modules", function() { // without extra config, should be marked external expect(importType('electron', context)).to.equal('external') + expect(importType('@org/foobar', context)).to.equal('external') const electronContext = testContext({ 'import/core-modules': ['electron'] }) expect(importType('electron', electronContext)).to.equal('builtin') + + const scopedContext = testContext({ 'import/core-modules': ['@org/foobar'] }) + expect(importType('@org/foobar', scopedContext)).to.equal('builtin') + }) + + it("should return 'builtin' for resources inside additional core modules", function() { + const electronContext = testContext({ 'import/core-modules': ['electron'] }) + expect(importType('electron/some/path/to/resource.json', electronContext)).to.equal('builtin') + + const scopedContext = testContext({ 'import/core-modules': ['@org/foobar'] }) + expect(importType('@org/foobar/some/path/to/resource.json', scopedContext)).to.equal('builtin') }) it("should return 'external' for module from 'node_modules' with default config", function() {