From 1bb730c1af5012ae9e8d138a815678ce69b06d00 Mon Sep 17 00:00:00 2001 From: Alberto Ricart Date: Fri, 26 May 2023 09:27:08 -0500 Subject: [PATCH] [WIP] js-module --- .gitignore | 1 + bin/cjs-fix-imports.ts | 5 +++++ package.json | 7 ++++--- src/connect.ts | 2 +- src/mod.ts | 3 ++- src/nats-base-client.ts | 2 +- src/ws_transport.ts | 4 ++-- test/jetstream.js | 3 +-- tsconfig.json | 2 +- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 9c2a4b4..0527f31 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ certs/ cjs-build/ cjs-wst/ nats-base-client/ +jetstream/ nats-server nats.js diff --git a/bin/cjs-fix-imports.ts b/bin/cjs-fix-imports.ts index cffb7fb..24292f9 100644 --- a/bin/cjs-fix-imports.ts +++ b/bin/cjs-fix-imports.ts @@ -98,6 +98,11 @@ for (const fn of files) { "../nats-base-client", ); + mod = mod.replace( + /(https:\/\/raw.githubusercontent.com\/nats-io\/nats.deno\/\S+\/jetstream)/gim, + "../jetstream", + ); + // some of the imports are references to external projects // that in node we resolve with requires - if we encounter one that // the script is not configured for, the build fails diff --git a/package.json b/package.json index a4820ef..b10292b 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,13 @@ "install-certs": "env CAROOT=./certs mkcert -cert-file ./certs/cert.pem -key-file ./certs/key.pem -install localhost 127.0.0.1 ::1", "install-ns": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch=main https://github.com/nats-io/nats-server.git && cd nats-server && go build && shx mv nats-server ../../", "prepack": "npm run build", - "clean": "shx rm -Rf ./esm/nats.js ./lib ./.deps ./nats-base-client ./wst", + "clean": "shx rm -Rf ./esm/nats.js ./lib ./.deps ./nats-base-client ./jetstream ./wst", "build": "npm run clean && npm run check-imports && npm run check-package && npm run build-cjs && npm run build-esm", - "build-cjs": "npm run stage && npm run cjs-nbc && npm run cjs-wst && shx rm -Rf ./deps/ && tsc && shx rm -Rf ./wst && shx mv ./lib/wst ./lib/src && rm -Rf ./nats-base-client", + "build-cjs": "npm run stage && npm run cjs-nbc && npm run cjs-jetstream && npm run cjs-wst && shx rm -Rf ./deps/ && tsc && shx rm -Rf ./wst && shx mv ./lib/wst ./lib/src && rm -Rf ./nats-base-client ./jetstream", "build-esm": "deno run --allow-all --unstable --reload src/mod.ts && deno bundle --log-level info --unstable src/mod.ts ./esm/nats.js", "stage": "npm run clone-nbc", - "cjs-nbc": "deno run --allow-all ./bin/cjs-fix-imports.ts -o nats-base-client/ ./.deps/nats.deno/nats-base-client/", + "cjs-nbc": "deno run --allow-all ./bin/cjs-fix-imports.ts -o nats-base-client/ ./.deps/nats.deno/nats-base-client", + "cjs-jetstream": "deno run --allow-all ./bin/cjs-fix-imports.ts -o jetstream/ ./.deps/nats.deno/jetstream/", "cjs-wst": "deno run --allow-all ./bin/cjs-fix-imports.ts -o wst/ ./src", "clone-nbc": "deno run --allow-all bin/clone-nd.ts", "ava": "nyc ava --verbose -T 60000", diff --git a/src/connect.ts b/src/connect.ts index 7a58aa0..7fbc672 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -19,7 +19,7 @@ import { setTransportFactory, Transport, TransportFactory, -} from "https://raw.githubusercontent.com/nats-io/nats.deno/dev/nats-base-client/internal_mod.ts"; +} from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/nats-base-client/internal_mod.ts"; import { WsTransport } from "./ws_transport.ts"; diff --git a/src/mod.ts b/src/mod.ts index 6fa1e62..098936a 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -12,5 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export * from "https://raw.githubusercontent.com/nats-io/nats.deno/dev/nats-base-client/mod.ts"; +export * from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/nats-base-client/mod.ts"; +export * from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/jetstream/mod.ts"; export { connect } from "./connect.ts"; diff --git a/src/nats-base-client.ts b/src/nats-base-client.ts index 30dd5c9..4bf4e95 100644 --- a/src/nats-base-client.ts +++ b/src/nats-base-client.ts @@ -13,4 +13,4 @@ * limitations under the License. */ // this import here to drive the build system -export * from "https://raw.githubusercontent.com/nats-io/nats.deno/dev/nats-base-client/internal_mod.ts"; +export * from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/nats-base-client/internal_mod.ts"; diff --git a/src/ws_transport.ts b/src/ws_transport.ts index 3b68f56..689fd6e 100644 --- a/src/ws_transport.ts +++ b/src/ws_transport.ts @@ -19,7 +19,7 @@ import type { Server, ServerInfo, Transport, -} from "https://raw.githubusercontent.com/nats-io/nats.deno/dev/nats-base-client/internal_mod.ts"; +} from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/nats-base-client/internal_mod.ts"; import { checkOptions, DataBuffer, @@ -30,7 +30,7 @@ import { INFO, NatsError, render, -} from "https://raw.githubusercontent.com/nats-io/nats.deno/dev/nats-base-client/internal_mod.ts"; +} from "https://raw.githubusercontent.com/nats-io/nats.deno/js-module/nats-base-client/internal_mod.ts"; const VERSION = "1.16.0-1"; const LANG = "nats.ws"; diff --git a/test/jetstream.js b/test/jetstream.js index bd0b7a4..5772c72 100644 --- a/test/jetstream.js +++ b/test/jetstream.js @@ -13,14 +13,13 @@ * limitations under the License. */ const test = require("ava"); -const { delay } = require("../lib/nats-base-client/internal_mod"); +const { delay, DataBuffer } = require("../lib/nats-base-client/internal_mod"); const { connect, Empty, consumerOpts, AckPolicy, headers, StringCodec } = require( "./index", ); const { NatsServer, wsConfig } = require("./helpers/launcher"); const { jetstreamServerConf } = require("./helpers/jsutil"); -const { DataBuffer } = require("../lib/nats-base-client/databuffer"); const { setTimeout } = require("timers"); test("jetstream - jsm", async (t) => { diff --git a/tsconfig.json b/tsconfig.json index 94eb270..096f03e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "allowJs": true }, "include": [ - "wst" + "wst", ], "exclude": [ "src/**/*",