File tree Expand file tree Collapse file tree 4 files changed +570
-379
lines changed
test/unit/commands/module Expand file tree Collapse file tree 4 files changed +570
-379
lines changed Original file line number Diff line number Diff line change 48
48
"chokidar" : " ^4.0.3" ,
49
49
"citty" : " ^0.1.6" ,
50
50
"clipboardy" : " ^4.0.0" ,
51
+ "confbox" : " ^0.2.2" ,
51
52
"consola" : " ^3.4.2" ,
52
53
"defu" : " ^6.1.4" ,
53
54
"fuse.js" : " ^7.1.0" ,
Original file line number Diff line number Diff line change
1
+ import { parseINI } from 'confbox'
1
2
import { $fetch } from 'ofetch'
2
3
import { readPackageJSON } from 'pkg-types'
3
4
import { coerce , satisfies } from 'semver'
@@ -126,20 +127,23 @@ export async function getNuxtVersion(cwd: string) {
126
127
}
127
128
128
129
export function getRegistryFromContent ( content : string , scope : string | null ) {
129
- if ( scope ) {
130
- const scopedRegex = new RegExp ( `^${ scope } :registry=(.+)$` , 'm' )
131
- const scopedMatch = content . match ( scopedRegex ) ?. [ 1 ]
132
- if ( scopedMatch ) {
133
- return scopedMatch . trim ( )
130
+ try {
131
+ const npmConfig = parseINI < Record < string , string | undefined > > ( content )
132
+
133
+ if ( scope ) {
134
+ const scopeKey = `${ scope } :registry`
135
+ if ( npmConfig [ scopeKey ] ) {
136
+ return npmConfig [ scopeKey ] . trim ( )
137
+ }
134
138
}
135
- }
136
139
137
- // If no scoped registry found or no scope provided, look for the default registry
138
- const defaultRegex = / ^ \s * r e g i s t r y = ( .+ ) $ / m
139
- const defaultMatch = content . match ( defaultRegex ) ?. [ 1 ]
140
- if ( defaultMatch ) {
141
- return defaultMatch . trim ( )
142
- }
140
+ if ( npmConfig . registry ) {
141
+ return npmConfig . registry . trim ( )
142
+ }
143
143
144
- return null
144
+ return null
145
+ }
146
+ catch {
147
+ return null
148
+ }
145
149
}
Original file line number Diff line number Diff line change @@ -45,4 +45,14 @@ some-other-setting=value
45
45
expect ( getRegistryFromContent ( '' , null ) ) . toBeNull ( )
46
46
expect ( getRegistryFromContent ( '' , '@myorg' ) ) . toBeNull ( )
47
47
} )
48
+
49
+ it ( 'extracts registry from line with comments' , ( ) => {
50
+ const content = `
51
+ registry=https://registry.npmjs.org/ # with comment
52
+ @myorg:registry=https://my-registry.org/ # another comment
53
+ `
54
+
55
+ expect ( getRegistryFromContent ( content , null ) ) . toBe ( 'https://registry.npmjs.org/' )
56
+ expect ( getRegistryFromContent ( content , '@myorg' ) ) . toBe ( 'https://my-registry.org/' )
57
+ } )
48
58
} )
You can’t perform that action at this time.
0 commit comments