@@ -6,6 +6,7 @@ const JF_URL = "https://a0us.jfrog.io";
66const OIDC_PROVIDER_NAME = "vercel" ;
77const ARTIFACTORY_NPM_HOST = "a0us.jfrog.io/artifactory/api/npm/npm" ;
88const PUBLIC_NPM_HOST = "registry.npmjs.org" ;
9+ const BUILD_NPMRC_PATH = ".npmrc.oidc" ;
910
1011async function exchangeVercelOidcTokenForArtifactoryToken ( ) {
1112 const oidcToken = process . env . VERCEL_OIDC_TOKEN ;
@@ -50,14 +51,24 @@ function pointLockfileAtArtifactory() {
5051 writeFileSync ( "package-lock.json" , rewritten ) ;
5152}
5253
54+ // Written fresh for this build only, under --userconfig, so the Artifactory
55+ // registry override never leaks into a plain `npm ci` elsewhere (e.g. the
56+ // GitHub Actions test workflows, which install straight from the public
57+ // registry and have no access to this token).
58+ function writeBuildScopedNpmrc ( npmToken ) {
59+ writeFileSync (
60+ BUILD_NPMRC_PATH ,
61+ `registry=https://${ ARTIFACTORY_NPM_HOST } /\n` +
62+ `//${ ARTIFACTORY_NPM_HOST } /:_authToken=${ npmToken } \n`
63+ ) ;
64+ }
65+
5366const npmToken = await exchangeVercelOidcTokenForArtifactoryToken ( ) ;
5467
5568// Only this ephemeral Vercel build checkout is rewritten to fetch through
5669// Artifactory; the committed lockfile (used by GitHub Actions' npm ci) is
5770// untouched and keeps resolving against the public registry.
5871pointLockfileAtArtifactory ( ) ;
72+ writeBuildScopedNpmrc ( npmToken ) ;
5973
60- execSync ( "npm ci" , {
61- stdio : "inherit" ,
62- env : { ...process . env , NPM_TOKEN : npmToken } ,
63- } ) ;
74+ execSync ( `npm ci --userconfig ${ BUILD_NPMRC_PATH } ` , { stdio : "inherit" } ) ;
0 commit comments