UNPKG

@yarnpkg/pnpify

Version:
27 lines (26 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dynamicRequireNoCache = exports.dynamicRequire = void 0; const fslib_1 = require("@yarnpkg/fslib"); // This file is copied from miscUtils.ts - make sure your changes are synced there exports.dynamicRequire = eval(`require`); function dynamicRequireNoCache(path) { const physicalPath = fslib_1.npath.fromPortablePath(path); const currentCacheEntry = exports.dynamicRequire.cache[physicalPath]; delete exports.dynamicRequire.cache[physicalPath]; let result; try { result = (0, exports.dynamicRequire)(physicalPath); const freshCacheEntry = exports.dynamicRequire.cache[physicalPath]; const dynamicModule = eval(`module`); const freshCacheIndex = dynamicModule.children.indexOf(freshCacheEntry); if (freshCacheIndex !== -1) { dynamicModule.children.splice(freshCacheIndex, 1); } } finally { exports.dynamicRequire.cache[physicalPath] = currentCacheEntry; } return result; } exports.dynamicRequireNoCache = dynamicRequireNoCache;