Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/base/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ pub trait GetRuntimeContext {
fn get_runtime_context(
conf: &WorkerRuntimeOpts,
use_inspector: bool,
migrated: bool,
version: Option<&str>,
) -> impl Serialize {
serde_json::json!({
"target": env!("TARGET"),
"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
Expand Down Expand Up @@ -488,6 +490,7 @@ where
.unwrap_or_else(|| get_default_permissions(conf.to_worker_kind()));

struct Bootstrap {
migrated: bool,
waker: Arc<AtomicWaker>,
js_runtime: JsRuntime,
mem_check: Arc<MemCheck>,
Expand Down Expand Up @@ -637,6 +640,7 @@ where
.await?;

let RuntimeProviders {
migrated,
module_loader,
node_services,
npm_snapshot,
Expand Down Expand Up @@ -968,6 +972,7 @@ where
}

Ok(Bootstrap {
migrated,
waker,
js_runtime,
mem_check,
Expand Down Expand Up @@ -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);
Expand All @@ -1011,16 +1017,17 @@ where
serde_json::json!(RuntimeContext::get_runtime_context(
&conf,
has_inspector,
migrated,
option_env!("GIT_V_TAG"),
));

let tokens = {
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()))
})
};

Expand Down
5 changes: 4 additions & 1 deletion crates/deno_facade/eszip/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")),
Expand Down
12 changes: 12 additions & 0 deletions crates/deno_facade/eszip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async fn read_u32<R: futures::io::AsyncRead + Unpin>(
pub struct LazyLoadableEszip {
eszip: EszipV2,
maybe_data_section: Option<Arc<EszipDataSection>>,
migrated: bool,
}

impl std::ops::Deref for LazyLoadableEszip {
Expand All @@ -122,6 +123,7 @@ impl Clone for LazyLoadableEszip {
options: self.eszip.options,
},
maybe_data_section: self.maybe_data_section.clone(),
migrated: false,
}
}
}
Expand Down Expand Up @@ -156,6 +158,7 @@ impl LazyLoadableEszip {
Self {
eszip,
maybe_data_section,
migrated: false,
}
}

Expand Down Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions crates/deno_facade/module_loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod standalone;
pub mod util;

pub struct RuntimeProviders {
pub migrated: bool,
pub module_loader: Rc<dyn ModuleLoader>,
pub node_services: NodeExtInitServices,
pub npm_snapshot: Option<ValidSerializedNpmResolutionSnapshot>,
Expand Down
2 changes: 2 additions & 0 deletions crates/deno_facade/module_loader/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ pub async fn create_module_loader_for_eszip(
permissions_options: PermissionsOptions,
include_source_map: bool,
) -> Result<RuntimeProviders, AnyError> {
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();
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions ext/runtime/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
* target: string,
* kind: 'user' | 'main' | 'event',
* inspector: boolean,
* migrated: boolean,
* debug: boolean,
* version: {
* runtime: string,
Expand All @@ -532,6 +533,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
* }}
*/
const {
migrated,
target,
kind,
version,
Expand Down Expand Up @@ -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);
Expand Down