@@ -582,7 +582,11 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
582
582
583
583
switch {
584
584
case zipFile (i ):
585
- file , err := newFunctionFile (filePath , i , jsRuntime , observer )
585
+ runtime , err := readZipRuntime (filePath )
586
+ if err != nil {
587
+ return nil , err
588
+ }
589
+ file , err := newFunctionFile (filePath , i , runtime , observer )
586
590
if err != nil {
587
591
return nil , err
588
592
}
@@ -609,6 +613,43 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
609
613
return functions , nil
610
614
}
611
615
616
+ func readZipRuntime (filePath string ) (string , error ) {
617
+ zf , err := zip .OpenReader (filePath )
618
+ if err != nil {
619
+ return "" , err
620
+ }
621
+ defer zf .Close ()
622
+
623
+ for _ , file := range zf .File {
624
+ if file .Name == "netlify-toolchain" {
625
+ fc , err := file .Open ()
626
+ if err != nil {
627
+ // Ignore any errors and choose the default runtime.
628
+ // This preserves the current behavior in this library.
629
+ return jsRuntime , nil
630
+ }
631
+ defer fc .Close ()
632
+
633
+ reader := bufio .NewReader (fc )
634
+ for {
635
+ line , err := reader .ReadString ('\n' )
636
+ if err != nil && err != io .EOF {
637
+ // Ignore any errors and choose the default runtime.
638
+ // This preserves the current behavior in this library.
639
+ return jsRuntime , nil
640
+ }
641
+
642
+ if strings .HasPrefix (line , "runtime=" ) {
643
+ split := strings .SplitN (line , "=" , 2 )
644
+ return split [1 ], nil
645
+ }
646
+ }
647
+ }
648
+ }
649
+
650
+ return jsRuntime , nil
651
+ }
652
+
612
653
func newFunctionFile (filePath string , i os.FileInfo , runtime string , observer DeployObserver ) (* FileBundle , error ) {
613
654
file := & FileBundle {
614
655
Name : strings .TrimSuffix (i .Name (), filepath .Ext (i .Name ())),
0 commit comments