Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): support NODE_DEBUG env #23583

Merged
merged 2 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions ext/node/polyfills/02_init.js
Expand Up @@ -29,7 +29,12 @@ function initialize(

// FIXME(bartlomieju): not nice to depend on `Deno` namespace here
// but it's the only way to get `args` and `version` and this point.
internals.__bootstrapNodeProcess(argv0, Deno.args, Deno.version);
internals.__bootstrapNodeProcess(
argv0,
Deno.args,
Deno.version,
Deno.env.get("NODE_DEBUG") ?? "",
satyarohith marked this conversation as resolved.
Show resolved Hide resolved
);
internals.__initWorkerThreads(
runningOnMainThread,
workerId,
Expand All @@ -40,7 +45,13 @@ function initialize(
delete internals.requireImpl;
} else {
// Warm up the process module
internals.__bootstrapNodeProcess(undefined, undefined, undefined, true);
internals.__bootstrapNodeProcess(
undefined,
undefined,
undefined,
undefined,
true,
);
}
}

Expand Down
18 changes: 1 addition & 17 deletions ext/node/polyfills/internal/util/debuglog.ts
Expand Up @@ -12,7 +12,7 @@ let debugImpls: Record<string, (...args: unknown[]) => void>;
let testEnabled: (str: string) => boolean;

// `debugEnv` is initial value of process.env.NODE_DEBUG
function initializeDebugEnv(debugEnv: string) {
export function initializeDebugEnv(debugEnv: string) {
debugImpls = Object.create(null);
if (debugEnv) {
// This is run before any user code, it's OK not to use primordials.
Expand Down Expand Up @@ -106,20 +106,4 @@ export function debuglog(
return logger;
}

let debugEnv;
/* TODO(kt3k): enable initializing debugEnv.
It's not possible to access env var when snapshotting.
try {
debugEnv = Deno.env.get("NODE_DEBUG") ?? "";
} catch (error) {
if (error instanceof Deno.errors.PermissionDenied) {
debugEnv = "";
} else {
throw error;
}
}
*/
initializeDebugEnv(debugEnv);

export default { debuglog };
4 changes: 4 additions & 0 deletions ext/node/polyfills/process.ts
Expand Up @@ -5,6 +5,7 @@
// deno-lint-ignore-file prefer-primordials

import { core, internals } from "ext:core/mod.js";
import { initializeDebugEnv } from "ext:deno_node/internal/util/debuglog.ts";
import {
op_geteuid,
op_node_process_kill,
Expand Down Expand Up @@ -845,6 +846,7 @@ internals.__bootstrapNodeProcess = function (
argv0Val: string | undefined,
args: string[],
denoVersions: Record<string, string>,
nodeDebug: string,
warmup = false,
) {
if (!warmup) {
Expand Down Expand Up @@ -891,6 +893,8 @@ internals.__bootstrapNodeProcess = function (
platform = isWindows ? "win32" : Deno.build.os;
pid = Deno.pid;

initializeDebugEnv(nodeDebug);

// @ts-ignore Remove setStartTime and #startTime is not modifiable
delete process.setStartTime;
delete internals.__bootstrapNodeProcess;
Expand Down