Skip to content

Commit 039a77b

Browse files
committed
Add support for scoped packages in importType
1 parent 6c3fe44 commit 039a77b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/core/importType.js

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function isExternalModule(name, path) {
1818
return (!path || -1 < path.indexOf(join('node_modules', name)))
1919
}
2020

21+
const scopedRegExp = /^@\w+\/\w+/
22+
function isScoped(name) {
23+
return scopedRegExp.test(name)
24+
}
25+
2126
function isInternalModule(name, path) {
2227
if (!externalModuleRegExp.test(name)) return false
2328
return (path && -1 === path.indexOf(join('node_modules', name)))
@@ -39,6 +44,7 @@ function isRelativeToSibling(name) {
3944
const typeTest = cond([
4045
[isBuiltIn, constant('builtin')],
4146
[isExternalModule, constant('external')],
47+
[isScoped, constant('external')],
4248
[isInternalModule, constant('internal')],
4349
[isRelativeToParent, constant('parent')],
4450
[isIndex, constant('index')],

tests/src/core/importType.js

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ describe('importType(name)', function () {
2222
expect(importType('lodash/fp', context)).to.equal('external')
2323
})
2424

25+
it("should return 'external' for scopes packages", function() {
26+
expect(importType('@cycle/core', context)).to.equal('external')
27+
expect(importType('@cycle/dom', context)).to.equal('external')
28+
})
29+
2530
it("should return 'internal' for non-builtins resolved outside of node_modules", function () {
2631
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } })
2732
expect(importType('importType', pathContext)).to.equal('internal')

0 commit comments

Comments
 (0)