From a662fc14f6833daf3b7a71f9137d1cbf9abb2b7c Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 30 Jul 2020 13:17:51 +0800 Subject: [PATCH 1/2] feat: rename option `directory` to `project` - close #23 --- README.md | 8 ++++---- src/index.ts | 30 ++++++++++++++++++++++-------- tests/baseEslintConfig.js | 4 ++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cb9d201..ebe384f 100644 --- a/README.md +++ b/README.md @@ -69,19 +69,19 @@ Add the following to your `.eslintrc` config: // use /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" ] @@ -89,7 +89,7 @@ Add the following to your `.eslintrc` config: // use an array of glob patterns "typescript": { - "directory": [ + "project": [ "packages/*/tsconfig.json", "other-packages/*/tsconfig.json" ] diff --git a/src/index.ts b/src/index.ts index bd5b5b7..8260b1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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,7 +25,11 @@ export const interfaceVersion = 2 export interface TsResolverOptions { alwaysTryTypes?: boolean + /** + * @deprecated use `project` instead + */ directory?: string | string[] + project?: string | string[] extensions?: string[] packageFilter?: (pkg: Record) => Record } @@ -31,6 +37,7 @@ export interface TsResolverOptions { /** * @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( (paths, path) => paths.concat(isGlob(path) ? globSync(path) : path), diff --git a/tests/baseEslintConfig.js b/tests/baseEslintConfig.js index 7e86097..45a8257 100644 --- a/tests/baseEslintConfig.js +++ b/tests/baseEslintConfig.js @@ -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, }, }, From 05f7c0d9123ea4a1759091121a50b0f72b5daca6 Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 30 Jul 2020 13:26:41 +0800 Subject: [PATCH 2/2] chore(release): 2.2.0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6a2b0..4056888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 17076f2..6e9822e 100644 --- a/package.json +++ b/package.json @@ -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 ",