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/.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" } diff --git a/package.json b/package.json index cdb0e03..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", @@ -8,8 +8,8 @@ "blocknative", "notifications" ], - "main": "dist/bnc-sdk.js", - "module": "dist/bnc-sdk.esm.js", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", "typings": "dist/types/src/index.d.ts", "files": [ "dist" @@ -21,7 +21,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..4e742af 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,32 +3,50 @@ 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/', + }, + ], external: ['sturdy-websocket', 'crypto-es'], plugins: [ json(), resolve(), - typescript({ useTsconfigDeclarationDir: true }) - ] - } + 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 }), + ], + }, ] 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/**/*"] }