Skip to content

Commit

Permalink
chore(node): update compat layer to node 18.8.0 (#2585)
Browse files Browse the repository at this point in the history
The rest of the update can be tracked in
#2631
  • Loading branch information
cjihrig committed Sep 8, 2022
1 parent ebeecac commit 9a19e98
Show file tree
Hide file tree
Showing 524 changed files with 2,053 additions and 796 deletions.
2 changes: 1 addition & 1 deletion node/_fs/_fs_appendFile_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Deno.test({
appendFile("some/path", "some data", "utf8");
},
Error,
"Callback must be a function. Received 'utf8'",
"The \"cb\" argument must be of type function. Received type string ('utf8')",
);
},
});
Expand Down
6 changes: 3 additions & 3 deletions node/_fs/_fs_common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { validateCallback } from "../internal/validators.mjs";
import { validateFunction } from "../internal/validators.mjs";
import type { ErrnoException } from "../_global.d.ts";
import {
BinaryEncodings,
Expand Down Expand Up @@ -168,7 +168,7 @@ export function getOpenOptions(flag: string | undefined): Deno.OpenOptions {
export { isUint32 as isFd } from "../internal/validators.mjs";

export function maybeCallback(cb: unknown) {
validateCallback(cb);
validateFunction(cb, "cb");

return cb as CallbackWithError;
}
Expand All @@ -180,7 +180,7 @@ export function makeCallback(
this: unknown,
cb?: (err: Error | null, result?: unknown) => void,
) {
validateCallback(cb);
validateFunction(cb, "cb");

return (...args: unknown[]) => Reflect.apply(cb!, this, args);
}
6 changes: 4 additions & 2 deletions node/_fs/_fs_mkdtemp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { existsSync } from "./_fs_exists.ts";
import { mkdir, mkdirSync } from "./_fs_mkdir.ts";
import {
ERR_INVALID_CALLBACK,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_OPT_VALUE_ENCODING,
} from "../internal/errors.ts";
import { promisify } from "../internal/util.mjs";
Expand All @@ -27,7 +27,9 @@ export function mkdtemp(
) {
const callback: mkdtempCallback | undefined =
typeof optionsOrCallback == "function" ? optionsOrCallback : maybeCallback;
if (!callback) throw new ERR_INVALID_CALLBACK(callback);
if (!callback) {
throw new ERR_INVALID_ARG_TYPE("callback", "function", callback);
}

const encoding: string | undefined = parseEncoding(optionsOrCallback);
const path = tempDirPath(prefix);
Expand Down
4 changes: 4 additions & 0 deletions node/_fs/_fs_write.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Buffer } from "../buffer.ts";
import { validateEncoding, validateInteger } from "../internal/validators.mjs";
import {
getValidatedFd,
showStringCoercionDeprecation,
validateOffsetLengthWrite,
validateStringAfterArrayBufferView,
} from "../internal/fs/utils.mjs";
Expand Down Expand Up @@ -104,6 +105,9 @@ export function write(fd, buffer, offset, length, position, callback) {
// `fs.write(fd, string[, position[, encoding]], callback)`

validateStringAfterArrayBufferView(buffer, "buffer");
if (typeof buffer !== "string") {
showStringCoercionDeprecation();
}

if (typeof position !== "function") {
if (typeof offset === "function") {
Expand Down
11 changes: 10 additions & 1 deletion node/_fs/_fs_writeFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
} from "./_fs_common.ts";
import { isWindows } from "../../_util/os.ts";
import { AbortError, denoErrorToNodeError } from "../internal/errors.ts";
import { validateStringAfterArrayBufferView } from "../internal/fs/utils.mjs";
import {
showStringCoercionDeprecation,
validateStringAfterArrayBufferView,
} from "../internal/fs/utils.mjs";
import { promisify } from "../internal/util.mjs";

export function writeFile(
Expand Down Expand Up @@ -47,6 +50,9 @@ export function writeFile(

if (!ArrayBuffer.isView(data)) {
validateStringAfterArrayBufferView(data, "data");
if (typeof data !== "string") {
showStringCoercionDeprecation();
}
data = Buffer.from(String(data), encoding);
}

Expand Down Expand Up @@ -110,6 +116,9 @@ export function writeFileSync(

if (!ArrayBuffer.isView(data)) {
validateStringAfterArrayBufferView(data, "data");
if (typeof data !== "string") {
showStringCoercionDeprecation();
}
data = Buffer.from(String(data), encoding);
}

Expand Down
2 changes: 1 addition & 1 deletion node/_http_agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Agent.defaultMaxSockets = Infinity;
Agent.prototype.createConnection = net.createConnection;

// Get the key for a given set of request options
Agent.prototype.getName = function getName(options) {
Agent.prototype.getName = function getName(options = {}) {
let name = options.host || "localhost";

name += ":";
Expand Down
4 changes: 2 additions & 2 deletions node/_next_tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// deno-lint-ignore-file no-inner-declarations

import { core } from "./_core.ts";
import { validateCallback } from "./internal/validators.mjs";
import { validateFunction } from "./internal/validators.mjs";
import { _exiting } from "./_process/exiting.ts";
import { FixedQueue } from "./internal/fixed_queue.ts";

Expand Down Expand Up @@ -94,7 +94,7 @@ if (typeof core.setNextTickCallback !== "undefined") {
callback: (...args: T) => void,
...args: T
) {
validateCallback(callback);
validateFunction(callback, "callback");

if (_exiting) {
return;
Expand Down
Loading

0 comments on commit 9a19e98

Please sign in to comment.