UNPKG

613 BJavaScriptView Raw
1const resolve = require('resolve');
2const path = require('path');
3
4function opts(file, config) {
5 return Object.assign(
6 { extensions: ['.ts', '.tsx', '.d.ts'] },
7 config,
8 // path.resolve will handle paths relative to CWD
9 { basedir: path.dirname(path.resolve(file)) }
10 );
11}
12
13module.exports = {
14 interfaceVersion: 2,
15 resolve: function(source, file, config) {
16 if (resolve.isCore(source)) {
17 return { found: true, path: null };
18 }
19
20 try {
21 return { found: true, path: resolve.sync(source, opts(file, config)) };
22 } catch (err) {
23 return { found: false };
24 }
25 },
26};