diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 1dca4a0..bad31ae 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -20,6 +20,10 @@ jobs: cache: 'npm' - name: install run: npm install --legacy-peer-deps + - name: lint + run: npm run lint + - name: test + run: npm run test - name: build run: npm run build #- name: print diff if failed diff --git a/.gitignore b/.gitignore index 0667ab2..ae8ab9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .DS_Store node_modules dist +esm +cjs .nyc_output coverage diff --git a/package-lock.json b/package-lock.json index 120779e..78c8980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,8 @@ "@web3-react/walletlink-connector": "^6.2.13", "ethers": "^6.9.1", "magic-sdk": "^21.4.1", - "socket.io-client": "^4.7.2" + "socket.io-client": "^4.7.2", + "tslib": "^2.6.2" }, "devDependencies": { "@types/chai": "^4.2.14", @@ -4132,6 +4133,11 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==" }, + "node_modules/ethers/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + }, "node_modules/ethers/node_modules/ws": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", @@ -9174,7 +9180,6 @@ }, "node_modules/npm/node_modules/lodash._baseindexof": { "version": "3.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -9190,19 +9195,16 @@ }, "node_modules/npm/node_modules/lodash._bindcallback": { "version": "3.0.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._cacheindexof": { "version": "3.0.2", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._createcache": { "version": "3.1.2", - "extraneous": true, "inBundle": true, "license": "MIT", "dependencies": { @@ -9217,7 +9219,6 @@ }, "node_modules/npm/node_modules/lodash._getnative": { "version": "3.9.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -9235,7 +9236,6 @@ }, "node_modules/npm/node_modules/lodash.restparam": { "version": "3.6.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -13653,9 +13653,9 @@ } }, "node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/tslint": { "version": "5.20.1", @@ -18056,6 +18056,11 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==" }, + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + }, "ws": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", @@ -21862,8 +21867,7 @@ }, "lodash._baseindexof": { "version": "3.1.0", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._baseuniq": { "version": "4.6.0", @@ -21876,18 +21880,15 @@ }, "lodash._bindcallback": { "version": "3.0.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._cacheindexof": { "version": "3.0.2", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._createcache": { "version": "3.1.2", "bundled": true, - "extraneous": true, "requires": { "lodash._getnative": "^3.0.0" } @@ -21899,8 +21900,7 @@ }, "lodash._getnative": { "version": "3.9.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._root": { "version": "3.0.1", @@ -21914,8 +21914,7 @@ }, "lodash.restparam": { "version": "3.6.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash.union": { "version": "4.6.0", @@ -25344,9 +25343,9 @@ } }, "tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "tslint": { "version": "5.20.1", diff --git a/package.json b/package.json index 52786dc..aed9f1f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,25 @@ { "name": "decentraland-connect", "version": "0.0.0-development", - "main": "dist", + "main": "cjs/index.js", + "module": "esm/index.js", + "exports": { + ".": { + "import": "./esm/index.js", + "require": "./cjs/index.js" + } + }, + "files": [ + "esm", + "cjs" + ], "scripts": { - "prebuild": "rimraf dist", "lint": "tslint --project tsconfig.json -e '*.json' -c tslint.json 'src/**/*.ts{,x}'", "lint:fix": "tslint --fix --project tsconfig.json -e '*.json' -c tslint.json 'src/**/*.ts{,x}'", - "build": "npm run lint && npm run test && tsc --project tsconfig.json", + "postbuild": "node scripts/postbuild.js", + "build:esm": "tsc --project tsconfig.esm.json", + "build:cjs": "tsc --project tsconfig.cjs.json", + "build": "npm run build:esm && npm run build:cjs", "test": "TS_NODE_PROJECT=tsconfig-tests.json nyc mocha --require ts-node/register --project ./tsconfig-tests.json --watch-files src, test/**/*.ts", "test:watch": "npm test -- --watch", "test:report": "npx nyc --silent --no-clean npm run test && npx nyc report --reporter=lcov --reporter=text", @@ -25,7 +38,8 @@ "@web3-react/walletlink-connector": "^6.2.13", "ethers": "^6.9.1", "magic-sdk": "^21.4.1", - "socket.io-client": "^4.7.2" + "socket.io-client": "^4.7.2", + "tslib": "^2.6.2" }, "devDependencies": { "@types/chai": "^4.2.14", diff --git a/scripts/postbuild.js b/scripts/postbuild.js new file mode 100644 index 0000000..d17dff8 --- /dev/null +++ b/scripts/postbuild.js @@ -0,0 +1,15 @@ +const fs = require('fs') + +fs.writeFileSync( + 'cjs/package.json', + JSON.stringify({ + type: 'commonjs' + }) +) + +fs.writeFileSync( + 'esm/package.json', + JSON.stringify({ + type: 'module' + }) +) diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..87cce2e --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "cjs", + "target": "es6", + }, + "exclude": ["node_modules", "dist", "esm", "cjs", "test"] +} \ No newline at end of file diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..32f0e2f --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,10 @@ + +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "esnext", + "outDir": "esm", + "target": "esnext" + }, + "exclude": ["node_modules", "dist", "esm", "cjs", "test"] +} diff --git a/tsconfig.json b/tsconfig.json index 82ddfe9..ecd1b89 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,7 @@ { "compilerOptions": { "baseUrl": ".", - "outDir": "dist", - "module": "CommonJS", - "target": "es2017", - "lib": ["es2017", "dom"], + "lib": ["es2020", "dom"], "strict": true, "sourceMap": true, "moduleResolution": "node", @@ -15,6 +12,7 @@ "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedParameters": true, + "importHelpers": true, "noUnusedLocals": true, "plugins": [{ "name": "tslint-language-service" }], "declaration": true, @@ -25,6 +23,8 @@ "exclude": [ "node_modules", "dist", + "esm", + "cjs", "build", "test", "scripts",