Skip to content

Commit

Permalink
feat: Build with ESM and CommonJS (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio authored Jan 30, 2024
1 parent 4d812b6 commit 350dc03
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
node_modules
dist
esm
cjs
.nyc_output
coverage
47 changes: 23 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions scripts/postbuild.js
Original file line number Diff line number Diff line change
@@ -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'
})
)
9 changes: 9 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "cjs",
"target": "es6",
},
"exclude": ["node_modules", "dist", "esm", "cjs", "test"]
}
10 changes: 10 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "esm",
"target": "esnext"
},
"exclude": ["node_modules", "dist", "esm", "cjs", "test"]
}
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"module": "CommonJS",
"target": "es2017",
"lib": ["es2017", "dom"],
"lib": ["es2020", "dom"],
"strict": true,
"sourceMap": true,
"moduleResolution": "node",
Expand All @@ -15,6 +12,7 @@
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedParameters": true,
"importHelpers": true,
"noUnusedLocals": true,
"plugins": [{ "name": "tslint-language-service" }],
"declaration": true,
Expand All @@ -25,6 +23,8 @@
"exclude": [
"node_modules",
"dist",
"esm",
"cjs",
"build",
"test",
"scripts",
Expand Down

0 comments on commit 350dc03

Please sign in to comment.