diff --git a/.eslintrc b/.eslintrc index e29e0170..fc43258f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,5 @@ { - "extends": [ - "eslint-config-unjs" - ], + "extends": ["eslint-config-unjs"], "rules": { "@typescript-eslint/no-unused-vars": 0, "unicorn/no-null": 0, @@ -14,6 +12,7 @@ "unicorn/number-literal-case": 0, "generator-star-spacing": 0, "indent": 0, - "unicorn/no-nested-ternary": 0 + "unicorn/no-nested-ternary": 0, + "require-await": 0 } } diff --git a/src/runtime/node/buffer/_file.ts b/src/runtime/node/buffer/_file.ts new file mode 100644 index 00000000..d41d1a2a --- /dev/null +++ b/src/runtime/node/buffer/_file.ts @@ -0,0 +1,30 @@ +import type buffer from "node:buffer"; +import { Buffer } from "./_buffer"; + +export class File extends Blob implements buffer.File { + size: number = 0; + type: any = ""; + name: string = ""; + lastModified: number = 0; + + constructor(...args: any[]) { + super(...args); + throw new Error("[unenv] buffer.File is not implemented"); + } + + arrayBuffer(): Promise { + throw new Error("Not implemented"); + } + + slice(): any { + throw new Error("Not implemented"); + } + + text(): any { + throw new Error("Not implemented"); + } + + stream(): any { + throw new Error("Not implemented"); + } +} diff --git a/src/runtime/node/buffer/index.ts b/src/runtime/node/buffer/index.ts index 1492d73c..a3b51694 100644 --- a/src/runtime/node/buffer/index.ts +++ b/src/runtime/node/buffer/index.ts @@ -2,15 +2,18 @@ import type buffer from "node:buffer"; import { notImplemented } from "../../_internal/utils"; import { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer"; +import { File } from "./_file"; // @ts-ignore export { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer"; +export { File } from "./_file"; // @ts-expect-eerror https://github.com/unjs/unenv/issues/64 export const Blob = globalThis.Blob as unknown as typeof buffer.Blob; export const resolveObjectURL = notImplemented("buffer.resolveObjectURL"); export const transcode = notImplemented("buffer.transcode"); export const isUtf8 = notImplemented("buffer.isUtf8"); +export const isAscii = notImplemented("buffer.isAscii"); export const btoa = global.btoa; export const atob = globalThis.atob; @@ -34,4 +37,6 @@ export default { kStringMaxLength, constants, isUtf8, + isAscii, + File, }; diff --git a/src/runtime/node/net/index.ts b/src/runtime/node/net/index.ts index 1459e71a..4bc672f8 100644 --- a/src/runtime/node/net/index.ts +++ b/src/runtime/node/net/index.ts @@ -1,9 +1,23 @@ // https://nodejs.org/api/net.html import type net from "node:net"; +import { notImplemented } from "../../_internal/utils"; import * as socket from "./socket"; export * from "./socket"; +export const createServer = notImplemented( + "net.createServer" +) as typeof net.createServer; + +export const connect = notImplemented("net.connect") as typeof net.connect; + +export const createConnection = notImplemented( + "net.createConnection" +) as typeof net.createConnection; + export default { ...socket, + createServer, + connect, + createConnection, }; diff --git a/src/runtime/node/net/socket.ts b/src/runtime/node/net/socket.ts index 890aa371..96b6348f 100644 --- a/src/runtime/node/net/socket.ts +++ b/src/runtime/node/net/socket.ts @@ -9,6 +9,7 @@ export class Socket extends Duplex implements net.Socket { readonly bytesWritten: number = 0; readonly connecting: boolean = false; readonly destroyed: boolean = false; + readonly pending: boolean = false; readonly localAddress: string = ""; readonly localPort: number = 0; readonly remoteAddress?: string = "";