v1.2でS3のサポートなどが話題になっていたbunですが
1.2.x初のパッチリリース v1.2.1がリリースされました
このリリースではnpm, verdaccio以外のレジストリを対象にした際にbun publishがコケるバグが修正されています
npm publish->bun publish
今回対象にするパッケージはこちら
ちなむとこのパッケージは当ブログの最初の投稿でやりたいことに挙げていた専用プラグインです
このパッケージではパッケージマネージャ兼トランスコンパイラとしてbunを使用しているのですが
件のバグが理由でpublishコマンドのみnpm publish
を利用していました
せっかくなのでこれを機にpublishコマンドもbunに統一していきます
GitHub Actions
リリース用ワークフローを修正
name: Release
on:
release:
types: [published]
jobs:
publish:
runs-on: $
timeout-minutes: 30
strategy:
matrix:
os: [ubuntu-latest]
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
- bun-version: latest
+ bun-version: 1.2.1 # 元々latestなので敢えて変更する必要はない
- name: Install dependencies
run: bun install
- - name: Setup Node.js
- uses: actions/setup-node@v4
- - run: npm publish
- env:
- GITHUB_TOKEN: $
+ - name: Bun Publish
+ run: bun publish
+ env:
+ GITHUB_TOKEN: $
npmrcを使用しないパターン
name: Release
on:
release:
types: [published]
jobs:
publish:
runs-on: $
timeout-minutes: 30
strategy:
matrix:
os: [ubuntu-latest]
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.1
registry-url: 'https://npm.pkg.github.com/'
scope: '@miyamo2'
- name: Install dependencies
run: bun install
- name: Bun Publish
run: bun publish
env:
BUN_AUTH_TOKEN: $
.npmrc
npm publish
ではpackage.jsonのpublishConfigにスコープとレジストリURLの設定、
.npmrcにトークンの設定という形で分けて記述していても問題なく公開できていたのですが
bun publishでは認証エラーが起きてしまいました
Run bun publish
bun publish
shell: /usr/bin/bash -e {0}
env:
GITHUB_TOKEN: ***
bun publish v1.2.1 (ce532901)
$ bun build ./src/index.ts ./src/graphqlgen.ts ./src/gatsby-node.ts --outdir ./ --target node
index.js 0.00 KB
gatsby-node.js 2052.43 KB
graphqlgen.js 535.73 KB
[67ms] bundle 399 modules
error: missing authentication (run `bunx npm login`)
packed 1.0KB package.json
packed 130B .gitmodules
packed 1.1KB LICENSE
packed 83B README.md
packed 2.1MB gatsby-node.js
packed 0.54MB graphqlgen.js
packed 0KB index.js
Total files: 7
Shasum: b2be19a15573eaea021b2bcb20910d848f4acc8c
Integrity: sha512-YCID7BXIoBGkQ[...]iJNeCHYquOvaw==
Unpacked size: 2.59MB
Packed size: 0.50MB
Error: Process complete
パッと見だと bun が publishConfig.registry、 publishConfig.@scope:registry をサポートしていなさそうです
公開先のレジストリをnpmだと解釈されたっぽい
スコープ、レジストリURLの設定を追記
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
+ @miyamo2:registry=https://npm.pkg.github.com
package.json
変更なし
publishConfig.@scope:registry はもう使っていないので消してもよかったかも
{
"name": "@miyamo2/gatsby-source-blogapi-miyamo-today",
"version": "0.1.6",
"repository": {
"type": "git",
"url": "https://github.com/miyamo2/gatsby-source-blogapi-miyamo-today.git"
},
"publishConfig": {
"access": "restricted",
"@miyamo2:registry": "https://npm.pkg.github.com"
},
"main": "index.js",
"type": "module",
"scripts": {
"prepublishOnly": "bun build ./src/index.ts ./src/graphqlgen.ts ./src/gatsby-node.ts --outdir ./ --target node",
"build": "bun build ./src/index.ts ./src/graphqlgen.ts ./src/gatsby-node.ts --outdir ./ --target node",
"graphqlgen": "cd ./src && bunx graphql-codegen generate"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.7.2"
},
"dependencies": {
"@formkit/tempo": "^0.1.2",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"gatsby": "^5.14.1",
"gatsby-source-filesystem": "^5.14.0",
"graphql": "16.9.0"
}
}
実行結果
無事パスしました
bun publish v1.2.1 (ce532901)
$ bun build ./src/index.ts ./src/graphqlgen.ts ./src/gatsby-node.ts --outdir ./ --target node
index.js 0.00 KB
gatsby-node.js 2052.43 KB
graphqlgen.js 535.73 KB
[61ms] bundle 399 modules
packed 1.0KB package.json
packed 130B .gitmodules
packed 1.1KB LICENSE
packed 83B README.md
packed 2.1MB gatsby-node.js
packed 0.54MB graphqlgen.js
packed 0KB index.js
Total files: 7
Shasum: b2be19a15573eaea021b2bcb20910d848f4acc8c
Integrity: sha512-YCID7BXIoBGkQ[...]iJNeCHYquOvaw==
Unpacked size: 2.59MB
Packed size: 0.50MB
Tag: latest
Access: restricted
Registry: https://npm.pkg.github.com
+ @miyamo2/gatsby-source-blogapi-miyamo-today@0.1.7