Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): count preloaded modules in bundle size and use decimal system for file size #77

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}
}