diff --git a/scripts/test-size.js b/scripts/test-size.js index f2f09e2f14..ac43ea6f3c 100644 --- a/scripts/test-size.js +++ b/scripts/test-size.js @@ -16,10 +16,10 @@ try { } // The last recorded size for these assets, as reported by `yarn build`. -const MAX_SIZE_MAIN_KB = 361.36 +const LAST_SIZE_MAIN_KB = 374 // This is the async-loaded js, called ..js, with a matching css file. -const MAX_SIZE_ENTRY_MB = 1.38 +const LAST_SIZE_ENTRY_KB = 1417 const SIZE_TOLERANCE_KB = 5 @@ -30,20 +30,22 @@ let fail = false console.log('File sizes after gzip:\n') jsEntrypoints.forEach((entrypoint) => { const name = entrypoint.match(/\/([\w\d-]*)\./)[1] - const size = gzipSize(fs.readFileSync(path.join(buildDir, entrypoint))) + const size = gzipSize(fs.readFileSync(path.join(buildDir, entrypoint))) / 1024 - let maxSize = MAX_SIZE_ENTRY_MB * 1024 * 1024 + let maxSize = LAST_SIZE_ENTRY_KB + SIZE_TOLERANCE_KB if (name === 'runtime-main') { return } else if (name === 'main') { - maxSize = MAX_SIZE_MAIN_KB * 1024 + maxSize = LAST_SIZE_MAIN_KB + SIZE_TOLERANCE_KB } - maxSize += SIZE_TOLERANCE_KB * 1024 + const report = `\t${size.toFixed(2).padEnd(8)}kB\t${chalk.dim( + `max: ${maxSize.toFixed().padEnd(4)} kB` + )}\t${entrypoint}` if (maxSize > size) { - console.log(chalk.green(`\t${toKb(maxSize)}\t${entrypoint}`)) + console.log(chalk.green(report)) } else { - console.log(chalk.red(`\t${toKb(maxSize)}\t${entrypoint}`), '\tdid you import an unnecessary dependency?') + console.log(chalk.red(report), '\tdid you import an unnecessary dependency?') fail = true } }) @@ -52,7 +54,3 @@ if (fail) { console.log(chalk.yellow('Reduce the file size or update the size limit (in scripts/test-size.js)')) process.exit(1) } - -function toKb(bytes) { - return ((bytes / 1024).toFixed(2) + ' kB').padEnd(8) -}