diff --git a/.github/authorized_keys b/.github/authorized_keys deleted file mode 100644 index c7fea18..0000000 --- a/.github/authorized_keys +++ /dev/null @@ -1 +0,0 @@ -41898282+github-actions[bot]@users.noreply.github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKOzgFi8S4xZHCSjGi3u0T2OZYvefkFu8px+bLncFhq8 41898282+github-actions[bot]@users.noreply.github.com diff --git a/.github/workflows/github-pages.yaml b/.github/workflows/github-pages.yaml index 38a3c79..558e637 100644 --- a/.github/workflows/github-pages.yaml +++ b/.github/workflows/github-pages.yaml @@ -15,7 +15,7 @@ jobs: version: latest - uses: actions/setup-node@v4 with: - node-version: 21 + node-version: 23 cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm run docs diff --git a/.github/workflows/node.js.yaml b/.github/workflows/node.js.yaml index 2ff1aa9..c57ba1a 100644 --- a/.github/workflows/node.js.yaml +++ b/.github/workflows/node.js.yaml @@ -1,10 +1,15 @@ name: Node.js CI on: - push: - branches: main + merge_group: + branches: + - main pull_request: - branches: main + branches: + - main + push: + branches: + - main jobs: test: @@ -17,9 +22,68 @@ jobs: version: latest - uses: actions/setup-node@v4 with: - node-version: 21 + node-version: 23 cache: pnpm - - run: pnpm install --frozen-lockfile + - run: pnpm install --frozen-lockfile --strict-peer-dependencies - run: pnpm run build --noEmit - run: pnpm run lint - run: pnpm run test + + fix: + runs-on: ubuntu-latest + + permissions: + contents: write + + if: failure() && github.event_name != 'merge_group' && github.actor != 'github-actions[bot]' && github.actor != 'nektos/act' + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + cache: pnpm + node-version: 23 + + - run: | + pnpm install --fix-lockfile --no-frozen-lockfile + git add . + - id: commit-lockfile + uses: qoomon/actions--create-commit@v1 + with: + message: | + 📌 pnpm install --fix-lockfile + + [dependabot skip] + skip-empty: true + + - run: | + pnpm run format + git add . + - id: commit-format + uses: qoomon/actions--create-commit@v1 + with: + message: | + 🎨 pnpm run format + + [dependabot skip] + skip-empty: true + + - run: | + pnpm run lint:fix + git add . + - id: commit-lint + uses: qoomon/actions--create-commit@v1 + with: + message: | + 🚨 pnpm run lint:fix + + [dependabot skip] + skip-empty: true + + - if: steps.commit-lockfile.outputs.commit || steps.commit-format.outputs.commit || steps.commit-lint.outputs.commit + run: git push diff --git a/.github/workflows/pnpm-publish.yaml b/.github/workflows/pnpm-publish.yaml index 63ab9a3..c7d31d2 100644 --- a/.github/workflows/pnpm-publish.yaml +++ b/.github/workflows/pnpm-publish.yaml @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-node@v4 with: cache: pnpm - node-version: 21 + node-version: 23 - run: pnpm install - run: pnpm build @@ -43,13 +43,6 @@ jobs: NODE_AUTH_TOKEN: ${{ secrets.CODERABBIT_NPMTOKEN }} - run: pnpm pack --pack-gzip-level 9 - - name: Sign - run: | - eval `ssh-agent -s` - ssh-add - <<< '${{ secrets.DEPLOY_KEY_PRIVATE }}' - echo '${{ vars.DEPLOY_KEY_PUBLIC }}' > '${{ runner.temp }}/DEPLOY_KEY_PUBLIC.pub' - ssh-keygen -Y sign -f '${{ runner.temp }}/DEPLOY_KEY_PUBLIC.pub' -n file coderabbitai-openai-chat-tokens-*.tgz - ssh-keygen -Y verify -f ./.github/authorized_keys -I '41898282+github-actions[bot]@users.noreply.github.com' -n file -s coderabbitai-openai-chat-tokens-*.tgz.sig < coderabbitai-openai-chat-tokens-*.tgz - - run: gh release upload ${{ github.ref_name }} coderabbitai-openai-chat-tokens-*.tgz coderabbitai-openai-chat-tokens-*.tgz.sig + - run: gh release upload ${{ github.ref_name }} coderabbitai-openai-chat-tokens-*.tgz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pnpm-version-patch.yaml b/.github/workflows/pnpm-version-patch.yaml index 828521a..b1708d2 100644 --- a/.github/workflows/pnpm-version-patch.yaml +++ b/.github/workflows/pnpm-version-patch.yaml @@ -12,35 +12,29 @@ jobs: steps: - uses: actions/checkout@v4 with: - ssh-key: ${{ secrets.DEPLOY_KEY_PRIVATE }} + ref: ${{ github.ref }} - uses: pnpm/action-setup@v4 with: version: latest - uses: actions/setup-node@v4 with: cache: pnpm - node-version: 21 - - name: Configure Git, patch, release and push - run: | - git config user.name 'github-actions[bot]' - git config user.email '41898282+github-actions[bot]@users.noreply.github.com' - - git config commit.gpgsign true - git config gpg.format ssh - git config push.gpgSign 'if-asked' - git config tag.gpgSign true - git config user.signingkey 'key::${{ vars.DEPLOY_KEY_PUBLIC }}' + node-version: 23 - eval `ssh-agent -s` - ssh-add - <<< '${{ secrets.DEPLOY_KEY_PRIVATE }}' + - id: patch + run: | + echo "VERSION=$(pnpm version patch --no-git-tag-version)" >> "$GITHUB_OUTPUT" + git add . - VERSION=$(pnpm version patch --no-git-tag-version) + - id: commit + uses: qoomon/actions--create-commit@v1 + with: + message: 🔖 ${{ steps.patch.outputs.VERSION }} - git commit --all --message "🔖 $VERSION" - git tag --annotate --message "🔖 $VERSION" --sign $VERSION + - run: | git push - git push --tags - - gh release create $VERSION --generate-notes --title $VERSION --verify-tag + gh release create "$VERSION" --generate-notes --target "$COMMIT" --title "$VERSION" env: + COMMIT: ${{ steps.commit.outputs.commit }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.patch.outputs.VERSION }} diff --git a/README.md b/README.md index 554a250..5d4c0c5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This library handles both of those cases, as well as a minor adjustment needed f ## Usage ```typescript -import { promptTokensEstimate } from "openai-chat-tokens" +import { promptTokensEstimate } from "@coderabbitai/openai-chat-tokens" const estimate = promptTokensEstimate({ messages: [ diff --git a/package.json b/package.json index c6c8b28..75d0e40 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "format": "prettier --write .", "lint": "eslint . && prettier --check .", "lint:fix": "eslint --fix .; prettier --list-different --write .", - "test": "vitest", - "test:watch": "vitest --watch" + "test": "vitest run", + "test:watch": "vitest" }, "devDependencies": { "@eslint/js": "^9.9.1", @@ -30,7 +30,7 @@ "openai": "^4.56.0", "prettier": "^3.3.3", "typedoc": "^0.26.6", - "typescript": "5.7.3", + "typescript": "5.8.0-beta", "typescript-eslint": "^8.2.0", "vite": "^6.0.7", "vitest": "^3.0.5" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d75f12..98c7e68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,13 +29,13 @@ importers: version: 3.4.2 typedoc: specifier: ^0.26.6 - version: 0.26.10(typescript@5.7.3) + version: 0.26.10(typescript@5.8.0-beta) typescript: - specifier: 5.7.3 - version: 5.7.3 + specifier: 5.8.0-beta + version: 5.8.0-beta typescript-eslint: specifier: ^8.2.0 - version: 8.2.0(eslint@9.9.1)(typescript@5.7.3) + version: 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) vite: specifier: ^6.0.7 version: 6.1.0(@types/node@18.19.75)(yaml@2.6.0) @@ -1130,8 +1130,8 @@ packages: typescript: optional: true - typescript@5.7.3: - resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==} + typescript@5.8.0-beta: + resolution: {integrity: sha512-7VGUiBOGi+BYhiuy3iITIgu6m2wVW2Vb4CW+OJsW6OJS/TgvezKbAN3WBfiSErE8QOLdce0ilm6VANMkzNWW1A==} engines: {node: '>=14.17'} hasBin: true @@ -1507,34 +1507,34 @@ snapshots: '@types/unist@3.0.3': {} - '@typescript-eslint/eslint-plugin@8.2.0(@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.7.3))(eslint@9.9.1)(typescript@5.7.3)': + '@typescript-eslint/eslint-plugin@8.2.0(@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta))(eslint@9.9.1)(typescript@5.8.0-beta)': dependencies: '@eslint-community/regexpp': 4.11.0 - '@typescript-eslint/parser': 8.2.0(eslint@9.9.1)(typescript@5.7.3) + '@typescript-eslint/parser': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) '@typescript-eslint/scope-manager': 8.2.0 - '@typescript-eslint/type-utils': 8.2.0(eslint@9.9.1)(typescript@5.7.3) - '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.7.3) + '@typescript-eslint/type-utils': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) + '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) '@typescript-eslint/visitor-keys': 8.2.0 eslint: 9.9.1 graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.7.3) + ts-api-utils: 1.3.0(typescript@5.8.0-beta) optionalDependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.7.3)': + '@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta)': dependencies: '@typescript-eslint/scope-manager': 8.2.0 '@typescript-eslint/types': 8.2.0 - '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.7.3) + '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.8.0-beta) '@typescript-eslint/visitor-keys': 8.2.0 debug: 4.4.0 eslint: 9.9.1 optionalDependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta transitivePeerDependencies: - supports-color @@ -1543,21 +1543,21 @@ snapshots: '@typescript-eslint/types': 8.2.0 '@typescript-eslint/visitor-keys': 8.2.0 - '@typescript-eslint/type-utils@8.2.0(eslint@9.9.1)(typescript@5.7.3)': + '@typescript-eslint/type-utils@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta)': dependencies: - '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.7.3) - '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.7.3) + '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.8.0-beta) + '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) debug: 4.4.0 - ts-api-utils: 1.3.0(typescript@5.7.3) + ts-api-utils: 1.3.0(typescript@5.8.0-beta) optionalDependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta transitivePeerDependencies: - eslint - supports-color '@typescript-eslint/types@8.2.0': {} - '@typescript-eslint/typescript-estree@8.2.0(typescript@5.7.3)': + '@typescript-eslint/typescript-estree@8.2.0(typescript@5.8.0-beta)': dependencies: '@typescript-eslint/types': 8.2.0 '@typescript-eslint/visitor-keys': 8.2.0 @@ -1566,18 +1566,18 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.7.3) + ts-api-utils: 1.3.0(typescript@5.8.0-beta) optionalDependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.2.0(eslint@9.9.1)(typescript@5.7.3)': + '@typescript-eslint/utils@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.9.1) '@typescript-eslint/scope-manager': 8.2.0 '@typescript-eslint/types': 8.2.0 - '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.7.3) + '@typescript-eslint/typescript-estree': 8.2.0(typescript@5.8.0-beta) eslint: 9.9.1 transitivePeerDependencies: - supports-color @@ -2269,35 +2269,35 @@ snapshots: trim-lines@3.0.1: {} - ts-api-utils@1.3.0(typescript@5.7.3): + ts-api-utils@1.3.0(typescript@5.8.0-beta): dependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta type-check@0.4.0: dependencies: prelude-ls: 1.2.1 - typedoc@0.26.10(typescript@5.7.3): + typedoc@0.26.10(typescript@5.8.0-beta): dependencies: lunr: 2.3.9 markdown-it: 14.1.0 minimatch: 9.0.5 shiki: 1.22.2 - typescript: 5.7.3 + typescript: 5.8.0-beta yaml: 2.6.0 - typescript-eslint@8.2.0(eslint@9.9.1)(typescript@5.7.3): + typescript-eslint@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta): dependencies: - '@typescript-eslint/eslint-plugin': 8.2.0(@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.7.3))(eslint@9.9.1)(typescript@5.7.3) - '@typescript-eslint/parser': 8.2.0(eslint@9.9.1)(typescript@5.7.3) - '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.7.3) + '@typescript-eslint/eslint-plugin': 8.2.0(@typescript-eslint/parser@8.2.0(eslint@9.9.1)(typescript@5.8.0-beta))(eslint@9.9.1)(typescript@5.8.0-beta) + '@typescript-eslint/parser': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) + '@typescript-eslint/utils': 8.2.0(eslint@9.9.1)(typescript@5.8.0-beta) optionalDependencies: - typescript: 5.7.3 + typescript: 5.8.0-beta transitivePeerDependencies: - eslint - supports-color - typescript@5.7.3: {} + typescript@5.8.0-beta: {} uc.micro@2.1.0: {} diff --git a/tsconfig.json b/tsconfig.json index 6e15ce9..bace9e3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,6 +33,7 @@ "isolatedModules": true, "verbatimModuleSyntax": true, "isolatedDeclarations": true, + "erasableSyntaxOnly": true, "forceConsistentCasingInFileNames": true, /* Type Checking */