From d78abee1e8ccf3be019dfafeb5a95ff7207e1861 Mon Sep 17 00:00:00 2001 From: John Rees Date: Sat, 15 Jan 2022 00:43:24 +0000 Subject: [PATCH] build: generate commonjs and esmodules builds --- packages/governance-sdk/bin/after-build.sh | 13 +++++++++ packages/governance-sdk/package.json | 13 +++++++-- packages/governance-sdk/tsconfig-base.json | 20 ++++++++++++++ packages/governance-sdk/tsconfig.cjs.json | 8 ++++++ packages/governance-sdk/tsconfig.json | 32 ++++------------------ 5 files changed, 57 insertions(+), 29 deletions(-) create mode 100755 packages/governance-sdk/bin/after-build.sh create mode 100644 packages/governance-sdk/tsconfig-base.json create mode 100644 packages/governance-sdk/tsconfig.cjs.json diff --git a/packages/governance-sdk/bin/after-build.sh b/packages/governance-sdk/bin/after-build.sh new file mode 100755 index 00000000..91fa6cc4 --- /dev/null +++ b/packages/governance-sdk/bin/after-build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +cat >lib/cjs/package.json <lib/mjs/package.json <", "homepage": "https://github.com/solana-labs/oyster/blob/main/packages/governance-sdk/README.md", "license": "MIT", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "lib/cjs/index.js", + "module": "lib/mjs/index.js", + "types": "lib/mjs/index.d.ts", + "source": "src/index.ts", + "exports": { + "import": "./lib/mjs/index.js", + "require": "./lib/cjs/index.js" + }, "directories": { "lib": "lib" }, @@ -19,7 +25,7 @@ }, "sideEffects": false, "scripts": { - "build": "tsc", + "build": "rimraf lib && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && ./bin/after-build.sh", "test": "jest", "start": "npm-run-all --parallel watch", "watch": "tsc --watch" @@ -40,6 +46,7 @@ "esbuild": "^0.14.11", "esbuild-jest": "^0.5.0", "jest": "^27.4.7", + "rimraf": "^3.0.2", "typescript": "^4.5.4" }, "jest": { diff --git a/packages/governance-sdk/tsconfig-base.json b/packages/governance-sdk/tsconfig-base.json new file mode 100644 index 00000000..af9078b7 --- /dev/null +++ b/packages/governance-sdk/tsconfig-base.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "lib": ["esnext"], + "module": "esnext", + "moduleResolution": "node", + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "pretty": true, + "resolveJsonModule": true, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": true, + "strict": true + }, + "include": ["src"] +} diff --git a/packages/governance-sdk/tsconfig.cjs.json b/packages/governance-sdk/tsconfig.cjs.json new file mode 100644 index 00000000..9ad1b33e --- /dev/null +++ b/packages/governance-sdk/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig-base.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "lib/cjs", + "target": "es2015" + } +} diff --git a/packages/governance-sdk/tsconfig.json b/packages/governance-sdk/tsconfig.json index 60e1a5d4..b02d817a 100644 --- a/packages/governance-sdk/tsconfig.json +++ b/packages/governance-sdk/tsconfig.json @@ -1,28 +1,8 @@ { + "extends": "./tsconfig-base.json", "compilerOptions": { - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "target": "es6", - "lib": [ - "es2019" - ], - "module": "commonjs", - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "outDir": "./lib", - "pretty": true, - "resolveJsonModule": true, - "rootDir": "./src", - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - }, - "include": [ - "src" - ], - "exclude": [ - "node_modules", - ] -} \ No newline at end of file + "module": "esnext", + "outDir": "lib/mjs", + "target": "esnext" + } +}