Skip to content

Commit cd77133

Browse files
authored
Merge pull request #891 from mplewis/master
Allow core modules to resolve files inside declared modules
2 parents dd28130 + 2f2dfb0 commit cd77133

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/core/importType.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ function constant(value) {
88
return () => value
99
}
1010

11+
function baseModule(name) {
12+
if (isScoped(name)) {
13+
const [scope, pkg] = name.split('/')
14+
return `${scope}/${pkg}`
15+
}
16+
const [pkg] = name.split('/')
17+
return pkg
18+
}
19+
1120
export function isAbsolute(name) {
1221
return name.indexOf('/') === 0
1322
}
1423

1524
export function isBuiltIn(name, settings) {
25+
const base = baseModule(name)
1626
const extras = (settings && settings['import/core-modules']) || []
17-
return builtinModules.indexOf(name) !== -1 || extras.indexOf(name) > -1
27+
return builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1
1828
}
1929

2030
function isExternalPath(path, name, settings) {

tests/src/core/importType.js

+12
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,21 @@ describe('importType(name)', function () {
7272
it("should return 'builtin' for additional core modules", function() {
7373
// without extra config, should be marked external
7474
expect(importType('electron', context)).to.equal('external')
75+
expect(importType('@org/foobar', context)).to.equal('external')
7576

7677
const electronContext = testContext({ 'import/core-modules': ['electron'] })
7778
expect(importType('electron', electronContext)).to.equal('builtin')
79+
80+
const scopedContext = testContext({ 'import/core-modules': ['@org/foobar'] })
81+
expect(importType('@org/foobar', scopedContext)).to.equal('builtin')
82+
})
83+
84+
it("should return 'builtin' for resources inside additional core modules", function() {
85+
const electronContext = testContext({ 'import/core-modules': ['electron'] })
86+
expect(importType('electron/some/path/to/resource.json', electronContext)).to.equal('builtin')
87+
88+
const scopedContext = testContext({ 'import/core-modules': ['@org/foobar'] })
89+
expect(importType('@org/foobar/some/path/to/resource.json', scopedContext)).to.equal('builtin')
7890
})
7991

8092
it("should return 'external' for module from 'node_modules' with default config", function() {

0 commit comments

Comments
 (0)