1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 06:09:25 -05:00

fix(ext/node): init arch, pid, platform at startup (#22561)

This commit is contained in:
Satya Rohith 2024-02-23 19:06:17 +05:30 committed by GitHub
parent f49abcc1ac
commit 156cfe5c90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 20 deletions

View file

@ -48,13 +48,10 @@ import { Command } from "ext:runtime/40_process.js";
let argv0Getter = () => ""; let argv0Getter = () => "";
export let argv0 = "deno"; export let argv0 = "deno";
// TODO(kt3k): This should be set at start up time
export let arch = ""; export let arch = "";
// TODO(kt3k): This should be set at start up time
export let platform = ""; export let platform = "";
// TODO(kt3k): This should be set at start up time
export let pid = 0; export let pid = 0;
let stdin, stdout, stderr; let stdin, stdout, stderr;
@ -368,9 +365,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_arch */ /** https://nodejs.org/api/process.html#process_process_arch */
get arch() { get arch() {
if (!arch) {
arch = arch_();
}
return arch; return arch;
} }
@ -561,9 +555,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_pid */ /** https://nodejs.org/api/process.html#process_process_pid */
get pid() { get pid() {
if (!pid) {
pid = Deno.pid;
}
return pid; return pid;
} }
@ -574,9 +565,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_platform */ /** https://nodejs.org/api/process.html#process_process_platform */
get platform() { get platform() {
if (!platform) {
platform = isWindows ? "win32" : Deno.build.os;
}
return platform; return platform;
} }
@ -939,6 +927,10 @@ internals.__bootstrapNodeProcess = function (
process.setStartTime(Date.now()); process.setStartTime(Date.now());
arch = arch_();
platform = isWindows ? "win32" : Deno.build.os;
pid = Deno.pid;
// @ts-ignore Remove setStartTime and #startTime is not modifiable // @ts-ignore Remove setStartTime and #startTime is not modifiable
delete process.setStartTime; delete process.setStartTime;
delete internals.__bootstrapNodeProcess; delete internals.__bootstrapNodeProcess;

View file

@ -1,7 +1,14 @@
// deno-lint-ignore-file no-undef // deno-lint-ignore-file no-undef
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import process, { argv, env } from "node:process"; import process, {
arch as importedArch,
argv,
env,
pid as importedPid,
platform as importedPlatform,
} from "node:process";
import { Readable } from "node:stream"; import { Readable } from "node:stream";
import { once } from "node:events"; import { once } from "node:events";
import { import {
@ -83,7 +90,11 @@ Deno.test({
Deno.test({ Deno.test({
name: "process.platform", name: "process.platform",
fn() { fn() {
const expectedOs = Deno.build.os == "windows" ? "win32" : Deno.build.os;
assertEquals(typeof process.platform, "string"); assertEquals(typeof process.platform, "string");
assertEquals(process.platform, expectedOs);
assertEquals(typeof importedPlatform, "string");
assertEquals(importedPlatform, expectedOs);
}, },
}); });
@ -102,14 +113,20 @@ Deno.test({
Deno.test({ Deno.test({
name: "process.arch", name: "process.arch",
fn() { fn() {
assertEquals(typeof process.arch, "string"); function testValue(arch: string) {
if (Deno.build.arch == "x86_64") { if (Deno.build.arch == "x86_64") {
assertEquals(process.arch, "x64"); assertEquals(arch, "x64");
} else if (Deno.build.arch == "aarch64") { } else if (Deno.build.arch == "aarch64") {
assertEquals(process.arch, "arm64"); assertEquals(arch, "arm64");
} else { } else {
throw new Error("unreachable"); throw new Error("unreachable");
} }
}
assertEquals(typeof process.arch, "string");
testValue(process.arch);
assertEquals(typeof importedArch, "string");
testValue(importedArch);
}, },
}); });
@ -118,6 +135,8 @@ Deno.test({
fn() { fn() {
assertEquals(typeof process.pid, "number"); assertEquals(typeof process.pid, "number");
assertEquals(process.pid, Deno.pid); assertEquals(process.pid, Deno.pid);
assertEquals(typeof importedPid, "number");
assertEquals(importedPid, Deno.pid);
}, },
}); });