Created
December 9, 2025 14:47
-
-
Save alanshaw/64ecc855a57230c95197ed29d5c49ab3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { registerHooks } from 'node:module' | |
| import fs from 'node:fs' | |
| const urls = [] | |
| registerHooks({ | |
| load(url, context, nextLoad) { | |
| if (!url.startsWith('file://')) { | |
| return nextLoad(url, context) | |
| } | |
| urls.push(url) | |
| return nextLoad(url, context) | |
| } | |
| }) | |
| console.time('load') | |
| await import('./test2.js') | |
| console.timeEnd('load') | |
| const sizes = new Map() | |
| for (const url of urls) { | |
| const stats = fs.statSync(url.replace('file://', '')) | |
| sizes.set(url, stats.size) | |
| } | |
| const entries = [...sizes.entries()].sort((a, b) => { | |
| if (a[1] < b[1]) return -1 | |
| if (a[1] > b[1]) return 1 | |
| return 0 | |
| }) | |
| let totalFiles = 0 | |
| let totalSize = 0 | |
| for (const [url, size] of entries) { | |
| // if (url.includes('node_modules')) continue | |
| console.log(size.toLocaleString(), url) | |
| totalSize += size | |
| totalFiles++ | |
| } | |
| console.log(`Total files: ${totalFiles.toLocaleString()}`) | |
| console.log(`Total size: ${totalSize.toLocaleString()}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment