@@ -9,7 +9,6 @@ import { parseINI } from 'confbox'
99
1010const PROTOCOL_RE = / ^ h t t p s ? : \/ \/ /
1111const TRAILING_SLASH_RE = / \/ $ /
12- const REGEX_SPECIAL_RE = / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g
1312
1413export interface RegistryMeta {
1514 registry : string
@@ -84,19 +83,20 @@ async function getRegistry(scope: string | null): Promise<string> {
8483
8584async function getAuthToken ( registry : RegistryMeta [ 'registry' ] ) : Promise < RegistryMeta [ 'authToken' ] > {
8685 const paths = getNpmrcPaths ( )
87- const registryHost = registry . replace ( PROTOCOL_RE , '' ) . replace ( TRAILING_SLASH_RE , '' ) . replace ( REGEX_SPECIAL_RE , '\\$&' )
88- const authTokenRegex = new RegExp ( `^ //${ registryHost } /:_authToken=(.+)$` , 'm' )
86+ const registryHost = registry . replace ( PROTOCOL_RE , '' ) . replace ( TRAILING_SLASH_RE , '' )
87+ const authTokenKey = ` //${ registryHost } /:_authToken`
8988
9089 for ( const npmrcPath of paths ) {
9190 let fd : FileHandle | undefined
9291 try {
9392 fd = await fs . promises . open ( npmrcPath , 'r' )
9493 if ( await fd . stat ( ) . then ( r => r . isFile ( ) ) ) {
9594 const npmrcContent = await fd . readFile ( 'utf-8' )
96- const authTokenMatch = npmrcContent . match ( authTokenRegex ) ?. [ 1 ]
95+ const npmConfig = parseINI < Record < string , string | undefined > > ( npmrcContent )
96+ const authToken = npmConfig [ authTokenKey ]
9797
98- if ( authTokenMatch ) {
99- return authTokenMatch . trim ( )
98+ if ( authToken ) {
99+ return authToken . trim ( )
100100 }
101101 }
102102 }
0 commit comments