Skip to content

Commit 29d3743

Browse files
authored
fix: if runtime is created with old eszip, emit warning message (#581)
* fix: if runtime is created with old eszip, emit warning message * stamp: wording
1 parent 5b8e3a2 commit 29d3743

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

crates/base/src/runtime/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ pub trait GetRuntimeContext {
238238
fn get_runtime_context(
239239
conf: &WorkerRuntimeOpts,
240240
use_inspector: bool,
241+
migrated: bool,
241242
version: Option<&str>,
242243
) -> impl Serialize {
243244
serde_json::json!({
244245
"target": env!("TARGET"),
245246
"kind": conf.to_worker_kind().to_string(),
246247
"debug": cfg!(debug_assertions),
247248
"inspector": use_inspector,
249+
"migrated": migrated,
248250
"version": {
249251
"runtime": version.unwrap_or("0.1.0"),
250252
"deno": MAYBE_DENO_VERSION
@@ -488,6 +490,7 @@ where
488490
.unwrap_or_else(|| get_default_permissions(conf.to_worker_kind()));
489491

490492
struct Bootstrap {
493+
migrated: bool,
491494
waker: Arc<AtomicWaker>,
492495
js_runtime: JsRuntime,
493496
mem_check: Arc<MemCheck>,
@@ -637,6 +640,7 @@ where
637640
.await?;
638641

639642
let RuntimeProviders {
643+
migrated,
640644
module_loader,
641645
node_services,
642646
npm_snapshot,
@@ -968,6 +972,7 @@ where
968972
}
969973

970974
Ok(Bootstrap {
975+
migrated,
971976
waker,
972977
js_runtime,
973978
mem_check,
@@ -996,6 +1001,7 @@ where
9961001
bootstrap.js_runtime.v8_isolate().exit();
9971002

9981003
let has_inspector = bootstrap.has_inspector;
1004+
let migrated = bootstrap.migrated;
9991005
let context = bootstrap.context.take().unwrap_or_default();
10001006
let mut bootstrap = scopeguard::guard(bootstrap, |mut it| {
10011007
cleanup_js_runtime(&mut it.js_runtime);
@@ -1011,16 +1017,17 @@ where
10111017
serde_json::json!(RuntimeContext::get_runtime_context(
10121018
&conf,
10131019
has_inspector,
1020+
migrated,
10141021
option_env!("GIT_V_TAG"),
10151022
));
10161023

10171024
let tokens = {
10181025
let op_state = locker.op_state();
10191026
let resource_table = &mut op_state.borrow_mut().resource_table;
10201027
serde_json::json!({
1021-
"terminationRequestToken":
1022-
resource_table
1023-
.add(DropToken(termination_request_token.clone()))
1028+
"terminationRequestToken":
1029+
resource_table
1030+
.add(DropToken(termination_request_token.clone()))
10241031
})
10251032
};
10261033

crates/deno_facade/eszip/migrate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ pub async fn try_migrate_if_needed(
6060
}
6161
};
6262

63-
result
63+
result.map(|mut it| {
64+
it.set_migrated(true);
65+
it
66+
})
6467
}
6568

6669
None => Err(anyhow!("failed to migrate (found unexpected error)")),

crates/deno_facade/eszip/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ async fn read_u32<R: futures::io::AsyncRead + Unpin>(
9797
pub struct LazyLoadableEszip {
9898
eszip: EszipV2,
9999
maybe_data_section: Option<Arc<EszipDataSection>>,
100+
migrated: bool,
100101
}
101102

102103
impl std::ops::Deref for LazyLoadableEszip {
@@ -122,6 +123,7 @@ impl Clone for LazyLoadableEszip {
122123
options: self.eszip.options,
123124
},
124125
maybe_data_section: self.maybe_data_section.clone(),
126+
migrated: false,
125127
}
126128
}
127129
}
@@ -156,6 +158,7 @@ impl LazyLoadableEszip {
156158
Self {
157159
eszip,
158160
maybe_data_section,
161+
migrated: false,
159162
}
160163
}
161164

@@ -215,6 +218,15 @@ impl LazyLoadableEszip {
215218

216219
Ok(())
217220
}
221+
222+
pub fn migrated(&self) -> bool {
223+
self.migrated
224+
}
225+
226+
pub fn set_migrated(&mut self, value: bool) -> &mut Self {
227+
self.migrated = value;
228+
self
229+
}
218230
}
219231

220232
#[derive(Debug, Clone, Copy, Default)]

crates/deno_facade/module_loader/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod standalone;
1616
pub mod util;
1717

1818
pub struct RuntimeProviders {
19+
pub migrated: bool,
1920
pub module_loader: Rc<dyn ModuleLoader>,
2021
pub node_services: NodeExtInitServices,
2122
pub npm_snapshot: Option<ValidSerializedNpmResolutionSnapshot>,

crates/deno_facade/module_loader/standalone.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ pub async fn create_module_loader_for_eszip(
552552
permissions_options: PermissionsOptions,
553553
include_source_map: bool,
554554
) -> Result<RuntimeProviders, AnyError> {
555+
let migrated = eszip.migrated();
555556
let current_exe_path = std::env::current_exe().unwrap();
556557
let current_exe_name =
557558
current_exe_path.file_name().unwrap().to_string_lossy();
@@ -810,6 +811,7 @@ pub async fn create_module_loader_for_eszip(
810811
});
811812

812813
Ok(RuntimeProviders {
814+
migrated,
813815
module_loader: module_loader.clone(),
814816
node_services: NodeExtInitServices {
815817
node_require_loader: module_loader.clone(),

ext/runtime/js/bootstrap.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
520520
* target: string,
521521
* kind: 'user' | 'main' | 'event',
522522
* inspector: boolean,
523+
* migrated: boolean,
523524
* debug: boolean,
524525
* version: {
525526
* runtime: string,
@@ -532,6 +533,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
532533
* }}
533534
*/
534535
const {
536+
migrated,
535537
target,
536538
kind,
537539
version,
@@ -588,6 +590,13 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
588590
setLanguage("en");
589591

590592
core.addMainModuleHandler((main) => {
593+
if (migrated) {
594+
globalThis.console.warn(
595+
"It appears this function was deployed using an older version of Supabase CLI.\n",
596+
"For best performance and compatibility we recommend re-deploying the function using the latest version of the CLI.",
597+
);
598+
}
599+
591600
// Find declarative fetch handler
592601
if (ObjectHasOwn(main, "default")) {
593602
registerDeclarativeServer(main.default);

0 commit comments

Comments
 (0)