@@ -62,24 +62,37 @@ const RELATIVE_BUN_BUILDER: &str = include_str!("../loader_builder.bun.js");
62
62
63
63
const NSJAIL_CONFIG_RUN_BUN_CONTENT : & str = include_str ! ( "../nsjail/run.bun.config.proto" ) ;
64
64
65
+ pub const BUN_LOCK_SPLIT : & str = "\n //bun.lock\n " ;
65
66
pub const BUN_LOCKB_SPLIT : & str = "\n //bun.lockb\n " ;
67
+ pub const BUN_LOCK_SPLIT_WINDOWS : & str = "\r \n //bun.lock\r \n " ;
66
68
pub const BUN_LOCKB_SPLIT_WINDOWS : & str = "\r \n //bun.lockb\r \n " ;
67
69
68
70
pub const EMPTY_FILE : & str = "<empty>" ;
69
71
70
- fn split_lockfile ( lockfile : & str ) -> ( & str , Option < & str > , bool ) {
71
- if let Some ( index) = lockfile. find ( BUN_LOCKB_SPLIT ) {
72
+ /// Returns (package.json, bun.lock(b), is_empty, is_binary)
73
+ fn split_lockfile ( lockfile : & str ) -> ( & str , Option < & str > , bool , bool ) {
74
+ if let Some ( index) = lockfile. find ( BUN_LOCK_SPLIT ) {
75
+ // Split using "\n//bun.lock\n"
76
+ let ( before, after_with_sep) = lockfile. split_at ( index) ;
77
+ let after = & after_with_sep[ BUN_LOCK_SPLIT . len ( ) ..] ;
78
+ ( before, Some ( after) , after == EMPTY_FILE , false )
79
+ } else if let Some ( index) = lockfile. find ( BUN_LOCKB_SPLIT ) {
72
80
// Split using "\n//bun.lockb\n"
73
81
let ( before, after_with_sep) = lockfile. split_at ( index) ;
74
82
let after = & after_with_sep[ BUN_LOCKB_SPLIT . len ( ) ..] ;
75
- ( before, Some ( after) , after == EMPTY_FILE )
83
+ ( before, Some ( after) , after == EMPTY_FILE , true )
84
+ } else if let Some ( index) = lockfile. find ( BUN_LOCK_SPLIT_WINDOWS ) {
85
+ // Split using "\r\n//bun.lock\r\n"
86
+ let ( before, after_with_sep) = lockfile. split_at ( index) ;
87
+ let after = & after_with_sep[ BUN_LOCK_SPLIT_WINDOWS . len ( ) ..] ;
88
+ ( before, Some ( after) , after == EMPTY_FILE , false )
76
89
} else if let Some ( index) = lockfile. find ( BUN_LOCKB_SPLIT_WINDOWS ) {
77
90
// Split using "\r\n//bun.lockb\r\n"
78
91
let ( before, after_with_sep) = lockfile. split_at ( index) ;
79
92
let after = & after_with_sep[ BUN_LOCKB_SPLIT_WINDOWS . len ( ) ..] ;
80
- ( before, Some ( after) , after == EMPTY_FILE )
93
+ ( before, Some ( after) , after == EMPTY_FILE , true )
81
94
} else {
82
- ( lockfile, None , false )
95
+ ( lockfile, None , false , false )
83
96
}
84
97
}
85
98
@@ -199,18 +212,18 @@ pub async fn gen_bun_lockfile(
199
212
}
200
213
if !npm_mode {
201
214
#[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
202
- content. push_str ( BUN_LOCKB_SPLIT ) ;
215
+ content. push_str ( BUN_LOCK_SPLIT ) ;
203
216
204
217
#[ cfg( target_os = "windows" ) ]
205
- content. push_str ( BUN_LOCKB_SPLIT_WINDOWS ) ;
218
+ content. push_str ( BUN_LOCK_SPLIT_WINDOWS ) ;
206
219
207
220
{
208
- let file = format ! ( "{job_dir}/bun.lockb " ) ;
221
+ let file = format ! ( "{job_dir}/bun.lock " ) ;
209
222
if !empty_deps && tokio:: fs:: metadata ( & file) . await . is_ok ( ) {
210
223
let mut file = File :: open ( & file) . await ?;
211
- let mut buf = vec ! [ ] ;
212
- file. read_to_end ( & mut buf) . await ?;
213
- content. push_str ( & base64 :: engine :: general_purpose :: STANDARD . encode ( & buf) ) ;
224
+ let mut buf = String :: default ( ) ;
225
+ file. read_to_string ( & mut buf) . await ?;
226
+ content. push_str ( & buf) ;
214
227
} else {
215
228
content. push_str ( & EMPTY_FILE ) ;
216
229
}
@@ -277,7 +290,7 @@ pub async fn install_bun_lockfile(
277
290
. env_clear ( )
278
291
. envs ( PROXY_ENVS . clone ( ) )
279
292
. envs ( common_bun_proc_envs)
280
- . args ( vec ! [ "install" ] )
293
+ . args ( vec ! [ "install" , "--save-text-lockfile" ] )
281
294
. stdout ( Stdio :: piped ( ) )
282
295
. stderr ( Stdio :: piped ( ) ) ;
283
296
@@ -785,26 +798,30 @@ async fn compute_bundle_local_and_remote_path(
785
798
}
786
799
787
800
pub async fn prepare_job_dir ( reqs : & str , job_dir : & str ) -> Result < ( ) > {
788
- let ( pkg, lock, empty) = split_lockfile ( reqs) ;
801
+ let ( pkg, lock, empty, is_binary ) = split_lockfile ( reqs) ;
789
802
let _ = write_file ( job_dir, "package.json" , pkg) ?;
790
803
791
804
if !empty {
792
805
if let Some ( lock) = lock {
793
- let _ = write_lockb ( lock, job_dir) . await ?;
806
+ let _ = write_lock ( lock, job_dir, is_binary ) . await ?;
794
807
}
795
808
}
796
809
797
810
Ok ( ( ) )
798
811
}
799
- async fn write_lockb ( splitted_lockb_2 : & str , job_dir : & str ) -> Result < ( ) > {
800
- write_file_binary (
801
- job_dir,
802
- "bun.lockb" ,
803
- & base64:: engine:: general_purpose:: STANDARD
804
- . decode ( splitted_lockb_2)
805
- . map_err ( |_| error:: Error :: InternalErr ( "Could not decode bun.lockb" . to_string ( ) ) ) ?,
806
- )
807
- . await ?;
812
+ async fn write_lock ( splitted_lockb_2 : & str , job_dir : & str , is_binary : bool ) -> Result < ( ) > {
813
+ if is_binary {
814
+ write_file_binary (
815
+ job_dir,
816
+ "bun.lockb" ,
817
+ & base64:: engine:: general_purpose:: STANDARD
818
+ . decode ( splitted_lockb_2)
819
+ . map_err ( |_| error:: Error :: InternalErr ( format ! ( "Could not decode bun.lockb" ) ) ) ?,
820
+ )
821
+ . await ?;
822
+ } else {
823
+ write_file ( job_dir, "bun.lock" , splitted_lockb_2) ?;
824
+ } ;
808
825
Ok ( ( ) )
809
826
}
810
827
@@ -900,26 +917,26 @@ pub async fn handle_bun_job(
900
917
} else if let Some ( codebase) = codebase. as_ref ( ) {
901
918
pull_codebase ( & job. workspace_id , codebase, job_dir) . await ?;
902
919
} else if let Some ( reqs) = requirements_o. as_ref ( ) {
903
- let ( pkg, lock, empty) = split_lockfile ( reqs) ;
920
+ let ( pkg, lock, empty, is_binary ) = split_lockfile ( reqs) ;
904
921
905
922
if lock. is_none ( ) && !annotation. npm {
906
923
return Err ( error:: Error :: ExecutionErr (
907
- format ! ( "Invalid requirements, expected to find //bun.lockb split pattern in reqs. Found: |{reqs}|" )
924
+ format ! ( "Invalid requirements, expected to find //bun.lock{} split pattern in reqs. Found: |{reqs}|" , if is_binary { "b" } else { "" } )
908
925
) ) ;
909
926
}
910
927
911
928
let _ = write_file ( job_dir, "package.json" , pkg) ?;
912
- let lockb = if annotation. npm { "" } else { lock. unwrap ( ) } ;
929
+ let lock = if annotation. npm { "" } else { lock. unwrap ( ) } ;
913
930
if !empty {
914
931
let mut skip_install = false ;
915
932
let mut create_buntar = false ;
916
933
let mut buntar_path = "" . to_string ( ) ;
917
934
918
935
if !annotation. npm {
919
- let _ = write_lockb ( lockb , job_dir) . await ?;
936
+ let _ = write_lock ( lock , job_dir, is_binary ) . await ?;
920
937
921
938
let mut sha_path = sha2:: Sha256 :: new ( ) ;
922
- sha_path. update ( lockb . as_bytes ( ) ) ;
939
+ sha_path. update ( lock . as_bytes ( ) ) ;
923
940
924
941
let buntar_name =
925
942
base64:: engine:: general_purpose:: URL_SAFE . encode ( sha_path. finalize ( ) ) ;
@@ -962,7 +979,7 @@ pub async fn handle_bun_job(
962
979
Some ( & vec ! [
963
980
"main.ts" . to_string( ) ,
964
981
"package.json" . to_string( ) ,
965
- "bun.lockb" . to_string( ) ,
982
+ if is_binary { "bun.lockb" } else { "bun.lock" } . to_string( ) ,
966
983
"shared" . to_string( ) ,
967
984
"bunfig.toml" . to_string( ) ,
968
985
] ) ,
@@ -1592,25 +1609,29 @@ pub async fn start_worker(
1592
1609
if let Some ( codebase) = codebase. as_ref ( ) {
1593
1610
pull_codebase ( w_id, codebase, job_dir) . await ?;
1594
1611
} else if let Some ( reqs) = requirements_o {
1595
- let ( pkg, lock, empty) = split_lockfile ( & reqs) ;
1612
+ let ( pkg, lock, empty, is_binary ) = split_lockfile ( & reqs) ;
1596
1613
if lock. is_none ( ) {
1597
1614
return Err ( error:: Error :: ExecutionErr (
1598
1615
format ! ( "Invalid requirements, expected to find //bun.lockb split pattern in reqs. Found: |{reqs}|" )
1599
1616
) ) ;
1600
1617
}
1601
1618
let _ = write_file ( job_dir, "package.json" , pkg) ?;
1602
- let lockb = lock. unwrap ( ) ;
1619
+ let lock = lock. unwrap ( ) ;
1603
1620
if !empty {
1604
- let _ = write_file_binary (
1605
- job_dir,
1606
- "bun.lockb" ,
1607
- & base64:: engine:: general_purpose:: STANDARD
1608
- . decode ( lockb)
1609
- . map_err ( |_| {
1610
- error:: Error :: InternalErr ( "Could not decode bun.lockb" . to_string ( ) )
1611
- } ) ?,
1612
- )
1613
- . await ?;
1621
+ if is_binary {
1622
+ let _ = write_file_binary (
1623
+ job_dir,
1624
+ "bun.lockb" ,
1625
+ & base64:: engine:: general_purpose:: STANDARD
1626
+ . decode ( lock)
1627
+ . map_err ( |_| {
1628
+ error:: Error :: InternalErr ( "Could not decode bun.lockb" . to_string ( ) )
1629
+ } ) ?,
1630
+ )
1631
+ . await ?;
1632
+ } else {
1633
+ write_file ( job_dir, "bun.lock" , lock) ?;
1634
+ }
1614
1635
1615
1636
install_bun_lockfile (
1616
1637
& mut mem_peak,
0 commit comments