Skip to content

Commit

Permalink
Merge 8804a48 into ff50964
Browse files Browse the repository at this point in the history
  • Loading branch information
zthxxx committed Jan 7, 2021
2 parents ff50964 + 8804a48 commit 12a2e43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 1 addition & 2 deletions utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
"homepage": "https://github.com/benmosher/eslint-plugin-import#readme",
"dependencies": {
"debug": "^2.6.9",
"pkg-dir": "^2.0.0"
"debug": "^2.6.9"
}
}
24 changes: 17 additions & 7 deletions utils/resolve.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
exports.__esModule = true

const pkgDir = require('pkg-dir')

const fs = require('fs')
const Module = require('module')
const path = require('path')
Expand Down Expand Up @@ -174,14 +172,26 @@ function resolverReducer(resolvers, map) {
throw err
}

function getBaseDir(sourceFile) {
return pkgDir.sync(sourceFile) || process.cwd()
}
function requireResolver(name, sourceFile) {
// Try to resolve package with conventional name
let resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile) ||
let resolver =
/**
* normal abbreviation for third-party package
* like config `webpack` convert to `eslint-import-resolver-webpack`
*/
tryRequire(`eslint-import-resolver-${name}`, sourceFile) ||
/**
* normal full-name for third-party package or absolute path
* like config `@xxx/webpack-resolver` or `/your/absolute/path/resolver.js`
*/
tryRequire(name, sourceFile) ||
tryRequire(path.resolve(getBaseDir(sourceFile), name))
/**
* relative path to current work dir in monorepo
* like config `./utils/simple-custom-resolver.js`
* convert to absolute path `/<project root path>/utils/simple-custom-resolver.js`
* for both all of monorepo
*/
tryRequire(path.resolve(name))

if (!resolver) {
const err = new Error(`unable to load resolver "${name}".`)
Expand Down

0 comments on commit 12a2e43

Please sign in to comment.