Skip to content

Commit a662fc1

Browse files
committed
feat: rename option directory to project - close import-js#23
1 parent d0f19d3 commit a662fc1

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ Add the following to your `.eslintrc` config:
6969

7070
// use <root>/path/to/folder/tsconfig.json
7171
"typescript": {
72-
"directory": "path/to/folder"
72+
"project": "path/to/folder"
7373
},
7474

7575
// Multiple tsconfigs (Useful for monorepos)
7676

7777
// use a glob pattern
7878
"typescript": {
79-
"directory": "packages/*/tsconfig.json"
79+
"project": "packages/*/tsconfig.json"
8080
},
8181

8282
// use an array
8383
"typescript": {
84-
"directory": [
84+
"project": [
8585
"packages/module-a/tsconfig.json",
8686
"packages/module-b/tsconfig.json"
8787
]
8888
},
8989

9090
// use an array of glob patterns
9191
"typescript": {
92-
"directory": [
92+
"project": [
9393
"packages/*/tsconfig.json",
9494
"other-packages/*/tsconfig.json"
9595
]

src/index.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import isGlob from 'is-glob'
1111
import { isCore, sync } from 'resolve'
1212
import debug from 'debug'
1313

14-
const log = debug('eslint-import-resolver-typescript')
14+
const IMPORTER_NAME = 'eslint-import-resolver-typescript'
15+
16+
const log = debug(IMPORTER_NAME)
1517

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

2426
export interface TsResolverOptions {
2527
alwaysTryTypes?: boolean
28+
/**
29+
* @deprecated use `project` instead
30+
*/
2631
directory?: string | string[]
32+
project?: string | string[]
2733
extensions?: string[]
2834
packageFilter?: (pkg: Record<string, string>) => Record<string, string>
2935
}
3036

3137
/**
3238
* @param {string} source the module to resolve; i.e './some-module'
3339
* @param {string} file the importing file's full path; i.e. '/usr/local/bin/file.js'
40+
* @param {TsResolverOptions} options
3441
*/
3542
export function resolve(
3643
source: string,
@@ -140,17 +147,24 @@ function initMappers(options: TsResolverOptions) {
140147
return
141148
}
142149

143-
const isArrayOfStrings = (array?: string | string[]) =>
144-
Array.isArray(array) && array.every(o => typeof o === 'string')
150+
if (options.directory) {
151+
console.warn(
152+
`[${IMPORTER_NAME}]: option \`directory\` is deprecated, please use \`project\` instead`,
153+
)
154+
155+
if (!options.project) {
156+
options.project = options.directory
157+
}
158+
}
145159

146160
const configPaths =
147-
typeof options.directory === 'string'
148-
? [options.directory]
149-
: isArrayOfStrings(options.directory)
150-
? options.directory
161+
typeof options.project === 'string'
162+
? [options.project]
163+
: Array.isArray(options.project)
164+
? options.project
151165
: [process.cwd()]
152166

153-
mappers = configPaths!
167+
mappers = configPaths
154168
// turn glob patterns into paths
155169
.reduce<string[]>(
156170
(paths, path) => paths.concat(isGlob(path) ? globSync(path) : path),

tests/baseEslintConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = directory => ({
1+
module.exports = project => ({
22
parser: '@typescript-eslint/parser',
33
extends: [
44
'eslint:recommended',
@@ -10,7 +10,7 @@ module.exports = directory => ({
1010
settings: {
1111
'import/resolver': {
1212
typescript: {
13-
directory,
13+
project,
1414
alwaysTryTypes: true,
1515
},
1616
},

0 commit comments

Comments
 (0)