Skip to content

Commit

Permalink
perf: upgrade get-tsconfig with caching
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Aug 11, 2023
1 parent f92b1f2 commit 544f4bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'];
Expand Down

0 comments on commit 544f4bd

Please sign in to comment.