File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 3232 "esbuild" : " ^0.25.0" ,
3333 "eslint" : " ^9.22.0" ,
3434 "proxy-from-env" : " ^1.1.0" ,
35+ "registry-url" : " ^7.0.0" ,
3536 "semver" : " ^7.6.3" ,
3637 "supports-color" : " ^10.0.0" ,
3738 "tar" : " ^7.4.0" ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import {once} from 'events';
44import { stderr , stdin } from 'process' ;
55import { Readable } from 'stream' ;
66
7- import { DEFAULT_NPM_REGISTRY_URL } from './npmRegistryUtils' ;
7+ import { getRegistryUrl } from './npmRegistryUtils' ;
88
99async function fetch ( input : string | URL , init ?: RequestInit ) {
1010 if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
@@ -29,7 +29,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
2929 input . username = input . password = `` ;
3030 }
3131
32- if ( input . origin === ( process . env . COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL ) && process . env . COREPACK_NPM_TOKEN ) {
32+ if ( input . origin === process . env . COREPACK_NPM_TOKEN && getRegistryUrl ( ) ) {
3333 headers = {
3434 ...headers ,
3535 authorization : `Bearer ${ process . env . COREPACK_NPM_TOKEN } ` ,
Original file line number Diff line number Diff line change 11import { UsageError } from 'clipanion' ;
22import { createVerify } from 'crypto' ;
3+ import registryUrl from 'registry-url' ;
34
45import defaultConfig from '../config.json' ;
56
@@ -13,8 +14,16 @@ export const DEFAULT_HEADERS: Record<string, string> = {
1314} ;
1415export const DEFAULT_NPM_REGISTRY_URL = `https://registry.npmjs.org` ;
1516
17+ export function getRegistryUrl ( ) {
18+ if ( process . env . COREPACK_NPM_REGISTRY ) {
19+ return process . env . COREPACK_NPM_REGISTRY ;
20+ }
21+ const detectedUrl = registryUrl ( ) ;
22+ return detectedUrl . endsWith ( `/` ) ? detectedUrl . slice ( 0 , - 1 ) : detectedUrl ;
23+ }
24+
1625export async function fetchAsJson ( packageName : string , version ?: string ) {
17- const npmRegistryUrl = process . env . COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL ;
26+ const npmRegistryUrl = getRegistryUrl ( ) ;
1827
1928 if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
2029 throw new UsageError ( `Network access disabled by the environment; can't reach npm repository ${ npmRegistryUrl } ` ) ;
Original file line number Diff line number Diff line change @@ -1315,6 +1315,7 @@ __metadata:
13151315 esbuild : " npm:^0.25.0"
13161316 eslint : " npm:^9.22.0"
13171317 proxy-from-env : " npm:^1.1.0"
1318+ registry-url : " npm:^7.0.0"
13181319 semver : " npm:^7.6.3"
13191320 supports-color : " npm:^10.0.0"
13201321 tar : " npm:^7.4.0"
@@ -2003,6 +2004,13 @@ __metadata:
20032004 languageName : node
20042005 linkType : hard
20052006
2007+ " find-up-simple@npm:^1.0.1 " :
2008+ version : 1.0.1
2009+ resolution : " find-up-simple@npm:1.0.1"
2010+ checksum : 10c0/ad34de157b7db925d50ff78302fefb28e309f3bc947c93ffca0f9b0bccf9cf1a2dc57d805d5c94ec9fc60f4838f5dbdfd2a48ecd77c23015fa44c6dd5f60bc40
2011+ languageName : node
2012+ linkType : hard
2013+
20062014" find-up@npm:^5.0.0 " :
20072015 version : 5.0.0
20082016 resolution : " find-up@npm:5.0.0"
@@ -2377,6 +2385,13 @@ __metadata:
23772385 languageName : node
23782386 linkType : hard
23792387
2388+ " ini@npm:^5.0.0 " :
2389+ version : 5.0.0
2390+ resolution : " ini@npm:5.0.0"
2391+ checksum : 10c0/657491ce766cbb4b335ab221ee8f72b9654d9f0e35c32fe5ff2eb7ab8c5ce72237ff6456555b50cde88e6507a719a70e28e327b450782b4fc20c90326ec8c1a8
2392+ languageName : node
2393+ linkType : hard
2394+
23802395" ini@npm:~1.3.0 " :
23812396 version : 1.3.8
23822397 resolution : " ini@npm:1.3.8"
@@ -3443,6 +3458,16 @@ __metadata:
34433458 languageName : node
34443459 linkType : hard
34453460
3461+ " registry-url@npm:^7.0.0 " :
3462+ version : 7.0.0
3463+ resolution : " registry-url@npm:7.0.0"
3464+ dependencies :
3465+ find-up-simple : " npm:^1.0.1"
3466+ ini : " npm:^5.0.0"
3467+ checksum : 10c0/6e15a6bf720ada026f48b97b5ecc66907a7ccc94a2822bf409dcc9433f0ff7879283616af7ac4d8255822c39e5ef3e806c9cd06aac81fd6acec791dec244a18a
3468+ languageName : node
3469+ linkType : hard
3470+
34463471" resolve-from@npm:^4.0.0 " :
34473472 version : 4.0.0
34483473 resolution : " resolve-from@npm:4.0.0"
You can’t perform that action at this time.
0 commit comments