From 366900d1c522a797db337f0f55f2e89a61a8c15d Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 22 Sep 2019 19:36:09 +0800 Subject: [PATCH] feat: replace glob with tiny-glob for faster spped, close #12 --- README.md | 6 ++--- codechecks.yml | 2 +- package.json | 10 ++++---- src/index.ts | 8 +++--- src/is-glob.d.ts | 4 --- src/tiny-glob.d.ts | 13 ++++++++++ tests/multipleTsconfigs/.eslintrc.js | 2 +- yarn.lock | 37 ++++++++++++++++++++++------ 8 files changed, 57 insertions(+), 25 deletions(-) delete mode 100644 src/is-glob.d.ts create mode 100644 src/tiny-glob.d.ts diff --git a/README.md b/README.md index a0f2b8c..402c43a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Add the following to your `.eslintrc` config: // use a glob pattern "ts": { - "directory": "./packages/**/tsconfig.json" + "directory": "./packages/*/tsconfig.json" }, // use an array @@ -83,8 +83,8 @@ Add the following to your `.eslintrc` config: // use an array of glob patterns "ts": { "directory": [ - "./packages/**/tsconfig.json", - "./other-packages/**/tsconfig.json" + "./packages/*/tsconfig.json", + "./other-packages/*/tsconfig.json" ] } } diff --git a/codechecks.yml b/codechecks.yml index a70a981..fa389b1 100644 --- a/codechecks.yml +++ b/codechecks.yml @@ -2,7 +2,7 @@ checks: - name: build-size-watcher options: files: - - path: 'lib/**/*.*' + - path: 'lib/index.js' - name: type-coverage-watcher options: atLeast: 100 diff --git a/package.json b/package.json index 574d9d1..e2d506b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-import-resolver-ts", - "version": "0.3.0", + "version": "0.4.0", "description": "TypeScript .ts .tsx module resolver for `eslint-plugin-import`.", "repository": "git@github.com/rx-ts/eslint-import-resolver-ts.git", "author": "Alex Gorbatchev ", @@ -18,7 +18,7 @@ ], "scripts": { "build:ts": "tsc -b src", - "build:bundle": "r", + "build:bundle": "r --externals tiny-glob/sync", "build": "run-p build:*", "lint": "eslint --ext md,js,ts -f friendly --ignore-pattern tests .", "test": "eslint -f friendly tests/**/*.{ts,tsx}", @@ -37,9 +37,9 @@ }, "dependencies": { "debug": "^4.1.1", - "glob": "^7.1.4", "is-glob": "^4.0.1", "resolve": "^1.12.0", + "tiny-glob": "^0.2.6", "tsconfig-paths": "^3.9.0" }, "devDependencies": { @@ -55,14 +55,14 @@ "@babel/core": "^7.6.0", "@commitlint/cli": "^8.2.0", "@types/debug": "^4.1.5", - "@types/glob": "^7.1.1", + "@types/is-glob": "^4.0.1", "@types/node": "^12.7.5", "@types/resolve": "^0.0.8", "@types/unist": "^2.0.3", "dummy.js": "link:dummy.js", "eslint": "^6.4.0", "husky": "^3.0.5", - "lint-staged": "^9.2.5", + "lint-staged": "^9.3.0", "npm-run-all": "^4.1.5", "prettier": "^1.18.2", "react": "^16.9.0", diff --git a/src/index.ts b/src/index.ts index 810873e..d249f5c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,11 +6,11 @@ import { loadConfig, ConfigLoaderResult, } from 'tsconfig-paths' -import isGlob from 'is-glob' +import globSync from 'tiny-glob/sync' +import isGlob from 'is-glob' import { isCore, sync } from 'resolve' import debug from 'debug' -import { sync as globSync } from 'glob' const log = debug('eslint-import-resolver-ts') @@ -96,7 +96,7 @@ export function resolve( } } - log("didn't find", source) + log("didn't find ", source) return { found: false, @@ -151,7 +151,7 @@ function initMappers(options: TsResolverOptions) { (paths, path) => paths.concat(isGlob(path) ? globSync(path) : path), [], ) - .map(path => loadConfig(path)) + .map(loadConfig) .filter(isConfigLoaderSuccessResult) .map(configLoaderResult => { const matchPath = createMatchPath( diff --git a/src/is-glob.d.ts b/src/is-glob.d.ts deleted file mode 100644 index e24eb10..0000000 --- a/src/is-glob.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'is-glob' { - const isGlob: (test: string) => boolean - export = isGlob -} diff --git a/src/tiny-glob.d.ts b/src/tiny-glob.d.ts new file mode 100644 index 0000000..93f9046 --- /dev/null +++ b/src/tiny-glob.d.ts @@ -0,0 +1,13 @@ +declare module 'tiny-glob/sync' { + interface Options { + cwd?: string + dot?: boolean + absolute?: boolean + filesOnly?: boolean + flush?: boolean + } + + const globSync: (str: string, opts?: Options) => string[] + + export = globSync +} diff --git a/tests/multipleTsconfigs/.eslintrc.js b/tests/multipleTsconfigs/.eslintrc.js index 1d6868e..3c52fd6 100644 --- a/tests/multipleTsconfigs/.eslintrc.js +++ b/tests/multipleTsconfigs/.eslintrc.js @@ -1,6 +1,6 @@ const path = require('path'); -const globPattern = './packages/**/tsconfig.json'; +const globPattern = './packages/*/tsconfig.json'; // in normal cases this is not needed because the __dirname would be the root const absoluteGlobPath = path.join(__dirname, globPattern); diff --git a/yarn.lock b/yarn.lock index ce9ef82..96192ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1427,6 +1427,11 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/is-glob@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/is-glob/-/is-glob-4.0.1.tgz#a93eec1714172c8eb3225a1cc5eb88c2477b7d00" + integrity sha512-k3RS5HyBPu4h+5hTmIEfPB2rl5P3LnGdQEZrV2b9OWTJVtsUQ2VBcedqYKGqxvZqle5UALUXdSfVA8nf3HfyWQ== + "@types/json-schema@^7.0.3": version "7.0.3" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636" @@ -2881,6 +2886,11 @@ globals@^11.1.0, globals@^11.7.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== +globalyzer@^0.1.0: + version "0.1.4" + resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f" + integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA== + globby@^10.0.1: version "10.0.1" resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22" @@ -2895,6 +2905,11 @@ globby@^10.0.1: merge2 "^1.2.3" slash "^3.0.0" +globrex@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098" + integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg== + graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" @@ -3343,10 +3358,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@^9.2.5: - version "9.2.5" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.2.5.tgz#5a3e1e0a539a403bd7f88542bc3d34ce52efdbb3" - integrity sha512-d99gTBFMJ29159+9iRvaMEQstmNcPAbQbhHSYw6D/1FncvFdIj8lWHztaq3Uq+tbZPABHXQ/fyN7Rp1QwF8HIw== +lint-staged@^9.3.0: + version "9.3.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.3.0.tgz#522a79f166050ab5777887348f2cbdb03f71acac" + integrity sha512-OuL3xo6XpBErl16+3W9PdnFmgeGp12lM8I1Ii/B56S8Edy1kyrf4W8VD4IBn9v17QlutRQEWUJ54YF/VVQ7J2A== dependencies: chalk "^2.4.2" commander "^2.20.0" @@ -4963,9 +4978,9 @@ remark-preset-lint-recommended@^3.0.3: remark-lint-ordered-list-marker-style "^1.0.0" remark-preset-prettier@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/remark-preset-prettier/-/remark-preset-prettier-0.2.0.tgz#cb369b86ce7d7980e90879fe468bae501fc06969" - integrity sha512-JC79MERKMoOrokjCsnMe1RXxH5KrZ2veg5eGRDzUbfKliXSTVMMvvw3PoZ5Gng8MhPrpOd+DkE+jpu937aS/wQ== + version "0.2.1" + resolved "https://registry.yarnpkg.com/remark-preset-prettier/-/remark-preset-prettier-0.2.1.tgz#00de65b8f3817428ba79aa535ee230530d0afd70" + integrity sha512-CH3CQi9sU1vrJGGmW4/+JlazpRsXJMaZYjmNmKyk58e7TUfKjE2VNVLJI8AIhA3G5sKZhEgD7FgmdIdp9Bxrsw== remark-stringify@^7.0.3: version "7.0.3" @@ -5542,6 +5557,14 @@ through2@^2.0.0, through2@^2.0.2: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= +tiny-glob@^0.2.6: + version "0.2.6" + resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.6.tgz#9e056e169d9788fe8a734dfa1ff02e9b92ed7eda" + integrity sha512-A7ewMqPu1B5PWwC3m7KVgAu96Ch5LA0w4SnEN/LbDREj/gAD0nPWboRbn8YoP9ISZXqeNAlMvKSKoEuhcfK3Pw== + dependencies: + globalyzer "^0.1.0" + globrex "^0.1.1" + tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"