UNPKG

1.11 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.dynamicRequireNoCache = exports.dynamicRequire = void 0;
4const fslib_1 = require("@yarnpkg/fslib");
5// This file is copied from miscUtils.ts - make sure your changes are synced there
6exports.dynamicRequire = eval(`require`);
7function dynamicRequireNoCache(path) {
8 const physicalPath = fslib_1.npath.fromPortablePath(path);
9 const currentCacheEntry = exports.dynamicRequire.cache[physicalPath];
10 delete exports.dynamicRequire.cache[physicalPath];
11 let result;
12 try {
13 result = (0, exports.dynamicRequire)(physicalPath);
14 const freshCacheEntry = exports.dynamicRequire.cache[physicalPath];
15 const dynamicModule = eval(`module`);
16 const freshCacheIndex = dynamicModule.children.indexOf(freshCacheEntry);
17 if (freshCacheIndex !== -1) {
18 dynamicModule.children.splice(freshCacheIndex, 1);
19 }
20 }
21 finally {
22 exports.dynamicRequire.cache[physicalPath] = currentCacheEntry;
23 }
24 return result;
25}
26exports.dynamicRequireNoCache = dynamicRequireNoCache;