Skip to content

Import Node.js APIs with node: prefix #349

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ jobs:
- run: npm test
- run: npm run lint

check-deno-compatibility:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- run: npm ci
- run: npm run build
- name: Check Deno compatibility
run: deno check dist/**/*.js

publish:
runs-on: ubuntu-latest
if: github.event_name == 'release'
Expand Down
2 changes: 1 addition & 1 deletion src/server/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo, RequestInfo } f
import getRawBody from "raw-body";
import contentType from "content-type";
import { AuthInfo } from "./auth/types.js";
import { URL } from 'url';
import { URL } from 'node:url';

const MAXIMUM_MESSAGE_SIZE = "4mb";

Expand Down
1 change: 1 addition & 0 deletions src/server/stdio.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Buffer } from "node:buffer";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this import type?

Copy link

@scarf005 scarf005 Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. In this file Buffer is referred only as an argument type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also used directly. this._readBuffer.append(chunk)

How its been tested?

Copy link
Author

@lacolaco lacolaco Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ReadBuffer you mention is imported from shared/stdio.js, which is modified to use node:buffer.
What this Issue is concerned with and resolves is a direct reference to the global variable Buffer. It is fine if the object of type Buffer is derived from node:buffer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to add a test to prevent regressions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihrpr Is the test intended to prevent regression in a Node.js environment? Or is it intended to test for viability in deno?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test to make sure if anyone adds any new use of Buffer (or any other way to break compatibility) sdk will still be compatible with Deno

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test to check compatibility. 0e1c586

import process from "node:process";
import { Readable, Writable } from "node:stream";
import { ReadBuffer, serializeMessage } from "../shared/stdio.js";
Expand Down
1 change: 1 addition & 0 deletions src/shared/stdio.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "node:buffer";
import { JSONRPCMessage } from "../types.js";
import { ReadBuffer } from "./stdio.js";

Expand Down
1 change: 1 addition & 0 deletions src/shared/stdio.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "node:buffer";
import { JSONRPCMessage, JSONRPCMessageSchema } from "../types.js";

/**
Expand Down