Skip to content

Commit

Permalink
Add support for scoped packages in importType
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Apr 25, 2016
1 parent 6c3fe44 commit 039a77b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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')],
Expand Down
5 changes: 5 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 039a77b

Please sign in to comment.