Skip to content

Commit 6a046de

Browse files
feat: allows disabling function size check (#1570)
* feat: allows disabling function size check * Update packages/runtime/src/helpers/verification.ts Co-authored-by: Eduardo Bouças <[email protected]> * fix(test): update mocking so that dependencies work Co-authored-by: Eduardo Bouças <[email protected]>
1 parent 4776ad5 commit 6a046de

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 variable. 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,11 +1,15 @@
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 {
12+
...jest.requireActual('fs'),
913
existsSync: jest.fn(),
1014
}
1115
})
@@ -78,3 +82,21 @@ describe('checkNextSiteHasBuilt', () => {
7882
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
7983
})
8084
})
85+
86+
describe('checkZipSize', () => {
87+
let consoleSpy
88+
89+
beforeEach(() => {
90+
consoleSpy = jest.spyOn(global.console, 'warn')
91+
})
92+
93+
afterEach(() => {
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 = 'true'
99+
await checkZipSize(chance.string())
100+
expect(consoleSpy).toHaveBeenCalledWith('Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment variable. 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)