Created
October 30, 2017 02:30
-
-
Save layerssss/68eb1db9a43a5cf3325fbe25d62bad12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolve = require('resolve'); | |
const Path = require('path'); | |
// | |
// Play together with: | |
// | |
// * https://github.com/entwicklerstube/babel-plugin-root-import | |
// * https://github.com/benmosher/eslint-plugin-import | |
// | |
// API: https://github.com/benmosher/eslint-plugin-import/blob/master/resolvers/README.md | |
// | |
// Usage: (in .babalrc) | |
// | |
// settings: { | |
// 'import/resolver': { | |
// [Path.resolve('./lib/rootResolver.js')]: { | |
// rootPathSuffix: 'src', | |
// rootPathPrefix: '#', | |
// }, | |
// }, | |
// }, | |
// }, | |
// | |
exports.interfaceVersion = 2; | |
exports.resolve = function(source, file, config) { | |
var rootPathPrefix = config.rootPathPrefix || '~'; | |
var rootPathSuffix = config.rootPathSuffix || '.'; | |
if (source.indexOf(rootPathPrefix) !== 0) return { found: false }; | |
var sourcePath = | |
Path.resolve(rootPathSuffix) + source.substring(rootPathPrefix.length); | |
try { | |
return { found: true, path: resolve.sync(sourcePath, config) }; | |
} catch (error) { | |
return { found: false }; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment