MCPcopy
hub / github.com/Blazity/next-enterprise / getScriptSize

Function getScriptSize

report-bundle-size.js:98–114  ·  view source on GitHub ↗
(scriptPath)

Source from the content-addressed store, hash-verified

96
97// given an individual path to a script, return its file size
98function 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`

Callers 1

getScriptSizesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected