Skip to content

Commit cde798f

Browse files
committed
feat(sdk-core): add ESM build support
Add dual CJS/ESM build to enable Turbopack compatibility. - Add tsconfig.esm.json for ES module build - Update tsconfig.json to output to dist/cjs - Add conditional exports and module field in package.json - Fix lodash import syntax for ESM compatibility SCAAS-2084
1 parent 6e44eca commit cde798f

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

modules/sdk-core/package.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22
"name": "@bitgo/sdk-core",
33
"version": "36.22.0",
44
"description": "core library functions for BitGoJS",
5-
"main": "./dist/src/index.js",
6-
"types": "./dist/src/index.d.ts",
5+
"main": "./dist/cjs/src/index.js",
6+
"module": "./dist/esm/index.js",
7+
"browser": "./dist/esm/index.js",
8+
"types": "./dist/cjs/src/index.d.ts",
79
"files": [
8-
"dist"
10+
"dist/cjs",
11+
"dist/esm"
912
],
13+
"exports": {
14+
".": {
15+
"import": {
16+
"types": "./dist/esm/index.d.ts",
17+
"default": "./dist/esm/index.js"
18+
},
19+
"require": {
20+
"types": "./dist/cjs/src/index.d.ts",
21+
"default": "./dist/cjs/src/index.js"
22+
}
23+
}
24+
},
1025
"scripts": {
1126
"test": "yarn unit-test",
1227
"unit-test": "nyc -- mocha --recursive test",
13-
"build": "yarn tsc --build --incremental --verbose .",
28+
"build": "yarn build:cjs && yarn build:esm",
29+
"build:cjs": "yarn tsc --build --incremental --verbose .",
30+
"build:esm": "yarn tsc --project tsconfig.esm.json",
1431
"fmt": "prettier --write .",
1532
"check-fmt": "prettier --check '**/*.{ts,js,json}'",
1633
"clean": "rm -r ./dist",

modules/sdk-core/src/bitgo/tss/eddsa/eddsa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '../../utils';
2424
import { BaseTransaction } from '../../../account-lib';
2525
import { Ed25519Bip32HdTree } from '@bitgo/sdk-lib-mpc';
26-
import _ = require('lodash');
26+
import _ from 'lodash';
2727
import { commonVerifyWalletSignature, getTxRequest, sendSignatureShare } from '../common';
2828
import { IRequestTracer } from '../../../api';
2929

modules/sdk-core/tsconfig.esm.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist/esm",
5+
"rootDir": "./src",
6+
"module": "ES2020",
7+
"target": "ES2020",
8+
"moduleResolution": "bundler",
9+
"lib": ["ES2020", "DOM"],
10+
"declaration": true,
11+
"declarationMap": true,
12+
"skipLibCheck": true
13+
},
14+
"include": ["src/**/*"],
15+
"exclude": ["node_modules", "test", "dist"],
16+
"references": []
17+
}

modules/sdk-core/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "./dist",
4+
"outDir": "./dist/cjs",
55
"rootDir": "./",
6+
"module": "node16",
7+
"moduleResolution": "node16",
68
"strictPropertyInitialization": false,
79
"esModuleInterop": true,
810
"typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"]

0 commit comments

Comments
 (0)