@rollup/plugin-commonjs 22.0.0-5 → 22.0.0-6

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/es/index.js CHANGED
@@ -7,9 +7,9 @@ import { walk } from 'estree-walker';
7
7
  import MagicString from 'magic-string';
8
8
  import isReference from 'is-reference';
9
9
 
10
- var version = "22.0.0-5";
10
+ var version = "22.0.0-6";
11
11
  var peerDependencies = {
12
- rollup: "^2.64.0"
12
+ rollup: "^2.66.1"
13
13
  };
14
14
 
15
15
  function tryParse(parse, code, id) {
@@ -328,7 +328,8 @@ const WRAPPED_SUFFIX = '?commonjs-wrapped';
328
328
  const EXTERNAL_SUFFIX = '?commonjs-external';
329
329
  const EXPORTS_SUFFIX = '?commonjs-exports';
330
330
  const MODULE_SUFFIX = '?commonjs-module';
331
- const ES_IMPORT_SUFFIX = '?es-import';
331
+ const ENTRY_SUFFIX = '?commonjs-entry';
332
+ const ES_IMPORT_SUFFIX = '?commonjs-es-import';
332
333
 
333
334
  const DYNAMIC_MODULES_ID = '\0commonjs-dynamic-modules';
334
335
  const HELPERS_ID = '\0commonjsHelpers.js';
@@ -420,6 +421,22 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
420
421
  return `export { default } from ${JSON.stringify(id)};`;
421
422
  }
422
423
 
424
+ async function getEntryProxy(id, defaultIsModuleExports, loadModule) {
425
+ const {
426
+ meta: { commonjs: commonjsMeta },
427
+ hasDefaultExport
428
+ } = await loadModule({ id, moduleSideEffects: true });
429
+ if (!commonjsMeta || commonjsMeta.isCommonJS !== IS_WRAPPED_COMMONJS) {
430
+ const stringifiedId = JSON.stringify(id);
431
+ let code = `export * from ${stringifiedId};`;
432
+ if (hasDefaultExport) {
433
+ code += `export { default } from ${stringifiedId};`;
434
+ }
435
+ return code;
436
+ }
437
+ return getEsImportProxy(id, defaultIsModuleExports);
438
+ }
439
+
423
440
  function getEsImportProxy(id, defaultIsModuleExports) {
424
441
  const name = getName(id);
425
442
  const exportsName = `${name}Exports`;
@@ -488,13 +505,15 @@ function getResolveId(extensions) {
488
505
  }
489
506
 
490
507
  if (
491
- isWrappedId(importee, MODULE_SUFFIX) ||
492
- isWrappedId(importee, EXPORTS_SUFFIX) ||
493
- isWrappedId(importee, PROXY_SUFFIX) ||
494
- isWrappedId(importee, ES_IMPORT_SUFFIX) ||
495
- isWrappedId(importee, EXTERNAL_SUFFIX) ||
496
- importee.startsWith(HELPERS_ID) ||
497
- importee === DYNAMIC_MODULES_ID
508
+ importee.startsWith('\0') &&
509
+ (isWrappedId(importee, MODULE_SUFFIX) ||
510
+ isWrappedId(importee, EXPORTS_SUFFIX) ||
511
+ isWrappedId(importee, PROXY_SUFFIX) ||
512
+ isWrappedId(importee, ES_IMPORT_SUFFIX) ||
513
+ importee.endsWith(ENTRY_SUFFIX) ||
514
+ isWrappedId(importee, EXTERNAL_SUFFIX) ||
515
+ importee.startsWith(HELPERS_ID) ||
516
+ importee === DYNAMIC_MODULES_ID)
498
517
  ) {
499
518
  return importee;
500
519
  }
@@ -504,7 +523,8 @@ function getResolveId(extensions) {
504
523
  importer === DYNAMIC_MODULES_ID ||
505
524
  // Proxies are only importing resolved ids, no need to resolve again
506
525
  isWrappedId(importer, PROXY_SUFFIX) ||
507
- isWrappedId(importer, ES_IMPORT_SUFFIX)
526
+ isWrappedId(importer, ES_IMPORT_SUFFIX) ||
527
+ importer.endsWith(ENTRY_SUFFIX)
508
528
  ) {
509
529
  return importee;
510
530
  }
@@ -537,6 +557,10 @@ function getResolveId(extensions) {
537
557
  if (!resolved || resolved.external) {
538
558
  return resolved;
539
559
  }
560
+ if (resolveOptions.isEntry) {
561
+ // We must not precede entry proxies with a `\0` as that will mess up relative external resolution
562
+ return resolved.id + ENTRY_SUFFIX;
563
+ }
540
564
  const {
541
565
  meta: { commonjs: commonjsMeta }
542
566
  } = await this.load(resolved);
@@ -2017,6 +2041,11 @@ function commonjs(options = {}) {
2017
2041
  );
2018
2042
  }
2019
2043
 
2044
+ // entry suffix is just appended to not mess up relative external resolution
2045
+ if (id.endsWith(ENTRY_SUFFIX)) {
2046
+ return getEntryProxy(id.slice(0, -ENTRY_SUFFIX.length), defaultIsModuleExports, this.load);
2047
+ }
2048
+
2020
2049
  if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
2021
2050
  return getEsImportProxy(unwrapId(id, ES_IMPORT_SUFFIX), defaultIsModuleExports);
2022
2051
  }