From 1de5078630d2b0fcaa1a2db680880f18900de60c Mon Sep 17 00:00:00 2001 From: Marek Polak Date: Fri, 6 Oct 2023 12:20:39 +0200 Subject: [PATCH] feat: default node env with browser overload --- jest.config.js | 4 ---- package.json | 7 +++++-- src/constants/index.ts | 2 +- src/methods/largestFirst.ts | 2 +- src/methods/randomImprove.ts | 2 +- src/types/types.ts | 4 ++-- src/utils/common.ts | 2 +- src/utils/trezor/sign.ts | 2 +- tests/setup.ts | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/jest.config.js b/jest.config.js index 6145831..85c9f69 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,10 +13,6 @@ module.exports = { transform: { '^.+\\.(t|j)sx?$': ['@swc-node/jest'], }, - moduleNameMapper: { - // Workaround for an error "Cannot find module @emurgo/cardano-serialization-lib-browser" - "@emurgo/cardano-serialization-lib-browser": "@emurgo/cardano-serialization-lib-nodejs", - }, coverageThreshold: { // global: { // branches: 37, diff --git a/package.json b/package.json index ddcf3c8..7ae081d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "author": "fivebinaries.com", "main": "lib/cjs/index.js", "module": "lib/esm/index.js", + "browser": { + "@emurgo/cardano-serialization-lib-nodejs": "@emurgo/cardano-serialization-lib-browser" + }, "files": [ "lib/**/*.js", "lib/**/*.ts" @@ -24,7 +27,6 @@ "test:badges": "make-coverage-badge --output-path ./docs/badge-coverage.svg" }, "devDependencies": { - "@emurgo/cardano-serialization-lib-nodejs": "11.0.0", "@swc-node/jest": "^1.5.2", "@types/jest": "^28.1.6", "@types/node": "^16.3.2", @@ -42,7 +44,8 @@ "typescript": "^4.7.4" }, "dependencies": { - "@emurgo/cardano-serialization-lib-browser": "^11.0.0" + "@emurgo/cardano-serialization-lib-browser": "^11.0.0", + "@emurgo/cardano-serialization-lib-nodejs": "11.0.0" }, "packageManager": "yarn@3.2.2" } diff --git a/src/constants/index.ts b/src/constants/index.ts index a4b2009..b2aa138 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,4 +1,4 @@ -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; export const CertificateType = { STAKE_REGISTRATION: 0, diff --git a/src/methods/largestFirst.ts b/src/methods/largestFirst.ts index 87cbb5d..935f73f 100644 --- a/src/methods/largestFirst.ts +++ b/src/methods/largestFirst.ts @@ -1,5 +1,5 @@ import { ERROR } from '../constants'; -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; import { ChangeOutput, CoinSelectionParams, diff --git a/src/methods/randomImprove.ts b/src/methods/randomImprove.ts index 57cfd7b..1a8ccae 100644 --- a/src/methods/randomImprove.ts +++ b/src/methods/randomImprove.ts @@ -1,5 +1,5 @@ import { ERROR } from '../constants'; -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; import { CoinSelectionParams, CoinSelectionResult, diff --git a/src/types/types.ts b/src/types/types.ts index 87c4008..7977da2 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1,5 +1,5 @@ -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; -import { BigNum } from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; +import { BigNum } from '@emurgo/cardano-serialization-lib-nodejs'; import { CertificateType } from '../constants'; export interface Asset { diff --git a/src/utils/common.ts b/src/utils/common.ts index b105cc8..c7dd5b4 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,4 @@ -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; import { CARDANO_PARAMS, CertificateType, diff --git a/src/utils/trezor/sign.ts b/src/utils/trezor/sign.ts index 9b162e0..6ec3ce5 100644 --- a/src/utils/trezor/sign.ts +++ b/src/utils/trezor/sign.ts @@ -1,4 +1,4 @@ -import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; +import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; import { CardanoSignedTxWitness, CardanoTxWitnessType, diff --git a/tests/setup.ts b/tests/setup.ts index 3efe47c..a5a05e3 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -3,7 +3,7 @@ jest.setTimeout(30000); import { BigNum, TransactionBody, -} from '@emurgo/cardano-serialization-lib-browser'; +} from '@emurgo/cardano-serialization-lib-nodejs'; import { CoinSelectionResult } from '../src/types/types'; import { multiAssetToArray } from '../src/utils/common';