@@ -107,20 +107,10 @@ var yarnToNpmTable = {
107
107
return [ 'rebuild' ] ;
108
108
}
109
109
args [ 0 ] = 'install' ;
110
- if ( ! args . includes ( '--dev' ) &&
111
- ! args . includes ( '--force' ) &&
112
- ! args . includes ( '--exact' ) &&
113
- ! args . includes ( '--optional' ) &&
114
- ! args . includes ( '--production' ) ) {
115
- args . push ( '--save' ) ;
116
- }
117
110
return convertAddRemoveArgs ( args ) ;
118
111
} ,
119
112
remove : function ( args ) {
120
113
args [ 0 ] = 'uninstall' ;
121
- if ( ! args . includes ( '--dev' ) ) {
122
- args . push ( '--save' ) ;
123
- }
124
114
return convertAddRemoveArgs ( args ) ;
125
115
} ,
126
116
version : function ( args ) {
@@ -149,6 +139,7 @@ var yarnToNpmTable = {
149
139
} ,
150
140
init : 'init' ,
151
141
create : 'init' ,
142
+ outdated : 'outdated' ,
152
143
run : 'run' ,
153
144
global : function ( args ) {
154
145
switch ( args [ 1 ] ) {
@@ -173,6 +164,14 @@ var yarnToNpmTable = {
173
164
args . push ( "\n# couldn't auto-convert command" ) ;
174
165
return args ;
175
166
}
167
+ } ,
168
+ pack : function ( args ) {
169
+ return args . map ( function ( item ) {
170
+ if ( item === '--filename' ) {
171
+ return '--pack-destination' ;
172
+ }
173
+ return item ;
174
+ } ) ;
176
175
}
177
176
} ;
178
177
function yarnToNPM ( _m , command ) {
@@ -249,6 +248,9 @@ var npmToYarnTable = {
249
248
args [ 0 ] = 'remove' ;
250
249
return convertInstallArgs ( args ) ;
251
250
} ,
251
+ un : function ( args ) {
252
+ return npmToYarnTable . uninstall ( args ) ;
253
+ } ,
252
254
remove : function ( args ) {
253
255
return npmToYarnTable . uninstall ( args ) ;
254
256
} ,
@@ -315,7 +317,17 @@ var npmToYarnTable = {
315
317
return args . filter ( function ( item ) { return item !== '--scope' ; } ) ;
316
318
} ,
317
319
ln : 'link' ,
318
- un : 'unlink'
320
+ t : 'test' ,
321
+ tst : 'test' ,
322
+ outdated : 'outdated' ,
323
+ pack : function ( args ) {
324
+ return args . map ( function ( item ) {
325
+ if ( item . startsWith ( '--pack-destination' ) ) {
326
+ return item . replace ( / ^ - - p a c k - d e s t i n a t i o n [ \s = ] / , '--filename ' ) ;
327
+ }
328
+ return item ;
329
+ } ) ;
330
+ }
319
331
} ;
320
332
function npmToYarn ( _m , command ) {
321
333
var args = parse ( ( command || '' ) . trim ( ) ) ;
@@ -324,7 +336,7 @@ function npmToYarn(_m, command) {
324
336
args . splice ( index , 1 ) ;
325
337
}
326
338
if ( unchangedCLICommands . includes ( args [ 0 ] ) ) {
327
- return 'yarn ' + args . join ( ' ' ) ;
339
+ return 'yarn ' + args . filter ( Boolean ) . join ( ' ' ) ;
328
340
}
329
341
else if ( args [ 0 ] in npmToYarnTable ) {
330
342
var converter = npmToYarnTable [ args [ 0 ] ] ;
@@ -337,7 +349,139 @@ function npmToYarn(_m, command) {
337
349
return 'yarn ' + args . filter ( Boolean ) . join ( ' ' ) ;
338
350
}
339
351
else {
340
- return 'yarn ' + command + "\n# couldn't auto-convert command" ;
352
+ return 'npm ' + command + "\n# couldn't auto-convert command" ;
353
+ }
354
+ }
355
+
356
+ function convertPnpmInstallArgs ( args ) {
357
+ return args . map ( function ( item ) {
358
+ switch ( item ) {
359
+ case '--save' :
360
+ case '-S' :
361
+ return '' ;
362
+ case '--no-package-lock' :
363
+ return '--frozen-lockfile' ;
364
+ // case '--save-dev':
365
+ // case '-D':
366
+ // case '--save-prod':
367
+ // case '-P':
368
+ // case '--save-optional':
369
+ // case '-O':
370
+ // case '--save-exact':
371
+ // case '-E':
372
+ // case '--global':
373
+ // case '-g':
374
+ default :
375
+ return item ;
376
+ }
377
+ } ) ;
378
+ }
379
+ function convertFilterArg ( args ) {
380
+ if ( args . length > 1 ) {
381
+ var filter = args . filter ( function ( item , index ) { return index !== 0 && ! item . startsWith ( '-' ) ; } ) ;
382
+ if ( filter . length > 0 ) {
383
+ args = args . filter ( function ( item , index ) { return index === 0 || item . startsWith ( '-' ) ; } ) ;
384
+ args . push ( '--filter' ) ;
385
+ args . push ( filter . join ( ' ' ) ) ;
386
+ }
387
+ }
388
+ return args ;
389
+ }
390
+ var npmToPnpmTable = {
391
+ // ------------------------------
392
+ install : function ( args ) {
393
+ if ( args . length > 1 && args . filter ( function ( item ) { return ! item . startsWith ( '-' ) ; } ) . length > 1 ) {
394
+ args [ 0 ] = 'add' ;
395
+ }
396
+ return convertPnpmInstallArgs ( args ) ;
397
+ } ,
398
+ i : function ( args ) {
399
+ return npmToPnpmTable . install ( args ) ;
400
+ } ,
401
+ // ------------------------------
402
+ uninstall : function ( args ) {
403
+ args [ 0 ] = 'remove' ;
404
+ return convertPnpmInstallArgs ( args ) ;
405
+ } ,
406
+ un : function ( args ) {
407
+ return npmToPnpmTable . uninstall ( args ) ;
408
+ } ,
409
+ remove : function ( args ) {
410
+ return npmToPnpmTable . uninstall ( args ) ;
411
+ } ,
412
+ r : function ( args ) {
413
+ return npmToPnpmTable . uninstall ( args ) ;
414
+ } ,
415
+ rm : function ( args ) {
416
+ return npmToPnpmTable . uninstall ( args ) ;
417
+ } ,
418
+ // ------------------------------
419
+ rb : function ( args ) {
420
+ return npmToPnpmTable . rebuild ( args ) ;
421
+ } ,
422
+ rebuild : function ( args ) {
423
+ args [ 0 ] = 'rebuild' ;
424
+ return convertFilterArg ( args ) ;
425
+ } ,
426
+ run : 'run' ,
427
+ exec : 'exec' ,
428
+ ls : function ( args ) {
429
+ return npmToPnpmTable . list ( args ) ;
430
+ } ,
431
+ list : function ( args ) {
432
+ return args . map ( function ( item ) {
433
+ if ( item . startsWith ( '--depth=' ) ) {
434
+ return "--depth " . concat ( item . split ( '=' ) [ 1 ] ) ;
435
+ }
436
+ switch ( item ) {
437
+ case '--production' :
438
+ return '--prod' ;
439
+ case '--development' :
440
+ return '--dev' ;
441
+ default :
442
+ return item ;
443
+ }
444
+ } ) ;
445
+ } ,
446
+ init : function ( args ) {
447
+ if ( args [ 1 ] && ! args [ 1 ] . startsWith ( '-' ) ) {
448
+ args [ 0 ] = 'create' ;
449
+ }
450
+ return args . filter ( function ( item ) { return item !== '--scope' ; } ) ;
451
+ } ,
452
+ ln : 'link' ,
453
+ t : 'test' ,
454
+ test : 'test' ,
455
+ tst : 'test' ,
456
+ start : 'start' ,
457
+ link : 'link' ,
458
+ unlink : function ( args ) {
459
+ return convertFilterArg ( args ) ;
460
+ } ,
461
+ outdated : 'outdated' ,
462
+ pack : function ( args ) {
463
+ return args . map ( function ( item ) {
464
+ if ( item . startsWith ( '--pack-destination' ) ) {
465
+ return item . replace ( / ^ - - p a c k - d e s t i n a t i o n [ \s = ] / , '--pack-destination ' ) ;
466
+ }
467
+ return item ;
468
+ } ) ;
469
+ }
470
+ } ;
471
+ function npmToPnpm ( _m , command ) {
472
+ var args = parse ( ( command || '' ) . trim ( ) ) ;
473
+ if ( args [ 0 ] in npmToPnpmTable ) {
474
+ var converter = npmToPnpmTable [ args [ 0 ] ] ;
475
+ if ( typeof converter === 'function' ) {
476
+ args = converter ( args ) ;
477
+ }
478
+ else {
479
+ args [ 0 ] = converter ;
480
+ }
481
+ return 'pnpm ' + args . filter ( Boolean ) . join ( ' ' ) ;
482
+ }
483
+ else {
484
+ return 'npm ' + command + "\n# couldn't auto-convert command" ;
341
485
}
342
486
}
343
487
@@ -348,6 +492,9 @@ function convert(str, to) {
348
492
if ( to === 'npm' ) {
349
493
return str . replace ( / y a r n (?: + ( [ ^ & \n \r ] * ) ) ? / gm, yarnToNPM ) ;
350
494
}
495
+ else if ( to === 'pnpm' ) {
496
+ return str . replace ( / n p m (?: + ( [ ^ & \n \r ] * ) ) ? / gm, npmToPnpm ) ;
497
+ }
351
498
else {
352
499
return str . replace ( / n p m (?: + ( [ ^ & \n \r ] * ) ) ? / gm, npmToYarn ) ;
353
500
}
0 commit comments