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.0.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.1.0
Choose a head ref
  • 11 commits
  • 29 files changed
  • 4 contributors

Commits on Nov 10, 2019

  1. Copy the full SHA
    68f45cd View commit details

Commits on Nov 14, 2019

  1. Copy the full SHA
    b2098a3 View commit details

Commits on Dec 8, 2019

  1. Copy the full SHA
    ef5c33d View commit details

Commits on Feb 15, 2020

  1. fix: typo (#40)

    dnalborczyk authored Feb 15, 2020
    Copy the full SHA
    585509e View commit details

Commits on Apr 10, 2020

  1. Copy the full SHA
    03d5017 View commit details
  2. 2
    Copy the full SHA
    81db8eb View commit details
  3. Copy the full SHA
    afbcdec View commit details

Commits on Jul 9, 2020

  1. fix: wrong path resolution in multiple eslintrc configurations (#51)

    close #50
    Co-authored-by: Alex Vasiuro <avasuro@Mac-mini-Alex.local>
    avasuro authored Jul 9, 2020
    Copy the full SHA
    d563eeb View commit details

Commits on Jul 16, 2020

  1. Copy the full SHA
    f984cef View commit details

Commits on Jul 30, 2020

  1. Copy the full SHA
    e5e6e6c View commit details
  2. chore(release): 2.1.0

    JounQin committed Jul 30, 2020
    Copy the full SHA
    d0f19d3 View commit details
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"plugin:prettier/recommended",
"plugin:mdx/recommended"
]
}
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [alexgorbatchev, JounQin]
open_collective: rxts
63 changes: 11 additions & 52 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -3,67 +3,26 @@ name: Node CI
on: [push, pull_request]

jobs:
build:
default:
strategy:
matrix:
node: [8.x, 10.x, 12.x]
os: [macOS-latest, ubuntu-latest]
node: [10, 12]
os: [macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: setup yarn
- name: Setup yarn
run: |
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$PATH"
- name: build, lint, test
run: |
yarn --frozen-lockfile
yarn build
yarn lint
yarn eslint -f friendly tests/**/*.{ts,tsx}
env:
CI: true
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true

# codecov:
# runs-on: macOS-latest
# needs: build
# steps:
# - name: Report Test Code Coverage
# if: matrix.node == '12.x'
# run: |
# yarn global add codecov codacy-coverage
# codecov
# cat ./coverage/lcov.info | codacy-coverage
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

deploy:
runs-on: macOS-latest
needs: build
steps:
- name: Publish Release and npm Package
if: github.event_name == 'push' && github.ref == 'master' && matrix.node == '12.x'
run: bash deploy.sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_BRANCH: ${{ github.ref }}
GH_REPO: ${{ github.repository }}
- name: Install Dependencies
run: yarn --frozen-lockfile

codecheck:
runs-on: macOS-latest
needs: [build, deploy]
steps:
- name: Code Check
if: matrix.node == '12.x'
run: |
yarn add -D @codechecks/client @codechecks/build-size-watcher
yarn codechecks
- name: Build, Lint and Test
run: yarn run-s build lint test type-coverage
env:
CC_SECRET: ${{ secrets.CC_SECRET }}
EFF_NO_LINK_RULES: 'true'
PARSER_NO_WATCH: 'true'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
lib
node_modules
*.log
.eslintcache
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,15 @@

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.1.0](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/compare/v2.0.0...v2.1.0) (2020-07-30)


### Bug Fixes

* options could be null - close [#42](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/42) ([81db8eb](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/81db8eb0ae81af437e11b6341d8f237bc4bc4e39))
* typo ([#40](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/40)) ([585509e](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/585509e95f93adf8b7ef5839029c19c55edbe76e))
* wrong path resolution in multiple eslintrc configurations ([#51](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/51)) ([d563eeb](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/d563eeb2af2938b9ff7f75e0492a5a26112a4772)), closes [#50](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/50)

## [2.0.0](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/compare/v1.1.1...v2.0.0) (2019-10-17)


21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -25,10 +25,17 @@ This means you can:

## TOC <!-- omit in toc -->

- [Notice](#notice)
- [Installation](#installation)
- [Configuration](#configuration)
- [Contributing](#contributing)

## Notice

After version 2.0.0, `.d.ts` will take higher priority then normal `.js` files on resolving `node_modules` packages in favor of `@types/*` definitions.

If you're facing some problems on rules `import/default` or `import/named` from [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import), do not post any issue here, because they are just working exactly as [expected](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take <https://github.com/benmosher/eslint-plugin-import/issues/1525> as reference or post a new issue to [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) instead.

## Installation

```sh
@@ -57,34 +64,34 @@ Add the following to your `.eslintrc` config:
"import/resolver": {
// use <root>/tsconfig.json
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<roo/>@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": {
"directory": "./path/to/folder"
"directory": "path/to/folder"
},

// Multiple tsconfigs (Useful for monorepos)

// use a glob pattern
"typescript": {
"directory": "./packages/*/tsconfig.json"
"directory": "packages/*/tsconfig.json"
},

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

// use an array of glob patterns
"typescript": {
"directory": [
"./packages/*/tsconfig.json",
"./other-packages/*/tsconfig.json"
"packages/*/tsconfig.json",
"other-packages/*/tsconfig.json"
]
}
}
10 changes: 0 additions & 10 deletions codechecks.yml

This file was deleted.

16 changes: 0 additions & 16 deletions deploy.sh

This file was deleted.

59 changes: 29 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "eslint-import-resolver-typescript",
"version": "2.0.0",
"version": "2.1.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>",
"contributors": [
"JounQin <admin@1stg.me>"
],
"license": "ISC",
"engines": {
"node": ">=4"
@@ -28,56 +31,52 @@
"build:r": "r",
"build:ts": "tsc -b",
"lint": "run-p lint:*",
"lint:es": "eslint src --ext md,js,ts -f friendly",
"lint:tsc": "tsc --noEmit",
"lint:es": "cross-env PARSER_NO_WATCH=true eslint src --cache --ext md,js,ts -f friendly",
"lint:tsc": "tsc --incremental false --noEmit",
"postinstall": "yarn-deduplicate || exit 0",
"prepublishOnly": "yarn build",
"pretest": "r",
"test": "eslint tests/**/*.{ts,tsx} -f friendly",
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict"
"release": "sh scripts/release.sh",
"test": "run-p test:*",
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict --update"
},
"peerDependencies": {
"eslint": "*",
"eslint-plugin-import": "*"
},
"dependencies": {
"debug": "^4.1.1",
"glob": "^7.1.6",
"is-glob": "^4.0.1",
"resolve": "^1.12.0",
"tiny-glob": "^0.2.6",
"resolve": "^1.17.0",
"tsconfig-paths": "^3.9.0"
},
"devDependencies": {
"@1stg/babel-preset": "^0.7.8",
"@1stg/commitlint-config": "^0.1.0",
"@1stg/eslint-config": "^0.12.21",
"@1stg/husky-config": "^0.3.1",
"@1stg/lint-staged": "^0.8.7",
"@1stg/prettier-config": "^0.4.2",
"@1stg/remark-config": "^0.2.2",
"@1stg/tsconfig": "^0.6.0",
"@babel/core": "^7.6.4",
"@commitlint/cli": "^8.2.0",
"@pkgr/rollup": "^0.2.5",
"@1stg/lib-config": "^0.5.5",
"@types/debug": "^4.1.5",
"@types/glob": "^7.1.3",
"@types/is-glob": "^4.0.1",
"@types/node": "^12.11.1",
"@types/resolve": "^0.0.8",
"@types/node": "^14.0.27",
"@types/resolve": "^1.17.1",
"@types/unist": "^2.0.3",
"dummy.js": "link:dummy.js",
"eslint": "^6.5.1",
"eslint-import-resolver-typescript": "link:.",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"react": "^16.10.2",
"rollup": "^1.24.0",
"type-coverage": "^2.3.0",
"typescript": "^3.6.4"
"react": "^16.13.1",
"standard-version": "^8.0.2",
"type-coverage": "^2.9.0",
"typescript": "^3.9.7",
"yarn-deduplicate": "^2.1.1"
},
"resolutions": {
"eslint-import-resolver-typescript": "link:."
"eslint-import-resolver-typescript": "link:.",
"prettier": "^2.0.5"
},
"typeCoverage": {
"atLeast": 100
"atLeast": 98.73
}
}
9 changes: 9 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

PKG_VERSION=$(jq -r '.version' package.json)

git fetch origin v"$PKG_VERSION" || {
yarn standard-version -a --release-as "$PKG_VERSION"
git push --follow-tags origin master
npm publish
}
2 changes: 1 addition & 1 deletion src/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@1stg/eslint-config/recommended"
"extends": "@1stg"
}
37 changes: 25 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -6,15 +6,14 @@ import {
loadConfig,
ConfigLoaderResult,
} from 'tsconfig-paths'
import globSync from 'tiny-glob/sync'

import { sync as globSync } from 'glob'
import isGlob from 'is-glob'
import { isCore, sync } from 'resolve'
import debug from 'debug'

const log = debug('eslint-import-resolver-ts')
const log = debug('eslint-import-resolver-typescript')

const extensions = ['.ts', '.tsx', '.d.ts'].concat(
const defaultExtensions = ['.ts', '.tsx', '.d.ts'].concat(
// eslint-disable-next-line node/no-deprecated-api
Object.keys(require.extensions),
'.jsx',
@@ -25,6 +24,8 @@ export const interfaceVersion = 2
export interface TsResolverOptions {
alwaysTryTypes?: boolean
directory?: string | string[]
extensions?: string[]
packageFilter?: (pkg: Record<string, string>) => Record<string, string>
}

/**
@@ -34,11 +35,13 @@ export interface TsResolverOptions {
export function resolve(
source: string,
file: string,
options: TsResolverOptions = {},
options: TsResolverOptions | null,
): {
found: boolean
path?: string | null
} {
options = options || {}

log('looking for:', source)

// don't worry about core node modules
@@ -61,11 +64,11 @@ export function resolve(
let foundNodePath: string | null | undefined
try {
foundNodePath = sync(mappedPath || source, {
extensions,
extensions: options.extensions || defaultExtensions,
basedir: path.dirname(path.resolve(file)),
packageFilter,
packageFilter: options.packageFilter || packageFilterDefault,
})
} catch (err) {
} catch {
foundNodePath = null
}

@@ -104,12 +107,13 @@ export function resolve(
}
}

function packageFilter(pkg: Record<string, string>) {
function packageFilterDefault(pkg: Record<string, string>) {
pkg.main =
pkg.types || pkg.typings || pkg.module || pkg['jsnext:main'] || pkg.main
return pkg
}

let mappersBuildForOptions: TsResolverOptions
let mappers:
| Array<(source: string, file: string) => string | undefined>
| undefined
@@ -132,7 +136,7 @@ function getMappedPath(source: string, file: string) {
}

function initMappers(options: TsResolverOptions) {
if (mappers) {
if (mappers && mappersBuildForOptions === options) {
return
}

@@ -152,7 +156,9 @@ function initMappers(options: TsResolverOptions) {
(paths, path) => paths.concat(isGlob(path) ? globSync(path) : path),
[],
)
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
.map(loadConfig)
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
.filter(isConfigLoaderSuccessResult)
.map(configLoaderResult => {
const matchPath = createMatchPath(
@@ -163,13 +169,20 @@ function initMappers(options: TsResolverOptions) {
return (source: string, file: string) => {
// exclude files that are not part of the config base url
if (!file.includes(configLoaderResult.absoluteBaseUrl)) {
return undefined
return
}

// look for files based on setup tsconfig "paths"
return matchPath(source, undefined, undefined, extensions)
return matchPath(
source,
undefined,
undefined,
options.extensions || defaultExtensions,
)
}
})

mappersBuildForOptions = options
}

function isConfigLoaderSuccessResult(
13 changes: 0 additions & 13 deletions src/tiny-glob.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../baseEslintConfig')(__dirname);
15 changes: 15 additions & 0 deletions tests/multipleEslintrcs/module-a/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import relative
import './tsImportee'
import './tsxImportee'
import './subfolder/tsImportee'
import './subfolder/tsxImportee'

// import using tsconfig.json path mapping
import 'folder/tsImportee'
import 'folder/tsxImportee'
import 'folder/subfolder/tsImportee'
import 'folder/subfolder/tsxImportee'

// import from node_module
import 'typescript'
import 'dummy.js'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/subfolder/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/subfolder/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
11 changes: 11 additions & 0 deletions tests/multipleEslintrcs/module-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react",
"paths": {
"folder/*": ["*"],
"*": ["../../../../node_modules/*"]
}
},
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
}
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../baseEslintConfig')(__dirname);
15 changes: 15 additions & 0 deletions tests/multipleEslintrcs/module-b/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import relative
import './tsImportee'
import './tsxImportee'
import './subfolder/tsImportee'
import './subfolder/tsxImportee'

// import using tsconfig.json path mapping
import 'folder/tsImportee'
import 'folder/tsxImportee'
import 'folder/subfolder/tsImportee'
import 'folder/subfolder/tsxImportee'

// import from node_module
import 'typescript'
import 'dummy.js'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/subfolder/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/subfolder/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
11 changes: 11 additions & 0 deletions tests/multipleEslintrcs/module-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react",
"paths": {
"folder/*": ["*"],
"*": ["../../../../node_modules/*"]
}
},
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
}
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@1stg/tsconfig/lib",
"extends": "./node_modules/@1stg/tsconfig/lib.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "lib"
9,825 changes: 6,836 additions & 2,989 deletions yarn.lock

Large diffs are not rendered by default.