| 96 | |
| 97 | // given an individual path to a script, return its file size |
| 98 | function getScriptSize(scriptPath) { |
| 99 | const encoding = "utf8" |
| 100 | const p = path.join(nextMetaRoot, scriptPath) |
| 101 | |
| 102 | let rawSize, gzipSize |
| 103 | if (Object.keys(memoryCache).includes(p)) { |
| 104 | rawSize = memoryCache[p][0] |
| 105 | gzipSize = memoryCache[p][1] |
| 106 | } else { |
| 107 | const textContent = fs.readFileSync(p, encoding) |
| 108 | rawSize = Buffer.byteLength(textContent, encoding) |
| 109 | gzipSize = gzSize.sync(textContent) |
| 110 | memoryCache[p] = [rawSize, gzipSize] |
| 111 | } |
| 112 | |
| 113 | return [rawSize, gzipSize] |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Reads options from `package.json` |