diff --git a/crates/base/src/runtime/mod.rs b/crates/base/src/runtime/mod.rs index 14e5e0a0e..f3e7b66bb 100644 --- a/crates/base/src/runtime/mod.rs +++ b/crates/base/src/runtime/mod.rs @@ -238,6 +238,7 @@ pub trait GetRuntimeContext { fn get_runtime_context( conf: &WorkerRuntimeOpts, use_inspector: bool, + migrated: bool, version: Option<&str>, ) -> impl Serialize { serde_json::json!({ @@ -245,6 +246,7 @@ pub trait GetRuntimeContext { "kind": conf.to_worker_kind().to_string(), "debug": cfg!(debug_assertions), "inspector": use_inspector, + "migrated": migrated, "version": { "runtime": version.unwrap_or("0.1.0"), "deno": MAYBE_DENO_VERSION @@ -488,6 +490,7 @@ where .unwrap_or_else(|| get_default_permissions(conf.to_worker_kind())); struct Bootstrap { + migrated: bool, waker: Arc, js_runtime: JsRuntime, mem_check: Arc, @@ -637,6 +640,7 @@ where .await?; let RuntimeProviders { + migrated, module_loader, node_services, npm_snapshot, @@ -968,6 +972,7 @@ where } Ok(Bootstrap { + migrated, waker, js_runtime, mem_check, @@ -996,6 +1001,7 @@ where bootstrap.js_runtime.v8_isolate().exit(); let has_inspector = bootstrap.has_inspector; + let migrated = bootstrap.migrated; let context = bootstrap.context.take().unwrap_or_default(); let mut bootstrap = scopeguard::guard(bootstrap, |mut it| { cleanup_js_runtime(&mut it.js_runtime); @@ -1011,6 +1017,7 @@ where serde_json::json!(RuntimeContext::get_runtime_context( &conf, has_inspector, + migrated, option_env!("GIT_V_TAG"), )); @@ -1018,9 +1025,9 @@ where let op_state = locker.op_state(); let resource_table = &mut op_state.borrow_mut().resource_table; serde_json::json!({ - "terminationRequestToken": - resource_table - .add(DropToken(termination_request_token.clone())) + "terminationRequestToken": + resource_table + .add(DropToken(termination_request_token.clone())) }) }; diff --git a/crates/deno_facade/eszip/migrate.rs b/crates/deno_facade/eszip/migrate.rs index 1e0adc618..58b888c4e 100644 --- a/crates/deno_facade/eszip/migrate.rs +++ b/crates/deno_facade/eszip/migrate.rs @@ -60,7 +60,10 @@ pub async fn try_migrate_if_needed( } }; - result + result.map(|mut it| { + it.set_migrated(true); + it + }) } None => Err(anyhow!("failed to migrate (found unexpected error)")), diff --git a/crates/deno_facade/eszip/mod.rs b/crates/deno_facade/eszip/mod.rs index 2506b8d80..134830aa6 100644 --- a/crates/deno_facade/eszip/mod.rs +++ b/crates/deno_facade/eszip/mod.rs @@ -97,6 +97,7 @@ async fn read_u32( pub struct LazyLoadableEszip { eszip: EszipV2, maybe_data_section: Option>, + migrated: bool, } impl std::ops::Deref for LazyLoadableEszip { @@ -122,6 +123,7 @@ impl Clone for LazyLoadableEszip { options: self.eszip.options, }, maybe_data_section: self.maybe_data_section.clone(), + migrated: false, } } } @@ -156,6 +158,7 @@ impl LazyLoadableEszip { Self { eszip, maybe_data_section, + migrated: false, } } @@ -215,6 +218,15 @@ impl LazyLoadableEszip { Ok(()) } + + pub fn migrated(&self) -> bool { + self.migrated + } + + pub fn set_migrated(&mut self, value: bool) -> &mut Self { + self.migrated = value; + self + } } #[derive(Debug, Clone, Copy, Default)] diff --git a/crates/deno_facade/module_loader/mod.rs b/crates/deno_facade/module_loader/mod.rs index 94a1e4c92..dd9fb2bd0 100644 --- a/crates/deno_facade/module_loader/mod.rs +++ b/crates/deno_facade/module_loader/mod.rs @@ -16,6 +16,7 @@ pub mod standalone; pub mod util; pub struct RuntimeProviders { + pub migrated: bool, pub module_loader: Rc, pub node_services: NodeExtInitServices, pub npm_snapshot: Option, diff --git a/crates/deno_facade/module_loader/standalone.rs b/crates/deno_facade/module_loader/standalone.rs index fb243647b..84e7cb6d4 100644 --- a/crates/deno_facade/module_loader/standalone.rs +++ b/crates/deno_facade/module_loader/standalone.rs @@ -552,6 +552,7 @@ pub async fn create_module_loader_for_eszip( permissions_options: PermissionsOptions, include_source_map: bool, ) -> Result { + let migrated = eszip.migrated(); let current_exe_path = std::env::current_exe().unwrap(); let current_exe_name = current_exe_path.file_name().unwrap().to_string_lossy(); @@ -810,6 +811,7 @@ pub async fn create_module_loader_for_eszip( }); Ok(RuntimeProviders { + migrated, module_loader: module_loader.clone(), node_services: NodeExtInitServices { node_require_loader: module_loader.clone(), diff --git a/ext/runtime/js/bootstrap.js b/ext/runtime/js/bootstrap.js index 4f73a2fdf..5dc5689ac 100644 --- a/ext/runtime/js/bootstrap.js +++ b/ext/runtime/js/bootstrap.js @@ -520,6 +520,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => { * target: string, * kind: 'user' | 'main' | 'event', * inspector: boolean, + * migrated: boolean, * debug: boolean, * version: { * runtime: string, @@ -532,6 +533,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => { * }} */ const { + migrated, target, kind, version, @@ -588,6 +590,13 @@ globalThis.bootstrapSBEdge = (opts, ctx) => { setLanguage("en"); core.addMainModuleHandler((main) => { + if (migrated) { + globalThis.console.warn( + "It appears this function was deployed using an older version of Supabase CLI.\n", + "For best performance and compatibility we recommend re-deploying the function using the latest version of the CLI.", + ); + } + // Find declarative fetch handler if (ObjectHasOwn(main, "default")) { registerDeclarativeServer(main.default);