diff --git a/commitlint.config.js b/commitlint.config.js index 9e3ff39289..32f2d0816b 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -12,7 +12,7 @@ module.exports = { 'scope-enum': async () => [ 2, 'always', - (await readdir('modules')).concat('root', 'deps', 'scripts', 'examples'), + (await readdir('modules')).concat('root', 'deps', 'scripts', 'examples', 'webpack'), ], 'footer-max-line-length': [0, 'always', Infinity], 'references-empty': [2, 'never'], diff --git a/modules/utxo-ord/package.json b/modules/utxo-ord/package.json index 1651359816..10eae025bc 100644 --- a/modules/utxo-ord/package.json +++ b/modules/utxo-ord/package.json @@ -1,11 +1,26 @@ { "name": "@bitgo/utxo-ord", "description": "Utilities for building ordinals with BitGo utxo-lib", - "main": "./dist/src/index.js", - "types": "./dist/src/index.d.ts", + "main": "./dist/cjs/src/index.js", + "module": "./dist/esm/index.js", + "browser": "./dist/esm/index.js", + "types": "./dist/cjs/src/index.d.ts", "version": "1.22.22", + "exports": { + ".": { + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/cjs/src/index.d.ts", + "default": "./dist/cjs/src/index.js" + } + } + }, "files": [ - "dist/**/*" + "dist/cjs", + "dist/esm" ], "keywords": [ "bitgo", @@ -16,7 +31,9 @@ ], "scripts": { "prepare": "npm run build", - "build": "yarn tsc --build --incremental --verbose .", + "build": "npm run build:cjs && npm run build:esm", + "build:cjs": "yarn tsc --build --incremental --verbose .", + "build:esm": "yarn tsc --project tsconfig.esm.json", "lint": "eslint --quiet .", "unit-test": "mocha --recursive test", "fmt": "prettier --write '{src,test}/**/*.{ts,js}'", diff --git a/modules/utxo-ord/tsconfig.esm.json b/modules/utxo-ord/tsconfig.esm.json new file mode 100644 index 0000000000..17f39ab0f3 --- /dev/null +++ b/modules/utxo-ord/tsconfig.esm.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist/esm", + "rootDir": "./src", + "module": "ES2020", + "target": "ES2020", + "moduleResolution": "bundler", + "lib": ["ES2020", "DOM"], + "declaration": true, + "declarationMap": true, + "skipLibCheck": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "test", "dist"], + "references": [] +} diff --git a/modules/utxo-ord/tsconfig.json b/modules/utxo-ord/tsconfig.json index d589c2e2a3..877b19b0ca 100644 --- a/modules/utxo-ord/tsconfig.json +++ b/modules/utxo-ord/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist/cjs", "rootDir": ".", "typeRoots": ["./node_modules/@types", "../../node_modules/@types"], "allowJs": false, diff --git a/webpack/bitgojs.config.js b/webpack/bitgojs.config.js index 0c226c2bb3..cafdef7b5b 100644 --- a/webpack/bitgojs.config.js +++ b/webpack/bitgojs.config.js @@ -15,8 +15,11 @@ module.exports = { // use the default version here since we're webpacking ourselves '@bitgo/sdk-api': path.resolve('../sdk-api/dist/src/index.js'), async: path.resolve('../../node_modules/async/index.js'), - // Force ESM version of wasm-utxo for browser bundles (has proper wasm import) + // Force ESM versions for browser bundles - required for proper WASM initialization. + // Note: We can't use global `conditionNames: ['browser', 'import', ...]` because + // third-party packages like @solana/spl-token and @bufbuild/protobuf have broken ESM builds. '@bitgo/wasm-utxo': path.resolve('../../node_modules/@bitgo/wasm-utxo/dist/esm/js/index.js'), + '@bitgo/utxo-ord': path.resolve('../utxo-ord/dist/esm/index.js'), }, fallback: { constants: false,