@@ -15,8 +15,6 @@ import {
1515} from '@angular-devkit/schematics' ;
1616import { NodePackageInstallTask , RunSchematicTask } from '@angular-devkit/schematics/tasks' ;
1717import * as npa from 'npm-package-arg' ;
18- import { Observable , from as observableFrom , of } from 'rxjs' ;
19- import { map , mergeMap , reduce , switchMap } from 'rxjs/operators' ;
2018import * as semver from 'semver' ;
2119import { getNpmPackageJson } from './npm' ;
2220import { NpmRepositoryPackageJson } from './npm-package-json' ;
@@ -240,7 +238,7 @@ function _performUpdate(
240238 logger : logging . LoggerApi ,
241239 migrateOnly : boolean ,
242240 migrateExternal : boolean ,
243- ) : Observable < void > {
241+ ) : void {
244242 const packageJsonContent = tree . read ( '/package.json' ) ;
245243 if ( ! packageJsonContent ) {
246244 throw new SchematicsException ( 'Could not find a package.json. Are you in a Node project?' ) ;
@@ -347,8 +345,6 @@ function _performUpdate(
347345 ( global as any ) . externalMigrations = externalMigrations ;
348346 }
349347 }
350-
351- return of < void > ( undefined ) ;
352348}
353349
354350function _migrateOnly (
@@ -358,12 +354,12 @@ function _migrateOnly(
358354 to ?: string ,
359355) {
360356 if ( ! info ) {
361- return of < void > ( ) ;
357+ return ;
362358 }
363359
364360 const target = info . installed ;
365361 if ( ! target || ! target . updateMetadata . migrations ) {
366- return of < void > ( undefined ) ;
362+ return ;
367363 }
368364
369365 const collection = (
@@ -379,8 +375,6 @@ function _migrateOnly(
379375 to : to || target . version ,
380376 } ) ,
381377 ) ;
382-
383- return of < void > ( undefined ) ;
384378}
385379
386380function _getUpdateMetadata (
@@ -508,7 +502,7 @@ function _usageMessage(
508502 if ( packagesToUpdate . length == 0 ) {
509503 logger . info ( 'We analyzed your package.json and everything seems to be in order. Good work!' ) ;
510504
511- return of < void > ( undefined ) ;
505+ return ;
512506 }
513507
514508 logger . info (
@@ -536,7 +530,7 @@ function _usageMessage(
536530 logger . info ( ' ' + fields . map ( ( x , i ) => x . padEnd ( pads [ i ] ) ) . join ( '' ) ) ;
537531 } ) ;
538532
539- return of < void > ( undefined ) ;
533+ return ;
540534}
541535
542536
@@ -860,7 +854,7 @@ export default function(options: UpdateSchema): Rule {
860854 options . to = _formatVersion ( options . to ) ;
861855 const usingYarn = options . packageManager === 'yarn' ;
862856
863- return ( tree : Tree , context : SchematicContext ) => {
857+ return async ( tree : Tree , context : SchematicContext ) => {
864858 const logger = context . logger ;
865859 const npmDeps = new Map ( _getAllDependencies ( tree ) . filter ( ( [ name , specifier ] ) => {
866860 try {
@@ -874,95 +868,87 @@ export default function(options: UpdateSchema): Rule {
874868 } ) ) ;
875869 const packages = _buildPackageList ( options , npmDeps , logger ) ;
876870
877- return observableFrom ( npmDeps . keys ( ) ) . pipe (
878- // Grab all package.json from the npm repository. This requires a lot of HTTP calls so we
879- // try to parallelize as many as possible.
880- mergeMap ( depName => getNpmPackageJson (
881- depName ,
882- logger ,
883- { registryUrl : options . registry , usingYarn, verbose : options . verbose } ,
884- ) ) ,
885-
886- // Build a map of all dependencies and their packageJson.
887- reduce < Partial < NpmRepositoryPackageJson > , Map < string , NpmRepositoryPackageJson > > (
888- ( acc , npmPackageJson ) => {
889- // If the package was not found on the registry. It could be private, so we will just
890- // ignore. If the package was part of the list, we will error out, but will simply ignore
891- // if it's either not requested (so just part of package.json. silently) or if it's a
892- // `--all` situation. There is an edge case here where a public package peer depends on a
893- // private one, but it's rare enough.
894- if ( ! npmPackageJson . name ) {
895- if ( npmPackageJson . requestedName && packages . has ( npmPackageJson . requestedName ) ) {
896- if ( options . all ) {
897- logger . warn ( `Package ${ JSON . stringify ( npmPackageJson . requestedName ) } was not `
898- + 'found on the registry. Skipping.' ) ;
899- } else {
900- throw new SchematicsException (
901- `Package ${ JSON . stringify ( npmPackageJson . requestedName ) } was not found on the `
902- + 'registry. Cannot continue as this may be an error.' ) ;
903- }
871+ // Grab all package.json from the npm repository. This requires a lot of HTTP calls so we
872+ // try to parallelize as many as possible.
873+ const allPackageMetadata = await Promise . all ( Array . from ( npmDeps . keys ( ) ) . map ( depName => getNpmPackageJson (
874+ depName ,
875+ logger ,
876+ { registryUrl : options . registry , usingYarn, verbose : options . verbose } ,
877+ ) ) ) ;
878+
879+ // Build a map of all dependencies and their packageJson.
880+ const npmPackageJsonMap = allPackageMetadata . reduce (
881+ ( acc , npmPackageJson ) => {
882+ // If the package was not found on the registry. It could be private, so we will just
883+ // ignore. If the package was part of the list, we will error out, but will simply ignore
884+ // if it's either not requested (so just part of package.json. silently) or if it's a
885+ // `--all` situation. There is an edge case here where a public package peer depends on a
886+ // private one, but it's rare enough.
887+ if ( ! npmPackageJson . name ) {
888+ if ( npmPackageJson . requestedName && packages . has ( npmPackageJson . requestedName ) ) {
889+ if ( options . all ) {
890+ logger . warn ( `Package ${ JSON . stringify ( npmPackageJson . requestedName ) } was not `
891+ + 'found on the registry. Skipping.' ) ;
892+ } else {
893+ throw new SchematicsException (
894+ `Package ${ JSON . stringify ( npmPackageJson . requestedName ) } was not found on the `
895+ + 'registry. Cannot continue as this may be an error.' ) ;
904896 }
905- } else {
906- // If a name is present, it is assumed to be fully populated
907- acc . set ( npmPackageJson . name , npmPackageJson as NpmRepositoryPackageJson ) ;
908897 }
898+ } else {
899+ // If a name is present, it is assumed to be fully populated
900+ acc . set ( npmPackageJson . name , npmPackageJson as NpmRepositoryPackageJson ) ;
901+ }
909902
910- return acc ;
911- } ,
912- new Map < string , NpmRepositoryPackageJson > ( ) ,
913- ) ,
914-
915- map ( npmPackageJsonMap => {
916- // Augment the command line package list with packageGroups and forward peer dependencies.
917- // Each added package may uncover new package groups and peer dependencies, so we must
918- // repeat this process until the package list stabilizes.
919- let lastPackagesSize ;
920- do {
921- lastPackagesSize = packages . size ;
922- npmPackageJsonMap . forEach ( ( npmPackageJson ) => {
923- _addPackageGroup ( tree , packages , npmDeps , npmPackageJson , logger ) ;
924- _addPeerDependencies ( tree , packages , npmDeps , npmPackageJson , npmPackageJsonMap , logger ) ;
925- } ) ;
926- } while ( packages . size > lastPackagesSize ) ;
927-
928- // Build the PackageInfo for each module.
929- const packageInfoMap = new Map < string , PackageInfo > ( ) ;
930- npmPackageJsonMap . forEach ( ( npmPackageJson ) => {
931- packageInfoMap . set (
932- npmPackageJson . name ,
933- _buildPackageInfo ( tree , packages , npmDeps , npmPackageJson , logger ) ,
934- ) ;
935- } ) ;
903+ return acc ;
904+ } ,
905+ new Map < string , NpmRepositoryPackageJson > ( ) ,
906+ ) ;
936907
937- return packageInfoMap ;
938- } ) ,
939-
940- switchMap ( infoMap => {
941- // Now that we have all the information, check the flags.
942- if ( packages . size > 0 ) {
943- if ( options . migrateOnly && options . from && options . packages ) {
944- return _migrateOnly (
945- infoMap . get ( options . packages [ 0 ] ) ,
946- context ,
947- options . from ,
948- options . to ,
949- ) ;
950- }
908+ // Augment the command line package list with packageGroups and forward peer dependencies.
909+ // Each added package may uncover new package groups and peer dependencies, so we must
910+ // repeat this process until the package list stabilizes.
911+ let lastPackagesSize ;
912+ do {
913+ lastPackagesSize = packages . size ;
914+ npmPackageJsonMap . forEach ( ( npmPackageJson ) => {
915+ _addPackageGroup ( tree , packages , npmDeps , npmPackageJson , logger ) ;
916+ _addPeerDependencies ( tree , packages , npmDeps , npmPackageJson , npmPackageJsonMap , logger ) ;
917+ } ) ;
918+ } while ( packages . size > lastPackagesSize ) ;
919+
920+ // Build the PackageInfo for each module.
921+ const packageInfoMap = new Map < string , PackageInfo > ( ) ;
922+ npmPackageJsonMap . forEach ( ( npmPackageJson ) => {
923+ packageInfoMap . set (
924+ npmPackageJson . name ,
925+ _buildPackageInfo ( tree , packages , npmDeps , npmPackageJson , logger ) ,
926+ ) ;
927+ } ) ;
951928
952- const sublog = new logging . LevelCapLogger (
953- 'validation' ,
954- logger . createChild ( '' ) ,
955- 'warn' ,
956- ) ;
957- _validateUpdatePackages ( infoMap , ! ! options . force , ! ! options . next , sublog ) ;
929+ // Now that we have all the information, check the flags.
930+ if ( packages . size > 0 ) {
931+ if ( options . migrateOnly && options . from && options . packages ) {
932+ _migrateOnly (
933+ packageInfoMap . get ( options . packages [ 0 ] ) ,
934+ context ,
935+ options . from ,
936+ options . to ,
937+ ) ;
958938
959- return _performUpdate ( tree , context , infoMap , logger , ! ! options . migrateOnly , ! ! options . migrateExternal ) ;
960- } else {
961- return _usageMessage ( options , infoMap , logger ) ;
962- }
963- } ) ,
939+ return ;
940+ }
964941
965- switchMap ( ( ) => of ( tree ) ) ,
966- ) ;
942+ const sublog = new logging . LevelCapLogger (
943+ 'validation' ,
944+ logger . createChild ( '' ) ,
945+ 'warn' ,
946+ ) ;
947+ _validateUpdatePackages ( packageInfoMap , ! ! options . force , ! ! options . next , sublog ) ;
948+
949+ _performUpdate ( tree , context , packageInfoMap , logger , ! ! options . migrateOnly , ! ! options . migrateExternal ) ;
950+ } else {
951+ _usageMessage ( options , packageInfoMap , logger ) ;
952+ }
967953 } ;
968954}
0 commit comments