bun publish
使用 bun publish 將包釋出到 npm 登錄檔
bun publish 會將你的包打包成 tarball,並從 package.json 中移除 catalog 和 workspace 協議,必要時解析版本。然後,它會發布到設定檔中指定的 registry。支援 bunfig.toml 和 .npmrc 檔案。
## 從當前工作目錄釋出包
bun publish
bun publish v1.3.3 (ca7428e9)
packed 203B package.json
packed 224B README.md
packed 30B index.ts
packed 0.64KB tsconfig.json
Total files: 4
Shasum: 79e2b4377b63f4de38dc7ea6e5e9dbee08311a69
Integrity: sha512-6QSNlDdSwyG/+[...]X6wXHriDWr6fA==
Unpacked size: 1.1KB
Packed size: 0.76KB
Tag: latest
Access: default
Registry: http://localhost:4873/
+ publish-1@1.0.0
如需分別執行打包和釋出,請執行 bun pm pack,然後將輸出 tarball 的路徑傳遞給 bun publish。
bun pm pack
...
bun publish ./package.tgz
--access
--access 用於設定所釋出包的訪問級別,可以是 public 或 restricted。無作用域的包始終為公開包,使用 --access restricted 釋出無作用域包會報錯。
bun publish --access public
你也可以在 package.json 的 publishConfig 欄位中設定 --access。
{
"publishConfig": {
"access": "restricted"
}
}
--tag
設定所釋出包版本的標籤。預設標籤為 latest。包的初始版本總是會被打上 latest 標籤,且會額外打上指定的標籤。
bun publish --tag alpha
你也可以在 package.json 的 publishConfig 欄位中設定 --tag。
{
"publishConfig": {
"tag": "next"
}
}
--dry-run
--dry-run 會執行釋出流程但不會發布包,因此你可以檢查實際會發布哪些內容。
bun publish --dry-run
--tolerate-republish
如果包版本已存在,使用該標誌時退出碼為 0 而不是 1。在可能重新執行作業的 CI/CD 場景中很有用。
bun publish --tolerate-republish
--gzip-level
設定打包包時使用的 gzip 壓縮級別,可設為 0 到 9(預設為 9)。僅適用於不帶 tarball 路徑引數的 bun publish。
--auth-type
如果你的 npm 賬戶啟用了雙因素認證,bun publish 會通過瀏覽器或 CLI 提示你輸入一次性密碼。--auth-type 用於告訴 npm registry 你偏好的驗證方式:web(預設)或 legacy。
bun publish --auth-type legacy
...
此操作需要一次性密碼。
輸入 OTP:123456
...
--otp
直接向 CLI 提供一次性密碼。如果密碼有效,bun publish 會跳過釋出前額外的一次性密碼提示:
bun publish --otp 123456
CLI 使用方法
bun publish dist
釋出選項
--accessstring設定要釋出的軟體包的訪問級別,可以是 public 或 restricted。無作用域的軟體包始終是公開的;使用 --access restricted 釋出無作用域的軟體包會報錯。
bun publish --access public
你也可以在 package.json 的 publishConfig 欄位中設定 --access。
{
"publishConfig": {
"access": "restricted" // [!code ++]
}
}
--tagstringdefault latest設定釋出包的版本標籤。預設標籤是 latest。包的初始版本始終會獲得 latest 標籤,此外還會標記指定的標籤。
bun publish --tag alpha
你也可以在 package.json 的 publishConfig 欄位中設定 --tag。
{
"publishConfig": {
"tag": "next" // [!code ++]
}
}
--dry-runboolean模擬釋出過程而不實際釋出軟體包,以便先驗證其內容。
bun publish --dry-run
--tolerate-republishboolean如果要釋出的版本已存在於登錄檔中,bun publish 將以程式碼 0 而不是 1 退出。
--gzip-levelstringdefault 9指定打包時使用的 gzip 壓縮級別。僅適用於未使用 tarball 路徑引數的 bun publish。數值範圍為 0 到 9(預設值為 9)。
--auth-typestringdefault web如果你的 npm 賬戶啟用了雙因素身份驗證(2FA),bun publish 會提示你輸入一次性密碼,你可以通過瀏覽器或 CLI 完成驗證。--auth-type 用於告知 npm 登錄檔你偏好的驗證方式:web(預設)或 legacy。
bun publish --auth-type legacy
...
此操作需要一次性密碼。
輸入 OTP:123456
...
--otpstring直接向 CLI 提供一次性密碼。有效的密碼可以跳過釋出前額外的一次性密碼提示。
bun publish --otp 123456
登錄檔設定
自定義登錄檔
--registrystring預設使用指定的登錄檔,覆蓋 .npmrc、bunfig.toml 和環境變數。為軟體包作用域設定的登錄檔(在 .npmrc 中設定 @scope:registry=,或在 bunfig.toml 中設定 [install.scopes])仍具有優先順序。
bun publish --registry https://my-private-registry.com
SSL 證書
--castring提供由證書頒發機構(CA)簽名的證書
--cafilestring證書頒發機構證書檔案路徑
bun publish --ca "-----BEGIN CERTIFICATE-----..."
bun publish --cafile ./ca-cert.pem
常規選項
相依管理
-p, --productionboolean不安裝 devDependencies
--omitstring排除相依型別:dev、optional 或 peer
-f, --forceboolean始終從登錄檔請求最新版本並重新安裝所有相依
指令碼控制
--ignore-scriptsboolean打包和釋出時跳過生命週期指令碼
--trustboolean將包新增到 trustedDependencies 並執行其指令碼
檔案管理
--no-saveboolean不更新 package.json 或鎖檔案
--frozen-lockfileboolean禁止更改鎖檔案
--yarnboolean生成 yarn.lock 檔案(相容 yarn v1)
效能
--backendstring平臺最佳化:clonefile(macOS 上的預設值)、hardlink(Linux 和 Windows 上的預設值)、symlink 或 copyfile
--network-concurrencynumberdefault 48最大並行網路請求數
--concurrent-scriptsnumber最大並行生命週期指令碼數(預設值:CPU 核心數的 2 倍)
輸出控制
--silentboolean禁止所有輸出
--verboseboolean顯示詳細日誌
--no-progressboolean隱藏進度條
--no-summaryboolean不打印發布摘要