From b4fd1234d59fb78b99a128cd7ec4f8fc57e83487 Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Wed, 29 Sep 2021 09:42:25 +0200 Subject: [PATCH] fix(nats): change in the way nats is referenced changed the way nats.ws is referenced according to document https://github.com/nats-io/nats.ws/blob/master/developer_notes.md --- bili.config.ts | 36 +++++++++-------------- src/iam.ts | 2 +- src/iam/iam-base.ts | 2 +- test/claimsTests/enrollmentClaimsTests.ts | 2 +- test/testUtils/mocks.ts | 2 +- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bili.config.ts b/bili.config.ts index 23570cc2..d61a8769 100644 --- a/bili.config.ts +++ b/bili.config.ts @@ -1,28 +1,20 @@ import { Config } from "bili"; const config: Config = { - plugins: { - typescript2: { - tsconfigOverride: { - include: ["src", "ethers"] - } - } - }, - extendConfig: config => ({ - ...config, - // The default externals are the package.json dependencies and can only bundle node_modules that are not a dependency. - // So need to clear out all externals, to bundle nats.ws package. - externals: [] - }), - // nats.ws is bundled because using standard import/require does not work for cjs format. - // nat.ws only provides a .mjs file which cannot be required. - // include tslib for clients using older version of tslib - bundleNodeModules: ["nats.ws", "tslib"], - input: "src/iam-client-lib.ts", - output: { - format: ["cjs", "esm"], - minify: false - } + plugins: { + typescript2: { + tsconfigOverride: { + include: ["src", "ethers"], + }, + }, + }, + // include tslib for clients using older version of tslib + bundleNodeModules: ["tslib"], + input: "src/iam-client-lib.ts", + output: { + format: ["cjs", "esm"], + minify: false, + }, }; export default config; diff --git a/src/iam.ts b/src/iam.ts index 44ff2b54..e3de099c 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -63,7 +63,7 @@ import { proof_type_hash, typedMsgPrefix, } from "./utils/constants"; -import { Subscription } from "nats.ws"; +import { Subscription } from "../node_modules/nats.ws/lib/src/mod.js"; import { AxiosError } from "axios"; import { DIDDocumentFull } from "@ew-did-registry/did-document"; import { Methods } from "@ew-did-registry/did"; diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index ed4bd3f8..dd1f6d0b 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -25,7 +25,7 @@ import { ClaimManager } from "../../ethers/ClaimManager"; import { JWT } from "@ew-did-registry/jwt"; import { ICacheServerClient } from "../cacheServerClient/ICacheServerClient"; import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment"; -import { connect, NatsConnection, JSONCodec, Codec } from "nats.ws"; +import { connect, NatsConnection, Codec, JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { ERROR_MESSAGES } from "../errors"; import { ClaimData } from "../cacheServerClient/cacheServerClient.types"; import difference from "lodash.difference"; diff --git a/test/claimsTests/enrollmentClaimsTests.ts b/test/claimsTests/enrollmentClaimsTests.ts index f1420548..5df99286 100644 --- a/test/claimsTests/enrollmentClaimsTests.ts +++ b/test/claimsTests/enrollmentClaimsTests.ts @@ -2,7 +2,7 @@ import { PreconditionType } from "@energyweb/iam-contracts"; import { Methods } from "@ew-did-registry/did"; import { addressOf } from "@ew-did-registry/did-ethr-resolver"; import { Wallet, utils } from "ethers"; -import { Codec } from "nats.ws"; +import { Codec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { IAM, RegistrationTypes, IRoleDefinition, NATS_EXCHANGE_TOPIC } from "../../src/iam-client-lib"; import { createIam, root, rootOwner } from "../iam.test"; import { claimManager, replenish } from "../setup_contracts"; diff --git a/test/testUtils/mocks.ts b/test/testUtils/mocks.ts index 53a6eb54..ad02551c 100644 --- a/test/testUtils/mocks.ts +++ b/test/testUtils/mocks.ts @@ -1,5 +1,5 @@ import { IRoleDefinition } from "@energyweb/iam-contracts"; -import { JSONCodec } from "nats.ws"; +import { JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { Claim } from "../../src/cacheServerClient/cacheServerClient.types"; import { IAM } from "../../src/iam";