|
| 1 | +const { existsSync, promises } = require('fs') |
1 | 2 | const path = require('path')
|
| 3 | +const { relative } = require('path') |
2 | 4 |
|
3 |
| -const { yellowBright, greenBright, blueBright } = require('chalk') |
4 |
| -const { existsSync } = require('fs-extra') |
| 5 | +const { yellowBright, greenBright, blueBright, redBright } = require('chalk') |
| 6 | +const { async: StreamZip } = require('node-stream-zip') |
5 | 7 | const outdent = require('outdent')
|
| 8 | +const prettyBytes = require('pretty-bytes') |
6 | 9 | const { satisfies } = require('semver')
|
7 | 10 |
|
8 | 11 | exports.verifyBuildTarget = (target) => {
|
@@ -53,6 +56,42 @@ exports.checkForRootPublish = ({ publish, failBuild }) => {
|
53 | 56 | }
|
54 | 57 | }
|
55 | 58 |
|
| 59 | +// 50MB, which is the documented max, though the hard max seems to be higher |
| 60 | +const LAMBDA_MAX_SIZE = 1024 * 1024 * 50 |
| 61 | + |
| 62 | +exports.checkZipSize = async (file) => { |
| 63 | + const size = await promises.stat(file).then(({ size }) => size) |
| 64 | + if (size < LAMBDA_MAX_SIZE) { |
| 65 | + return |
| 66 | + } |
| 67 | + // We don't fail the build, because the actual hard max size is larger so it might still succeed |
| 68 | + console.log( |
| 69 | + redBright(outdent` |
| 70 | +
|
| 71 | + The function zip ${yellowBright(relative(process.cwd(), file))} size is ${prettyBytes( |
| 72 | + size, |
| 73 | + )}, which is larger than the maximum supported size of ${prettyBytes(LAMBDA_MAX_SIZE)}. |
| 74 | + There are a few reasons this could happen. You may have accidentally bundled a large dependency, or you might have a |
| 75 | + large number of pre-rendered pages included. |
| 76 | + |
| 77 | + `), |
| 78 | + ) |
| 79 | + const zip = new StreamZip({ file }) |
| 80 | + console.log(`Contains ${await zip.entriesCount} files`) |
| 81 | + const sortedFiles = Object.values(await zip.entries()).sort((a, b) => b.size - a.size) |
| 82 | + |
| 83 | + const largest = {} |
| 84 | + for (let i = 0; i < 10; i++) { |
| 85 | + largest[`${i + 1}`] = { |
| 86 | + File: sortedFiles[i].name, |
| 87 | + 'Compressed Size': prettyBytes(sortedFiles[i].compressedSize), |
| 88 | + 'Uncompressed Size': prettyBytes(sortedFiles[i].size), |
| 89 | + } |
| 90 | + } |
| 91 | + console.log(yellowBright`\n\nThese are the largest files in the zip:`) |
| 92 | + console.table(largest) |
| 93 | +} |
| 94 | + |
56 | 95 | exports.logBetaMessage = () =>
|
57 | 96 | console.log(
|
58 | 97 | greenBright(
|
|
0 commit comments