Skip to content

Commit 9ad4604

Browse files
committed
fix: add new node shims
1 parent 7219d5c commit 9ad4604

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

.eslintrc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"extends": [
3-
"eslint-config-unjs"
4-
],
2+
"extends": ["eslint-config-unjs"],
53
"rules": {
64
"@typescript-eslint/no-unused-vars": 0,
75
"unicorn/no-null": 0,
@@ -14,6 +12,7 @@
1412
"unicorn/number-literal-case": 0,
1513
"generator-star-spacing": 0,
1614
"indent": 0,
17-
"unicorn/no-nested-ternary": 0
15+
"unicorn/no-nested-ternary": 0,
16+
"require-await": 0
1817
}
1918
}

src/runtime/node/buffer/_file.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type buffer from "node:buffer";
2+
import { Buffer } from "./_buffer";
3+
4+
export class File extends Blob implements buffer.File {
5+
size: number = 0;
6+
type: any = "";
7+
name: string = "";
8+
lastModified: number = 0;
9+
10+
constructor(...args: any[]) {
11+
super(...args);
12+
throw new Error("[unenv] buffer.File is not implemented");
13+
}
14+
15+
arrayBuffer(): Promise<ArrayBuffer> {
16+
throw new Error("Not implemented");
17+
}
18+
19+
slice(): any {
20+
throw new Error("Not implemented");
21+
}
22+
23+
text(): any {
24+
throw new Error("Not implemented");
25+
}
26+
27+
stream(): any {
28+
throw new Error("Not implemented");
29+
}
30+
}

src/runtime/node/buffer/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
import type buffer from "node:buffer";
33
import { notImplemented } from "../../_internal/utils";
44
import { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer";
5+
import { File } from "./_file";
56

67
// @ts-ignore
78
export { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer";
9+
export { File } from "./_file";
810

911
// @ts-expect-eerror https://github.com/unjs/unenv/issues/64
1012
export const Blob = globalThis.Blob as unknown as typeof buffer.Blob;
1113
export const resolveObjectURL = notImplemented("buffer.resolveObjectURL");
1214
export const transcode = notImplemented("buffer.transcode");
1315
export const isUtf8 = notImplemented("buffer.isUtf8");
16+
export const isAscii = notImplemented("buffer.isAscii");
1417

1518
export const btoa = global.btoa;
1619
export const atob = globalThis.atob;
@@ -34,4 +37,6 @@ export default <typeof buffer>{
3437
kStringMaxLength,
3538
constants,
3639
isUtf8,
40+
isAscii,
41+
File,
3742
};

src/runtime/node/net/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
// https://nodejs.org/api/net.html
22
import type net from "node:net";
3+
import { notImplemented } from "../../_internal/utils";
34
import * as socket from "./socket";
45

56
export * from "./socket";
67

8+
export const createServer = notImplemented(
9+
"net.createServer"
10+
) as typeof net.createServer;
11+
12+
export const connect = notImplemented("net.connect") as typeof net.connect;
13+
14+
export const createConnection = notImplemented(
15+
"net.createConnection"
16+
) as typeof net.createConnection;
17+
718
export default <typeof net>{
819
...socket,
20+
createServer,
21+
connect,
22+
createConnection,
923
};

src/runtime/node/net/socket.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class Socket extends Duplex implements net.Socket {
99
readonly bytesWritten: number = 0;
1010
readonly connecting: boolean = false;
1111
readonly destroyed: boolean = false;
12+
readonly pending: boolean = false;
1213
readonly localAddress: string = "";
1314
readonly localPort: number = 0;
1415
readonly remoteAddress?: string = "";

0 commit comments

Comments
 (0)