From 544f4bdbdfc10b4d8b3da467c6c243f5d6f5630f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 11 Aug 2023 17:08:29 +0900 Subject: [PATCH] perf: upgrade get-tsconfig with caching --- package.json | 2 +- pnpm-lock.yaml | 22 +++++++++++----------- src/loader.ts | 9 +++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 5e77d21..651843e 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "dependencies": { "esbuild": "^0.19.0", - "get-tsconfig": "^4.6.2", + "get-tsconfig": "^4.7.0", "loader-utils": "^2.0.4", "webpack-sources": "^1.4.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 585415e..0715764 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^0.19.0 version: 0.19.0 get-tsconfig: - specifier: ^4.6.2 - version: 4.6.2 + specifier: ^4.7.0 + version: 4.7.0 loader-utils: specifier: ^2.0.4 version: 2.0.4 @@ -140,7 +140,7 @@ packages: resolution: {integrity: sha512-BDXFbYOJzT/NBEtp71cvsrGPwGAMGRB/349rwKuoxNSiKjPraNNnlK6MIIabViCjqZugu6j+xeMDlEkWdHHJSg==} dependencies: '@esbuild-kit/core-utils': 3.1.0 - get-tsconfig: 4.6.2 + get-tsconfig: 4.7.0 dev: true /@esbuild-kit/core-utils@3.1.0: @@ -154,7 +154,7 @@ packages: resolution: {integrity: sha512-Qwfvj/qoPbClxCRNuac1Du01r9gvNOT+pMYtJDapfB1eoGN1YlJ1BixLyL9WVENRx5RXgNLdfYdx/CuswlGhMw==} dependencies: '@esbuild-kit/core-utils': 3.1.0 - get-tsconfig: 4.6.2 + get-tsconfig: 4.7.0 dev: true /@esbuild/android-arm64@0.17.19: @@ -908,7 +908,7 @@ packages: eslint-plugin-regexp: 1.15.0(eslint@8.45.0) eslint-plugin-unicorn: 47.0.0(eslint@8.45.0) eslint-plugin-vue: 9.15.1(eslint@8.45.0) - get-tsconfig: 4.6.2 + get-tsconfig: 4.7.0 transitivePeerDependencies: - eslint-import-resolver-node - eslint-import-resolver-webpack @@ -1029,12 +1029,12 @@ packages: /@types/eslint-scope@3.7.4: resolution: {integrity: sha512-9K4zoImiZc3HlIp6AVUDE4CWYx22a+lhSZMYNpbjW04+YF0KWj4pJXnEMjdnFTiQibFFmElcsasJXDbdI/EPhA==} dependencies: - '@types/eslint': 8.44.1 + '@types/eslint': 8.44.2 '@types/estree': 1.0.1 dev: true - /@types/eslint@8.44.1: - resolution: {integrity: sha512-XpNDc4Z5Tb4x+SW1MriMVeIsMoONHCkWFMkR/aPJbzEsxqHy+4Glu/BqTdPrApfDeMaXbtNh6bseNgl5KaWrSg==} + /@types/eslint@8.44.2: + resolution: {integrity: sha512-sdPRb9K6iL5XZOmBubg8yiFp5yS/JdUDQsq5e6h95km91MCYMuvp7mh1fjPEYUhvHepKpZOjnEaMBR4PxjWDzg==} dependencies: '@types/estree': 1.0.1 '@types/json-schema': 7.0.12 @@ -2913,7 +2913,7 @@ packages: eslint: 8.45.0 eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.62.0)(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5)(eslint@8.45.0) eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0)(eslint-import-resolver-typescript@3.5.5)(eslint@8.45.0) - get-tsconfig: 4.6.2 + get-tsconfig: 4.7.0 globby: 13.2.2 is-core-module: 2.12.1 is-glob: 4.0.3 @@ -3614,8 +3614,8 @@ packages: get-intrinsic: 1.2.1 dev: true - /get-tsconfig@4.6.2: - resolution: {integrity: sha512-E5XrT4CbbXcXWy+1jChlZmrmCwd5KGx502kDCXJJ7y898TtWW9FwoG5HfOLVRKmlmDGkWN2HM9Ho+/Y8F0sJDg==} + /get-tsconfig@4.7.0: + resolution: {integrity: sha512-pmjiZ7xtB8URYm74PlGJozDNyhvsVLUcpBa8DZBG3bWHwaHa9bPiRpiSfovw+fjhwONSCWKRyk+JQHEGZmMrzw==} dependencies: resolve-pkg-maps: 1.0.0 diff --git a/src/loader.ts b/src/loader.ts index 67146df..e5b1afc 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -57,13 +57,14 @@ async function ESBuildLoader( */ if (tsconfigPath) { const tsconfigFullPath = path.resolve(tsconfigPath); - let tsconfig = tsconfigCache.get(tsconfigFullPath); + const cacheKey = `esbuild-loader:${tsconfigFullPath}`; + let tsconfig = tsconfigCache.get(cacheKey); if (!tsconfig) { tsconfig = { - config: parseTsconfig(tsconfigFullPath), + config: parseTsconfig(tsconfigFullPath, tsconfigCache), path: tsconfigFullPath, }; - tsconfigCache.set(tsconfigFullPath, tsconfig); + tsconfigCache.set(cacheKey, tsconfig); } const filesMatcher = createFilesMatcher(tsconfig); @@ -80,7 +81,7 @@ async function ESBuildLoader( /* Detect tsconfig file */ // Webpack shouldn't be loading the same path multiple times so doesn't need to be cached - const tsconfig = getTsconfig(resourcePath); + const tsconfig = getTsconfig(resourcePath, 'tsconfig.json', tsconfigCache); if (tsconfig) { const fileMatcher = createFilesMatcher(tsconfig); transformOptions.tsconfigRaw = fileMatcher(resourcePath) as TransformOptions['tsconfigRaw'];