From f284747d61a2c7a4a5c6dcb81480eb27fd4c9e6b Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Thu, 19 Sep 2024 09:47:12 +0200 Subject: [PATCH] Esm Build (#64) * build esm and cjs * use github tag on publish --- .github/workflows/npm-publish.yaml | 16 +++++++++------- package.json | 4 +++- tsconfig.cjs.json | 7 +++++++ tsconfig.esm.json | 8 ++++++++ tsconfig.json | 2 -- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml index defc7be..e09285d 100644 --- a/.github/workflows/npm-publish.yaml +++ b/.github/workflows/npm-publish.yaml @@ -1,7 +1,4 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages - -name: Node.js Package +name: NPM Publish on: release: @@ -16,8 +13,13 @@ jobs: with: node-version: 20 registry-url: https://registry.npmjs.org/ - - run: yarn --frozen-lockfile - - run: yarn build - - run: npm publish --access public + - name: Build & Set Package Version to Tag + run: | + yarn --frozen-lockfile + yarn build + VERSION=${GITHUB_REF#refs/tags/} + npm version $VERSION --no-git-tag-version + - name: Publish + run: npm publish --access public env: NODE_AUTH_TOKEN: ${{secrets.DUNE_NPM_TOKEN}} diff --git a/package.json b/package.json index 38933dd..5cbfbe4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "dist/**/*" ], "scripts": { - "build": "tsc", + "build": "rm -rf dist/* && yarn build:esm && yarn build:cjs", + "build:esm": "tsc -p tsconfig.esm.json", + "build:cjs": "tsc -p tsconfig.cjs.json", "test": "jest", "fmt": "prettier --write \"./**/*.ts\"", "lint": "eslint ./src" diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..8e2ce17 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "dist/cjs", + } +} \ No newline at end of file diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..790bf24 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "outDir": "dist/esm", + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index f82f288..9e1c70c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,11 @@ { "compilerOptions": { "target": "ES2020", - "module": "CommonJS", "strict": true, "esModuleInterop": true, "resolveJsonModule": true, "moduleResolution": "node", "declaration": true, - "outDir": "dist", "rootDir": "src" }, "include": ["src"],