28 lines
886 B
TypeScript
28 lines
886 B
TypeScript
import path from 'path';
|
|
|
|
export { ScopedEventEmitter } from './events';
|
|
export { IProcessData, spawnProcess, execProcess } from './run';
|
|
|
|
/**
|
|
* Load a Node.js module without caching it.
|
|
* @param file JavaScript file
|
|
* @returns Loaded module
|
|
*/
|
|
export function requireNoCache(file: string): object | undefined {
|
|
const fullPath = path.resolve(file);
|
|
// TODO: maybe use new "import" function?
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
const mod = require(fullPath);
|
|
if (require.cache && require.cache[fullPath]) {
|
|
delete require.cache[fullPath];
|
|
|
|
// Delete in-plugin-folder requires from cache as well
|
|
const dirname = path.dirname(fullPath);
|
|
const cacheEntries = Object.keys(require.cache).filter((entry) => entry.startsWith(dirname));
|
|
cacheEntries.forEach((entry) => {
|
|
delete require.cache[entry];
|
|
});
|
|
}
|
|
return mod;
|
|
}
|