From c1c8eb3d558bedf6588179ae93737bd6afe5a368 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sun, 6 Aug 2023 00:47:15 +0100 Subject: build: allow disabling snapshots for dev (#20048) Closes #19399 (running without snapshots at all was suggested as an alternative solution). Adds a `__runtime_js_sources` pseudo-private feature to load extension JS sources at runtime for faster development, instead of building and loading snapshots or embedding sources in the binary. Will only work in a development environment obviously. Try running `cargo test --features __runtime_js_sources integration::node_unit_tests::os_test`. Then break some behaviour in `ext/node/polyfills/os.ts` e.g. make `function cpus() {}` return an empty array, and run it again. Fix and then run again. No more build time in between. --- cli/js.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'cli/js.rs') diff --git a/cli/js.rs b/cli/js.rs index 6a312a206..f87bf6d73 100644 --- a/cli/js.rs +++ b/cli/js.rs @@ -3,12 +3,20 @@ use deno_core::Snapshot; use log::debug; +#[cfg(not(feature = "__runtime_js_sources"))] static CLI_SNAPSHOT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin")); -pub fn deno_isolate_init() -> Snapshot { +pub fn deno_isolate_init() -> Option { debug!("Deno isolate init with snapshots."); - Snapshot::Static(CLI_SNAPSHOT) + #[cfg(not(feature = "__runtime_js_sources"))] + { + Some(Snapshot::Static(CLI_SNAPSHOT)) + } + #[cfg(feature = "__runtime_js_sources")] + { + None + } } #[cfg(test)] @@ -18,7 +26,7 @@ mod tests { #[test] fn runtime_snapshot() { let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - startup_snapshot: Some(deno_isolate_init()), + startup_snapshot: deno_isolate_init(), ..Default::default() }); js_runtime -- cgit v1.2.3