@@ -3,6 +3,7 @@ import { readFileSync } from 'fs';
3
3
import {
4
4
buildDepTreeFromFiles ,
5
5
parseNpmLockV2Project ,
6
+ parsePnpmProject ,
6
7
parseYarnLockV1Project ,
7
8
parseYarnLockV2Project ,
8
9
} from '../../../lib/' ;
@@ -454,3 +455,112 @@ describe('Testing aliases for npm', () => {
454
455
expect ( ( ) => JSON . parse ( JSON . stringify ( newDepGraph ) ) ) . not . toThrow ( ) ;
455
456
} ) ;
456
457
} ) ;
458
+
459
+ describe . each ( [ 'pnpm-lock-v5' , 'pnpm-lock-v6' , 'pnpm-lock-v9' ] ) (
460
+ 'Testing aliases for pnpm %s' ,
461
+ ( lockFileVersionPath ) => {
462
+ it ( 'match aliased package' , async ( ) => {
463
+ const fixtureName = 'pnpm-lock' ;
464
+ const pkgJsonContent = readFileSync (
465
+ join (
466
+ __dirname ,
467
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /package.json` ,
468
+ ) ,
469
+ 'utf8' ,
470
+ ) ;
471
+ const pkgLockContent = readFileSync (
472
+ join (
473
+ __dirname ,
474
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /pnpm-lock.yaml` ,
475
+ ) ,
476
+ 'utf8' ,
477
+ ) ;
478
+
479
+ const newDepGraph = await parsePnpmProject (
480
+ pkgJsonContent ,
481
+ pkgLockContent ,
482
+ {
483
+ includeDevDeps : true ,
484
+ includePeerDeps : true ,
485
+ includeOptionalDeps : true ,
486
+ strictOutOfSync : true ,
487
+ pruneWithinTopLevelDeps : true ,
488
+ } ,
489
+ ) ;
490
+
491
+ expect ( newDepGraph ) . toBeDefined ;
492
+ expect ( ( ) => JSON . parse ( JSON . stringify ( newDepGraph ) ) ) . not . toThrow ( ) ;
493
+ expect ( JSON . stringify ( newDepGraph ) ) . toContain ( '@yao-pkg/pkg' ) ;
494
+ expect ( JSON . stringify ( newDepGraph ) ) . not . toContain ( '"pkg"' ) ;
495
+ } ) ;
496
+ it ( 'match aliased package also used in transitive deps' , async ( ) => {
497
+ const fixtureName = 'pnpm-lock-with-npm-alias-also-on-transitive' ;
498
+ const pkgJsonContent = readFileSync (
499
+ join (
500
+ __dirname ,
501
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /package.json` ,
502
+ ) ,
503
+ 'utf8' ,
504
+ ) ;
505
+ const pkgLockContent = readFileSync (
506
+ join (
507
+ __dirname ,
508
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /pnpm-lock.yaml` ,
509
+ ) ,
510
+ 'utf8' ,
511
+ ) ;
512
+
513
+ const newDepGraph = await parsePnpmProject (
514
+ pkgJsonContent ,
515
+ pkgLockContent ,
516
+ {
517
+ includeDevDeps : true ,
518
+ includePeerDeps : true ,
519
+ includeOptionalDeps : true ,
520
+ strictOutOfSync : true ,
521
+ pruneWithinTopLevelDeps : true ,
522
+ } ,
523
+ ) ;
524
+
525
+ expect ( newDepGraph ) . toBeDefined ;
526
+ expect ( ( ) => JSON . parse ( JSON . stringify ( newDepGraph ) ) ) . not . toThrow ( ) ;
527
+ expect ( JSON . stringify ( newDepGraph ) ) . toContain ( '@yao-pkg/pkg' ) ;
528
+ expect ( JSON . stringify ( newDepGraph ) ) . not . toContain ( '"pkg"' ) ;
529
+ } ) ;
530
+
531
+ it ( 'ignore aliased package in transitive deps not throwing out of sync error' , async ( ) => {
532
+ const fixtureName = 'pnpm-lock-with-npm-prefixed-sub-dep-version' ;
533
+ const pkgJsonContent = readFileSync (
534
+ join (
535
+ __dirname ,
536
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /package.json` ,
537
+ ) ,
538
+ 'utf8' ,
539
+ ) ;
540
+ const pkgLockContent = readFileSync (
541
+ join (
542
+ __dirname ,
543
+ `./fixtures/aliases/pnpm/${ lockFileVersionPath } /${ fixtureName } /pnpm-lock.yaml` ,
544
+ ) ,
545
+ 'utf8' ,
546
+ ) ;
547
+
548
+ const newDepGraph = await parsePnpmProject (
549
+ pkgJsonContent ,
550
+ pkgLockContent ,
551
+ {
552
+ includeDevDeps : true ,
553
+ includePeerDeps : true ,
554
+ includeOptionalDeps : true ,
555
+ strictOutOfSync : true ,
556
+ pruneWithinTopLevelDeps : true ,
557
+ } ,
558
+ ) ;
559
+
560
+ expect ( newDepGraph ) . toBeDefined ;
561
+ expect ( ( ) => JSON . parse ( JSON . stringify ( newDepGraph ) ) ) . not . toThrow ( ) ;
562
+ expect ( JSON . stringify ( newDepGraph ) ) . toContain ( '@yao-pkg/pkg' ) ;
563
+ expect ( JSON . stringify ( newDepGraph ) ) . not . toContain ( '"pkg"' ) ;
564
+ } ) ;
565
+ } ,
566
+ ) ;
0 commit comments