diff --git a/src/core/importType.js b/src/core/importType.js index 30ac226a7..133acec60 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -18,6 +18,11 @@ function isExternalModule(name, path) { return (!path || -1 < path.indexOf(join('node_modules', name))) } +const scopedRegExp = /^@\w+\/\w+/ +function isScoped(name) { + return scopedRegExp.test(name) +} + function isInternalModule(name, path) { if (!externalModuleRegExp.test(name)) return false return (path && -1 === path.indexOf(join('node_modules', name))) @@ -39,6 +44,7 @@ function isRelativeToSibling(name) { const typeTest = cond([ [isBuiltIn, constant('builtin')], [isExternalModule, constant('external')], + [isScoped, constant('external')], [isInternalModule, constant('internal')], [isRelativeToParent, constant('parent')], [isIndex, constant('index')], diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 3db94578b..88de5eacb 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -22,6 +22,11 @@ describe('importType(name)', function () { expect(importType('lodash/fp', context)).to.equal('external') }) + it("should return 'external' for scopes packages", function() { + expect(importType('@cycle/core', context)).to.equal('external') + expect(importType('@cycle/dom', context)).to.equal('external') + }) + it("should return 'internal' for non-builtins resolved outside of node_modules", function () { const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } }) expect(importType('importType', pathContext)).to.equal('internal')