diff --git a/node/global_test.ts b/node/global_test.ts index 400d67a65f69..9eea2c3b8998 100644 --- a/node/global_test.ts +++ b/node/global_test.ts @@ -2,6 +2,7 @@ import "./global.ts"; import { assert, + assertEquals, assertNotEquals, assertStrictEquals, } from "../testing/asserts.ts"; @@ -86,3 +87,30 @@ Deno.test("clearImmediate is correctly defined", () => { assertStrictEquals(globalThis.clearImmediate, timers.clearImmediate); assertStrictEquals(window.clearImmediate, timers.clearImmediate); }); + +// https://github.com/denoland/deno_std/issues/2097 +Deno.test("global.ts evaluates synchronously", async () => { + const tempPath = await Deno.makeTempFile({ suffix: ".ts" }); + try { + await Deno.writeTextFile( + tempPath, + `\ + import "data:application/javascript,import '${ + new URL("global.ts", import.meta.url).href + }'; console.log(globalThis.async ? 'async' : 'sync')"; + import "data:application/javascript,globalThis.async = true";`, + ); + const process = Deno.run({ + cmd: [Deno.execPath(), "run", "--no-check", tempPath], + stdin: "null", + stdout: "piped", + stderr: "null", + }); + assertEquals((await process.status()).code, 0); + const stdout = new TextDecoder().decode(await process.output()); + assertEquals(stdout.trim(), "sync"); + process.close(); + } finally { + await Deno.remove(tempPath).catch(() => {}); + } +}); diff --git a/node/internal/util/debuglog.ts b/node/internal/util/debuglog.ts index e1aa0756db1b..36ebdd8ba34f 100644 --- a/node/internal/util/debuglog.ts +++ b/node/internal/util/debuglog.ts @@ -103,19 +103,16 @@ export function debuglog( return logger; } -let state = ""; - -if (Deno.permissions) { - state = (await Deno.permissions.query({ - name: "env", - variable: "NODE_DEBUG", - })).state; -} - -if (state === "granted") { - initializeDebugEnv(Deno.env.get("NODE_DEBUG") ?? ""); -} else { - initializeDebugEnv(""); +let debugEnv; +try { + debugEnv = Deno.env.get("NODE_DEBUG") ?? ""; +} catch (error) { + if (error instanceof Deno.errors.PermissionDenied) { + debugEnv = ""; + } else { + throw error; + } } +initializeDebugEnv(debugEnv); export default { debuglog };