- 
                Notifications
    
You must be signed in to change notification settings  - Fork 430
 
fix: bundle edge functions if they exist on deploy --no-build #7743
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -53,6 +53,7 @@ import { SiteInfo } from '../../utils/types.js' | |
| import type { DeployOptionValues } from './option_values.js' | ||
| import boxen from 'boxen' | ||
| import terminalLink from 'terminal-link' | ||
| import { anyEdgeFunctionsDirectoryExists } from '../../lib/edge-functions/get-directories.js' | ||
| 
     | 
||
| const triggerDeploy = async ({ | ||
| api, | ||
| 
          
            
          
           | 
    @@ -727,8 +728,11 @@ const bundleEdgeFunctions = async (options: DeployOptionValues, command: BaseCom | |
| // We log our own progress so we don't want this as well. Plus, this logs much of the same | ||
| // information as the build that (likely) came before this as part of the deploy build. | ||
| quiet: options.debug ?? true, | ||
| // @ts-expect-error FIXME(serhalp): This is missing from the `runCoreSteps` type in @netlify/build | ||
| // (cachedConfig type error hides this one, but it still is valid) @ts-expect-error FIXME(serhalp): This is missing from the `runCoreSteps` type in @netlify/build | ||
| edgeFunctionsBootstrapURL: await getBootstrapURL(), | ||
| // @ts-expect-error 'CachedConfig' is not assignable to type 'Record<string, unknown>'. | ||
| // Index signature for type 'string' is missing in type 'CachedConfig'. | ||
| cachedConfig: command.netlify.cachedConfig, | ||
| }) | ||
| 
     | 
||
| if (!success) { | ||
| 
          
            
          
           | 
    @@ -867,10 +871,11 @@ const prepAndRunDeploy = async ({ | |
| const functionsFolder = getFunctionsFolder({ workingDir, 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) { | ||
| // build flag wasn't used and edge functions directories exist | ||
| if (!options.build && (await anyEdgeFunctionsDirectoryExists(command))) { | ||
| // for the case of directories existing but not containing any edge functions, | ||
| // there is early bail in edge functions bundling after scanning for edge functions | ||
| // for this case and to avoid replicating scanning logic here, we defer to the bundling step | ||
| await bundleEdgeFunctions(options, command) | ||
| } | ||
| 
         
      Comment on lines
    
      +874
     to 
      880
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the previous condition doesn't seem to be met unless you specify some edge functions configuration in toml (?) so instead we check if there are edge functions dir present and trigger on-demand edge bundling if they are if directories exist but contain on edge functions - there will be early bail - that's just edge bundling function step in   | 
||
| 
     | 
||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { join } from 'path' | ||
| 
     | 
||
| import { getPathInProject } from '../settings.js' | ||
| import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.js' | ||
| import BaseCommand from '../../commands/base-command.js' | ||
| import { fileExistsAsync } from '../fs.js' | ||
| 
     | 
||
| export const getUserEdgeFunctionsDirectory = (command: BaseCommand): string | undefined => { | ||
| return command.netlify.config.build.edge_functions | ||
| } | ||
| 
     | 
||
| export const getInternalEdgeFunctionsDirectory = (command: BaseCommand): string => { | ||
| return join(command.workingDir, getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER])) | ||
| } | ||
| 
     | 
||
| export const getFrameworkEdgeFunctionsDirectory = (command: BaseCommand): string => { | ||
| return command.netlify.frameworksAPIPaths.edgeFunctions.path | ||
| } | ||
| 
     | 
||
| const getAllEdgeFunctionsDirectories = (command: BaseCommand) => { | ||
| return [ | ||
| getUserEdgeFunctionsDirectory(command), | ||
| getInternalEdgeFunctionsDirectory(command), | ||
| getFrameworkEdgeFunctionsDirectory(command), | ||
| ].filter(Boolean) as string[] | ||
| } | ||
| 
     | 
||
| export const anyEdgeFunctionsDirectoryExists = async (command: BaseCommand): Promise<boolean> => { | ||
| const directoriesToCheck = getAllEdgeFunctionsDirectories(command) | ||
| 
     | 
||
| return (await Promise.all(directoriesToCheck.map(fileExistsAsync))).some(Boolean) | ||
| } | 
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit frustrating, once I do add
cachedConfighere, it no longer complain aboutedgeFunctionsBootstrapURLand now it actually complain about@ts-expect-errorfor it ... but this is still valid, just somehow hidden because ofcachedConfigtype error ...Passing
cachedConfigseems needed to properly support--cwd other/dircase, as otherwise bundling was trying to look in current directory and there doesn't seem to be other arguments we can pass to tell it to look elsewhere (despite passingcwdexplitly above).