Skip to content

Commit 5406d6e

Browse files
authored
Merge pull request #35 from supabase/fix-deno-namespace
fix: missing values in global scope
2 parents 9c7d7b2 + 3668471 commit 5406d6e

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

crates/base/src/js_worker.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ impl MainWorker {
158158
stream: UnixStream,
159159
shutdown_tx: oneshot::Sender<()>,
160160
) -> Result<(), Error> {
161-
// set bootstrap options
162-
// TODO: Migrate this to `supacore`
163-
let script = format!(r#"globalThis.__build_target = "{}""#, env!("TARGET"));
164-
self.js_runtime
165-
.execute_script::<String>(located_script_name!(), script.into())
166-
.expect("Failed to execute bootstrap script");
167-
168161
let (unix_stream_tx, unix_stream_rx) = mpsc::unbounded_channel::<UnixStream>();
169162
if let Err(e) = unix_stream_tx.send(stream) {
170163
bail!(e)
@@ -329,12 +322,6 @@ impl UserWorker {
329322
});
330323

331324
// set bootstrap options
332-
// TODO: Move to `supacore`
333-
let script = format!("globalThis.__build_target = \"{}\"", env!("TARGET"));
334-
self.js_runtime
335-
.execute_script::<String>(&located_script_name!(), script.into())
336-
.expect("Failed to execute bootstrap script");
337-
338325
let (unix_stream_tx, unix_stream_rx) = mpsc::unbounded_channel::<UnixStream>();
339326
if let Err(e) = unix_stream_tx.send(stream) {
340327
bail!(e)

crates/sb_core/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// build script
2+
use std::env;
3+
4+
fn main() {
5+
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
6+
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
7+
}

crates/sb_core/js/bootstrap.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as tls from "ext:deno_net/02_tls.js";
2222
import * as net from "ext:deno_net/01_net.js";
2323
import * as response from "ext:deno_fetch/23_response.js";
2424
import * as request from "ext:deno_fetch/23_request.js";
25+
import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js";
2526
import { SUPABASE_USER_WORKERS } from "ext:sb_user_workers/user_workers.js";
2627
import { SUPABASE_ENV } from "ext:sb_env/env.js";
2728

@@ -537,6 +538,15 @@ delete globalThis.bootstrap;
537538

538539
ObjectDefineProperties(globalThis, globalScope);
539540

541+
const globalProperties = {
542+
Window: globalInterfaces.windowConstructorDescriptor,
543+
window: getterOnly(() => globalThis),
544+
self: getterOnly(() => globalThis),
545+
};
546+
547+
ObjectDefineProperties(globalThis, globalProperties);
548+
ObjectSetPrototypeOf(globalThis, Window.prototype);
549+
540550
// TODO: figure out if this is needed
541551
globalThis[webidl.brand] = webidl.brand;
542552

@@ -556,9 +566,8 @@ runtimeStart({
556566
tsVersion: "NA",
557567
noColor: true,
558568
isTty: false,
559-
target: "supabase",
569+
target: ops.op_build_target(),
560570
});
561-
delete globalThis.__build_target;
562571

563572
// set these overrides after runtimeStart
564573
ObjectDefineProperties(Deno, {

crates/sb_core/runtime.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::Path;
1010
#[op]
1111
fn op_main_module(state: &mut OpState) -> Result<String, AnyError> {
1212
let main = state.borrow::<ModuleSpecifier>().to_string();
13-
let main_url = deno_core::resolve_url_or_path(&main, Path::new("./steve-jobs"))?;
13+
let main_url = deno_core::resolve_url_or_path(&main, std::env::current_dir()?.as_path())?;
1414
if main_url.scheme() == "file" {
1515
let main_path = std::env::current_dir()
1616
.context("Failed to get current working directory")?
@@ -24,8 +24,14 @@ fn op_main_module(state: &mut OpState) -> Result<String, AnyError> {
2424
Ok(main)
2525
}
2626

27+
#[op]
28+
fn op_build_target(_state: &mut OpState) -> String {
29+
let target = env!("TARGET").to_string();
30+
target
31+
}
32+
2733
deno_core::extension!(sb_core_runtime,
28-
ops = [op_main_module],
34+
ops = [op_main_module, op_build_target],
2935
options = {
3036
main_module: Option<ModuleSpecifier>
3137
},

0 commit comments

Comments
 (0)