fix: RangeError: Invalid string length #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Release npm Packages' | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: npm-publish-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'pnpm' | |
| cache-dependency-path: pnpm-lock.yaml | |
| - name: Install dependencies | |
| run: pnpm i | |
| - name: Build packages | |
| run: pnpm build:packages | |
| release: | |
| if: startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'MaaXYZ' | |
| runs-on: ubuntu-latest | |
| needs: [build] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'pnpm' | |
| cache-dependency-path: pnpm-lock.yaml | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Update package versions from tag | |
| run: | | |
| ver=${{ github.ref_name }} | |
| ver=${ver#v} | |
| echo "Setting package version to ${ver}" | |
| packages=( | |
| "packages/maa-log-kernel" | |
| "packages/maa-log-parser" | |
| "packages/maa-log-runtime" | |
| "packages/maa-log-adapter" | |
| "packages/maa-log-tools" | |
| ) | |
| for pkg_dir in "${packages[@]}"; do | |
| npm --prefix "${pkg_dir}" pkg set version="${ver}" | |
| done | |
| - name: Build packages | |
| run: pnpm build:packages | |
| - name: Publish packages | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| if [ -z "${NODE_AUTH_TOKEN}" ]; then | |
| echo "NPM_TOKEN is not set." | |
| exit 1 | |
| fi | |
| npm config set registry https://registry.npmjs.org | |
| npm config set //registry.npmjs.org/:_authToken "${NODE_AUTH_TOKEN}" | |
| npm config delete always-auth || true | |
| echo "Publishing via npm token (NPM_TOKEN)" | |
| packages=( | |
| "packages/maa-log-kernel" | |
| "packages/maa-log-parser" | |
| "packages/maa-log-runtime" | |
| "packages/maa-log-adapter" | |
| "packages/maa-log-tools" | |
| ) | |
| for pkg_dir in "${packages[@]}"; do | |
| echo "==== ${pkg_dir} ====" | |
| cd "${pkg_dir}" | |
| pkg_name=$(node -p "require('./package.json').name") | |
| pkg_ver=$(node -p "require('./package.json').version") | |
| pkg_private=$(node -p "Boolean(require('./package.json').private)") | |
| pkg_has_ts_runtime=$(node -e " | |
| const p = require('./package.json'); | |
| const tsTargets = []; | |
| const visit = (value, path, isTypeField) => { | |
| if (typeof value === 'string') { | |
| if (!isTypeField && value.endsWith('.ts') && !value.endsWith('.d.ts')) { | |
| tsTargets.push(path + '=' + value); | |
| } | |
| return; | |
| } | |
| if (value && typeof value === 'object') { | |
| for (const [k, v] of Object.entries(value)) { | |
| const nextIsTypeField = isTypeField || k === 'types'; | |
| visit(v, path ? path + '.' + k : k, nextIsTypeField); | |
| } | |
| } | |
| }; | |
| visit(p.bin, 'bin', false); | |
| visit(p.exports, 'exports', false); | |
| if (tsTargets.length > 0) { | |
| console.error('Detected TypeScript runtime entries:'); | |
| for (const item of tsTargets) console.error(' - ' + item); | |
| process.stdout.write('true'); | |
| } else { | |
| process.stdout.write('false'); | |
| } | |
| ") | |
| if [ "${pkg_private}" = "true" ]; then | |
| echo "Skip private package: ${pkg_name}" | |
| cd - >/dev/null | |
| continue | |
| fi | |
| if [ "${pkg_has_ts_runtime}" = "true" ]; then | |
| echo "Skip package with TypeScript runtime entries: ${pkg_name}" | |
| cd - >/dev/null | |
| continue | |
| fi | |
| if npm view "${pkg_name}@${pkg_ver}" >/dev/null 2>&1; then | |
| echo "Skip existing version: ${pkg_name}@${pkg_ver}" | |
| cd - >/dev/null | |
| continue | |
| fi | |
| echo "Publish ${pkg_name}@${pkg_ver}" | |
| pnpm publish --access public --no-git-checks | |
| cd - >/dev/null | |
| done |