| 99 | }; |
| 100 | |
| 101 | function writeCacheFile(cacheFile, res) { |
| 102 | // If cache file already exists, return it. |
| 103 | if (fs.existsSync(cacheFile)) { |
| 104 | return cacheFile; |
| 105 | } |
| 106 | |
| 107 | // Otherwise, write it atomically to avoid race conditions between threads/processes. |
| 108 | let tmpFile = cacheFile + '.' + process.pid + (threadId != null ? '.' + threadId : ''); |
| 109 | fs.writeFileSync(tmpFile, res); |
| 110 | fs.renameSync(tmpFile, cacheFile); |
| 111 | return cacheFile; |
| 112 | } |
| 113 | |
| 114 | function processExports(exports) { |
| 115 | for (let key in exports) { |