From 3891997a975f88cb0c9fd02f372ace26ae5c65b5 Mon Sep 17 00:00:00 2001 From: Evan <96965321+0xIchigo@users.noreply.github.com> Date: Wed, 16 Aug 2023 05:28:49 -0400 Subject: [PATCH] fix(ext/node): allow for the reassignment of userInfo() on Windows (#20165) The goal of this PR is to address issue #20106 where a `TypeError` occurs when the variables `uid` and `gid` from `userInfo()` in `node:os` are reassigned if the user is on Windows. Both `uid` and `gid` are marked as `const` therefore producing a `TypeError` when the two are reassigned. This PR achieves that goal by marking `uid` and `gid` as `let` --- cli/tests/node_compat/test/parallel/test-os.js | 3 +-- ext/node/polyfills/os.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/tests/node_compat/test/parallel/test-os.js b/cli/tests/node_compat/test/parallel/test-os.js index 09d97222c5..d8425d0d52 100644 --- a/cli/tests/node_compat/test/parallel/test-os.js +++ b/cli/tests/node_compat/test/parallel/test-os.js @@ -216,7 +216,6 @@ if (common.isWindows && process.env.USERPROFILE) { process.env.HOME = home; } -/* TODO(kt3k): Enable this test const pwd = os.userInfo(); is.object(pwd); const pwdBuf = os.userInfo({ encoding: 'buffer' }); @@ -245,7 +244,7 @@ is.string(pwd.username); assert.ok(pwd.homedir.includes(path.sep)); assert.strictEqual(pwd.username, pwdBuf.username.toString('utf8')); assert.strictEqual(pwd.homedir, pwdBuf.homedir.toString('utf8')); -*/ + assert.strictEqual(`${os.hostname}`, os.hostname()); assert.strictEqual(`${os.homedir}`, os.homedir()); diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index a874c942cb..c552b5a0ad 100644 --- a/ext/node/polyfills/os.ts +++ b/ext/node/polyfills/os.ts @@ -320,8 +320,8 @@ export function uptime(): number { export function userInfo( options: UserInfoOptions = { encoding: "utf-8" }, ): UserInfo { - const uid = Deno.uid(); - const gid = Deno.gid(); + let uid = Deno.uid(); + let gid = Deno.gid(); if (isWindows) { uid = -1;