Skip to content

Commit

Permalink
fix: add new node shims
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 10, 2023
1 parent 7219d5c commit 9ad4604
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
7 changes: 3 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": [
"eslint-config-unjs"
],
"extends": ["eslint-config-unjs"],
"rules": {
"@typescript-eslint/no-unused-vars": 0,
"unicorn/no-null": 0,
Expand All @@ -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
}
}
30 changes: 30 additions & 0 deletions src/runtime/node/buffer/_file.ts
Original file line number Diff line number Diff line change
@@ -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<ArrayBuffer> {
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");
}
}
5 changes: 5 additions & 0 deletions src/runtime/node/buffer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,4 +37,6 @@ export default <typeof buffer>{
kStringMaxLength,
constants,
isUtf8,
isAscii,
File,
};
14 changes: 14 additions & 0 deletions src/runtime/node/net/index.ts
Original file line number Diff line number Diff line change
@@ -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 <typeof net>{
...socket,
createServer,
connect,
createConnection,
};
1 change: 1 addition & 0 deletions src/runtime/node/net/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit 9ad4604

Please sign in to comment.