@@ -96,16 +96,18 @@ export interface GRCOptions {
9696 /**
9797 * Simply required package.json.
9898 */
99- packageJSON : {
99+ packageJSON : Partial < {
100100 browser : string ;
101101 dependencies : Record < string , string > ;
102102 devDependencies : Record < string , string > ;
103+ exports : Record < string , Record < string , string | undefined > | undefined > ;
103104 files : string [ ] ;
104105 jsnext : string ;
105106 main : string ;
106107 module : string ;
107108 peerDependencies : Record < string , string > ;
108- } ;
109+ types : string ;
110+ } > ;
109111 /**
110112 * The path to tsconfig.json to be used in this build.
111113 */
@@ -569,14 +571,101 @@ export async function generateRollupConfiguration(
569571 ] ) ;
570572 } ) ;
571573
574+ const expectedExports = Object . fromEntries ( [
575+ [
576+ "." ,
577+ {
578+ import : `./peer/esm/${ libraryFilename } .mjs` ,
579+ require : `./peer/umd/${ libraryFilename } .cjs` ,
580+ types : "./declarations/index.d.ts" ,
581+ } ,
582+ ] ,
583+ [ "./package.json" , "./package.json" ] ,
584+ [
585+ "./declarations/index.d.ts" ,
586+ {
587+ types : "./declarations/index.d.ts" ,
588+ } ,
589+ ] ,
590+ ...[ "standalone" , "peer" , "esnext" ] . flatMap (
591+ ( variant ) : [ string , Record < string , string > ] [ ] => [
592+ [
593+ `./${ variant } ` ,
594+ {
595+ import : `./${ variant } /esm/${ libraryFilename } .mjs` ,
596+ require : `./${ variant } /umd/${ libraryFilename } .cjs` ,
597+ types : "./declarations/index.d.ts" ,
598+ } ,
599+ ] ,
600+ [
601+ `./${ variant } /esm/${ libraryFilename } .js` ,
602+ {
603+ import : `./${ variant } /esm/${ libraryFilename } .mjs` ,
604+ types : "./declarations/index.d.ts" ,
605+ } ,
606+ ] ,
607+ [
608+ `./${ variant } /esm/${ libraryFilename } .mjs` ,
609+ {
610+ import : `./${ variant } /esm/${ libraryFilename } .mjs` ,
611+ types : "./declarations/index.d.ts" ,
612+ } ,
613+ ] ,
614+ [
615+ `./${ variant } /esm/${ libraryFilename } .min.js` ,
616+ {
617+ import : `./${ variant } /esm/${ libraryFilename } .min.mjs` ,
618+ types : "./declarations/index.d.ts" ,
619+ } ,
620+ ] ,
621+ [
622+ `./${ variant } /esm/${ libraryFilename } .min.mjs` ,
623+ {
624+ import : `./${ variant } /esm/${ libraryFilename } .min.mjs` ,
625+ types : "./declarations/index.d.ts" ,
626+ } ,
627+ ] ,
628+ [
629+ `./${ variant } /umd/${ libraryFilename } .js` ,
630+ {
631+ require : `./${ variant } /umd/${ libraryFilename } .cjs` ,
632+ types : "./declarations/index.d.ts" ,
633+ } ,
634+ ] ,
635+ [
636+ `./${ variant } /umd/${ libraryFilename } .cjs` ,
637+ {
638+ require : `./${ variant } /umd/${ libraryFilename } .cjs` ,
639+ types : "./declarations/index.d.ts" ,
640+ } ,
641+ ] ,
642+ [
643+ `./${ variant } /umd/${ libraryFilename } .min.js` ,
644+ {
645+ require : `./${ variant } /umd/${ libraryFilename } .min.cjs` ,
646+ types : "./declarations/index.d.ts" ,
647+ } ,
648+ ] ,
649+ [
650+ `./${ variant } /umd/${ libraryFilename } .min.cjs` ,
651+ {
652+ require : `./${ variant } /umd/${ libraryFilename } .min.cjs` ,
653+ types : "./declarations/index.d.ts" ,
654+ } ,
655+ ] ,
656+ ] ,
657+ ) ,
658+ ] ) ;
659+
572660 validate ( ( expect ) : void => {
573661 expect (
574662 packageJSONRest ,
575663 "Package JSON's type property has to point to the declarations" ,
576664 )
577665 . to . have . ownProperty ( "types" )
578666 . that . is . a ( "string" )
579- . and . equals ( `declarations/index.d.ts` ) ;
667+ . and . equals ( "./declarations/index.d.ts" )
668+ . and . is . oneOf ( Object . keys ( expectedExports ) ) ;
580669 } ) ;
581670 validate ( ( expect ) : void => {
582671 expect (
@@ -585,7 +674,8 @@ export async function generateRollupConfiguration(
585674 )
586675 . to . have . ownProperty ( "browser" )
587676 . that . is . a ( "string" )
588- . and . equals ( `peer/umd/${ libraryFilename } .min.cjs` ) ;
677+ . and . equals ( `./peer/umd/${ libraryFilename } .min.cjs` )
678+ . and . is . oneOf ( Object . keys ( expectedExports ) ) ;
589679 } ) ;
590680 validate ( ( expect ) : void => {
591681 expect (
@@ -594,7 +684,8 @@ export async function generateRollupConfiguration(
594684 )
595685 . to . have . ownProperty ( "main" )
596686 . that . is . a ( "string" )
597- . and . equals ( `peer/umd/${ libraryFilename } .cjs` ) ;
687+ . and . equals ( `./peer/umd/${ libraryFilename } .cjs` )
688+ . and . is . oneOf ( Object . keys ( expectedExports ) ) ;
598689 } ) ;
599690 validate ( ( expect ) : void => {
600691 expect (
@@ -603,7 +694,8 @@ export async function generateRollupConfiguration(
603694 )
604695 . to . have . ownProperty ( "module" )
605696 . that . is . a ( "string" )
606- . and . equals ( `peer/esm/${ libraryFilename } .mjs` ) ;
697+ . and . equals ( `./peer/esm/${ libraryFilename } .mjs` )
698+ . and . is . oneOf ( Object . keys ( expectedExports ) ) ;
607699 } ) ;
608700 validate ( ( expect ) : void => {
609701 expect (
@@ -612,46 +704,19 @@ export async function generateRollupConfiguration(
612704 )
613705 . to . have . ownProperty ( "jsnext" )
614706 . that . is . a ( "string" )
615- . and . equals ( `esnext/esm/${ libraryFilename } .mjs` ) ;
616- } ) ;
617-
618- validate ( ( expect ) : void => {
619- expect ( packageJSONRest , "Package JSON's exports have to contain ./" )
620- . to . have . ownProperty ( "exports" )
621- . that . is . an ( "object" )
622- . and . has . ownProperty ( "." )
623- . that . is . an ( "object" )
624- . and . has . keys ( [ "import" , "require" , "types" ] ) ;
707+ . and . equals ( `./esnext/esm/${ libraryFilename } .mjs` )
708+ . and . is . oneOf ( Object . keys ( expectedExports ) ) ;
625709 } ) ;
626710
627711 validate ( ( expect ) : void => {
628712 expect (
629- packageJSONRest ,
630- "Package JSON's exports have to contain ./standalone" ,
631- )
632- . to . have . ownProperty ( "exports" )
633- . that . is . an ( "object" )
634- . and . has . ownProperty ( "./standalone" )
635- . that . is . an ( "object" )
636- . and . has . keys ( [ "import" , "require" , "types" ] ) ;
637- } ) ;
638-
639- validate ( ( expect ) : void => {
640- expect ( packageJSONRest , "Package JSON's exports have to contain ./peer" )
641- . to . have . ownProperty ( "exports" )
642- . that . is . an ( "object" )
643- . and . has . ownProperty ( "./peer" )
644- . that . is . an ( "object" )
645- . and . has . keys ( [ "import" , "require" , "types" ] ) ;
646- } ) ;
647-
648- validate ( ( expect ) : void => {
649- expect ( packageJSONRest , "Package JSON's exports have to contain ./esnext" )
650- . to . have . ownProperty ( "exports" )
651- . that . is . an ( "object" )
652- . and . has . ownProperty ( "./esnext" )
653- . that . is . an ( "object" )
654- . and . has . keys ( [ "import" , "require" , "types" ] ) ;
713+ Object . fromEntries (
714+ Object . entries ( packageJSONRest . exports ?? { } ) . filter ( ( [ key ] ) : boolean =>
715+ Object . keys ( expectedExports ) . includes ( key ) ,
716+ ) ,
717+ ) ,
718+ "Package JSON's exports have to contain common entries" ,
719+ ) . to . deep . equal ( expectedExports ) ;
655720 } ) ;
656721
657722 validate ( async ( expect ) : Promise < void > => {
0 commit comments