@@ -15,8 +15,6 @@ import {
15
15
} from '@angular-devkit/schematics' ;
16
16
import { NodePackageInstallTask , RunSchematicTask } from '@angular-devkit/schematics/tasks' ;
17
17
import * as npa from 'npm-package-arg' ;
18
- import { Observable , from as observableFrom , of } from 'rxjs' ;
19
- import { map , mergeMap , reduce , switchMap } from 'rxjs/operators' ;
20
18
import * as semver from 'semver' ;
21
19
import { getNpmPackageJson } from './npm' ;
22
20
import { NpmRepositoryPackageJson } from './npm-package-json' ;
@@ -240,7 +238,7 @@ function _performUpdate(
240
238
logger : logging . LoggerApi ,
241
239
migrateOnly : boolean ,
242
240
migrateExternal : boolean ,
243
- ) : Observable < void > {
241
+ ) : void {
244
242
const packageJsonContent = tree . read ( '/package.json' ) ;
245
243
if ( ! packageJsonContent ) {
246
244
throw new SchematicsException ( 'Could not find a package.json. Are you in a Node project?' ) ;
@@ -347,8 +345,6 @@ function _performUpdate(
347
345
( global as any ) . externalMigrations = externalMigrations ;
348
346
}
349
347
}
350
-
351
- return of < void > ( undefined ) ;
352
348
}
353
349
354
350
function _migrateOnly (
@@ -358,12 +354,12 @@ function _migrateOnly(
358
354
to ?: string ,
359
355
) {
360
356
if ( ! info ) {
361
- return of < void > ( ) ;
357
+ return ;
362
358
}
363
359
364
360
const target = info . installed ;
365
361
if ( ! target || ! target . updateMetadata . migrations ) {
366
- return of < void > ( undefined ) ;
362
+ return ;
367
363
}
368
364
369
365
const collection = (
@@ -379,8 +375,6 @@ function _migrateOnly(
379
375
to : to || target . version ,
380
376
} ) ,
381
377
) ;
382
-
383
- return of < void > ( undefined ) ;
384
378
}
385
379
386
380
function _getUpdateMetadata (
@@ -508,7 +502,7 @@ function _usageMessage(
508
502
if ( packagesToUpdate . length == 0 ) {
509
503
logger . info ( 'We analyzed your package.json and everything seems to be in order. Good work!' ) ;
510
504
511
- return of < void > ( undefined ) ;
505
+ return ;
512
506
}
513
507
514
508
logger . info (
@@ -536,7 +530,7 @@ function _usageMessage(
536
530
logger . info ( ' ' + fields . map ( ( x , i ) => x . padEnd ( pads [ i ] ) ) . join ( '' ) ) ;
537
531
} ) ;
538
532
539
- return of < void > ( undefined ) ;
533
+ return ;
540
534
}
541
535
542
536
@@ -860,7 +854,7 @@ export default function(options: UpdateSchema): Rule {
860
854
options . to = _formatVersion ( options . to ) ;
861
855
const usingYarn = options . packageManager === 'yarn' ;
862
856
863
- return ( tree : Tree , context : SchematicContext ) => {
857
+ return async ( tree : Tree , context : SchematicContext ) => {
864
858
const logger = context . logger ;
865
859
const npmDeps = new Map ( _getAllDependencies ( tree ) . filter ( ( [ name , specifier ] ) => {
866
860
try {
@@ -874,95 +868,87 @@ export default function(options: UpdateSchema): Rule {
874
868
} ) ) ;
875
869
const packages = _buildPackageList ( options , npmDeps , logger ) ;
876
870
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.' ) ;
904
896
}
905
- } else {
906
- // If a name is present, it is assumed to be fully populated
907
- acc . set ( npmPackageJson . name , npmPackageJson as NpmRepositoryPackageJson ) ;
908
897
}
898
+ } else {
899
+ // If a name is present, it is assumed to be fully populated
900
+ acc . set ( npmPackageJson . name , npmPackageJson as NpmRepositoryPackageJson ) ;
901
+ }
909
902
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
+ ) ;
936
907
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
+ } ) ;
951
928
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
+ ) ;
958
938
959
- return _performUpdate ( tree , context , infoMap , logger , ! ! options . migrateOnly , ! ! options . migrateExternal ) ;
960
- } else {
961
- return _usageMessage ( options , infoMap , logger ) ;
962
- }
963
- } ) ,
939
+ return ;
940
+ }
964
941
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
+ }
967
953
} ;
968
954
}
0 commit comments