@rollup/plugin-commonjs 18.0.0-0 → 19.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @rollup/plugin-commonjs ChangeLog
2
2
 
3
+ ## v19.0.0
4
+
5
+ _2021-05-07_
6
+
7
+ ### Breaking Changes
8
+
9
+ - feat!: Add support for circular dependencies (#658)
10
+
11
+ ## v18.1.0
12
+
13
+ _2021-05-04_
14
+
15
+ ### Bugfixes
16
+
17
+ - fix: idempotence issue (#871)
18
+
19
+ ### Features
20
+
21
+ - feat: Add `defaultIsModuleExports` option to match Node.js behavior (#838)
22
+
23
+ ## v18.0.0
24
+
25
+ _2021-03-26_
26
+
27
+ ### Breaking Changes
28
+
29
+ - feat!: Add ignore-dynamic-requires option (#819)
30
+
31
+ ### Bugfixes
32
+
33
+ - fix: `isRestorableCompiledEsm` should also trigger code transform (#816)
34
+
3
35
  ## v17.1.0
4
36
 
5
37
  _2021-01-29_
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -134,6 +134,25 @@ Due to the conversion of `require` to a static `import` - the call is hoisted to
134
134
  - `string[]`: Pass an array containing the IDs to left unconverted.
135
135
  - `((id: string) => boolean|'remove')`: Pass a function that control individual IDs.
136
136
 
137
+ ### `ignoreDynamicRequires`
138
+
139
+ Type: `boolean`
140
+ Default: false
141
+
142
+ Some `require` calls cannot be resolved statically to be translated to imports, e.g.
143
+
144
+ ```js
145
+ function wrappedRequire(target) {
146
+ return require(target);
147
+ }
148
+ wrappedRequire('foo');
149
+ wrappedRequire('bar');
150
+ ```
151
+
152
+ When this option is set to `false`, the generated code will either directly throw an error when such a call is encountered or, when `dynamicRequireTargets` is used, when such a call cannot be resolved with a configured dynamic require target.
153
+
154
+ Setting this option to `true` will instead leave the `require` call in the code or use it as a fallback for `dynamicRequireTargets`.
155
+
137
156
  ### `esmExternals`
138
157
 
139
158
  Type: `boolean | string[] | ((id: string) => boolean)`
@@ -155,6 +174,49 @@ If you set `esmExternals` to `true`, this plugins assumes that all external depe
155
174
 
156
175
  You can also supply an array of ids to be treated as ES modules, or a function that will be passed each external id to determine if it is an ES module.
157
176
 
177
+ ### `defaultIsModuleExports`
178
+
179
+ Type: `boolean | "auto"`<br>
180
+ Default: `"auto"`
181
+
182
+ Controls what is the default export when importing a CommonJS file from an ES module.
183
+
184
+ - `true`: The value of the default export is `module.exports`. This currently matches the behavior of Node.js when importing a CommonJS file.
185
+ ```js
186
+ // mod.cjs
187
+ exports.default = 3;
188
+ ```
189
+ ```js
190
+ import foo from './mod.cjs';
191
+ console.log(foo); // { default: 3 }
192
+ ```
193
+ - `false`: The value of the default export is `exports.default`.
194
+ ```js
195
+ // mod.cjs
196
+ exports.default = 3;
197
+ ```
198
+ ```js
199
+ import foo from './mod.cjs';
200
+ console.log(foo); // 3
201
+ ```
202
+ - `"auto"`: The value of the default export is `exports.default` if the CommonJS file has an `exports.__esModule === true` property; otherwise it's `module.exports`. This makes it possible to import
203
+ the default export of ES modules compiled to CommonJS as if they were not compiled.
204
+ ```js
205
+ // mod.cjs
206
+ exports.default = 3;
207
+ ```
208
+ ```js
209
+ // mod-compiled.cjs
210
+ exports.__esModule = true;
211
+ exports.default = 3;
212
+ ```
213
+ ```js
214
+ import foo from './mod.cjs';
215
+ import bar from './mod-compiled.cjs';
216
+ console.log(foo); // { default: 3 }
217
+ console.log(bar); // 3
218
+ ```
219
+
158
220
  ### `requireReturnsDefault`
159
221
 
160
222
  Type: `boolean | "namespace" | "auto" | "preferred" | ((id: string) => boolean | "auto" | "preferred")`<br>
package/dist/index.es.js CHANGED
@@ -9,7 +9,7 @@ import isReference from 'is-reference';
9
9
  import { sync } from 'resolve';
10
10
 
11
11
  var peerDependencies = {
12
- rollup: "^2.38.0"
12
+ rollup: "^2.38.3"
13
13
  };
14
14
 
15
15
  function tryParse(parse, code, id) {
@@ -128,13 +128,15 @@ export function getAugmentedNamespace(n) {
128
128
  }
129
129
  `;
130
130
 
131
+ const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`;
132
+
131
133
  const HELPER_NON_DYNAMIC = `
132
- export function commonjsRequire (target) {
133
- throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.');
134
+ export function commonjsRequire (path) {
135
+ ${FAILED_REQUIRE_ERROR}
134
136
  }
135
137
  `;
136
138
 
137
- const HELPERS_DYNAMIC = `
139
+ const getDynamicHelpers = (ignoreDynamicRequires) => `
138
140
  export function createModule(modulePath) {
139
141
  return {
140
142
  path: modulePath,
@@ -306,34 +308,22 @@ export function commonjsRequire (path, originalModuleDir) {
306
308
  return cachedModule.exports;
307
309
  };
308
310
  }
309
- return require(path);
311
+ ${ignoreDynamicRequires ? 'return require(path);' : FAILED_REQUIRE_ERROR}
310
312
  }
311
313
 
312
314
  commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;
313
315
  commonjsRequire.resolve = commonjsResolve;
314
316
  `;
315
317
 
316
- function getHelpersModule(isDynamicRequireModulesEnabled) {
317
- return `${HELPERS}${isDynamicRequireModulesEnabled ? HELPERS_DYNAMIC : HELPER_NON_DYNAMIC}`;
318
+ function getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires) {
319
+ return `${HELPERS}${
320
+ isDynamicRequireModulesEnabled ? getDynamicHelpers(ignoreDynamicRequires) : HELPER_NON_DYNAMIC
321
+ }`;
318
322
  }
319
323
 
320
324
  /* eslint-disable import/prefer-default-export */
321
325
 
322
- function deconflict(scope, globals, identifier) {
323
- let i = 1;
324
- let deconflicted = makeLegalIdentifier(identifier);
325
-
326
- while (scope.contains(deconflicted) || globals.has(deconflicted)) {
327
- deconflicted = makeLegalIdentifier(`${identifier}_${i}`);
328
- i += 1;
329
- }
330
- // eslint-disable-next-line no-param-reassign
331
- scope.declarations[deconflicted] = true;
332
-
333
- return deconflicted;
334
- }
335
-
336
- function deconflictScopes(scopes, globals, identifier) {
326
+ function deconflict(scopes, globals, identifier) {
337
327
  let i = 1;
338
328
  let deconflicted = makeLegalIdentifier(identifier);
339
329
  const hasConflicts = () =>
@@ -452,9 +442,7 @@ function getDynamicRequirePaths(patterns) {
452
442
  return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths };
453
443
  }
454
444
 
455
- const commonJSMetaPromises = new Map();
456
-
457
- function getCommonJSMetaPromise(id) {
445
+ function getCommonJSMetaPromise(commonJSMetaPromises, id) {
458
446
  let commonJSMetaPromise = commonJSMetaPromises.get(id);
459
447
  if (commonJSMetaPromise) return commonJSMetaPromise.promise;
460
448
 
@@ -470,7 +458,7 @@ function getCommonJSMetaPromise(id) {
470
458
  return promise;
471
459
  }
472
460
 
473
- function setCommonJSMetaPromise(id, commonjsMeta) {
461
+ function setCommonJSMetaPromise(commonJSMetaPromises, id, commonjsMeta) {
474
462
  const commonJSMetaPromise = commonJSMetaPromises.get(id);
475
463
  if (commonJSMetaPromise) {
476
464
  if (commonJSMetaPromise.resolve) {
@@ -524,10 +512,11 @@ async function getStaticRequireProxy(
524
512
  id,
525
513
  requireReturnsDefault,
526
514
  esModulesWithDefaultExport,
527
- esModulesWithNamedExports
515
+ esModulesWithNamedExports,
516
+ commonJsMetaPromises
528
517
  ) {
529
518
  const name = getName(id);
530
- const commonjsMeta = await getCommonJSMetaPromise(id);
519
+ const commonjsMeta = await getCommonJSMetaPromise(commonJsMetaPromises, id);
531
520
  if (commonjsMeta && commonjsMeta.isCommonJS) {
532
521
  return `export { __moduleExports as default } from ${JSON.stringify(id)};`;
533
522
  } else if (commonjsMeta === null) {
@@ -768,17 +757,6 @@ function getDefinePropertyCallName(node, targetName) {
768
757
  return { key: key.value, value: valueProperty.value };
769
758
  }
770
759
 
771
- function isLocallyShadowed(name, scope) {
772
- while (scope.parent) {
773
- if (scope.declarations[name]) {
774
- return true;
775
- }
776
- // eslint-disable-next-line no-param-reassign
777
- scope = scope.parent;
778
- }
779
- return false;
780
- }
781
-
782
760
  function isShorthandProperty(parent) {
783
761
  return parent && parent.type === 'Property' && parent.shorthand;
784
762
  }
@@ -814,7 +792,8 @@ function rewriteExportsAndGetExportsBlock(
814
792
  code,
815
793
  HELPERS_NAME,
816
794
  exportMode,
817
- detectWrappedDefault
795
+ detectWrappedDefault,
796
+ defaultIsModuleExports
818
797
  ) {
819
798
  const exports = [];
820
799
  const exportDeclarations = [];
@@ -823,6 +802,7 @@ function rewriteExportsAndGetExportsBlock(
823
802
  getExportsForReplacedModuleExports(
824
803
  magicString,
825
804
  exports,
805
+ exportDeclarations,
826
806
  moduleExportsAssignments,
827
807
  firstTopLevelModuleExportsAssignment,
828
808
  exportsName
@@ -831,11 +811,11 @@ function rewriteExportsAndGetExportsBlock(
831
811
  exports.push(`${exportsName} as __moduleExports`);
832
812
  if (wrapped) {
833
813
  getExportsWhenWrapping(
834
- exports,
835
814
  exportDeclarations,
836
815
  exportsName,
837
816
  detectWrappedDefault,
838
- HELPERS_NAME
817
+ HELPERS_NAME,
818
+ defaultIsModuleExports
839
819
  );
840
820
  } else {
841
821
  getExports(
@@ -849,7 +829,8 @@ function rewriteExportsAndGetExportsBlock(
849
829
  moduleName,
850
830
  exportsName,
851
831
  defineCompiledEsmExpressions,
852
- HELPERS_NAME
832
+ HELPERS_NAME,
833
+ defaultIsModuleExports
853
834
  );
854
835
  }
855
836
  }
@@ -863,6 +844,7 @@ function rewriteExportsAndGetExportsBlock(
863
844
  function getExportsForReplacedModuleExports(
864
845
  magicString,
865
846
  exports,
847
+ exportDeclarations,
866
848
  moduleExportsAssignments,
867
849
  firstTopLevelModuleExportsAssignment,
868
850
  exportsName
@@ -871,23 +853,26 @@ function getExportsForReplacedModuleExports(
871
853
  magicString.overwrite(left.start, left.end, exportsName);
872
854
  }
873
855
  magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, 'var ');
874
- exports.push(`${exportsName} as __moduleExports`, `${exportsName} as default`);
856
+ exports.push(`${exportsName} as __moduleExports`);
857
+ exportDeclarations.push(`export default ${exportsName};`);
875
858
  }
876
859
 
877
860
  function getExportsWhenWrapping(
878
- exports,
879
861
  exportDeclarations,
880
862
  exportsName,
881
863
  detectWrappedDefault,
882
- HELPERS_NAME
864
+ HELPERS_NAME,
865
+ defaultIsModuleExports
883
866
  ) {
884
- if (detectWrappedDefault) {
885
- exportDeclarations.push(
886
- `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
887
- );
888
- } else {
889
- exports.push(`${exportsName} as default`);
890
- }
867
+ exportDeclarations.push(
868
+ `export default ${
869
+ detectWrappedDefault && defaultIsModuleExports === 'auto'
870
+ ? `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName})`
871
+ : defaultIsModuleExports === false
872
+ ? `${exportsName}.default`
873
+ : exportsName
874
+ };`
875
+ );
891
876
  }
892
877
 
893
878
  function getExports(
@@ -901,7 +886,8 @@ function getExports(
901
886
  moduleName,
902
887
  exportsName,
903
888
  defineCompiledEsmExpressions,
904
- HELPERS_NAME
889
+ HELPERS_NAME,
890
+ defaultIsModuleExports
905
891
  ) {
906
892
  let deconflictedDefaultExportName;
907
893
  // Collect and rewrite module.exports assignments
@@ -941,16 +927,14 @@ function getExports(
941
927
  magicString.overwrite(moduleExportsExpression.start, moduleExportsExpression.end, exportsName);
942
928
  }
943
929
 
944
- if (isRestorableCompiledEsm) {
945
- if (moduleExportsAssignments.length === 0) {
946
- exports.push(`${deconflictedDefaultExportName || exportsName} as default`);
947
- } else {
948
- exportDeclarations.push(
949
- `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
950
- );
951
- }
930
+ if (!isRestorableCompiledEsm || defaultIsModuleExports === true) {
931
+ exportDeclarations.push(`export default ${exportsName};`);
932
+ } else if (moduleExportsAssignments.length === 0 || defaultIsModuleExports === false) {
933
+ exports.push(`${deconflictedDefaultExportName || exportsName} as default`);
952
934
  } else {
953
- exports.push(`${exportsName} as default`);
935
+ exportDeclarations.push(
936
+ `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
937
+ );
954
938
  }
955
939
  }
956
940
 
@@ -1076,17 +1060,11 @@ function getRequireHandlers() {
1076
1060
  id,
1077
1061
  exportMode
1078
1062
  ) {
1079
- const removedDeclarators = getDeclaratorsReplacedByImportsAndSetImportNames(
1080
- topLevelRequireDeclarators,
1081
- requiredByNode,
1082
- reassignedNames
1083
- );
1084
1063
  setRemainingImportNamesAndRewriteRequires(
1085
1064
  requireExpressionsWithUsedReturnValue,
1086
1065
  requiredByNode,
1087
1066
  magicString
1088
1067
  );
1089
- removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString);
1090
1068
  const imports = [];
1091
1069
  imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);
1092
1070
  if (exportMode === 'module') {
@@ -1124,30 +1102,6 @@ function getRequireHandlers() {
1124
1102
  };
1125
1103
  }
1126
1104
 
1127
- function getDeclaratorsReplacedByImportsAndSetImportNames(
1128
- topLevelRequireDeclarators,
1129
- requiredByNode,
1130
- reassignedNames
1131
- ) {
1132
- const removedDeclarators = new Set();
1133
- for (const declarator of topLevelRequireDeclarators) {
1134
- const { required } = requiredByNode.get(declarator.init);
1135
- if (!required.name) {
1136
- const potentialName = declarator.id.name;
1137
- if (
1138
- !reassignedNames.has(potentialName) &&
1139
- !required.nodesUsingRequired.some((node) =>
1140
- isLocallyShadowed(potentialName, requiredByNode.get(node).scope)
1141
- )
1142
- ) {
1143
- required.name = potentialName;
1144
- removedDeclarators.add(declarator);
1145
- }
1146
- }
1147
- }
1148
- return removedDeclarators;
1149
- }
1150
-
1151
1105
  function setRemainingImportNamesAndRewriteRequires(
1152
1106
  requireExpressionsWithUsedReturnValue,
1153
1107
  requiredByNode,
@@ -1169,25 +1123,6 @@ function setRemainingImportNamesAndRewriteRequires(
1169
1123
  }
1170
1124
  }
1171
1125
 
1172
- function removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString) {
1173
- for (const declaration of topLevelDeclarations) {
1174
- let keepDeclaration = false;
1175
- let [{ start }] = declaration.declarations;
1176
- for (const declarator of declaration.declarations) {
1177
- if (removedDeclarators.has(declarator)) {
1178
- magicString.remove(start, declarator.end);
1179
- } else if (!keepDeclaration) {
1180
- magicString.remove(start, declarator.start);
1181
- keepDeclaration = true;
1182
- }
1183
- start = declarator.end;
1184
- }
1185
- if (!keepDeclaration) {
1186
- magicString.remove(declaration.start, declaration.end);
1187
- }
1188
- }
1189
- }
1190
-
1191
1126
  /* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */
1192
1127
 
1193
1128
  const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
@@ -1201,13 +1136,15 @@ function transformCommonjs(
1201
1136
  isEsModule,
1202
1137
  ignoreGlobal,
1203
1138
  ignoreRequire,
1139
+ ignoreDynamicRequires,
1204
1140
  getIgnoreTryCatchRequireStatementMode,
1205
1141
  sourceMap,
1206
1142
  isDynamicRequireModulesEnabled,
1207
1143
  dynamicRequireModuleSet,
1208
1144
  disableWrap,
1209
1145
  commonDir,
1210
- astCache
1146
+ astCache,
1147
+ defaultIsModuleExports
1211
1148
  ) {
1212
1149
  const ast = astCache || tryParse(parse, code, id);
1213
1150
  const magicString = new MagicString(code);
@@ -1229,7 +1166,7 @@ function transformCommonjs(
1229
1166
  const globals = new Set();
1230
1167
 
1231
1168
  // TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
1232
- const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers');
1169
+ const HELPERS_NAME = deconflict([scope], globals, 'commonjsHelpers');
1233
1170
  const dynamicRegisterSources = new Set();
1234
1171
  let hasRemovedRequire = false;
1235
1172
 
@@ -1480,12 +1417,14 @@ function transformCommonjs(
1480
1417
  )}`
1481
1418
  );
1482
1419
  }
1483
- if (isShorthandProperty(parent)) {
1484
- magicString.appendRight(node.end, `: ${HELPERS_NAME}.commonjsRequire`);
1485
- } else {
1486
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
1487
- storeName: true
1488
- });
1420
+ if (!ignoreDynamicRequires) {
1421
+ if (isShorthandProperty(parent)) {
1422
+ magicString.appendRight(node.end, `: ${HELPERS_NAME}.commonjsRequire`);
1423
+ } else {
1424
+ magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
1425
+ storeName: true
1426
+ });
1427
+ }
1489
1428
  }
1490
1429
  usesDynamicRequire = true;
1491
1430
  return;
@@ -1572,11 +1511,11 @@ function transformCommonjs(
1572
1511
  });
1573
1512
 
1574
1513
  const nameBase = getName(id);
1575
- const exportsName = deconflictScopes([...exportsAccessScopes], globals, nameBase);
1576
- const moduleName = deconflictScopes([...moduleAccessScopes], globals, `${nameBase}Module`);
1514
+ const exportsName = deconflict([...exportsAccessScopes], globals, nameBase);
1515
+ const moduleName = deconflict([...moduleAccessScopes], globals, `${nameBase}Module`);
1577
1516
  const deconflictedExportNames = Object.create(null);
1578
1517
  for (const [exportName, { scopes }] of exportsAssignmentsByName) {
1579
- deconflictedExportNames[exportName] = deconflictScopes([...scopes], globals, exportName);
1518
+ deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
1580
1519
  }
1581
1520
 
1582
1521
  // We cannot wrap ES/mixed modules
@@ -1596,7 +1535,8 @@ function transformCommonjs(
1596
1535
  uses.exports ||
1597
1536
  uses.require ||
1598
1537
  usesDynamicRequire ||
1599
- hasRemovedRequire
1538
+ hasRemovedRequire ||
1539
+ topLevelDefineCompiledEsmExpressions.length > 0
1600
1540
  ) &&
1601
1541
  (ignoreGlobal || !uses.global)
1602
1542
  ) {
@@ -1651,7 +1591,8 @@ function transformCommonjs(
1651
1591
  code,
1652
1592
  HELPERS_NAME,
1653
1593
  exportMode,
1654
- detectWrappedDefault
1594
+ detectWrappedDefault,
1595
+ defaultIsModuleExports
1655
1596
  );
1656
1597
 
1657
1598
  if (shouldWrap) {
@@ -1676,6 +1617,7 @@ function commonjs(options = {}) {
1676
1617
  const filter = createFilter(options.include, options.exclude);
1677
1618
  const {
1678
1619
  ignoreGlobal,
1620
+ ignoreDynamicRequires,
1679
1621
  requireReturnsDefault: requireReturnsDefaultOption,
1680
1622
  esmExternals
1681
1623
  } = options;
@@ -1690,6 +1632,8 @@ function commonjs(options = {}) {
1690
1632
  : Array.isArray(esmExternals)
1691
1633
  ? ((esmExternalIds = new Set(esmExternals)), (id) => esmExternalIds.has(id))
1692
1634
  : () => esmExternals;
1635
+ const defaultIsModuleExports =
1636
+ typeof options.defaultIsModuleExports === 'boolean' ? options.defaultIsModuleExports : 'auto';
1693
1637
 
1694
1638
  const { dynamicRequireModuleSet, dynamicRequireModuleDirPaths } = getDynamicRequirePaths(
1695
1639
  options.dynamicRequireTargets
@@ -1701,6 +1645,7 @@ function commonjs(options = {}) {
1701
1645
 
1702
1646
  const esModulesWithDefaultExport = new Set();
1703
1647
  const esModulesWithNamedExports = new Set();
1648
+ const commonJsMetaPromises = new Map();
1704
1649
 
1705
1650
  const ignoreRequire =
1706
1651
  typeof options.ignore === 'function'
@@ -1767,13 +1712,15 @@ function commonjs(options = {}) {
1767
1712
  isEsModule,
1768
1713
  ignoreGlobal || isEsModule,
1769
1714
  ignoreRequire,
1715
+ ignoreDynamicRequires && !isDynamicRequireModulesEnabled,
1770
1716
  getIgnoreTryCatchRequireStatementMode,
1771
1717
  sourceMap,
1772
1718
  isDynamicRequireModulesEnabled,
1773
1719
  dynamicRequireModuleSet,
1774
1720
  disableWrap,
1775
1721
  commonDir,
1776
- ast
1722
+ ast,
1723
+ defaultIsModuleExports
1777
1724
  );
1778
1725
  }
1779
1726
 
@@ -1793,7 +1740,7 @@ function commonjs(options = {}) {
1793
1740
 
1794
1741
  load(id) {
1795
1742
  if (id === HELPERS_ID) {
1796
- return getHelpersModule(isDynamicRequireModulesEnabled);
1743
+ return getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires);
1797
1744
  }
1798
1745
 
1799
1746
  if (id.startsWith(HELPERS_ID)) {
@@ -1866,7 +1813,8 @@ function commonjs(options = {}) {
1866
1813
  actualId,
1867
1814
  getRequireReturnsDefault(actualId),
1868
1815
  esModulesWithDefaultExport,
1869
- esModulesWithNamedExports
1816
+ esModulesWithNamedExports,
1817
+ commonJsMetaPromises
1870
1818
  );
1871
1819
  }
1872
1820
 
@@ -1899,10 +1847,10 @@ function commonjs(options = {}) {
1899
1847
 
1900
1848
  moduleParsed({ id, meta: { commonjs: commonjsMeta } }) {
1901
1849
  if (commonjsMeta && commonjsMeta.isCommonJS != null) {
1902
- setCommonJSMetaPromise(id, commonjsMeta);
1850
+ setCommonJSMetaPromise(commonJsMetaPromises, id, commonjsMeta);
1903
1851
  return;
1904
1852
  }
1905
- setCommonJSMetaPromise(id, null);
1853
+ setCommonJSMetaPromise(commonJsMetaPromises, id, null);
1906
1854
  }
1907
1855
  };
1908
1856
  }