Skip to content

Commit f4ee7a4

Browse files
feat: make deploy command bundle edge functions (#4562)
* 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 <[email protected]> Co-authored-by: Eduardo Bouças <[email protected]>
1 parent 73b2d6a commit f4ee7a4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/commands/deploy/deploy.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const inquirer = require('inquirer')
88
const isObject = require('lodash/isObject')
99
const prettyjson = require('prettyjson')
1010

11+
const runCoreStepPromise = import('@netlify/build')
1112
const netlifyConfigPromise = import('@netlify/config')
1213

1314
const { cancelDeploy } = require('../../lib/api')
@@ -274,6 +275,10 @@ const deployProgressCb = function () {
274275
}
275276
return
276277
}
278+
case 'error':
279+
stopSpinner({ error: true, spinner: events[event.type], text: event.msg })
280+
delete events[event.type]
281+
return
277282
case 'stop':
278283
default: {
279284
stopSpinner({ spinner: events[event.type], text: event.msg })
@@ -381,6 +386,40 @@ const handleBuild = async ({ cachedConfig, options }) => {
381386
return { newConfig, configMutations }
382387
}
383388

389+
/**
390+
*
391+
* @param {object} options Bundling options
392+
* @returns
393+
*/
394+
const bundleEdgeFunctions = async (options) => {
395+
const { runCoreSteps } = await runCoreStepPromise
396+
const statusCb = options.silent ? () => {} : deployProgressCb()
397+
398+
statusCb({
399+
type: 'edge-functions-bundling',
400+
msg: 'Bundling edge functions...\n',
401+
phase: 'start',
402+
})
403+
404+
const { severityCode, success } = await runCoreSteps(['edge_functions_bundling'], { ...options, buffer: true })
405+
406+
if (!success) {
407+
statusCb({
408+
type: 'edge-functions-bundling',
409+
msg: 'Deploy aborted due to error while bundling edge functions',
410+
phase: 'error',
411+
})
412+
413+
exit(severityCode)
414+
}
415+
416+
statusCb({
417+
type: 'edge-functions-bundling',
418+
msg: 'Finished bundling edge functions',
419+
phase: 'stop',
420+
})
421+
}
422+
384423
/**
385424
*
386425
* @param {object} config
@@ -526,6 +565,12 @@ const deploy = async (options, command) => {
526565
const deployFolder = await getDeployFolder({ options, config, site, siteData })
527566
const functionsFolder = getFunctionsFolder({ options, config, site, siteData })
528567
const { configPath } = site
568+
const edgeFunctionsConfig = command.netlify.config.edge_functions
569+
570+
// build flag wasn't used and edge functions exist
571+
if (!options.build && edgeFunctionsConfig && edgeFunctionsConfig.length !== 0) {
572+
await bundleEdgeFunctions(options)
573+
}
529574

530575
log(
531576
prettyjson.render({

0 commit comments

Comments
 (0)