@@ -218,6 +218,7 @@ use model::{
218218 source_packages:: {
219219 types:: SourcePackage ,
220220 upload_download:: upload_package,
221+ SourcePackageModel ,
221222 } ,
222223 udf_config:: {
223224 types:: UdfConfig ,
@@ -340,7 +341,7 @@ pub struct ApplyConfigArgs {
340341 pub schema_id : Option < String > ,
341342 pub modules : Vec < ModuleConfig > ,
342343 pub udf_config : UdfConfig ,
343- pub source_package : Option < SourcePackage > ,
344+ pub source_package : SourcePackage ,
344345 pub analyze_results : BTreeMap < CanonicalizedModulePath , AnalyzedModule > ,
345346}
346347
@@ -1526,7 +1527,7 @@ impl<RT: Runtime> Application<RT> {
15261527 & self ,
15271528 udf_config : UdfConfig ,
15281529 new_modules : Vec < ModuleConfig > ,
1529- source_package : Option < SourcePackage > ,
1530+ source_package : SourcePackage ,
15301531 ) -> anyhow:: Result < Result < BTreeMap < CanonicalizedModulePath , AnalyzedModule > , JsError > > {
15311532 self . runner
15321533 . analyze ( udf_config, new_modules, source_package)
@@ -1746,7 +1747,7 @@ impl<RT: Runtime> Application<RT> {
17461747 config_metadata. clone ( ) ,
17471748 modules,
17481749 udf_config,
1749- source_package,
1750+ Some ( source_package) ,
17501751 analyze_results,
17511752 schema_id,
17521753 )
@@ -1837,7 +1838,7 @@ impl<RT: Runtime> Application<RT> {
18371838 & self ,
18381839 modules : & Vec < ModuleConfig > ,
18391840 external_deps_id_and_pkg : Option < ( ExternalDepsPackageId , ExternalDepsPackage ) > ,
1840- ) -> anyhow:: Result < Option < SourcePackage > > {
1841+ ) -> anyhow:: Result < SourcePackage > {
18411842 // If there are any node actions, turn on the lambdas.
18421843 if modules
18431844 . iter ( )
@@ -1879,12 +1880,12 @@ impl<RT: Runtime> Application<RT> {
18791880 tracing:: info!( "Source package size: {}" , package_size) ;
18801881 log_source_package_size_bytes_total ( package_size) ;
18811882
1882- Ok ( Some ( SourcePackage {
1883+ Ok ( SourcePackage {
18831884 storage_key,
18841885 sha256,
18851886 external_deps_package_id,
18861887 package_size,
1887- } ) )
1888+ } )
18881889 }
18891890
18901891 // Clear all records for specified tables concurrently, potentially taking
@@ -1915,6 +1916,11 @@ impl<RT: Runtime> Application<RT> {
19151916 )
19161917 . await ?;
19171918
1919+ // Write (and commit) the module source to S3.
1920+ // This will become a dangling reference since the _modules entry won't
1921+ // be committed to the database, but we have to deal with those anyway.
1922+ let source_package = self . upload_package ( & vec ! [ module. clone( ) ] , None ) . await ?;
1923+
19181924 let mut tx = self . begin ( identity. clone ( ) ) . await ?;
19191925
19201926 // Use the last pushed version. If there hasn't been a push
@@ -1936,7 +1942,11 @@ impl<RT: Runtime> Application<RT> {
19361942 } ;
19371943
19381944 let analyze_results = self
1939- . analyze ( udf_config. clone ( ) , vec ! [ module. clone( ) ] , None )
1945+ . analyze (
1946+ udf_config. clone ( ) ,
1947+ vec ! [ module. clone( ) ] ,
1948+ source_package. clone ( ) ,
1949+ )
19401950 . await ?
19411951 . map_err ( |js_error| {
19421952 let metadata = ErrorMetadata :: bad_request (
@@ -1963,16 +1973,20 @@ impl<RT: Runtime> Application<RT> {
19631973 }
19641974 let analyzed_function = analyzed_function. context ( "Missing default export." ) ?;
19651975
1976+ let source_package_id = SourcePackageModel :: new ( & mut tx) . put ( source_package) . await ?;
1977+
19661978 // 3. Add the module
19671979 ModuleModel :: new ( & mut tx)
1968- . put_standalone (
1980+ . put (
19691981 CanonicalizedComponentModulePath {
19701982 component : ComponentId :: Root ,
19711983 module_path : module_path. clone ( ) ,
19721984 } ,
19731985 module. source ,
1986+ source_package_id,
19741987 module. source_map ,
1975- analyzed_module,
1988+ Some ( analyzed_module) ,
1989+ ModuleEnvironment :: Isolate ,
19761990 )
19771991 . await ?;
19781992
0 commit comments