Skip to content

feat: allows disabling function size check #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/runtime/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,7 @@ export const getCustomImageResponseHeaders = (headers: Header[]): Record<string,
}
return null
}

export const isBundleSizeCheckDisabled = () =>
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === '1' || process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === 'true'
/* eslint-enable max-lines */
11 changes: 11 additions & 0 deletions packages/runtime/src/helpers/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { satisfies } from 'semver'

import { LAMBDA_MAX_SIZE } from '../constants'

import { isBundleSizeCheckDisabled } from './utils'

// This is when nft support was added
const REQUIRED_BUILD_VERSION = '>=18.16.0'

Expand Down Expand Up @@ -105,6 +107,15 @@ export const checkForRootPublish = ({
}

export const checkZipSize = async (file: string, maxSize: number = LAMBDA_MAX_SIZE): Promise<void> => {
// Requires contacting the Netlify Support team to fully enable.
// Enabling this without contacting them can result in failed deploys.
if (isBundleSizeCheckDisabled()) {
console.warn(
'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.',
)
return
}

if (!existsSync(file)) {
console.warn(`Could not check zip size because ${file} does not exist`)
return
Expand Down
24 changes: 23 additions & 1 deletion test/helpers/verification.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { checkNextSiteHasBuilt } from '../../packages/runtime/src/helpers/verification'
import Chance from 'chance'
import { checkNextSiteHasBuilt, checkZipSize } from '../../packages/runtime/src/helpers/verification'
import { outdent } from 'outdent'

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

const chance = new Chance()

jest.mock('fs', () => {
return {
...jest.requireActual('fs'),
existsSync: jest.fn(),
}
})
Expand Down Expand Up @@ -78,3 +82,21 @@ describe('checkNextSiteHasBuilt', () => {
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
})
})

describe('checkZipSize', () => {
let consoleSpy

beforeEach(() => {
consoleSpy = jest.spyOn(global.console, 'warn')
})

afterEach(() => {
delete process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK
})

it('emits a warning that DISABLE_BUNDLE_ZIP_SIZE_CHECK was enabled', async () => {
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK = 'true'
await checkZipSize(chance.string())
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.')
})
})