Skip to content

Commit d86fd9b

Browse files
authored
fix: make large lambda warning message more informative (#578)
* Update max lambda size message * fix: error message format
1 parent ca4b0c0 commit d86fd9b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plugin/src/helpers/verification.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
import process from 'process'
22

3-
import { yellowBright, redBright } from 'chalk'
3+
import { yellowBright, blueBright } from 'chalk'
44
import { stripIndent } from 'common-tags'
55
import { existsSync, promises } from 'fs-extra'
66
import { async as StreamZip } from 'node-stream-zip'
77
import { relative } from 'pathe'
88
import prettyBytes from 'pretty-bytes'
99

10-
// 50MB, which is the documented max, though the hard max seems to be higher
10+
// 50MB, which is the warning max
1111
// 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
1317

1418
// eslint-disable-next-line max-statements
1519
export const checkZipSize = async (
1620
file: string,
21+
warningSize: number = LAMBDA_WARNING_SIZE,
1722
maxSize: number = LAMBDA_MAX_SIZE,
1823
): Promise<void> => {
1924
if (!existsSync(file)) {
2025
console.warn(`Could not check zip size because ${file} does not exist`)
2126
return
2227
}
2328
const fileSize = await promises.stat(file).then(({ size }) => size)
24-
if (fileSize < maxSize) {
29+
if (fileSize < warningSize) {
2530
return
2631
}
2732
// We don't fail the build, because the actual hard max size is larger so it might still succeed
2833
console.log(
29-
redBright(stripIndent`
30-
The function zip ${yellowBright(
34+
yellowBright(stripIndent`
35+
The function zip ${blueBright(
3136
relative(process.cwd(), file),
3237
)} size is ${prettyBytes(
3338
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(
3542
maxSize,
36-
)}.
43+
)}
3744
There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files".
3845
`),
3946
)

0 commit comments

Comments
 (0)