-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global Buffer */ | ||
import { BlobReader, TextWriter, ZipReader } from '@zip.js/zip.js'; | ||
import assert from 'node:assert/strict'; | ||
import fs from 'node:fs'; | ||
|
||
/** @import {Bundle} from '@agoric/swingset-vat'; */ | ||
|
||
const PACKAGE_NAME_RE = /(?<packageName>.*-v[\d.]+)\//; | ||
|
||
/** | ||
* @typedef CompartmentMap | ||
* @property {string[]} tags | ||
* @property {{compartment: string, module: string}} entry | ||
* @property {Record<string, {name: string, label: string, location: string, modules: Record<string, {compartment: string, module: string}>}} compartments | ||
*/ | ||
|
||
/** @param {Bundle} bundleObj*/ | ||
export const extractBundleInfo = async bundleObj => { | ||
await null; | ||
if (bundleObj.moduleFormat === 'endoZipBase64') { | ||
const contents = Buffer.from(bundleObj.endoZipBase64, 'base64'); | ||
const zipBlob = new Blob([contents], { type: 'application/zip' }); | ||
|
||
const zipFileReader = new BlobReader(zipBlob); | ||
const writer = new TextWriter('utf-8'); | ||
|
||
const zipReader = new ZipReader(zipFileReader); | ||
const entries = await zipReader.getEntries(); | ||
await zipReader.close(); | ||
|
||
assert(entries[0].filename, 'compartment-map.json'); | ||
const cmapStr = await entries[0].getData(writer); | ||
/** @type {CompartmentMap} */ | ||
const compartmentMap = JSON.parse(cmapStr); | ||
|
||
const fileSizes = Object.fromEntries( | ||
entries.map(e => [e.filename, e.compressedSize]), | ||
); | ||
|
||
return { compartmentMap, fileSizes }; | ||
} | ||
}; | ||
|
||
// UNTIL https://github.com/endojs/endo/issues/1656 | ||
/** @param {string} bundleFilename */ | ||
export const statBundle = async bundleFilename => { | ||
const bundle = fs.readFileSync(bundleFilename, 'utf8'); | ||
/** @type {Bundle} */ | ||
const bundleObj = JSON.parse(bundle); | ||
console.log('\nBUNDLE', bundleObj.moduleFormat, bundleFilename); | ||
|
||
const info = await extractBundleInfo(bundleObj); | ||
|
||
/** @type {Record<string, number>} */ | ||
const byPackage = {}; | ||
let totalSize = 0; | ||
for (const [filename, size] of Object.entries(info.fileSizes)) { | ||
totalSize += size; | ||
if (filename === 'compartment-map.json') { | ||
continue; | ||
} | ||
const { packageName } = filename.match(PACKAGE_NAME_RE).groups; | ||
byPackage[packageName] ||= 0; | ||
byPackage[packageName] += size; | ||
} | ||
|
||
console.table(byPackage); | ||
|
||
console.log('total size:', totalSize); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters