From 4aa11cfd9f47c77c381923d3f7da5cecd701943a Mon Sep 17 00:00:00 2001 From: Rajhans Jadhao Date: Wed, 8 Jan 2025 17:54:18 +0530 Subject: [PATCH 1/4] fix(ext/node): use primordials in `ext/node/polyfills/_fs_common.ts` --- ext/node/polyfills/_fs/_fs_common.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/node/polyfills/_fs/_fs_common.ts b/ext/node/polyfills/_fs/_fs_common.ts index 9ec474afa98df5..02575018e29dde 100644 --- a/ext/node/polyfills/_fs/_fs_common.ts +++ b/ext/node/polyfills/_fs/_fs_common.ts @@ -1,8 +1,8 @@ // Copyright 2018-2025 the Deno authors. MIT license. -// TODO(petamoriken): enable prefer-primordials for node polyfills -// deno-lint-ignore-file prefer-primordials - +import { primordials } from "ext:core/mod.js"; +const { StringPrototypeToLowerCase, ArrayPrototypeIncludes, ReflectApply } = + primordials; import { O_APPEND, O_CREAT, @@ -75,9 +75,8 @@ export function getEncoding( return null; } - const encoding = typeof optOrCallback === "string" - ? optOrCallback - : optOrCallback.encoding; + const encoding = + typeof optOrCallback === "string" ? optOrCallback : optOrCallback.encoding; if (!encoding) return null; return encoding; } @@ -85,8 +84,10 @@ export function getEncoding( export function checkEncoding(encoding: Encodings | null): Encodings | null { if (!encoding) return null; - encoding = encoding.toLowerCase() as Encodings; - if (["utf8", "hex", "base64", "ascii"].includes(encoding)) return encoding; + encoding = StringPrototypeToLowerCase(encoding) as Encodings; + if (ArrayPrototypeIncludes(["utf8", "hex", "base64", "ascii"], encoding)) { + return encoding; + } if (encoding === "utf-8") { return "utf8"; @@ -241,5 +242,5 @@ export function makeCallback( ) { validateFunction(cb, "cb"); - return (...args: unknown[]) => Reflect.apply(cb!, this, args); + return (...args: unknown[]) => ReflectApply(cb!, this, args); } From 1910b42f1f28874393b1a6dd4cf50c0f5de3b659 Mon Sep 17 00:00:00 2001 From: Rajhans Jadhao Date: Wed, 8 Jan 2025 18:09:02 +0530 Subject: [PATCH 2/4] fix(ext/node): fix lint issue --- ext/node/polyfills/_fs/_fs_common.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/node/polyfills/_fs/_fs_common.ts b/ext/node/polyfills/_fs/_fs_common.ts index 02575018e29dde..0e1e899b0a10d9 100644 --- a/ext/node/polyfills/_fs/_fs_common.ts +++ b/ext/node/polyfills/_fs/_fs_common.ts @@ -75,8 +75,9 @@ export function getEncoding( return null; } - const encoding = - typeof optOrCallback === "string" ? optOrCallback : optOrCallback.encoding; + const encoding = typeof optOrCallback === "string" + ? optOrCallback + : optOrCallback.encoding; if (!encoding) return null; return encoding; } From 5eda9cafcdab0ccb6be5ea0cfaf2d00aa356377e Mon Sep 17 00:00:00 2001 From: Rajhans Jadhao Date: Wed, 8 Jan 2025 18:18:34 +0530 Subject: [PATCH 3/4] fix(ext/node): use ArrayPrototypeIncludes instead of includes --- ext/node/polyfills/_fs/_fs_common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/node/polyfills/_fs/_fs_common.ts b/ext/node/polyfills/_fs/_fs_common.ts index 0e1e899b0a10d9..dd7d457e4a1c9f 100644 --- a/ext/node/polyfills/_fs/_fs_common.ts +++ b/ext/node/polyfills/_fs/_fs_common.ts @@ -101,7 +101,7 @@ export function checkEncoding(encoding: Encodings | null): Encodings | null { const notImplementedEncodings = ["utf16le", "latin1", "ucs2"]; - if (notImplementedEncodings.includes(encoding as string)) { + if (ArrayPrototypeIncludes(notImplementedEncodings, encoding as string)) { notImplemented(`"${encoding}" encoding`); } From 9188b30e678344ec94e1ec3fc8a26b2750a33044 Mon Sep 17 00:00:00 2001 From: Rajhans Jadhao Date: Wed, 8 Jan 2025 18:32:31 +0530 Subject: [PATCH 4/4] fix(ext/node): update import --- ext/node/polyfills/_fs/_fs_common.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/node/polyfills/_fs/_fs_common.ts b/ext/node/polyfills/_fs/_fs_common.ts index dd7d457e4a1c9f..8358f0271c088c 100644 --- a/ext/node/polyfills/_fs/_fs_common.ts +++ b/ext/node/polyfills/_fs/_fs_common.ts @@ -1,8 +1,12 @@ // Copyright 2018-2025 the Deno authors. MIT license. import { primordials } from "ext:core/mod.js"; -const { StringPrototypeToLowerCase, ArrayPrototypeIncludes, ReflectApply } = - primordials; +const { + StringPrototypeToLowerCase, + ArrayPrototypeIncludes, + ReflectApply, + Error, +} = primordials; import { O_APPEND, O_CREAT,