@@ -17,6 +17,7 @@ import mkdirp from "mkdirp";
1717import { createCommand } from "../command" ;
1818import { BobConfig } from "../config" ;
1919import { rewriteExports } from "../utils/rewrite-exports" ;
20+ import { presetFields } from "./bootstrap" ;
2021
2122interface BuildOptions {
2223 external ?: string [ ] ;
@@ -406,17 +407,7 @@ function rewritePackageJson(pkg: Record<string, any>, distPath: string) {
406407 if ( pkg . exports ) {
407408 newPkg . exports = rewriteExports ( pkg . exports , DIST_DIR ) ;
408409 } else {
409- newPkg . exports = {
410- "." : {
411- require : "./index.js" ,
412- import : "./index.mjs" ,
413- } ,
414- "./*" : {
415- require : "./*.js" ,
416- import : "./*.mjs" ,
417- } ,
418- "./package.json" : "./package.json" ,
419- } ;
410+ newPkg . exports = presetFields . exports ;
420411 }
421412
422413 if ( pkg . bin ) {
@@ -449,21 +440,23 @@ export function validatePackageJson(pkg: any) {
449440 expect ( "typescript.definition" , `${ DIST_DIR } /index.d.ts` ) ;
450441
451442 expect ( "exports['.'].require" , {
452- default : `./${ DIST_DIR } /index.js` ,
453443 types : `./${ DIST_DIR } /index.d.ts` ,
444+ default : `./${ DIST_DIR } /index.js` ,
454445 } ) ;
455446 expect ( "exports['.'].import" , {
456- default : `./${ DIST_DIR } /index.mjs` ,
457447 types : `./${ DIST_DIR } /index.d.ts` ,
448+ default : `./${ DIST_DIR } /index.mjs` ,
458449 } ) ;
450+ expect ( "exports['.'].default" , `./${ DIST_DIR } /index.mjs` ) ;
459451 expect ( "exports['./*'].require" , {
460- default : `./${ DIST_DIR } /*.js` ,
461452 types : `./${ DIST_DIR } /*.d.ts` ,
453+ default : `./${ DIST_DIR } /*.js` ,
462454 } ) ;
463455 expect ( "exports['./*'].import" , {
464- default : `./${ DIST_DIR } /*.mjs` ,
465456 types : `./${ DIST_DIR } /*.d.ts` ,
457+ default : `./${ DIST_DIR } /*.mjs` ,
466458 } ) ;
459+ expect ( "exports['./*'].default" , `./${ DIST_DIR } /*.mjs` ) ;
467460}
468461
469462async function copyToDist ( cwd : string , files : string [ ] , distDir : string ) {
0 commit comments