Skip to content

Commit

Permalink
[FIX] changed "web-streams-polifill/ponyfill" to "stream/web" (built …
Browse files Browse the repository at this point in the history
…into node 16+) - this is required to support ReadableStream in ObjectStore and not create inconsistencies with fetch and other libraries. FIX #555 (#558)
  • Loading branch information
aricart committed Feb 21, 2023
1 parent 8a07054 commit 9efb5ec
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
20 changes: 3 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nats",
"version": "2.12.0",
"version": "2.12.1",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -40,7 +40,7 @@
"build": "tsc",
"cjs": "deno run --allow-all bin/cjs-fix-imports.ts -o nats-base-client/ ./.deps/nats.deno/nats-base-client/",
"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.12.0 https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.12.1 https://github.com/nats-io/nats.deno.git",
"fmt": "deno fmt ./src/ ./examples/ ./test/",
"prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build",
"ava": "nyc ava --verbose -T 60000",
Expand All @@ -57,8 +57,7 @@
"node": ">= 14.0.0"
},
"dependencies": {
"nkeys.js": "1.0.5",
"web-streams-polyfill": "^3.2.1"
"nkeys.js": "1.0.5"
},
"devDependencies": {
"@types/node": "^18.13.x",
Expand Down
13 changes: 11 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ if (typeof TextEncoder === "undefined") {

if (typeof globalThis.crypto === "undefined") {
const c = require("crypto");
// this will patch to undefined if webcrypto is not available (node 14)
// views will toss if crypto is not available
global.crypto = c.webcrypto;
}

if (typeof globalThis.ReadableStream === "undefined") {
const streams = require("web-streams-polyfill/ponyfill");
global.ReadableStream = streams.ReadableStream;
// @ts-ignore: node global
const chunks = process.versions.node.split(".");
const v = parseInt(chunks[0]);
if (v >= 16) {
// this won't mess up fetch
const streams = require("stream/web");
// views will toss if ReadableStream is not available
global.ReadableStream = streams.ReadableStream;
}
}

export { connect } from "./connect";
Expand Down
2 changes: 1 addition & 1 deletion src/node_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { resolve } = require("path");
const { readFile, existsSync } = require("fs");
const dns = require("dns");

const VERSION = "2.12.0";
const VERSION = "2.12.1";
const LANG = "nats.js";

export class NodeTransport implements Transport {
Expand Down
4 changes: 2 additions & 2 deletions test/jetstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ async function fromReadableStream(
}

test("jetstream - os basics", async (t) => {
if (process.version.startsWith("v14.")) {
if (parseInt(process.versions.node.split(".")[0]) < 16) {
t.log(
`node ${process.version} cannot run objectstore as webcrypto is not available`,
`node ${process.versions.node} cannot run objectstore as webcrypto and ReadableStream are not available`,
);
t.pass();
return;
Expand Down

0 comments on commit 9efb5ec

Please sign in to comment.