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.1.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.2.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jul 30, 2020

  1. Copy the full SHA
    a662fc1 View commit details
  2. chore(release): 2.2.0

    JounQin committed Jul 30, 2020
    Copy the full SHA
    05f7c0d View commit details
Showing with 36 additions and 15 deletions.
  1. +7 −0 CHANGELOG.md
  2. +4 −4 README.md
  3. +1 −1 package.json
  4. +22 −8 src/index.ts
  5. +2 −2 tests/baseEslintConfig.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@

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


### Features

* rename option `directory` to `project` - close [#23](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/23) ([a662fc1](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/commit/a662fc14f6833daf3b7a71f9137d1cbf9abb2b7c))

## [2.1.0](https://github.com/alexgorbatchev/eslint-import-resolver-typescript/compare/v2.0.0...v2.1.0) (2020-07-30)


8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -69,27 +69,27 @@ Add the following to your `.eslintrc` config:

// use <root>/path/to/folder/tsconfig.json
"typescript": {
"directory": "path/to/folder"
"project": "path/to/folder"
},

// Multiple tsconfigs (Useful for monorepos)

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

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

// use an array of glob patterns
"typescript": {
"directory": [
"project": [
"packages/*/tsconfig.json",
"other-packages/*/tsconfig.json"
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-import-resolver-typescript",
"version": "2.1.0",
"version": "2.2.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>",
30 changes: 22 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ import isGlob from 'is-glob'
import { isCore, sync } from 'resolve'
import debug from 'debug'

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

const log = debug(IMPORTER_NAME)

const defaultExtensions = ['.ts', '.tsx', '.d.ts'].concat(
// eslint-disable-next-line node/no-deprecated-api
@@ -23,14 +25,19 @@ export const interfaceVersion = 2

export interface TsResolverOptions {
alwaysTryTypes?: boolean
/**
* @deprecated use `project` instead
*/
directory?: string | string[]
project?: string | string[]
extensions?: string[]
packageFilter?: (pkg: Record<string, string>) => Record<string, string>
}

/**
* @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'
* @param {TsResolverOptions} options
*/
export function resolve(
source: string,
@@ -140,17 +147,24 @@ function initMappers(options: TsResolverOptions) {
return
}

const isArrayOfStrings = (array?: string | string[]) =>
Array.isArray(array) && array.every(o => typeof o === 'string')
if (options.directory) {
console.warn(
`[${IMPORTER_NAME}]: option \`directory\` is deprecated, please use \`project\` instead`,
)

if (!options.project) {
options.project = options.directory
}
}

const configPaths =
typeof options.directory === 'string'
? [options.directory]
: isArrayOfStrings(options.directory)
? options.directory
typeof options.project === 'string'
? [options.project]
: Array.isArray(options.project)
? options.project
: [process.cwd()]

mappers = configPaths!
mappers = configPaths
// turn glob patterns into paths
.reduce<string[]>(
(paths, path) => paths.concat(isGlob(path) ? globSync(path) : path),
4 changes: 2 additions & 2 deletions tests/baseEslintConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = directory => ({
module.exports = project => ({
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
@@ -10,7 +10,7 @@ module.exports = directory => ({
settings: {
'import/resolver': {
typescript: {
directory,
project,
alwaysTryTypes: true,
},
},