Skip to content

Commit

Permalink
fix(cjs): add separate cjs and esm outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 18, 2023
1 parent dbb8065 commit c8b2101
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@
},
"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": {
"import": "./lib/web/index.js",
"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": {
Expand All @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/web/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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';

Expand Down Expand Up @@ -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(

Check warning on line 56 in src/web/signer.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Unexpected any. Specify a different type

Check warning on line 56 in src/web/signer.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Unexpected any. Specify a different type
this.privateKey,
buffer,
{},
);

return {
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./lib/cjs"
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"allowSyntheticDefaultImports": true,
"declaration": true,
"lib": ["esnext", "dom"],
"outDir": "./lib",
"outDir": "./lib/esm",
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "nodenext",
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.web.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit c8b2101

Please sign in to comment.