Skip to content

Commit ee980c9

Browse files
nipunn1313Convex, Inc.
authored and
Convex, Inc.
committed
Use functions for accessing bundled system UDFs (#24174)
Sets us up to overlay system udfs more easily rather than directly accessing global variables. GitOrigin-RevId: 61ae14269bbf2196cfdd3a9c6f9d60c833a27197
1 parent cb39589 commit ee980c9

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

crates/isolate/src/bundled_js.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
use value::sha256::Sha256Digest;
2+
13
/// This file includes the generated table of all of the system JS
24
/// files, which we mount under "_system/" in the module namespace.
35
mod system_udf_js_data {
46
include!(concat!(env!("OUT_DIR"), "/system_udf_js_data.rs"));
57
}
6-
pub use self::system_udf_js_data::FILES as SYSTEM_UDF_FILES;
7-
#[allow(dead_code)]
8-
static UNUSED: [u8; 32] = self::system_udf_js_data::FILES_SHA256;
98

109
/// This file includes the generated table of all of the system JS
1110
/// files, which we mount under "_system/" in the module namespace.
1211
mod node_executor_js_data {
1312
include!(concat!(env!("OUT_DIR"), "/node_executor_js_data.rs"));
1413
}
15-
pub use self::node_executor_js_data::{
16-
FILES as NODE_EXECUTOR_FILES,
17-
FILES_SHA256 as NODE_EXECUTOR_SHA256,
18-
};
14+
15+
/// Source and sourcemap
16+
pub type BundledJsFile = (&'static str, Option<&'static str>);
17+
18+
pub fn system_udf_file(path: &str) -> Option<BundledJsFile> {
19+
system_udf_js_data::FILES.get(path).copied()
20+
}
21+
pub fn system_udf_files_sha256() -> Sha256Digest {
22+
system_udf_js_data::FILES_SHA256.into()
23+
}
24+
pub fn node_executor_file(path: &str) -> Option<BundledJsFile> {
25+
node_executor_js_data::FILES.get(path).copied()
26+
}
27+
pub fn node_executor_files_sha256() -> Sha256Digest {
28+
node_executor_js_data::FILES_SHA256.into()
29+
}
1930

2031
#[cfg(any(test, feature = "testing"))]
2132
pub const UDF_TEST_BUNDLE_PATH: &str = concat!(env!("OUT_DIR"), "/udf_test_bundle.json");

crates/isolate/src/execution_scope.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use serde_json::Value as JsonValue;
3535
use value::heap_size::HeapSize;
3636

3737
use crate::{
38-
bundled_js::SYSTEM_UDF_FILES,
38+
bundled_js::system_udf_file,
3939
environment::IsolateEnvironment,
4040
helpers::{
4141
self,
@@ -414,8 +414,7 @@ impl<'a, 'b: 'a, RT: Runtime, E: IsolateEnvironment<RT>> ExecutionScope<'a, 'b,
414414

415415
// Overlay our "_system/" files on top of the user's UDFs.
416416
if let Some(system_path) = module_path.strip_prefix(SYSTEM_PREFIX) {
417-
let (source, source_map) = SYSTEM_UDF_FILES
418-
.get(system_path)
417+
let (source, source_map) = system_udf_file(system_path)
419418
.ok_or_else(|| SystemModuleNotFoundError::new(system_path))?;
420419
return Ok((
421420
source.to_string(),

crates/isolate/src/isolate2/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
FunctionId,
2222
};
2323
use crate::{
24-
bundled_js::SYSTEM_UDF_FILES,
24+
bundled_js::system_udf_file,
2525
isolate::SETUP_URL,
2626
strings,
2727
};
@@ -85,9 +85,8 @@ impl Context {
8585

8686
ctx.enter(session, |mut ctx| {
8787
let setup_url = ModuleSpecifier::parse(SETUP_URL)?;
88-
let (source, _) = SYSTEM_UDF_FILES
89-
.get("setup.js")
90-
.ok_or_else(|| anyhow!("Setup module not found"))?;
88+
let (source, _) =
89+
system_udf_file("setup.js").ok_or_else(|| anyhow!("Setup module not found"))?;
9190
let unresolved_imports = ctx.register_module(&setup_url, source)?;
9291
anyhow::ensure!(
9392
unresolved_imports.is_empty(),

crates/isolate/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ mod user_error;
4040
pub mod test_helpers;
4141

4242
pub use self::{
43-
bundled_js::{
44-
NODE_EXECUTOR_FILES,
45-
NODE_EXECUTOR_SHA256,
46-
},
4743
client::{
4844
ActionCallbacks,
4945
ActionRequest,

crates/node_executor/src/local.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use futures::{
1313
FutureExt,
1414
StreamExt,
1515
};
16-
use isolate::NODE_EXECUTOR_FILES;
16+
use isolate::bundled_js::node_executor_file;
1717
use serde_json::Value as JsonValue;
1818
use tempfile::TempDir;
1919
use tokio::process::Command as TokioCommand;
@@ -46,9 +46,8 @@ impl LocalNodeExecutor {
4646
pub fn new(node_process_timeout: Duration) -> anyhow::Result<Self> {
4747
// Write the source of local.cjs to a temp file.
4848
let source_dir = TempDir::new()?;
49-
let (source, source_map) = NODE_EXECUTOR_FILES
50-
.get("local.cjs")
51-
.expect("local.cjs not generated!");
49+
let (source, source_map) =
50+
node_executor_file("local.cjs").expect("local.cjs not generated!");
5251
let source_map = source_map.context("Missing local.cjs.map")?;
5352
let source_path = source_dir.path().join("local.cjs");
5453
let source_map_path = source_dir.path().join("local.cjs.map");

0 commit comments

Comments
 (0)