@@ -27,7 +27,12 @@ import {
2727 fetchPackageManifest ,
2828 fetchPackageMetadata ,
2929} from '../utilities/package-metadata' ;
30- import { PackageTreeNode , findNodeDependencies , readPackageTree } from '../utilities/package-tree' ;
30+ import {
31+ PackageTreeNode ,
32+ findPackageJson ,
33+ getProjectDependencies ,
34+ readPackageJson ,
35+ } from '../utilities/package-tree' ;
3136import { Schema as UpdateCommandSchema } from './update' ;
3237
3338const npa = require ( 'npm-package-arg' ) as ( selector : string ) => PackageIdentifier ;
@@ -377,15 +382,14 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
377382
378383 this . logger . info ( 'Collecting installed dependencies...' ) ;
379384
380- const packageTree = await readPackageTree ( this . workspace . root ) ;
381- const rootDependencies = findNodeDependencies ( packageTree ) ;
385+ const rootDependencies = await getProjectDependencies ( this . workspace . root ) ;
382386
383- this . logger . info ( `Found ${ Object . keys ( rootDependencies ) . length } dependencies.` ) ;
387+ this . logger . info ( `Found ${ rootDependencies . size } dependencies.` ) ;
384388
385389 if ( options . all ) {
386390 // 'all' option and a zero length packages have already been checked.
387391 // Add all direct dependencies to be updated
388- for ( const dep of Object . keys ( rootDependencies ) ) {
392+ for ( const dep of rootDependencies . keys ( ) ) {
389393 const packageIdentifier = npa ( dep ) ;
390394 if ( options . next ) {
391395 packageIdentifier . fetchSpec = 'next' ;
@@ -400,7 +404,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
400404 next : options . next || false ,
401405 verbose : options . verbose || false ,
402406 packageManager : this . packageManager ,
403- packages : options . all ? Object . keys ( rootDependencies ) : [ ] ,
407+ packages : options . all ? rootDependencies . keys ( ) : [ ] ,
404408 } ) ;
405409
406410 return success ? 0 : 1 ;
@@ -424,8 +428,9 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
424428 }
425429
426430 const packageName = packages [ 0 ] . name ;
427- const packageDependency = rootDependencies [ packageName ] ;
428- let packageNode = packageDependency && packageDependency . node ;
431+ const packageDependency = rootDependencies . get ( packageName ) ;
432+ let packagePath = packageDependency ?. path ;
433+ let packageNode = packageDependency ?. package ;
429434 if ( packageDependency && ! packageNode ) {
430435 this . logger . error ( 'Package found in package.json but is not installed.' ) ;
431436
@@ -434,19 +439,20 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
434439 // Allow running migrations on transitively installed dependencies
435440 // There can technically be nested multiple versions
436441 // TODO: If multiple, this should find all versions and ask which one to use
437- const child = packageTree . children . find ( c => c . name === packageName ) ;
438- if ( child ) {
439- packageNode = child ;
442+ const packageJson = findPackageJson ( this . workspace . root , packageName ) ;
443+ if ( packageJson ) {
444+ packagePath = path . dirname ( packageJson ) ;
445+ packageNode = await readPackageJson ( packagePath ) ;
440446 }
441447 }
442448
443- if ( ! packageNode ) {
449+ if ( ! packageNode || ! packagePath ) {
444450 this . logger . error ( 'Package is not installed.' ) ;
445451
446452 return 1 ;
447453 }
448454
449- const updateMetadata = packageNode . package [ 'ng-update' ] ;
455+ const updateMetadata = packageNode [ 'ng-update' ] ;
450456 let migrations = updateMetadata && updateMetadata . migrations ;
451457 if ( migrations === undefined ) {
452458 this . logger . error ( 'Package does not provide migrations.' ) ;
@@ -477,14 +483,14 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
477483 }
478484
479485 // Check if it is a package-local location
480- const localMigrations = path . join ( packageNode . path , migrations ) ;
486+ const localMigrations = path . join ( packagePath , migrations ) ;
481487 if ( fs . existsSync ( localMigrations ) ) {
482488 migrations = localMigrations ;
483489 } else {
484490 // Try to resolve from package location.
485491 // This avoids issues with package hoisting.
486492 try {
487- migrations = require . resolve ( migrations , { paths : [ packageNode . path ] } ) ;
493+ migrations = require . resolve ( migrations , { paths : [ packagePath ] } ) ;
488494 } catch ( e ) {
489495 if ( e . code === 'MODULE_NOT_FOUND' ) {
490496 this . logger . error ( 'Migrations for package were not found.' ) ;
@@ -513,7 +519,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
513519 }
514520
515521 const migrationRange = new semver . Range (
516- '>' + from + ' <=' + ( options . to || packageNode . package . version ) ,
522+ '>' + from + ' <=' + ( options . to || packageNode . version ) ,
517523 ) ;
518524
519525 success = await this . executeMigrations (
@@ -529,7 +535,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
529535 packageName === '@angular/core'
530536 && options . from
531537 && + options . from . split ( '.' ) [ 0 ] < 9
532- && ( options . to || packageNode . package . version ) . split ( '.' ) [ 0 ] === '9'
538+ && ( options . to || packageNode . version ) . split ( '.' ) [ 0 ] === '9'
533539 ) {
534540 this . logger . info ( NG_VERSION_9_POST_MSG ) ;
535541 }
@@ -547,8 +553,8 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
547553
548554 // Validate packages actually are part of the workspace
549555 for ( const pkg of packages ) {
550- const node = rootDependencies [ pkg . name ] && rootDependencies [ pkg . name ] . node ;
551- if ( ! node ) {
556+ const node = rootDependencies . get ( pkg . name ) ;
557+ if ( ! node ?. package ) {
552558 this . logger . error ( `Package '${ pkg . name } ' is not a dependency.` ) ;
553559
554560 return 1 ;
@@ -627,7 +633,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
627633 return 1 ;
628634 }
629635
630- if ( manifest . version === node . package . version ) {
636+ if ( manifest . version === node . package ? .version ) {
631637 this . logger . info ( `Package '${ packageName } ' is already up to date.` ) ;
632638 continue ;
633639 }
0 commit comments