@@ -41,6 +41,8 @@ const (
4141 functionUpload
4242
4343 lfsVersionString = "version https://git-lfs.github.com/spec/v1"
44+
45+ edgeFunctionsInternalPath = ".netlify/internal/edge-functions/"
4446)
4547
4648var installDirs = []string {"node_modules/" , "bower_components/" }
@@ -75,6 +77,7 @@ type DeployOptions struct {
7577 SiteID string
7678 Dir string
7779 FunctionsDir string
80+ EdgeFunctionsDir string
7881 BuildDir string
7982 LargeMediaEnabled bool
8083
@@ -210,6 +213,16 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
210213 }
211214 }
212215
216+ if options .EdgeFunctionsDir != "" {
217+ err = addEdgeFunctionsToDeployFiles (options .EdgeFunctionsDir , files , options .Observer )
218+ if err != nil {
219+ if options .Observer != nil {
220+ options .Observer .OnFailedWalk ()
221+ }
222+ return nil , err
223+ }
224+ }
225+
213226 options .files = files
214227
215228 functions , schedules , err := bundle (ctx , options .FunctionsDir , options .Observer )
@@ -513,6 +526,28 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
513526 }
514527}
515528
529+ func createFileBundle (rel , path string ) (* FileBundle , error ) {
530+ o , err := os .Open (path )
531+ if err != nil {
532+ return nil , err
533+ }
534+ defer o .Close ()
535+
536+ file := & FileBundle {
537+ Name : rel ,
538+ Path : path ,
539+ }
540+
541+ s := sha1 .New ()
542+ if _ , err := io .Copy (s , o ); err != nil {
543+ return nil , err
544+ }
545+
546+ file .Sum = hex .EncodeToString (s .Sum (nil ))
547+
548+ return file , nil
549+ }
550+
516551func walk (dir string , observer DeployObserver , useLargeMedia , ignoreInstallDirs bool ) (* deployFiles , error ) {
517552 files := newDeployFiles ()
518553
@@ -532,22 +567,10 @@ func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs
532567 return nil
533568 }
534569
535- o , err := os . Open ( path )
570+ file , err := createFileBundle ( rel , path )
536571 if err != nil {
537572 return err
538573 }
539- defer o .Close ()
540-
541- file := & FileBundle {
542- Name : rel ,
543- Path : path ,
544- }
545-
546- s := sha1 .New ()
547- if _ , err := io .Copy (s , o ); err != nil {
548- return err
549- }
550- file .Sum = hex .EncodeToString (s .Sum (nil ))
551574
552575 if useLargeMedia {
553576 o , err := os .Open (path )
@@ -585,6 +608,37 @@ func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs
585608 return files , err
586609}
587610
611+ func addEdgeFunctionsToDeployFiles (dir string , files * deployFiles , observer DeployObserver ) error {
612+ return filepath .Walk (dir , func (path string , info os.FileInfo , err error ) error {
613+ if err != nil {
614+ return err
615+ }
616+
617+ if ! info .IsDir () && info .Mode ().IsRegular () {
618+ osRel , err := filepath .Rel (dir , path )
619+ if err != nil {
620+ return err
621+ }
622+ rel := edgeFunctionsInternalPath + forceSlashSeparators (osRel )
623+
624+ file , err := createFileBundle (rel , path )
625+ if err != nil {
626+ return err
627+ }
628+
629+ files .Add (rel , file )
630+
631+ if observer != nil {
632+ if err := observer .OnSuccessfulStep (file ); err != nil {
633+ return err
634+ }
635+ }
636+ }
637+
638+ return nil
639+ })
640+ }
641+
588642func bundle (ctx context.Context , functionDir string , observer DeployObserver ) (* deployFiles , []* models.FunctionSchedule , error ) {
589643 if functionDir == "" {
590644 return nil , nil , nil
0 commit comments