From dbc9ec735d9fd32ae69499c235f2a0deb106be94 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 9 Jul 2017 14:47:01 -0600 Subject: [PATCH 1/4] bugfix: #886 --- src/core/importType.js | 3 ++- tests/src/core/importType.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/importType.js b/src/core/importType.js index 23bc6350d0..c196ecd397 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -13,8 +13,9 @@ export function isAbsolute(name) { } export function isBuiltIn(name, settings) { + const baseModule = name.split('/')[0] const extras = (settings && settings['import/core-modules']) || [] - return builtinModules.indexOf(name) !== -1 || extras.indexOf(name) > -1 + return builtinModules.indexOf(baseModule) !== -1 || extras.indexOf(baseModule) > -1 } function isExternalPath(path, name, settings) { diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 5b63910af1..e5e6f85ea4 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -5,7 +5,7 @@ import importType from 'core/importType' import { testContext } from '../utils' -describe('importType(name)', function () { +describe.only('importType(name)', function () { const context = testContext() it("should return 'absolute' for paths starting with a /", function() { @@ -74,6 +74,11 @@ describe('importType(name)', function () { expect(importType('electron', electronContext)).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') + }) + it("should return 'external' for module from 'node_modules' with default config", function() { expect(importType('builtin-modules', context)).to.equal('external') }) From 307ddeb587ce5abc382e9c827da045f0e5dcb292 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 9 Jul 2017 14:49:52 -0600 Subject: [PATCH 2/4] cleanup: no exclusive tests --- tests/src/core/importType.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index e5e6f85ea4..20bdd676dc 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -5,7 +5,7 @@ import importType from 'core/importType' import { testContext } from '../utils' -describe.only('importType(name)', function () { +describe('importType(name)', function () { const context = testContext() it("should return 'absolute' for paths starting with a /", function() { From ed65a7412a90f4e3cf475efaff7a8ea001d6adc1 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 9 Jul 2017 15:47:24 -0600 Subject: [PATCH 3/4] logic: improve scoped module scoping --- src/core/importType.js | 13 +++++++++++-- tests/src/core/importType.js | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/importType.js b/src/core/importType.js index c196ecd397..cc97de0d3f 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -8,14 +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 baseModule = name.split('/')[0] + const base = baseModule(name) const extras = (settings && settings['import/core-modules']) || [] - return builtinModules.indexOf(baseModule) !== -1 || extras.indexOf(baseModule) > -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 20bdd676dc..6f6c1ea73f 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -5,7 +5,7 @@ import importType from 'core/importType' import { testContext } from '../utils' -describe('importType(name)', function () { +describe.only('importType(name)', function () { const context = testContext() it("should return 'absolute' for paths starting with a /", function() { @@ -69,14 +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() { From 2f2dfb0a818f0c5cc6f5939627568636548bce97 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 9 Jul 2017 15:48:12 -0600 Subject: [PATCH 4/4] cleanup: no exclusive tests --- tests/src/core/importType.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 6f6c1ea73f..1a4816d1a7 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -5,7 +5,7 @@ import importType from 'core/importType' import { testContext } from '../utils' -describe.only('importType(name)', function () { +describe('importType(name)', function () { const context = testContext() it("should return 'absolute' for paths starting with a /", function() {