Skip to content

Commit

Permalink
feat: make deploy command bundle edge functions (#4562)
Browse files Browse the repository at this point in the history
* feat: make deploy command bundle edge functions

* chore: use options used by buildSite

* chore: update contributors field

* chore: remove no longer needed constants

* chore: import runCoreSteps from @Netlify/build instead

* chore: update netlify/build

* Revert "chore: update netlify/build"

This reverts commit f2ca95a.

* chore: update netlify/build

* chore: handle for failed bundling

* Revert "chore: update netlify/build"

This reverts commit 74bef38.

* refactor: add progress messages

Co-authored-by: jackiewmacharia <jackiewmacharia@users.noreply.github.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
  • Loading branch information
3 people authored May 6, 2022
1 parent 73b2d6a commit f4ee7a4
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/commands/deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const inquirer = require('inquirer')
const isObject = require('lodash/isObject')
const prettyjson = require('prettyjson')

const runCoreStepPromise = import('@netlify/build')
const netlifyConfigPromise = import('@netlify/config')

const { cancelDeploy } = require('../../lib/api')
Expand Down Expand Up @@ -274,6 +275,10 @@ const deployProgressCb = function () {
}
return
}
case 'error':
stopSpinner({ error: true, spinner: events[event.type], text: event.msg })
delete events[event.type]
return
case 'stop':
default: {
stopSpinner({ spinner: events[event.type], text: event.msg })
Expand Down Expand Up @@ -381,6 +386,40 @@ const handleBuild = async ({ cachedConfig, options }) => {
return { newConfig, configMutations }
}

/**
*
* @param {object} options Bundling options
* @returns
*/
const bundleEdgeFunctions = async (options) => {
const { runCoreSteps } = await runCoreStepPromise
const statusCb = options.silent ? () => {} : deployProgressCb()

statusCb({
type: 'edge-functions-bundling',
msg: 'Bundling edge functions...\n',
phase: 'start',
})

const { severityCode, success } = await runCoreSteps(['edge_functions_bundling'], { ...options, buffer: true })

if (!success) {
statusCb({
type: 'edge-functions-bundling',
msg: 'Deploy aborted due to error while bundling edge functions',
phase: 'error',
})

exit(severityCode)
}

statusCb({
type: 'edge-functions-bundling',
msg: 'Finished bundling edge functions',
phase: 'stop',
})
}

/**
*
* @param {object} config
Expand Down Expand Up @@ -526,6 +565,12 @@ const deploy = async (options, command) => {
const deployFolder = await getDeployFolder({ options, config, site, siteData })
const functionsFolder = getFunctionsFolder({ options, config, site, siteData })
const { configPath } = site
const edgeFunctionsConfig = command.netlify.config.edge_functions

// build flag wasn't used and edge functions exist
if (!options.build && edgeFunctionsConfig && edgeFunctionsConfig.length !== 0) {
await bundleEdgeFunctions(options)
}

log(
prettyjson.render({
Expand Down

1 comment on commit f4ee7a4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 285 MB

Please sign in to comment.