Skip to content

Commit

Permalink
Wrap require-cache part with try-catch (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhermelin committed Apr 19, 2021
1 parent ce1dcee commit 3ef86c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ const isExist = <T = unknown>(data: T): boolean => {
return data !== undefined && data !== null;
};

// Prevent caching of this module so module.parent is always accurate
let parentDir = '';
try {
// Prevent caching of this module so module.parent is always accurate.
// Note: This trick won't work with ESM or inside a webworker
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete require.cache[__filename];
const parentDir = path.dirname(module.parent?.filename ?? '.');
delete require.cache[__filename];
parentDir = path.dirname(module.parent?.filename ?? '.');
} catch {}

const checkValueType = (key: string, value: unknown): void => {
const nonJsonTypes = new Set([
Expand Down

0 comments on commit 3ef86c8

Please sign in to comment.