@@ -6,9 +6,9 @@ import process from "node:process";
66/**
77 * Release publishing entrypoint.
88 *
9- * - If an npm token is present, we keep the Bun-based publish path .
10- * - If no npm token is present but GitHub OIDC variables exist , we fall back to
11- * npm trusted publishing .
9+ * - On GitHub Actions, OIDC trusted publishing is preferred whenever available .
10+ * - If OIDC is unavailable but an npm token is present , we keep the Bun-based
11+ * publish path .
1212 * - In dry-run mode we only pack the package, so local validation never needs auth.
1313 */
1414const isDryRun = process . argv . includes ( "--dry-run" ) ;
@@ -25,6 +25,7 @@ const hasNpmToken = Boolean(npmToken);
2525const hasOidc = Boolean (
2626 env . ACTIONS_ID_TOKEN_REQUEST_TOKEN && env . ACTIONS_ID_TOKEN_REQUEST_URL
2727) ;
28+ const forceTokenPublish = env . FORCE_NPM_TOKEN_PUBLISH === "1" ;
2829
2930if ( npmToken && ! env . NPM_CONFIG_TOKEN ) {
3031 env . NPM_CONFIG_TOKEN = npmToken ;
@@ -60,19 +61,28 @@ function run(command, args, mode) {
6061}
6162
6263if ( isDryRun ) {
63- run ( "bun" , [ "pm" , "pack" ] , hasNpmToken ? "bun-token" : hasOidc ? "npm-oidc" : "pack-only" ) ;
64+ run (
65+ "bun" ,
66+ [ "pm" , "pack" ] ,
67+ hasOidc && ! forceTokenPublish
68+ ? "npm-oidc"
69+ : hasNpmToken
70+ ? "bun-token"
71+ : "pack-only"
72+ ) ;
6473}
6574
66- if ( hasNpmToken ) {
67- run ( "bun " , [ "publish" , "--access" , "public" , "--tolerate-republish " ] , "bun-token " ) ;
75+ if ( hasOidc && ! forceTokenPublish ) {
76+ run ( "npm " , [ "publish" , "--access" , "public" , "--provenance " ] , "npm-oidc " ) ;
6877}
6978
70- if ( hasOidc ) {
71- run ( "npm " , [ "publish" , "--access" , "public" , "--provenance " ] , "npm-oidc " ) ;
79+ if ( hasNpmToken ) {
80+ run ( "bun " , [ "publish" , "--access" , "public" , "--tolerate-republish " ] , "bun-token " ) ;
7281}
7382
7483console . error (
7584 "[release] Missing publish credentials. Provide NPM_TOKEN/NPM_CONFIG_TOKEN " +
76- "or configure npm trusted publishing with GitHub OIDC (id-token: write)."
85+ "or configure npm trusted publishing with GitHub OIDC (id-token: write). " +
86+ "GitHub Actions prefers OIDC unless FORCE_NPM_TOKEN_PUBLISH=1 is set."
7787) ;
7888process . exit ( 1 ) ;
0 commit comments