@@ -11,6 +11,7 @@ import {getPackageJson} from '../utils/package-json.js';
1111
1212export async function run ( ctx : CommandContext < typeof meta > ) {
1313 const [ _commandName , ...targetModules ] = ctx . positionals ;
14+ const all = ctx . values . all === true ;
1415 const dryRun = ctx . values [ 'dry-run' ] === true ;
1516 const interactive = ctx . values . interactive === true ;
1617 const include = ctx . values . include ;
@@ -37,7 +38,7 @@ export async function run(ctx: CommandContext<typeof meta>) {
3738 . map ( ( rep ) => rep . from )
3839 ) ;
3940
40- if ( interactive ) {
41+ if ( interactive && ! all ) {
4142 const additionalTargets = await prompts . autocompleteMultiselect ( {
4243 message : 'Select packages to migrate' ,
4344 maxItems : 10 ,
@@ -60,34 +61,50 @@ export async function run(ctx: CommandContext<typeof meta>) {
6061 }
6162 }
6263
63- if ( targetModules . length === 0 ) {
64- prompts . cancel (
65- 'Error: Please specify a package to migrate. For example, `migrate chalk`'
66- ) ;
67- return ;
68- }
64+ let selectedReplacements : Replacement [ ] ;
6965
70- const selectedReplacements : Replacement [ ] = [ ] ;
71-
72- for ( const targetModule of targetModules ) {
73- const replacement = fixableReplacements . find (
74- ( rep ) => rep . from === targetModule
66+ if ( all ) {
67+ selectedReplacements = fixableReplacements . filter ( ( rep ) =>
68+ fixableReplacementsTargets . has ( rep . from )
7569 ) ;
76- if ( ! replacement ) {
70+ } else {
71+ if ( targetModules . length === 0 ) {
7772 prompts . cancel (
78- ` Error: Target package has no available migrations ( ${ targetModule } )`
73+ ' Error: Please specify a package to migrate. For example, `migrate chalk`'
7974 ) ;
8075 return ;
8176 }
8277
83- selectedReplacements . push ( replacement ) ;
78+ selectedReplacements = [ ] ;
79+
80+ for ( const targetModule of targetModules ) {
81+ if ( ! fixableReplacementsTargets . has ( targetModule ) ) {
82+ prompts . cancel (
83+ `Error: Target package is not in project dependencies (${ targetModule } )`
84+ ) ;
85+ return ;
86+ }
87+
88+ const replacement = fixableReplacements . find (
89+ ( rep ) => rep . from === targetModule
90+ ) ;
91+ if ( ! replacement ) {
92+ prompts . cancel (
93+ `Error: Target package has no available migrations (${ targetModule } )`
94+ ) ;
95+ return ;
96+ }
97+
98+ selectedReplacements . push ( replacement ) ;
99+ }
84100 }
85101
86102 if ( ! interactive ) {
103+ const targetNames = selectedReplacements . map ( ( r ) => r . from ) ;
87104 const targetModuleSummary =
88- targetModules . length > 6
89- ? `${ targetModules . slice ( 0 , 6 ) . join ( ', ' ) } and ${ targetModules . length - 6 } more`
90- : targetModules . join ( ', ' ) ;
105+ targetNames . length > 6
106+ ? `${ targetNames . slice ( 0 , 6 ) . join ( ', ' ) } and ${ targetNames . length - 6 } more`
107+ : targetNames . join ( ', ' ) ;
91108 prompts . log . message ( `Targets: ${ styleText ( 'dim' , targetModuleSummary ) } ` ) ;
92109 }
93110
@@ -106,6 +123,8 @@ export async function run(ctx: CommandContext<typeof meta>) {
106123 return ;
107124 }
108125
126+ let filesMigratedCount = 0 ;
127+
109128 for ( const filename of files ) {
110129 const log = prompts . taskLog ( {
111130 title : `${ filename } ...` ,
@@ -140,10 +159,13 @@ export async function run(ctx: CommandContext<typeof meta>) {
140159 }
141160 totalMigrations ++ ;
142161 }
162+ if ( totalMigrations > 0 ) {
163+ filesMigratedCount ++ ;
164+ }
143165 log . success (
144166 `${ filename } ${ styleText ( 'dim' , `(${ totalMigrations } migrated)` ) } `
145167 ) ;
146168 }
147169
148- prompts . outro ( ' Migration complete.' ) ;
170+ prompts . outro ( ` Migration complete - ${ filesMigratedCount } files migrated.` ) ;
149171}
0 commit comments