Skip to content

Commit 7ab3b59

Browse files
fix: memory leak (#642)
1 parent e4212a3 commit 7ab3b59

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/utils.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function exec(code, loaderContext) {
3434
return module.exports;
3535
}
3636

37+
let tsLoader;
38+
3739
async function loadConfig(loaderContext, config, postcssOptions) {
3840
const searchPath =
3941
typeof config === "string"
@@ -166,13 +168,16 @@ async function loadConfig(loaderContext, config, postcssOptions) {
166168
};
167169

168170
if (isTsNodeInstalled) {
169-
// eslint-disable-next-line global-require
170-
const { TypeScriptLoader } = require("cosmiconfig-typescript-loader");
171-
const loader = TypeScriptLoader();
171+
if (!tsLoader) {
172+
// eslint-disable-next-line global-require
173+
const { TypeScriptLoader } = require("cosmiconfig-typescript-loader");
174+
175+
tsLoader = TypeScriptLoader();
176+
}
172177

173-
loaders[".cts"] = loader;
174-
loaders[".mts"] = loader;
175-
loaders[".ts"] = loader;
178+
loaders[".cts"] = tsLoader;
179+
loaders[".mts"] = tsLoader;
180+
loaders[".ts"] = tsLoader;
176181
}
177182

178183
const explorer = cosmiconfig(moduleName, {

0 commit comments

Comments
 (0)