Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b651e67

Browse files
committedApr 20, 2023
fix: make large lambda warning message more informative
1 parent a37fb72 commit b651e67

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed
 

‎package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/runtime/src/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export const CATCH_ALL_REGEX = /\/\[\.{3}(.*)](.json)?$/
2727
export const OPTIONAL_CATCH_ALL_REGEX = /\/\[{2}\.{3}(.*)]{2}(.json)?$/
2828
export const DYNAMIC_PARAMETER_REGEX = /\/\[(.*?)]/g
2929
export const MINIMUM_REVALIDATE_SECONDS = 60
30-
// 50MB, which is the documented max, though the hard max seems to be higher
31-
export const LAMBDA_MAX_SIZE = 1024 * 1024 * 50
30+
// 50MB, which is the warning max
31+
export const LAMBDA_WARNING_SIZE = 1024 * 1024 * 50
32+
// 250MB, which is the hard max
33+
export const LAMBDA_MAX_SIZE = 1024 * 1024 * 250
3234

3335
export const DIVIDER = `
3436
────────────────────────────────────────────────────────────────

‎packages/runtime/src/helpers/verification.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { existsSync, promises } from 'fs'
22
import path, { relative, join } from 'path'
33

44
import type { NetlifyConfig, NetlifyPluginUtils } from '@netlify/build'
5-
import { yellowBright, greenBright, blueBright, redBright, reset } from 'chalk'
5+
import { yellowBright, greenBright, blueBright, reset } from 'chalk'
66
import { async as StreamZip } from 'node-stream-zip'
77
import { outdent } from 'outdent'
88
import prettyBytes from 'pretty-bytes'
99
import { satisfies } from 'semver'
1010

11-
import { LAMBDA_MAX_SIZE } from '../constants'
11+
import { LAMBDA_MAX_SIZE, LAMBDA_WARNING_SIZE } from '../constants'
1212

1313
import { isBundleSizeCheckDisabled } from './utils'
1414

@@ -105,7 +105,11 @@ export const checkForRootPublish = ({
105105
}
106106
}
107107

108-
export const checkZipSize = async (file: string, maxSize: number = LAMBDA_MAX_SIZE): Promise<void> => {
108+
export const checkZipSize = async (
109+
file: string,
110+
maxSize: number = LAMBDA_MAX_SIZE,
111+
warningSize: number = LAMBDA_WARNING_SIZE,
112+
): Promise<void> => {
109113
// Requires contacting the Netlify Support team to fully enable.
110114
// Enabling this without contacting them can result in failed deploys.
111115
if (isBundleSizeCheckDisabled()) {
@@ -120,15 +124,16 @@ export const checkZipSize = async (file: string, maxSize: number = LAMBDA_MAX_SI
120124
return
121125
}
122126
const fileSize = await promises.stat(file).then(({ size }) => size)
123-
if (fileSize < maxSize) {
127+
if (fileSize < warningSize) {
124128
return
125129
}
126130
// We don't fail the build, because the actual hard max size is larger so it might still succeed
127131
console.log(
128-
redBright(outdent`
129-
The function zip ${yellowBright(relative(process.cwd(), file))} size is ${prettyBytes(
132+
yellowBright(outdent`
133+
The function zip ${blueBright(relative(process.cwd(), file))} size is ${prettyBytes(
130134
fileSize,
131-
)}, which is larger than the maximum supported size of ${prettyBytes(maxSize)}.
135+
)}, which is larger than the recommended maximum size of ${prettyBytes(warningSize)}.
136+
This will fail the build if the unzipped size is bigger than the maximum size of ${prettyBytes(maxSize)}.
132137
There are a few reasons this could happen. You may have accidentally bundled a large dependency, or you might have a
133138
large number of pre-rendered pages included.
134139
`),

0 commit comments

Comments
 (0)
Please sign in to comment.