Skip to content

Commit

Permalink
fix: ts-import strategy removes cache directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Jun 25, 2023
1 parent e073eac commit 13c9c3f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/lib/configuration/strategies/ts-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ import log from 'lib/log';
* Uses ts-import to dynamically import TypeScript configuration files.
*/
export async function tsImportStrategy(filePath: string) {
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,
// N.B. Even with this set to false, ts-import still seems to create (and
// leave behind) a .cache directory.
useCache: false
});

// Clean-up the cache directory left behind by ts-import.
const cacheDir = path.join(path.dirname(filePath), '.cache');

try {
await fs.remove(path.join(path.dirname(filePath), '.cache'));
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,
// N.B. Even with this set to false, ts-import still seems to create (and
// leave behind) a .cache directory.
useCache: false
});

return result?.default || result;
} catch (err: any) {
log.error(log.prefix('ts-import'), 'Error removing cache directory:', err);
} finally {
if (await fs.exists(cacheDir)) await fs.remove(cacheDir);
}

return result?.default || result;
}

0 comments on commit 13c9c3f

Please sign in to comment.