@@ -161,19 +161,18 @@ export default defineCommand({
161161description : 'Force upgrade to recreate lockfile and node_modules' ,
162162} ,
163163channel : {
164- type : 'string ' ,
164+ type : 'enum ' ,
165165alias : 'ch' ,
166166default : 'stable' ,
167167description : 'Specify a channel to install from' ,
168- valueHint : 'stable| nightly|v3|v4| v4-nightly| v3-nightly' ,
168+ options : [ 'stable' , ' nightly' , 'v3' , 'v4' , ' v4-nightly' , ' v3-nightly'] ,
169169} ,
170170} ,
171171async run ( ctx ) {
172172const cwd = resolveRootDir ( ctx . args )
173173
174174intro ( styleText ( 'cyan' , 'Upgrading Nuxt ...' ) )
175175
176- // Check package manager
177176const [ packageManager , workspaceDir = cwd ] = await Promise . all ( [ detectPackageManager ( cwd ) , findWorkspaceDir ( cwd , { try : true } ) ] )
178177if ( ! packageManager ) {
179178logger . error (
@@ -186,19 +185,16 @@ export default defineCommand({
186185const packageManagerVersion = getPackageManagerVersion ( packageManagerName )
187186logger . step ( `Package manager: ${ styleText ( 'cyan' , packageManagerName ) } ${ packageManagerVersion } ` )
188187
189- // Check currently installed Nuxt version
190188const currentVersion = ( await getNuxtVersion ( cwd ) ) || '[unknown]'
191189logger . step ( `Current Nuxt version: ${ styleText ( 'cyan' , currentVersion ) } ` )
192190
193191const pkg = await readPackageJSON ( cwd ) . catch ( ( ) => null )
194192
195- // Check if Nuxt is a dependency or devDependency
196193const nuxtDependencyType = pkg ? checkNuxtDependencyType ( pkg ) : 'dependencies'
197194const corePackages = [ '@nuxt/kit' , '@nuxt/schema' , '@nuxt/vite-builder' , '@nuxt/webpack-builder' , '@nuxt/rspack-builder' ]
198195
199196const packagesToUpdate = pkg ? corePackages . filter ( p => pkg . dependencies ?. [ p ] || pkg . devDependencies ?. [ p ] ) : [ ]
200197
201- // Install latest version
202198const packageNames = [ 'nuxt' , ...packagesToUpdate ]
203199const { npmPackages, nuxtVersion } = await getRequiredNewVersion ( packageNames , ctx . args . channel )
204200
@@ -217,7 +213,6 @@ export default defineCommand({
217213}
218214}
219215
220- // Force install
221216const toRemove = [ 'node_modules' ]
222217
223218const lockFile = findLockFile ( cwd , workspaceDir , lockFileCandidates )
@@ -280,13 +275,15 @@ export default defineCommand({
280275const resolved : Array < { catalog : string , pkg : string , specifier : string } > = [ ]
281276const unresolved : string [ ] = [ ]
282277
283- for ( const { catalog, current, spec } of catalogUpdates ) {
284- const specifier = await resolveCatalogSpecifier ( spec , current )
285- if ( ! specifier ) {
278+ const specifiers = await Promise . all ( catalogUpdates . map ( ( { current, spec } ) => resolveCatalogSpecifier ( spec , current ) ) )
279+ for ( const [ index , specifier ] of specifiers . entries ( ) ) {
280+ const { catalog, spec } = catalogUpdates [ index ] !
281+ if ( specifier ) {
282+ resolved . push ( { catalog, pkg : spec . name , specifier } )
283+ }
284+ else {
286285unresolved . push ( spec . name )
287- continue
288286}
289- resolved . push ( { catalog, pkg : spec . name , specifier } )
290287}
291288
292289if ( resolved . length > 0 ) {
@@ -347,7 +344,7 @@ export default defineCommand({
347344recreateLockfile ? `Recreating ${ forceRemovals } ` : 'Deduping dependencies' ,
348345recreateLockfile ? 'Lockfile recreated' : 'Dependencies deduped' ,
349346{ verbose } ,
350- hooks => runDedupe ( { cwd, packageManager, recreateLockfile, ...hooks } ) ,
347+ hooks => runDedupe ( { cwd, packageManager, recreateLockfile, lockFile , ...hooks } ) ,
351348)
352349
353350if ( failed ) {
@@ -373,7 +370,6 @@ export default defineCommand({
373370logger . info ( `If you encounter any issues, revert the changes and try with ${ styleText ( 'cyan' , '--no-force' ) } ` )
374371}
375372
376- // Check installed Nuxt version again
377373const upgradedVersion = ( await getNuxtVersion ( cwd ) ) || '[unknown]'
378374
379375if ( upgradedVersion === '[unknown]' ) {
@@ -450,7 +446,6 @@ async function withInstallSpinner(
450446return ! result . success
451447}
452448
453- // Find which lock file is in use since `nypm.detectPackageManager` doesn't return this
454449export function findLockFile ( cwd : string , workspaceDir : string , lockFiles : string | Array < string > | undefined ) {
455450const candidates = typeof lockFiles === 'string' ? [ lockFiles ] : lockFiles
456451
0 commit comments