Skip to content

Commit

Permalink
fix(cli): count preloaded modules in bundle size and use decimal syst…
Browse files Browse the repository at this point in the history
…em for file size (#77)
  • Loading branch information
byCedric authored Oct 16, 2024
1 parent 8fefca6 commit 8495e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export async function GET(request: Request, params: Record<'bundle', string>) {
data: finalizeModuleTree(createModuleTree(bundle, filteredModules)),
bundle: {
platform: bundle.platform as any,
moduleSize: allModules.reduce((size, module) => size + module.size, 0),
moduleFiles: bundle.modules.size,
moduleFiles: bundle.modules.size + bundle.runtimeModules.length,
moduleSize: allModules
.concat(bundle.runtimeModules)
.reduce((size, module) => size + module.size, 0),
},
filtered: {
moduleSize: filteredModules.reduce((size, module) => size + module.size, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export async function GET(request: Request, params: Record<'bundle', string>) {
})),
bundle: {
platform: bundle.platform as any,
moduleSize: allModules.reduce((size, module) => size + module.size, 0),
moduleFiles: bundle.modules.size,
moduleFiles: bundle.modules.size + bundle.runtimeModules.length,
moduleSize: allModules
.concat(bundle.runtimeModules)
.reduce((size, module) => size + module.size, 0),
},
filtered: {
moduleSize: filteredModules.reduce((size, module) => size + module.size, 0),
Expand Down
17 changes: 10 additions & 7 deletions packages/expo-atlas-ui/components/FileSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ export function FileSize(props: BundleFileSizeProps) {
);
}

/** Format files or bundle size, from bytes to the nearest unit */
export function formatByteSize(size: number) {
if (size < 1024) {
return size + 'B';
} else if (size < 1024 * 1024) {
return (size / 1024).toFixed(1) + 'KB';
/**
* Format files or bundle size, from bytes to the nearest unit.
* This uses the decimal system with a scaling factor of `1000`.
*/
export function formatByteSize(byteSize: number, scalingFactor = 1000) {
if (byteSize < scalingFactor) {
return byteSize + 'B';
} else if (byteSize < scalingFactor * scalingFactor) {
return (byteSize / scalingFactor).toFixed(1) + 'KB';
} else {
return (size / 1024 / 1024).toFixed(1) + 'MB';
return (byteSize / scalingFactor / scalingFactor).toFixed(1) + 'MB';
}
}

0 comments on commit 8495e5a

Please sign in to comment.