eslint-import-resolver-typescript
Advanced tools
Comparing version 1.1.0 to 1.1.1
90
index.js
@@ -1,9 +0,9 @@ | ||
'use strict' | ||
'use strict'; | ||
const path = require('path') | ||
const resolve = require('resolve') | ||
const tsconfigPaths = require('tsconfig-paths') | ||
const debug = require('debug') | ||
const path = require('path'); | ||
const resolve = require('resolve'); | ||
const tsconfigPaths = require('tsconfig-paths'); | ||
const debug = require('debug'); | ||
const log = debug('eslint-import-resolver-typescript') | ||
const log = debug('eslint-import-resolver-typescript'); | ||
@@ -15,7 +15,7 @@ /** | ||
function resolveFile(source, file, config) { | ||
log('looking for:', source) | ||
log('looking for:', source); | ||
// don't worry about core node modules | ||
if (resolve.isCore(source)) { | ||
log('matched core:', source) | ||
log('matched core:', source); | ||
@@ -25,37 +25,47 @@ return { | ||
path: null, | ||
} | ||
}; | ||
} | ||
let foundTsPath = null; | ||
const extensions = Object.keys(require.extensions).concat( | ||
'.ts', | ||
'.tsx', | ||
'.d.ts', | ||
); | ||
// setup tsconfig-paths | ||
const searchStart = config.directory || process.cwd() | ||
const configLoaderResult = tsconfigPaths.loadConfig(searchStart) | ||
if (configLoaderResult.resultType !== 'success') { | ||
throw new Error(`Unable to find tsconfig in ${searchStart}: ${configLoaderResult.message}`) | ||
} | ||
const matchPath = tsconfigPaths.createMatchPath( | ||
configLoaderResult.absoluteBaseUrl, | ||
configLoaderResult.paths, | ||
) | ||
const searchStart = config.directory || process.cwd(); | ||
const configLoaderResult = tsconfigPaths.loadConfig(searchStart); | ||
if (configLoaderResult.resultType === 'success') { | ||
const matchPath = tsconfigPaths.createMatchPath( | ||
configLoaderResult.absoluteBaseUrl, | ||
configLoaderResult.paths, | ||
); | ||
// look for files based on setup tsconfig "paths" | ||
const extensions = Object.keys(require.extensions).concat('.ts', '.tsx', '.d.ts') | ||
const foundTsPath = matchPath( | ||
source, | ||
undefined, | ||
undefined, | ||
extensions, | ||
) | ||
// look for files based on setup tsconfig "paths" | ||
foundTsPath = matchPath(source, undefined, undefined, extensions); | ||
if (foundTsPath) { | ||
log('matched ts path:', foundTsPath) | ||
if (foundTsPath) { | ||
log('matched ts path:', foundTsPath); | ||
} | ||
} else { | ||
log('failed to init tsconfig-paths:', configLoaderResult.message); | ||
// this can happen if the user has problems with their tsconfig | ||
// or if it's valid, but they don't have baseUrl set | ||
} | ||
// note that even if we match via tsconfig-paths, we still need to do a final resolve | ||
const foundNodePath = resolve.sync(foundTsPath || source, { | ||
extensions, | ||
basedir: path.dirname(path.resolve(file)), | ||
}) | ||
let foundNodePath; | ||
try { | ||
foundNodePath = resolve.sync(foundTsPath || source, { | ||
extensions, | ||
basedir: path.dirname(path.resolve(file)), | ||
packageFilter, | ||
}); | ||
} catch (err) { | ||
foundNodePath = null; | ||
} | ||
if (foundNodePath) { | ||
log('matched node path:', foundNodePath) | ||
log('matched node path:', foundNodePath); | ||
@@ -65,10 +75,16 @@ return { | ||
path: foundNodePath, | ||
} | ||
}; | ||
} | ||
log('didnt find', source) | ||
log('didnt find', source); | ||
return { | ||
found: false | ||
found: false, | ||
}; | ||
} | ||
function packageFilter(pkg) { | ||
if (pkg['jsnext:main']) { | ||
pkg['main'] = pkg['jsnext:main']; | ||
} | ||
return pkg; | ||
} | ||
@@ -79,2 +95,2 @@ | ||
resolve: resolveFile, | ||
} | ||
}; |
{ | ||
"name": "eslint-import-resolver-typescript", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "TypeScript .ts .tsx module resolver for `eslint-plugin-import`.", | ||
@@ -32,2 +32,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"dummy.js": "file:dummy.js", | ||
"eslint": "^5.6.1", | ||
@@ -38,4 +39,4 @@ "eslint-plugin-import": "^2.14.0", | ||
"scripts": { | ||
"test": "eslint ./tests/index.ts" | ||
"test": "eslint ./tests/withPaths/index.ts && eslint ./tests/withoutPaths/index.ts" | ||
} | ||
} |
@@ -20,3 +20,3 @@ # eslint-import-resolver-typescript | ||
```JSON | ||
```CJSON | ||
{ | ||
@@ -23,0 +23,0 @@ "settings": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4287
77
4