From df8031841fc9c9869b2413bc67d99acc7c33be16 Mon Sep 17 00:00:00 2001 From: utkarsh patrikar Date: Mon, 11 May 2026 01:14:50 +0530 Subject: [PATCH] fix: convert to ESM and add publish workflow --- .github/workflows/publish.yml | 65 +++++++++++++++++++++++++++++++++++ bin/kdm.js | 2 +- package-lock.json | 4 +-- package.json | 5 +-- tsconfig.json | 4 +-- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0fd6226 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +name: Publish to npm and GitHub Release + +on: + workflow_dispatch: + inputs: + release_type: + description: 'Release type (patch, minor, major)' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + - major + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm install + + - name: Build project + run: npm run build + + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Bump version + run: npm version ${{ github.event.inputs.release_type }} -m "chore: release v%s" + + - name: Push changes and tags + run: git push --follow-tags + + - name: Publish to npm + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Get Version + id: get_version + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + tag_name: v${{ steps.get_version.outputs.VERSION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/bin/kdm.js b/bin/kdm.js index edda235..0277db3 100755 --- a/bin/kdm.js +++ b/bin/kdm.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -require('../dist/index.js'); +import '../dist/index.js'; diff --git a/package-lock.json b/package-lock.json index acee837..612b6c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@utkarsh232005/kdm-cli", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@utkarsh232005/kdm-cli", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "dependencies": { "@kubernetes/client-node": "^0.20.0", diff --git a/package.json b/package.json index 3163d8d..b5fb602 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@utkarsh232005/kdm-cli", "version": "1.1.0", "description": "Kubernetes and Docker Monitoring CLI", + "type": "module", "main": "dist/index.js", "repository": { "type": "git", @@ -21,8 +22,8 @@ "LICENSE" ], "scripts": { - "build": "tsup src/index.ts --format cjs --dts", - "dev": "tsup src/index.ts --format cjs --watch", + "build": "tsup src/index.ts --format esm --dts", + "dev": "tsup src/index.ts --format esm --watch", "test": "vitest run", "prepublishOnly": "npm run build" }, diff --git a/tsconfig.json b/tsconfig.json index 2917ec8..482f160 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "target": "es2022", - "module": "commonjs", + "module": "ESNext", + "moduleResolution": "bundler", "lib": ["es2022", "dom"], "declaration": true, "outDir": "./dist", @@ -9,7 +10,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", "jsx": "react" }, "include": ["src/**/*"],