Skip to content

Commit

Permalink
refactor: Use compile mode of ts-import, don't use cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Jun 22, 2023
1 parent 3acbefa commit 23f8321
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib/configuration-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ function TypeScriptLoader(options: RegisterOptions = {}) {
// `default` is used when exporting using export default, some modules
// may still use `module.exports` or if in TS `export = `
return (result.default || result) as Loader;
} catch (err: any) {
log.error(log.prefix('TypeScriptLoader'), err?.message);
throw err;
} finally {
if (tempConfigFilePath.length > 0) {
await fs.remove(tempConfigFilePath);
Expand All @@ -146,7 +143,20 @@ function TypeScriptLoader(options: RegisterOptions = {}) {
* Uses ts-import to dynamically import TypeScript configuration files.
*/
async function withTsImport(filePath: string) {
const result = await tsImport.load(filePath);
const result = await tsImport.load(filePath, {
// Slower, but allows files to be considered as part of larger TypeScript
// programs, which should allow path mappings to work.
mode: tsImport.LoadMode.Compile,
useCache: false
});

// Clean-up the cache directory left behind by ts-import.
// try {
// await fs.remove(path.join(path.dirname(filePath), '.cache'));
// } catch (err: any) {
// log.error(log.prefix('ts-import'), 'Error removing cache directory:', err);
// }

return result?.default || result;
}

Expand Down

0 comments on commit 23f8321

Please sign in to comment.