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 32
32
"esbuild" : " ^0.25.0" ,
33
33
"eslint" : " ^9.22.0" ,
34
34
"proxy-from-env" : " ^1.1.0" ,
35
+ "registry-url" : " ^7.0.0" ,
35
36
"semver" : " ^7.6.3" ,
36
37
"supports-color" : " ^10.0.0" ,
37
38
"tar" : " ^7.4.0" ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import {once} from 'events';
4
4
import { stderr , stdin } from 'process' ;
5
5
import { Readable } from 'stream' ;
6
6
7
- import { DEFAULT_NPM_REGISTRY_URL } from './npmRegistryUtils' ;
7
+ import { getRegistryUrl } from './npmRegistryUtils' ;
8
8
9
9
async function fetch ( input : string | URL , init ?: RequestInit ) {
10
10
if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
@@ -29,7 +29,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
29
29
input . username = input . password = `` ;
30
30
}
31
31
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 ( ) ) {
33
33
headers = {
34
34
...headers ,
35
35
authorization : `Bearer ${ process . env . COREPACK_NPM_TOKEN } ` ,
Original file line number Diff line number Diff line change 1
1
import { UsageError } from 'clipanion' ;
2
2
import { createVerify } from 'crypto' ;
3
+ import registryUrl from 'registry-url' ;
3
4
4
5
import defaultConfig from '../config.json' ;
5
6
@@ -13,8 +14,16 @@ export const DEFAULT_HEADERS: Record<string, string> = {
13
14
} ;
14
15
export const DEFAULT_NPM_REGISTRY_URL = `https://registry.npmjs.org` ;
15
16
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
+
16
25
export async function fetchAsJson ( packageName : string , version ?: string ) {
17
- const npmRegistryUrl = process . env . COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL ;
26
+ const npmRegistryUrl = getRegistryUrl ( ) ;
18
27
19
28
if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
20
29
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:
1315
1315
esbuild : " npm:^0.25.0"
1316
1316
eslint : " npm:^9.22.0"
1317
1317
proxy-from-env : " npm:^1.1.0"
1318
+ registry-url : " npm:^7.0.0"
1318
1319
semver : " npm:^7.6.3"
1319
1320
supports-color : " npm:^10.0.0"
1320
1321
tar : " npm:^7.4.0"
@@ -2003,6 +2004,13 @@ __metadata:
2003
2004
languageName : node
2004
2005
linkType : hard
2005
2006
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
+
2006
2014
" find-up@npm:^5.0.0 " :
2007
2015
version : 5.0.0
2008
2016
resolution : " find-up@npm:5.0.0"
@@ -2377,6 +2385,13 @@ __metadata:
2377
2385
languageName : node
2378
2386
linkType : hard
2379
2387
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
+
2380
2395
" ini@npm:~1.3.0 " :
2381
2396
version : 1.3.8
2382
2397
resolution : " ini@npm:1.3.8"
@@ -3443,6 +3458,16 @@ __metadata:
3443
3458
languageName : node
3444
3459
linkType : hard
3445
3460
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
+
3446
3471
" resolve-from@npm:^4.0.0 " :
3447
3472
version : 4.0.0
3448
3473
resolution : " resolve-from@npm:4.0.0"
You can’t perform that action at this time.
0 commit comments