fix: pass npm auth token when fetching from the registry - #90924
fix: pass npm auth token when fetching from the registry#90924sverdlov93 wants to merge 1 commit into
Conversation
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
5bdc952 to
09d2b8b
Compare
getRegistry() returned only the registry URL, and every caller then used
fetch() without auth headers, so any registry that requires authentication
answered 401 - breaking SWC binary downloads, lockfile patching and
next info on private/proxied registries.
getRegistry() now also reads the registry's _authToken from .npmrc and
returns { registry, authToken }; the three callers send it as a Bearer
header when present. Same execSync-based npm config lookup already used
for the URL, no new dependencies.
Closes vercel#59081
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b486b46 to
7ab8934
Compare
|
Rebased onto today's canary ( Verified locally on that base:
One scoping note on the implementation: it reads @bgw — the workflow run needs a maintainer to approve it; would you mind kicking it off now that it's on a current base? @eps1lon — you touched |
Why?
getRegistry()returns the registry URL, but every caller then usesfetch()without auth headers. This causes 401 on any npm registry that requires authentication.How?
getRegistry()now also reads the registry's_authTokenfrom the npm config and returns{ registry, authToken? }. All three callers — SWC binary download, lockfile patching andnext info— pass it as aBearerheader when present.Same
execSync-basednpm config getpattern already used for the URL. No new dependencies. Adds one unit test file (test/unit/get-registry.test.ts, 5 cases: token present,undefinedtoken,config getthrowing, registries with a path, and non-URL output falling back to the default registry).Scope: bearer-token registries (Artifactory, GitHub Packages, Verdaccio, npm). Legacy
_auth/_passwordbasic auth is not handled — that needs a different header scheme and was left out to keep the change minimal.Related
next buildnot using npm token when downloading SWCgetRegistrypattern)The last three are discussions rather than issues, so bare
#-references to them don't link; using full URLs instead.Related but deliberately not fixed here
#85071 (
getVersionInfofails behind corporate firewalls) asks for the same thing one layer over: the dev-server staleness check inhot-reloader-shared-utils.tshardcodeshttps://registry.npmjs.org/-/package/next/dist-tagsinstead of consulting.npmrc. Routing it throughgetRegistry()would fix that report and pick up auth for free, butgetRegistry()shells out tonpm config getviaexecSync, and putting that on the dev-startup path would regress exactly what #67309 optimized. It needs a cached or lazy lookup, so I left it out of this PR. Happy to follow up separately if that's the direction you'd want.