Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created December 9, 2025 14:47
Show Gist options
  • Select an option

  • Save alanshaw/64ecc855a57230c95197ed29d5c49ab3 to your computer and use it in GitHub Desktop.

Select an option

Save alanshaw/64ecc855a57230c95197ed29d5c49ab3 to your computer and use it in GitHub Desktop.
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