Skip to content

Commit

Permalink
Merge pull request #891 from mplewis/master
Browse files Browse the repository at this point in the history
Allow core modules to resolve files inside declared modules
  • Loading branch information
ljharb committed Aug 14, 2017
2 parents dd28130 + 2f2dfb0 commit cd77133
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +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 base = baseModule(name)
const extras = (settings && settings['import/core-modules']) || []
return builtinModules.indexOf(name) !== -1 || extras.indexOf(name) > -1
return builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1
}

function isExternalPath(path, name, settings) {
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,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() {
Expand Down

0 comments on commit cd77133

Please sign in to comment.