Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: import-js/eslint-import-resolver-typescript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.0
Choose a base ref
...
head repository: import-js/eslint-import-resolver-typescript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.4.0
Choose a head ref
  • 5 commits
  • 13 files changed
  • 5 contributors

Commits on Sep 29, 2020

  1. Copy the full SHA
    15f2849 View commit details

Commits on Dec 11, 2020

  1. Copy the full SHA
    2029cae View commit details

Commits on Feb 5, 2021

  1. Copy the full SHA
    82ef357 View commit details

Commits on Feb 16, 2021

  1. fix: remove redundant condition (#69)

    * Failing test
    
    * Remove redundant condition
    
    Fixes #68
    OliverJAsh authored and JounQin committed Feb 16, 2021
    Copy the full SHA
    ba62e65 View commit details
  2. chore(release): 2.4.0

    JounQin committed Feb 16, 2021
    Copy the full SHA
    9b34271 View commit details
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.4.0](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/compare/v2.3.0...v2.4.0) (2021-02-16)


### Features

* remove any querystring from imports ([#67](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/67)) ([82ef357](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/82ef3573fa1258e0de8d8181de57ae7109e35ec5))


### Bug Fixes

* remove .tsbuildinfo and d.ts.map files from package ([#57](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/57)) ([15f2849](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/15f2849c49bf1b4eb7719f027c61ca48b6e1f2a2))
* remove redundant condition ([#69](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/69)) ([ba62e65](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/ba62e65e7cfe382ff976238de3f100cd41c73e8f))

## [2.3.0](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/compare/v2.2.1...v2.3.0) (2020-09-01)


29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -62,33 +62,26 @@ Add the following to your `.eslintrc` config:
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
// use <root>/tsconfig.json
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
},
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

// use <root>/path/to/folder/tsconfig.json
"typescript": {
"project": "path/to/folder"
},
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default

// Multiple tsconfigs (Useful for monorepos)
// use <root>/path/to/folder/tsconfig.json
"project": "path/to/folder",

// use a glob pattern
"typescript": {
"project": "packages/*/tsconfig.json"
},
// Multiple tsconfigs (Useful for monorepos)

// use an array
"typescript": {
// use a glob pattern
"project": "packages/*/tsconfig.json",

// use an array
"project": [
"packages/module-a/tsconfig.json",
"packages/module-b/tsconfig.json"
]
},
],

// use an array of glob patterns
"typescript": {
// use an array of glob patterns
"project": [
"packages/*/tsconfig.json",
"other-packages/*/tsconfig.json"
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-import-resolver-typescript",
"version": "2.3.0",
"version": "2.4.0",
"description": "TypeScript .ts .tsx module resolver for `eslint-plugin-import`.",
"repository": "https://github.com/alexgorbatchev/eslint-import-resolver-typescript",
"author": "Alex Gorbatchev <alex.gorbatchev@gmail.com>",
@@ -17,7 +17,7 @@
"fesm5": "lib/esm",
"types": "lib",
"files": [
"lib"
"lib/*.{js,js.map,d.ts}"
],
"keywords": [
"typescript",
@@ -42,6 +42,8 @@
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
"test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring",
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict --update"
},
30 changes: 16 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -51,6 +51,8 @@ export function resolve(

log('looking for:', source)

source = removeQuerystring(source)

// don't worry about core node modules
if (isCore(source)) {
log('matched core:', source)
@@ -62,7 +64,7 @@ export function resolve(
}

initMappers(options)
const mappedPath = getMappedPath(source, file)
const mappedPath = getMappedPath(source)
if (mappedPath) {
log('matched ts path:', mappedPath)
}
@@ -136,25 +138,30 @@ function tsResolve(id: string, opts?: SyncOpts): string {
}
}

/** Remove any trailing querystring from module id. */
function removeQuerystring(id: string) {
const querystringIndex = id.lastIndexOf('?')
if (querystringIndex >= 0) {
return id.slice(0, querystringIndex)
}
return id
}

/** Remove .js or .jsx extension from module id. */
function removeJsExtension(id: string) {
return id.replace(/\.jsx?$/, '')
}

let mappersBuildForOptions: TsResolverOptions
let mappers:
| Array<(source: string, file: string) => string | undefined>
| undefined
let mappers: Array<(source: string) => string | undefined> | undefined

/**
* @param {string} source the module to resolve; i.e './some-module'
* @param {string} file the importing file's full path; i.e. '/usr/local/bin/file.js'
* @returns The mapped path of the module or undefined
*/
function getMappedPath(source: string, file: string) {
const paths = mappers!
.map(mapper => mapper(source, file))
.filter(path => !!path)
function getMappedPath(source: string) {
const paths = mappers!.map(mapper => mapper(source)).filter(path => !!path)

if (paths.length > 1) {
log('found multiple matching ts paths:', paths)
@@ -219,12 +226,7 @@ function initMappers(options: TsResolverOptions) {
configLoaderResult.paths,
)

return (source: string, file: string) => {
// exclude files that are not part of the config base url
if (!file.includes(configLoaderResult.absoluteBaseUrl)) {
return
}

return (source: string) => {
// look for files based on setup tsconfig "paths"
return matchPath(
source,
1 change: 1 addition & 0 deletions tests/withPathsAndNestedBaseUrl/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../baseEslintConfig')(__dirname)
2 changes: 2 additions & 0 deletions tests/withPathsAndNestedBaseUrl/other/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// import using tsconfig.json `baseUrl`
import 'foo'
2 changes: 2 additions & 0 deletions tests/withPathsAndNestedBaseUrl/root/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// import using tsconfig.json path mapping
import 'other/bar'
9 changes: 9 additions & 0 deletions tests/withPathsAndNestedBaseUrl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": "root/",
"paths": {
"other/*": ["../other/*"]
}
},
"files": ["root/foo.ts", "other/bar.ts"]
}
1 change: 1 addition & 0 deletions tests/withQuerystring/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../baseEslintConfig')(__dirname)
3 changes: 3 additions & 0 deletions tests/withQuerystring/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/withQuerystring/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// import svg without querystring
import './image.svg'
import './subfolder/image.svg'

// import svg with querystring
import './image.svg?raw'
import './subfolder/image.svg?raw'
3 changes: 3 additions & 0 deletions tests/withQuerystring/subfolder/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/withQuerystring/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compilerOptions": {},
"files": ["index.ts"]
}