1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -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 = () => "";
export let argv0 = "deno";
// TODO(kt3k): This should be set at start up time
export let arch = "";
// TODO(kt3k): This should be set at start up time
export let platform = "";
// TODO(kt3k): This should be set at start up time
export let pid = 0;
let stdin, stdout, stderr;
@ -368,9 +365,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_arch */
get arch() {
if (!arch) {
arch = arch_();
}
return arch;
}
@ -561,9 +555,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_pid */
get pid() {
if (!pid) {
pid = Deno.pid;
}
return pid;
}
@ -574,9 +565,6 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_platform */
get platform() {
if (!platform) {
platform = isWindows ? "win32" : Deno.build.os;
}
return platform;
}
@ -939,6 +927,10 @@ internals.__bootstrapNodeProcess = function (
process.setStartTime(Date.now());
arch = arch_();
platform = isWindows ? "win32" : Deno.build.os;
pid = Deno.pid;
// @ts-ignore Remove setStartTime and #startTime is not modifiable
delete process.setStartTime;
delete internals.__bootstrapNodeProcess;

View file

@ -1,7 +1,14 @@
// deno-lint-ignore-file no-undef
// 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 { once } from "node:events";
import {
@ -83,7 +90,11 @@ Deno.test({
Deno.test({
name: "process.platform",
fn() {
const expectedOs = Deno.build.os == "windows" ? "win32" : Deno.build.os;
assertEquals(typeof process.platform, "string");
assertEquals(process.platform, expectedOs);
assertEquals(typeof importedPlatform, "string");
assertEquals(importedPlatform, expectedOs);
},
});
@ -102,14 +113,20 @@ Deno.test({
Deno.test({
name: "process.arch",
fn() {
assertEquals(typeof process.arch, "string");
if (Deno.build.arch == "x86_64") {
assertEquals(process.arch, "x64");
} else if (Deno.build.arch == "aarch64") {
assertEquals(process.arch, "arm64");
} else {
throw new Error("unreachable");
function testValue(arch: string) {
if (Deno.build.arch == "x86_64") {
assertEquals(arch, "x64");
} else if (Deno.build.arch == "aarch64") {
assertEquals(arch, "arm64");
} else {
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() {
assertEquals(typeof process.pid, "number");
assertEquals(process.pid, Deno.pid);
assertEquals(typeof importedPid, "number");
assertEquals(importedPid, Deno.pid);
},
});