Kai Ninomiya | 55bb9ce | 2020-06-09 12:31:14 -0700 | [diff] [blame] | 1 | const path = require('path'); |
| 2 | const resolve = require('resolve') |
| 3 | |
| 4 | // Implements the following resolver spec: |
| 5 | // https://github.com/benmosher/eslint-plugin-import/blob/master/resolvers/README.md |
| 6 | exports.interfaceVersion = 2 |
| 7 | |
| 8 | exports.resolve = function (source, file, config) { |
| 9 | if (resolve.isCore(source)) return { found: true, path: null } |
| 10 | |
| 11 | source = source.replace(/\.js$/, '.ts'); |
| 12 | try { |
| 13 | return { |
| 14 | found: true, path: resolve.sync(source, { |
| 15 | extensions: [], |
| 16 | basedir: path.dirname(path.resolve(file)), |
| 17 | ...config, |
| 18 | }) |
| 19 | } |
| 20 | } catch (err) { |
| 21 | return { found: false } |
| 22 | } |
| 23 | } |