Skip to content

Commit

Permalink
[webpack] [fix] match coreLibs after resolveSync in webpack-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
echenley authored and ljharb committed Mar 9, 2019
1 parent a49ab8a commit ba0aed9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions resolvers/webpack/index.js
Expand Up @@ -38,10 +38,6 @@ exports.resolve = function (source, file, settings) {
source = source.slice(0, finalQuestionMark)
}

if (source in coreLibs) {
return { found: true, path: coreLibs[source] }
}

var webpackConfig

var configPath = get(settings, 'config')
Expand Down Expand Up @@ -73,7 +69,7 @@ exports.resolve = function (source, file, settings) {
throw e
}
} else {
log("No config path found relative to", file, "; using {}")
log('No config path found relative to', file, '; using {}')
webpackConfig = {}
}

Expand Down Expand Up @@ -123,6 +119,10 @@ exports.resolve = function (source, file, settings) {
try {
return { found: true, path: resolveSync(path.dirname(file), source) }
} catch (err) {
if (source in coreLibs) {
return { found: true, path: coreLibs[source] }
}

log('Error during module resolution:', err)
return { found: false }
}
Expand All @@ -136,7 +136,7 @@ function getResolveSync(configPath, webpackConfig) {
if (!cached) {
cached = {
key: cacheKey,
value: createResolveSync(configPath, webpackConfig)
value: createResolveSync(configPath, webpackConfig),
}
// put in front and pop last item
if (_cache.unshift(cached) > MAX_CACHE) {
Expand Down
3 changes: 1 addition & 2 deletions tests/src/core/importType.js
Expand Up @@ -70,8 +70,7 @@ describe('importType(name)', function () {
const pathContext = testContext({ 'import/resolver': { webpack: { config: webpackConfig } } })
expect(importType('constants/index', pathContext)).to.equal('internal')
expect(importType('constants/', pathContext)).to.equal('internal')
// the following assertion fails because the webpack resolver runs an resolve.isCore('constants') without first checking paths config
// expect(importType('constants', pathContext)).to.equal('internal')
expect(importType('constants', pathContext)).to.equal('internal')
})

it("should return 'parent' for internal modules that go through the parent", function() {
Expand Down

0 comments on commit ba0aed9

Please sign in to comment.