Skip to content

Commit ec6b08a

Browse files
committed
fix: resolve npm auth token from parseINI result
1 parent ae1dfc2 commit ec6b08a

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

packages/nuxt-cli/src/utils/registry.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { parseINI } from 'confbox'
99

1010
const PROTOCOL_RE = /^https?:\/\//
1111
const TRAILING_SLASH_RE = /\/$/
12-
const REGEX_SPECIAL_RE = /[.*+?^${}()|[\]\\]/g
1312

1413
export interface RegistryMeta {
1514
registry: string
@@ -84,19 +83,20 @@ async function getRegistry(scope: string | null): Promise<string> {
8483

8584
async 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

Comments
 (0)