diff --git a/crates/base/src/js_worker.rs b/crates/base/src/js_worker.rs index 2f1169ecd..b5c9a549e 100644 --- a/crates/base/src/js_worker.rs +++ b/crates/base/src/js_worker.rs @@ -158,13 +158,6 @@ impl MainWorker { stream: UnixStream, shutdown_tx: oneshot::Sender<()>, ) -> Result<(), Error> { - // set bootstrap options - // TODO: Migrate this to `supacore` - let script = format!(r#"globalThis.__build_target = "{}""#, env!("TARGET")); - self.js_runtime - .execute_script::(located_script_name!(), script.into()) - .expect("Failed to execute bootstrap script"); - let (unix_stream_tx, unix_stream_rx) = mpsc::unbounded_channel::(); if let Err(e) = unix_stream_tx.send(stream) { bail!(e) @@ -329,12 +322,6 @@ impl UserWorker { }); // set bootstrap options - // TODO: Move to `supacore` - let script = format!("globalThis.__build_target = \"{}\"", env!("TARGET")); - self.js_runtime - .execute_script::(&located_script_name!(), script.into()) - .expect("Failed to execute bootstrap script"); - let (unix_stream_tx, unix_stream_rx) = mpsc::unbounded_channel::(); if let Err(e) = unix_stream_tx.send(stream) { bail!(e) diff --git a/crates/sb_core/build.rs b/crates/sb_core/build.rs new file mode 100644 index 000000000..f39d6d2f4 --- /dev/null +++ b/crates/sb_core/build.rs @@ -0,0 +1,7 @@ +// build script +use std::env; + +fn main() { + println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); + println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap()); +} diff --git a/crates/sb_core/js/bootstrap.js b/crates/sb_core/js/bootstrap.js index 03845a319..789059bd8 100644 --- a/crates/sb_core/js/bootstrap.js +++ b/crates/sb_core/js/bootstrap.js @@ -22,6 +22,7 @@ import * as tls from "ext:deno_net/02_tls.js"; import * as net from "ext:deno_net/01_net.js"; import * as response from "ext:deno_fetch/23_response.js"; import * as request from "ext:deno_fetch/23_request.js"; +import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js"; import { SUPABASE_USER_WORKERS } from "ext:sb_user_workers/user_workers.js"; import { SUPABASE_ENV } from "ext:sb_env/env.js"; @@ -537,6 +538,15 @@ delete globalThis.bootstrap; ObjectDefineProperties(globalThis, globalScope); +const globalProperties = { + Window: globalInterfaces.windowConstructorDescriptor, + window: getterOnly(() => globalThis), + self: getterOnly(() => globalThis), +}; + +ObjectDefineProperties(globalThis, globalProperties); +ObjectSetPrototypeOf(globalThis, Window.prototype); + // TODO: figure out if this is needed globalThis[webidl.brand] = webidl.brand; @@ -556,9 +566,8 @@ runtimeStart({ tsVersion: "NA", noColor: true, isTty: false, - target: "supabase", + target: ops.op_build_target(), }); -delete globalThis.__build_target; // set these overrides after runtimeStart ObjectDefineProperties(Deno, { diff --git a/crates/sb_core/runtime.rs b/crates/sb_core/runtime.rs index d7f27c703..984d8329e 100644 --- a/crates/sb_core/runtime.rs +++ b/crates/sb_core/runtime.rs @@ -10,7 +10,7 @@ use std::path::Path; #[op] fn op_main_module(state: &mut OpState) -> Result { let main = state.borrow::().to_string(); - let main_url = deno_core::resolve_url_or_path(&main, Path::new("./steve-jobs"))?; + let main_url = deno_core::resolve_url_or_path(&main, std::env::current_dir()?.as_path())?; if main_url.scheme() == "file" { let main_path = std::env::current_dir() .context("Failed to get current working directory")? @@ -24,8 +24,14 @@ fn op_main_module(state: &mut OpState) -> Result { Ok(main) } +#[op] +fn op_build_target(_state: &mut OpState) -> String { + let target = env!("TARGET").to_string(); + target +} + deno_core::extension!(sb_core_runtime, - ops = [op_main_module], + ops = [op_main_module, op_build_target], options = { main_module: Option },