From c8b2101ecf2b0fc5ae86bbf70b14f50ad5c6be0d Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 18 Sep 2023 13:25:51 -0600 Subject: [PATCH] fix(cjs): add separate cjs and esm outputs --- package.json | 12 +++--------- src/web/signer.ts | 8 +++++--- tsconfig.cjs.json | 8 ++++++++ tsconfig.json | 2 +- tsconfig.web.json | 5 ++++- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 tsconfig.cjs.json diff --git a/package.json b/package.json index 5c65efae..958ea360 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ }, "exports": { "./node": { - "import": "./lib/node/index.js", - "require": "./lib/node/index.js", + "import": "./lib/esm/node/index.js", + "require": "./lib/cjs/node/index.js", "types": "./lib/node/index.d.ts" }, "./web": { @@ -30,11 +30,6 @@ "require": "./lib/web/index.js", "types": "./lib/web/index.d.ts", "browser": "./bundles/web.bundle.min.js" - }, - "./*": { - "import": "./*.js", - "require": "./*.js", - "types": "./*.d.ts" } }, "engines": { @@ -43,8 +38,7 @@ "license": "AGPL-3.0-or-later", "scripts": { "build:web": "node bundle.cjs", - "build:esm": "yarn tsc -p tsconfig.node.json && yarn tsc -p tsconfig.web.json", - "build": "yarn clean && yarn build:web && yarn build:esm", + "build": "yarn clean && yarn tsc -p tsconfig.json && yarn tsc -p tsconfig.cjs.json", "clean": "rimraf [ lib coverage bundles ]", "lint": "eslint src", "lint:fix": "eslint src --fix", diff --git a/src/web/signer.ts b/src/web/signer.ts index 89c245da..af63f5dc 100644 --- a/src/web/signer.ts +++ b/src/web/signer.ts @@ -14,8 +14,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { ArweaveSigner, createData } from 'arbundles/web'; -import Arweave from 'arweave/web/index.js'; +import { ArweaveSigner, createData } from 'arbundles'; +import Arweave from 'arweave'; import { randomBytes } from 'node:crypto'; import { ReadableStream } from 'node:stream/web'; @@ -52,9 +52,11 @@ export class TurboWebArweaveSigner implements TurboWalletSigner { async generateSignedRequestHeaders() { const nonce = randomBytes(16).toString('hex'); const buffer = Buffer.from(nonce); - const signature = await Arweave.default.crypto.sign( + // a bit hacky - but easiest way to solve web signing issues while still building for cjs + const signature = await (Arweave as any).default.crypto.sign( this.privateKey, buffer, + {}, ); return { diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 00000000..b6b7e42e --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "moduleResolution": "node", + "outDir": "./lib/cjs" + } +} diff --git a/tsconfig.json b/tsconfig.json index 9bd4dc22..b12725de 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "allowSyntheticDefaultImports": true, "declaration": true, "lib": ["esnext", "dom"], - "outDir": "./lib", + "outDir": "./lib/esm", "listEmittedFiles": false, "listFiles": false, "moduleResolution": "nodenext", diff --git a/tsconfig.web.json b/tsconfig.web.json index c58d0b01..4380fb06 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -1,4 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["src/web", "src/common", "src/utils"] + "include": ["src/web", "src/common", "src/utils"], + "compilerOptions": { + "outDir": "./lib/web" + } }