@rollup/plugin-commonjs 19.0.1 → 19.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -788,6 +788,20 @@ function isShorthandProperty(parent) {
788
788
  return parent && parent.type === 'Property' && parent.shorthand;
789
789
  }
790
790
 
791
+ function hasDefineEsmProperty(node) {
792
+ return node.properties.some((property) => {
793
+ if (
794
+ property.type === 'Property' &&
795
+ property.key.type === 'Identifier' &&
796
+ property.key.name === '__esModule' &&
797
+ isTruthy(property.value)
798
+ ) {
799
+ return true;
800
+ }
801
+ return false;
802
+ });
803
+ }
804
+
791
805
  function wrapCode(magicString, uses, moduleName, exportsName) {
792
806
  const args = [];
793
807
  const passedArgs = [];
@@ -1263,6 +1277,18 @@ function transformCommonjs(
1263
1277
  } else if (!firstTopLevelModuleExportsAssignment) {
1264
1278
  firstTopLevelModuleExportsAssignment = node;
1265
1279
  }
1280
+
1281
+ if (defaultIsModuleExports === false) {
1282
+ shouldWrap = true;
1283
+ } else if (defaultIsModuleExports === 'auto') {
1284
+ if (node.right.type === 'ObjectExpression') {
1285
+ if (hasDefineEsmProperty(node.right)) {
1286
+ shouldWrap = true;
1287
+ }
1288
+ } else if (defaultIsModuleExports === false) {
1289
+ shouldWrap = true;
1290
+ }
1291
+ }
1266
1292
  } else if (exportName === KEY_COMPILED_ESM) {
1267
1293
  if (programDepth > 3) {
1268
1294
  shouldWrap = true;