From 15f2849c49bf1b4eb7719f027c61ca48b6e1f2a2 Mon Sep 17 00:00:00 2001 From: Gabriel Cangussu <gabrielcangussu@gmail.com> Date: Tue, 29 Sep 2020 05:38:13 -0300 Subject: [PATCH 1/5] fix: remove .tsbuildinfo and d.ts.map files from package (#57) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 52c20db..b198940 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "fesm5": "lib/esm", "types": "lib", "files": [ - "lib" + "lib/*.{js,js.map,d.ts}" ], "keywords": [ "typescript", From 2029caed4ac86a87c8519ba54cb84afb41a279f1 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 10 Dec 2020 18:45:24 -0800 Subject: [PATCH 2/5] docs: clarify example in README (#63) --- README.md | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ebe384f..b27871b 100644 --- a/README.md +++ b/README.md @@ -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" From 82ef3573fa1258e0de8d8181de57ae7109e35ec5 Mon Sep 17 00:00:00 2001 From: Joakim Carlstein <joakim@beng.se> Date: Fri, 5 Feb 2021 12:48:23 +0100 Subject: [PATCH 3/5] feat: remove any querystring from imports (#67) --- package.json | 1 + src/index.ts | 11 +++++++++++ tests/withQuerystring/.eslintrc.js | 1 + tests/withQuerystring/image.svg | 3 +++ tests/withQuerystring/index.ts | 7 +++++++ tests/withQuerystring/subfolder/image.svg | 3 +++ tests/withQuerystring/tsconfig.json | 4 ++++ 7 files changed, 30 insertions(+) create mode 100644 tests/withQuerystring/.eslintrc.js create mode 100644 tests/withQuerystring/image.svg create mode 100644 tests/withQuerystring/index.ts create mode 100644 tests/withQuerystring/subfolder/image.svg create mode 100644 tests/withQuerystring/tsconfig.json diff --git a/package.json b/package.json index b198940..f2d7695 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "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: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" }, diff --git a/src/index.ts b/src/index.ts index 89ee9a4..fe63fdb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) @@ -136,6 +138,15 @@ 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?$/, '') diff --git a/tests/withQuerystring/.eslintrc.js b/tests/withQuerystring/.eslintrc.js new file mode 100644 index 0000000..cc90fb8 --- /dev/null +++ b/tests/withQuerystring/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../baseEslintConfig')(__dirname) diff --git a/tests/withQuerystring/image.svg b/tests/withQuerystring/image.svg new file mode 100644 index 0000000..582f744 --- /dev/null +++ b/tests/withQuerystring/image.svg @@ -0,0 +1,3 @@ +<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> + <rect width="100" height="100" /> +</svg> diff --git a/tests/withQuerystring/index.ts b/tests/withQuerystring/index.ts new file mode 100644 index 0000000..cd73fdb --- /dev/null +++ b/tests/withQuerystring/index.ts @@ -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' diff --git a/tests/withQuerystring/subfolder/image.svg b/tests/withQuerystring/subfolder/image.svg new file mode 100644 index 0000000..582f744 --- /dev/null +++ b/tests/withQuerystring/subfolder/image.svg @@ -0,0 +1,3 @@ +<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> + <rect width="100" height="100" /> +</svg> diff --git a/tests/withQuerystring/tsconfig.json b/tests/withQuerystring/tsconfig.json new file mode 100644 index 0000000..abdb5af --- /dev/null +++ b/tests/withQuerystring/tsconfig.json @@ -0,0 +1,4 @@ +{ + "compilerOptions": {}, + "files": ["index.ts"] +} From ba62e65e7cfe382ff976238de3f100cd41c73e8f Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash <oliverjash@gmail.com> Date: Sat, 13 Feb 2021 04:48:48 +0000 Subject: [PATCH 4/5] fix: remove redundant condition (#69) * Failing test * Remove redundant condition Fixes https://github.com/alexgorbatchev/eslint-import-resolver-typescript/issues/68 --- package.json | 1 + src/index.ts | 19 +++++-------------- tests/withPathsAndNestedBaseUrl/.eslintrc.js | 1 + tests/withPathsAndNestedBaseUrl/other/bar.ts | 2 ++ tests/withPathsAndNestedBaseUrl/root/foo.ts | 2 ++ tests/withPathsAndNestedBaseUrl/tsconfig.json | 9 +++++++++ 6 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 tests/withPathsAndNestedBaseUrl/.eslintrc.js create mode 100644 tests/withPathsAndNestedBaseUrl/other/bar.ts create mode 100644 tests/withPathsAndNestedBaseUrl/root/foo.ts create mode 100644 tests/withPathsAndNestedBaseUrl/tsconfig.json diff --git a/package.json b/package.json index f2d7695..979d5c1 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "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" diff --git a/src/index.ts b/src/index.ts index fe63fdb..054a1fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,7 @@ export function resolve( } initMappers(options) - const mappedPath = getMappedPath(source, file) + const mappedPath = getMappedPath(source) if (mappedPath) { log('matched ts path:', mappedPath) } @@ -153,19 +153,15 @@ function removeJsExtension(id: string) { } 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) @@ -230,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, diff --git a/tests/withPathsAndNestedBaseUrl/.eslintrc.js b/tests/withPathsAndNestedBaseUrl/.eslintrc.js new file mode 100644 index 0000000..cc90fb8 --- /dev/null +++ b/tests/withPathsAndNestedBaseUrl/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../baseEslintConfig')(__dirname) diff --git a/tests/withPathsAndNestedBaseUrl/other/bar.ts b/tests/withPathsAndNestedBaseUrl/other/bar.ts new file mode 100644 index 0000000..827b976 --- /dev/null +++ b/tests/withPathsAndNestedBaseUrl/other/bar.ts @@ -0,0 +1,2 @@ +// import using tsconfig.json `baseUrl` +import 'foo' diff --git a/tests/withPathsAndNestedBaseUrl/root/foo.ts b/tests/withPathsAndNestedBaseUrl/root/foo.ts new file mode 100644 index 0000000..2589e1d --- /dev/null +++ b/tests/withPathsAndNestedBaseUrl/root/foo.ts @@ -0,0 +1,2 @@ +// import using tsconfig.json path mapping +import 'other/bar' diff --git a/tests/withPathsAndNestedBaseUrl/tsconfig.json b/tests/withPathsAndNestedBaseUrl/tsconfig.json new file mode 100644 index 0000000..7c01a48 --- /dev/null +++ b/tests/withPathsAndNestedBaseUrl/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "baseUrl": "root/", + "paths": { + "other/*": ["../other/*"] + } + }, + "files": ["root/foo.ts", "other/bar.ts"] +} From 9b34271d1689061eab4e6ac0727520a077c42267 Mon Sep 17 00:00:00 2001 From: JounQin <admin@1stg.me> Date: Tue, 16 Feb 2021 13:01:11 +0800 Subject: [PATCH 5/5] chore(release): 2.4.0 --- CHANGELOG.md | 13 +++++++++++++ package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2305f7..da19e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 979d5c1..7069fb7 100644 --- a/package.json +++ b/package.json @@ -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>",