Skip to content

Commit 6bf0713

Browse files
committed
feat: allows disabling function size check
1 parent 28a751d commit 6bf0713

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/runtime/src/helpers/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,7 @@ export const getCustomImageResponseHeaders = (headers: Header[]): Record<string,
196196
}
197197
return null
198198
}
199+
200+
export const isBundleSizeCheckDisabled = () =>
201+
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === '1' || process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === 'true'
199202
/* eslint-enable max-lines */

packages/runtime/src/helpers/verification.ts

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { satisfies } from 'semver'
1111

1212
import { LAMBDA_MAX_SIZE } from '../constants'
1313

14+
import { isBundleSizeCheckDisabled } from './utils'
15+
1416
// This is when nft support was added
1517
const REQUIRED_BUILD_VERSION = '>=18.16.0'
1618

@@ -105,6 +107,15 @@ export const checkForRootPublish = ({
105107
}
106108

107109
export const checkZipSize = async (file: string, maxSize: number = LAMBDA_MAX_SIZE): Promise<void> => {
110+
// Requires contacting the Netlify Support team to fully enable.
111+
// Enabling this without contacting them can result in failed deploys.
112+
if (isBundleSizeCheckDisabled()) {
113+
console.warn(
114+
'Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.',
115+
)
116+
return
117+
}
118+
108119
if (!existsSync(file)) {
109120
console.warn(`Could not check zip size because ${file} does not exist`)
110121
return

test/helpers/verification.spec.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { checkNextSiteHasBuilt } from '../../packages/runtime/src/helpers/verification'
1+
import Chance from 'chance'
2+
import { checkNextSiteHasBuilt, checkZipSize } from '../../packages/runtime/src/helpers/verification'
23
import { outdent } from 'outdent'
34

45
import type { NetlifyPluginUtils } from '@netlify/build'
56
type FailBuild = NetlifyPluginUtils['build']['failBuild']
67

8+
const chance = new Chance()
9+
710
jest.mock('fs', () => {
811
return {
912
existsSync: jest.fn(),
@@ -78,3 +81,22 @@ describe('checkNextSiteHasBuilt', () => {
7881
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
7982
})
8083
})
84+
85+
describe('checkZipSize', () => {
86+
let consoleSpy
87+
88+
beforeEach(() => {
89+
consoleSpy = jest.spyOn(global.console, 'warn')
90+
})
91+
92+
afterEach(() => {
93+
jest.restoreAllMocks()
94+
delete process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK
95+
})
96+
97+
it('emits a warning that DISABLE_BUNDLE_ZIP_SIZE_CHECK was enabled', async () => {
98+
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK = 'false'
99+
await checkZipSize(chance.string())
100+
expect(consoleSpy).toHaveBeenCalledWith('Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.')
101+
})
102+
})

0 commit comments

Comments
 (0)