From c6cb7be243d6a242f07fc3b9a2fe34b723e39f45 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 09:15:21 +1000 Subject: [PATCH 1/7] Fix build outputs --- .circleci/config.yml | 12 ++++++------ package.json | 7 ++++--- rollup.config.js | 27 ++++++++++++++++----------- src/interfaces.ts | 6 +++--- tsconfig.json | 11 ++++------- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e88633c..7fee990 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,13 +30,13 @@ jobs: - run: npm publish --dry-run - run: ls -al - run: pwd - - run: gzip -9 /root/project/dist/bnc-sdk.js - - run: mv /root/project/dist/bnc-sdk.js.gz /root/project/dist/bnc-sdk.js + - run: gzip -9 /root/project/dist/iife/index.js + - run: mv /root/project/dist/iife/index.js.gz /root/project/dist/iife/index.js - run: ls -al - run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV - run: mkdir /root/project/deploy-temp - run: mkdir /root/project/deploy-temp/${VERSION} - - run: mv /root/project/dist/*.js /root/project/deploy-temp/${VERSION}/ + - run: mv /root/project/dist/iife/*.js /root/project/deploy-temp/${VERSION}/ - run: aws s3 sync /root/project/deploy-temp/${VERSION}/ s3://staging.sdk.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers deploy_prod: docker: @@ -50,13 +50,13 @@ jobs: - run: sudo npm i -g add npm-cli-login - run: NPM_USER=$NPM_USERNAME NPM_EMAIL=$NPM_EMAIL NPM_PASS=$NPM_PASSWORD npm-cli-login - run: npm publish - - run: gzip -9 /root/project/dist/bnc-sdk.js - - run: mv /root/project/dist/bnc-sdk.js.gz /root/project/dist/bnc-sdk.js + - run: gzip -9 /root/project/dist/iife/index.js + - run: mv /root/project/dist/iife/index.js.gz /root/project/dist/iife/index.js - run: ls -al - run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV - run: mkdir /root/project/deploy-temp - run: mkdir /root/project/deploy-temp/${VERSION} - - run: mv /root/project/dist/*.js /root/project/deploy-temp/${VERSION}/ + - run: mv /root/project/dist/iife/*.js /root/project/deploy-temp/${VERSION}/ - run: aws s3 sync /root/project/deploy-temp/${VERSION}/ s3://sdk.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers workflows: version: 2 diff --git a/package.json b/package.json index cdb0e03..fc360d3 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,9 @@ "blocknative", "notifications" ], - "main": "dist/bnc-sdk.js", - "module": "dist/bnc-sdk.esm.js", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "browser": "dist/iife/index.js", "typings": "dist/types/src/index.d.ts", "files": [ "dist" @@ -21,7 +22,7 @@ }, "license": "MIT", "scripts": { - "build": "rimraf dist && rollup -c && babel dist/bnc-sdk.esm.js -o dist/bnc-sdk.esm.js && babel dist/bnc-sdk.js -o dist/bnc-sdk.js", + "build": "rimraf dist && rollup -c && babel dist/esm/index.js -o dist/esm/index.js && babel dist/cjs/index.js -o dist/cjs/index.js", "test": "echo \"TBD\" && exit 0" }, "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js index e457808..a601fa1 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,32 +3,37 @@ import json from '@rollup/plugin-json' import typescript from 'rollup-plugin-typescript2' import commonjs from '@rollup/plugin-commonjs' -const pkg = require('./package.json') - export default [ { input: `src/index.ts`, output: { - file: pkg.main, + dir: 'dist/iife/', + format: 'iife', name: 'bncSdk', - format: 'umd', - globals: ['SturdyWebSocket'] + globals: ['SturdyWebSocket', 'crypto-es'], }, plugins: [ json(), resolve(), commonjs(), - typescript({ useTsconfigDeclarationDir: true }) - ] + typescript({ useTsconfigDeclarationDir: true, clean: true }), + ], }, { input: `src/index.ts`, - output: { file: pkg.module, format: 'esm' }, + output: [ + { + format: 'esm', + dir: 'dist/esm/', + }, + { format: 'cjs', dir: 'dist/cjs/' }, + ], external: ['sturdy-websocket', 'crypto-es'], plugins: [ json(), resolve(), - typescript({ useTsconfigDeclarationDir: true }) - ] - } + commonjs(), + typescript({ useTsconfigDeclarationDir: true, clean: true }), + ], + }, ] diff --git a/src/interfaces.ts b/src/interfaces.ts index 2a71415..2e96d73 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -43,7 +43,7 @@ export interface TransactionData { } export interface TransactionEvent { - emitterResult: undefined | boolean | NotificationObject + emitterResult: void | boolean | NotificationObject transaction: TransactionData } @@ -61,7 +61,7 @@ export interface Emitter { [key: string]: EmitterListener } on: (eventCode: string, listener: EmitterListener) => void - emit: (state: TransactionData) => boolean | undefined | NotificationObject + emit: (state: TransactionData) => boolean | void | NotificationObject } export interface Ac { @@ -109,7 +109,7 @@ export interface TransactionHandler { } export interface EmitterListener { - (state: TransactionData): boolean | undefined | NotificationObject + (state: TransactionData): boolean | undefined | NotificationObject | void } export interface Transaction { diff --git a/tsconfig.json b/tsconfig.json index 8117293..9924318 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,14 @@ { "compilerOptions": { "moduleResolution": "node", - "target": "es5", - "module": "es2015", - "lib": ["es2015", "es2016", "es2017", "dom"], + "target": "ESNEXT", + "module": "ESNEXT", "strict": true, - "sourceMap": true, "declaration": true, "allowSyntheticDefaultImports": true, "declarationDir": "dist/types", - "outDir": "dist/lib", - "typeRoots": ["node_modules/@types"], + "esModuleInterop": true, "resolveJsonModule": true }, - "include": ["src"] + "include": ["src/**/*"] } From 30d4ac9234455dc0beb95f5ea72d63a3f2b4181b Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 09:20:45 +1000 Subject: [PATCH 2/7] Add prepare script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fc360d3..94beafd 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "license": "MIT", "scripts": { "build": "rimraf dist && rollup -c && babel dist/esm/index.js -o dist/esm/index.js && babel dist/cjs/index.js -o dist/cjs/index.js", - "test": "echo \"TBD\" && exit 0" + "test": "echo \"TBD\" && exit 0", + "prepare": "npm run build" }, "devDependencies": { "@babel/cli": "^7.7.0", From 79aae3c5e5c80ca25b9e090fdd9130d71b1e874f Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 09:47:19 +1000 Subject: [PATCH 3/7] Separate cjs build and commonjs node modules --- rollup.config.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index a601fa1..4e742af 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -26,13 +26,26 @@ export default [ format: 'esm', dir: 'dist/esm/', }, - { format: 'cjs', dir: 'dist/cjs/' }, ], external: ['sturdy-websocket', 'crypto-es'], plugins: [ json(), resolve(), - commonjs(), + typescript({ useTsconfigDeclarationDir: true, clean: true }), + ], + }, + { + input: `src/index.ts`, + output: [ + { + format: 'cjs', + dir: 'dist/cjs/', + }, + ], + plugins: [ + json(), + resolve(), + commonjs({ include: /node_modules/ }), typescript({ useTsconfigDeclarationDir: true, clean: true }), ], }, From db861b047507af1229ce6585765319a84e90d2aa Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 09:50:28 +1000 Subject: [PATCH 4/7] Remove prepare script --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 94beafd..fc360d3 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "license": "MIT", "scripts": { "build": "rimraf dist && rollup -c && babel dist/esm/index.js -o dist/esm/index.js && babel dist/cjs/index.js -o dist/cjs/index.js", - "test": "echo \"TBD\" && exit 0", - "prepare": "npm run build" + "test": "echo \"TBD\" && exit 0" }, "devDependencies": { "@babel/cli": "^7.7.0", From 1343a94a3dc7f91aab1b10f48ab7f21ba202ab3c Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 10:36:23 +1000 Subject: [PATCH 5/7] Remove browser field --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index fc360d3..a623110 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ ], "main": "dist/cjs/index.js", "module": "dist/esm/index.js", - "browser": "dist/iife/index.js", "typings": "dist/types/src/index.d.ts", "files": [ "dist" From c10df75e64f26465c56a5654f4f76f37db0b3e74 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 10:36:30 +1000 Subject: [PATCH 6/7] Update prettier config --- .prettierrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 466499b..273b4d3 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,5 +3,6 @@ "tabWidth": 2, "useTabs": false, "semi": false, - "singleQuote": true + "singleQuote": true, + "trailingComma": "none" } From bf408123e2a78d56ebf113c35f4c0f9a55c49c89 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 17 Apr 2020 10:57:34 +1000 Subject: [PATCH 7/7] Change to version 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a623110..7280d28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bnc-sdk", - "version": "2.0.0", + "version": "2.0.1", "description": "SDK to connect to the blocknative backend via a websocket connection", "keywords": [ "ethereum",