File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -421,11 +421,14 @@ export class Package {
421
421
let mainEntry = '' ;
422
422
let moduleEntry = '' ;
423
423
let browserEntry = '' ;
424
+ let buildCount = 0 ;
424
425
425
426
// eslint-disable-next-line complexity
426
427
this . artifacts . forEach ( ( artifact ) => {
427
428
// Build files
428
429
if ( artifact instanceof CodeArtifact ) {
430
+ buildCount += artifact . builds . length ;
431
+
429
432
// Generate `main`, `module`, and `browser` fields
430
433
if ( artifact . inputs . index ) {
431
434
if ( ! mainEntry || artifact . platform === 'node' ) {
@@ -464,10 +467,13 @@ export class Package {
464
467
if ( mainEntry ) {
465
468
this . packageJson . main = mainEntry ;
466
469
467
- if ( mainEntry . includes ( 'mjs/' ) || mainEntry . includes ( 'esm/' ) ) {
468
- this . packageJson . type = 'module' ;
469
- } else if ( mainEntry . includes ( 'cjs/' ) ) {
470
- this . packageJson . type = 'commonjs' ;
470
+ // Only set when we have 1 build, otherwise its confusing
471
+ if ( buildCount === 1 ) {
472
+ if ( mainEntry . includes ( 'mjs/' ) || mainEntry . includes ( 'esm/' ) ) {
473
+ this . packageJson . type = 'module' ;
474
+ } else if ( mainEntry . includes ( 'cjs/' ) ) {
475
+ this . packageJson . type = 'commonjs' ;
476
+ }
471
477
}
472
478
}
473
479
Original file line number Diff line number Diff line change @@ -862,7 +862,6 @@ describe('Package', () => {
862
862
863
863
expect ( pkg . packageJson ) . toEqual (
864
864
expect . objectContaining ( {
865
- type : 'commonjs' ,
866
865
main : './cjs/index.cjs' ,
867
866
bin : './lib/bin.js' ,
868
867
exports : {
@@ -912,7 +911,6 @@ describe('Package', () => {
912
911
913
912
expect ( pkg . packageJson ) . toEqual (
914
913
expect . objectContaining ( {
915
- type : 'commonjs' ,
916
914
main : './cjs/node.cjs' ,
917
915
bin : './lib/cli.js' ,
918
916
exports : {
@@ -959,7 +957,6 @@ describe('Package', () => {
959
957
960
958
expect ( pkg . packageJson ) . toEqual (
961
959
expect . objectContaining ( {
962
- type : 'commonjs' ,
963
960
main : './cjs/node.cjs' ,
964
961
bin : './lib/cli.js' ,
965
962
exports : {
You can’t perform that action at this time.
0 commit comments