Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): never use relative import for node packages #352

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/runtime/node/http/internal/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type http from "node:http";
import { Socket } from "node:net";
import { Readable } from "../../stream/internal/readable";
import { Readable } from "node:stream";
import { rawHeaders } from "../../../_internal/utils";

// Docs: https://nodejs.org/api/http.html#http_class_http_incomingmessage
Expand Down Expand Up @@ -51,6 +51,8 @@ export class IncomingMessage extends Readable implements http.IncomingMessage {
get trailersDistinct() {
return _distinct(this.trailers);
}

_read() {}
}

function _distinct(obj: Record<string, any>) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/http/internal/response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type http from "node:http";
import type { Socket } from "node:net";
import { Callback } from "../../../_internal/types";
import { Writable } from "../../stream";
import { Writable } from "node:stream";

// Docs: https://nodejs.org/api/http.html#http_class_http_serverresponse
// Implementation: https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/net/internal/socket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as net from "node:net";
import { Callback, BufferEncoding } from "../../../_internal/types";
import { Duplex } from "../../stream/internal/duplex";
import { Duplex } from "node:stream";

// Docs: https://nodejs.org/api/net.html#net_class_net_socket
export class Socket extends Duplex implements net.Socket {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/stream/internal/readable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as stream from "node:stream";
import type { BufferEncoding, Callback } from "../../../_internal/types";
import { createNotImplementedError } from "../../../_internal/utils";
import { EventEmitter } from "../../events";
import { EventEmitter } from "node:events";

// Docs: https://nodejs.org/api/stream.html#stream_readable_streams
// Implementation: https://github.com/nodejs/node/blob/master/lib/internal/streams/readable.js
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/stream/internal/writable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as stream from "node:stream";
import type { BufferEncoding, Callback } from "../../../_internal/types";

import { EventEmitter } from "../../events";
import { EventEmitter } from "node:events";

// Docs: https://nodejs.org/api/stream.html#stream_writable_streams
// Implementation: https://github.com/nodejs/node/blob/master/lib/internal/streams/writable.js
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/tls/internal/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type tls from "node:tls";
import { createNotImplementedError } from "../../../_internal/utils";
import { Server as _Server } from "../../net";
import { Server as _Server } from "node:net";

export class Server extends _Server implements tls.Server {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/tls/internal/tls-socket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type tls from "node:tls";
import { Socket } from "../../net";
import { Socket } from "node:net";
import { createNotImplementedError } from "../../../_internal/utils";

export class TLSSocket extends Socket implements tls.TLSSocket {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/tty/internal/read-stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type tty from "node:tty";
import { Socket } from "../../net";
import { Socket } from "node:net";

export class ReadStream extends Socket implements tty.ReadStream {
isRaw = false;
Expand Down
16 changes: 16 additions & 0 deletions test/workerd/tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,19 @@ export const workerd_path = {
assert.strictEqual(pathPosix.delimiter, ":");
},
};

// --- node:http

export const workerd_http = {
async test() {
const http = await import("unenv/runtime/node/http");
const net = await import("unenv/runtime/node/net");
const message = new http.IncomingMessage(new net.Socket());
await assert.doesNotThrow(async () => {
// Would throw if the async iterator is not implemented
for await (const chunk of message) {
// empty
}
});
},
};