Skip to content

Commit e7f343b

Browse files
committed
Add dual commonjs/esm build process
- commonjs bundle is found at dist/main - esm bundle is found at dist/module
1 parent 98cd937 commit e7f343b

13 files changed

Lines changed: 6259 additions & 335 deletions

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"electrum",
5454
"equalverify",
5555
"eslintignore",
56+
"esnext",
5657
"ethereum",
5758
"ethereum's",
5859
"eval",

examples/webapp/src/App.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'bootstrap/dist/css/bootstrap.css'
33

44
import React from 'react'
55
import { Container, Row, Col, Form, Button } from 'react-bootstrap'
6-
import { BITBOX, Crypto } from 'bitbox-sdk'
6+
import { BITBOX } from 'bitbox-sdk'
77
import { ECPair } from 'bitcoincashjs-lib'
88
import { CashCompiler, ElectrumNetworkProvider, Contract, SignatureTemplate } from 'cashscript'
99

@@ -12,16 +12,13 @@ interface AppState {
1212
balance?: number
1313
seed: string
1414
keypair?: ECPair
15-
loading: boolean
1615
receiveAddress: string
1716
transactionLink?: string
1817
}
1918

20-
2119
class App extends React.Component<{}, AppState> {
2220
state: AppState = {
2321
seed: 'CashScript',
24-
loading: false,
2522
receiveAddress: 'bchtest:pzfsp649y00eay9mm3ky63ln72v3h6tx6gul8mlg93',
2623
}
2724

@@ -32,7 +29,6 @@ class App extends React.Component<{}, AppState> {
3229
}
3330

3431
async compileContract(seed: string) {
35-
this.setState({ loading: true })
3632
// Fetch CashFile
3733
const source = await this.getContractSource()
3834

@@ -61,7 +57,7 @@ class App extends React.Component<{}, AppState> {
6157
// Retrieve contract balance
6258
const balance = await contract.getBalance()
6359

64-
this.setState({ contract, balance, keypair: alice, loading: false })
60+
this.setState({ contract, balance, keypair: alice })
6561
}
6662

6763
async sendTestTransaction(receiveAddress: string) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"workspaces": [
55
"packages/*",
6-
"examples"
6+
"examples",
7+
"examples/webapp"
78
],
89
"devDependencies": {
910
"@types/jest": "^24.0.25",

packages/cashc/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cashc",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "Compile Bitcoin Cash contracts to Bitcoin Cash Script or artifacts",
55
"keywords": [
66
"bitcoin",
@@ -22,10 +22,11 @@
2222
"contributors": [
2323
"Gabriel Cardona <gabriel@bitcoin.com>"
2424
],
25-
"main": "dist/index",
26-
"types": "dist/index",
25+
"main": "dist/main/index",
26+
"module": "dist/module/index",
27+
"types": "dist/module/index",
2728
"bin": {
28-
"cashc": "dist/cashc-cli.js"
29+
"cashc": "dist/main/cashc-cli.js"
2930
},
3031
"directories": {
3132
"lib": "src",
@@ -35,7 +36,9 @@
3536
"antlr": "antlr4ts -visitor -listener src/grammar/CashScript.g4",
3637
"build": "npm run clean && npm run compile",
3738
"clean": "rm -rf ./dist",
38-
"compile": "tsc -p tsconfig.build.json",
39+
"compile": "npm run compile:main && npm run compile:module",
40+
"compile:main": "tsc -p tsconfig.build.main.json",
41+
"compile:module": "tsc -p tsconfig.build.module.json",
3942
"lint": "eslint . --ext .ts --ignore-path ../../.eslintignore",
4043
"prepare": "npm run build",
4144
"prepublishOnly": "npm test && npm run lint",

packages/cashc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export {
1515
CashCompiler,
1616
} from './util';
1717

18-
export const version = '0.5.3';
18+
export const version = '0.5.4';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.build.json",
3+
4+
"compilerOptions": {
5+
"outDir": "./dist/main",
6+
"module": "commonjs",
7+
},
8+
9+
"include": [
10+
"src/**/*"
11+
]
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.build.json",
3+
4+
"compilerOptions": {
5+
"outDir": "./dist/module",
6+
"module": "esnext",
7+
"target": "es2019",
8+
},
9+
10+
"include": [
11+
"src/**/*"
12+
]
13+
}

packages/cashscript/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cashscript",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "Easily write and interact with Bitcoin Cash contracts",
55
"keywords": [
66
"bitcoin cash",
@@ -21,16 +21,19 @@
2121
"contributors": [
2222
"Gabriel Cardona <gabriel@bitcoin.com>"
2323
],
24-
"main": "dist/index",
25-
"types": "dist/index",
24+
"main": "dist/main/index",
25+
"module": "dist/module/index",
26+
"types": "dist/module/index",
2627
"directories": {
2728
"lib": "src",
2829
"test": "test"
2930
},
3031
"scripts": {
3132
"build": "npm run clean && npm run compile",
3233
"clean": "rm -rf ./dist",
33-
"compile": "tsc -p tsconfig.build.json",
34+
"compile": "npm run compile:main && npm run compile:module",
35+
"compile:main": "tsc -p tsconfig.build.main.json",
36+
"compile:module": "tsc -p tsconfig.build.module.json",
3437
"lint": "eslint . --ext .ts --ignore-path ../../.eslintignore",
3538
"prepare": "npm run build",
3639
"prepublishOnly": "npm test && npm run lint",
@@ -39,7 +42,7 @@
3942
"dependencies": {
4043
"@bitauth/libauth": "^1.17.2",
4144
"bip68": "^1.0.4",
42-
"cashc": "^0.5.3",
45+
"cashc": "^0.5.4",
4346
"delay": "^4.3.0",
4447
"electrum-cash": "^2.0.4",
4548
"hash.js": "^1.1.7"

packages/cashscript/test/fixture/update_fixtures.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DIR=$(dirname "$0")
44
cd $DIR
55

6-
CASHC="../../../cashc/dist/cashc-cli.js"
6+
CASHC="../../../cashc/dist/main/cashc-cli.js"
77

88
find . -name "*.cash" | while read fn; do
99
echo node "$CASHC" -o "$(basename "$fn" .cash).json" "$fn"

packages/cashc/tsconfig.build.json renamed to packages/cashscript/tsconfig.build.main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.build.json",
33

44
"compilerOptions": {
5-
"outDir": "./dist"
5+
"outDir": "./dist/main",
6+
"module": "commonjs"
67
},
78

89
"include": [

0 commit comments

Comments
 (0)