@@ -557,6 +557,11 @@ class Socket {
557557 return path . join ( session . getDistPath ( ) , `${ this . name } .env.zip` )
558558 }
559559
560+ isEmptyEnv ( ) {
561+ debug ( 'isEmptyEnv' , ! fs . existsSync ( this . getSocketEnvZip ( ) ) )
562+ return ! fs . existsSync ( this . getSocketEnvZip ( ) )
563+ }
564+
560565 getSocketNodeModulesChecksum ( ) {
561566 debug ( 'getSocketNodeModulesChecksum' )
562567 return hashdirectory . sync ( path . join ( this . socketPath , '.dist' , 'node_modules' ) )
@@ -797,6 +802,8 @@ class Socket {
797802 mkdirp . sync ( envFolder )
798803 }
799804
805+ let filesInZip = 0
806+
800807 archive . pipe ( output )
801808 archive . on ( 'error' , reject )
802809
@@ -808,16 +815,24 @@ class Socket {
808815
809816 files . forEach ( file => {
810817 archive . file ( path . join ( envFolder , file ) , { name : path . join ( 'node_modules' , file ) } )
818+ filesInZip += 1
811819 } )
812820
813- archive . finalize ( )
821+ if ( filesInZip ) {
822+ archive . finalize ( )
823+ } else {
824+ fs . unlinkSync ( this . getSocketEnvZip ( ) )
825+ resolve ( )
826+ }
827+
814828 output . on ( 'close' , ( ) => {
815829 resolve ( )
816830 } )
817831 } )
818832 }
819833
820834 updateEnvCall ( method ) {
835+ debug ( 'updateEnvCall' )
821836 return new Promise ( ( resolve , reject ) => {
822837 const form = new FormData ( )
823838
@@ -876,7 +891,9 @@ class Socket {
876891 const resp = await this . socketEnvShouldBeUpdated ( )
877892 if ( resp ) {
878893 await this . createEnvZip ( )
879- return this . updateEnvCall ( resp )
894+ if ( ! this . isEmptyEnv ( ) ) {
895+ return this . updateEnvCall ( resp )
896+ }
880897 }
881898 return 'No need to update'
882899 }
@@ -910,7 +927,13 @@ class Socket {
910927 const form = new FormData ( )
911928
912929 form . append ( 'name' , this . name )
913- form . append ( 'environment' , this . name )
930+
931+ if ( this . isEmptyEnv ( ) ) {
932+ debug ( 'environment is null' )
933+ form . append ( 'environment' , '' )
934+ } else {
935+ form . append ( 'environment' , this . name )
936+ }
914937
915938 if ( config ) {
916939 form . append ( 'config' , JSON . stringify ( config ) )
0 commit comments