|
1 | 1 | import process from 'process'
|
2 | 2 |
|
3 |
| -import { yellowBright, redBright } from 'chalk' |
| 3 | +import { yellowBright, blueBright } from 'chalk' |
4 | 4 | import { stripIndent } from 'common-tags'
|
5 | 5 | import { existsSync, promises } from 'fs-extra'
|
6 | 6 | import { async as StreamZip } from 'node-stream-zip'
|
7 | 7 | import { relative } from 'pathe'
|
8 | 8 | import prettyBytes from 'pretty-bytes'
|
9 | 9 |
|
10 |
| -// 50MB, which is the documented max, though the hard max seems to be higher |
| 10 | +// 50MB, which is the warning max |
11 | 11 | // eslint-disable-next-line no-magic-numbers
|
12 |
| -export const LAMBDA_MAX_SIZE = 1024 * 1024 * 50 |
| 12 | +export const LAMBDA_WARNING_SIZE = 1024 * 1024 * 50 |
| 13 | + |
| 14 | +// 250MB, which is the hard max |
| 15 | +// eslint-disable-next-line no-magic-numbers |
| 16 | +export const LAMBDA_MAX_SIZE = 1024 * 1024 * 250 |
13 | 17 |
|
14 | 18 | // eslint-disable-next-line max-statements
|
15 | 19 | export const checkZipSize = async (
|
16 | 20 | file: string,
|
| 21 | + warningSize: number = LAMBDA_WARNING_SIZE, |
17 | 22 | maxSize: number = LAMBDA_MAX_SIZE,
|
18 | 23 | ): Promise<void> => {
|
19 | 24 | if (!existsSync(file)) {
|
20 | 25 | console.warn(`Could not check zip size because ${file} does not exist`)
|
21 | 26 | return
|
22 | 27 | }
|
23 | 28 | const fileSize = await promises.stat(file).then(({ size }) => size)
|
24 |
| - if (fileSize < maxSize) { |
| 29 | + if (fileSize < warningSize) { |
25 | 30 | return
|
26 | 31 | }
|
27 | 32 | // We don't fail the build, because the actual hard max size is larger so it might still succeed
|
28 | 33 | console.log(
|
29 |
| - redBright(stripIndent` |
30 |
| - The function zip ${yellowBright( |
| 34 | + yellowBright(stripIndent` |
| 35 | + The function zip ${blueBright( |
31 | 36 | relative(process.cwd(), file),
|
32 | 37 | )} size is ${prettyBytes(
|
33 | 38 | fileSize,
|
34 |
| - )}, which is larger than the maximum supported size of ${prettyBytes( |
| 39 | + )}, which is larger than the recommended maximum size of ${prettyBytes( |
| 40 | + warningSize, |
| 41 | + )}. This will fail the build if the unzipped size is bigger than the maximum size of ${prettyBytes( |
35 | 42 | maxSize,
|
36 |
| - )}. |
| 43 | + )} |
37 | 44 | There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files".
|
38 | 45 | `),
|
39 | 46 | )
|
|
0 commit comments