@rollup/plugin-commonjs 22.0.0 → 22.0.1

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,7 +7,7 @@ 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";
10
+ var version = "22.0.1";
11
11
  var peerDependencies = {
12
12
  rollup: "^2.68.0"
13
13
  };
@@ -489,7 +489,7 @@ function resolveExtensions(importee, importer, extensions) {
489
489
  return undefined;
490
490
  }
491
491
 
492
- function getResolveId(extensions) {
492
+ function getResolveId(extensions, isPossibleCjsId) {
493
493
  const currentlyResolving = new Map();
494
494
 
495
495
  return {
@@ -581,21 +581,27 @@ function getResolveId(extensions) {
581
581
  !resolved ||
582
582
  resolved.external ||
583
583
  resolved.id.endsWith(ENTRY_SUFFIX) ||
584
- isWrappedId(resolved.id, ES_IMPORT_SUFFIX)
584
+ isWrappedId(resolved.id, ES_IMPORT_SUFFIX) ||
585
+ !isPossibleCjsId(resolved.id)
585
586
  ) {
586
587
  return resolved;
587
588
  }
588
589
  const moduleInfo = await this.load(resolved);
589
- if (resolveOptions.isEntry) {
590
- moduleInfo.moduleSideEffects = true;
591
- // We must not precede entry proxies with a `\0` as that will mess up relative external resolution
592
- return resolved.id + ENTRY_SUFFIX;
593
- }
594
590
  const {
595
591
  meta: { commonjs: commonjsMeta }
596
592
  } = moduleInfo;
597
- if (commonjsMeta && commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS) {
598
- return { id: wrapId(resolved.id, ES_IMPORT_SUFFIX), meta: { commonjs: { resolved } } };
593
+ if (commonjsMeta) {
594
+ const { isCommonJS } = commonjsMeta;
595
+ if (isCommonJS) {
596
+ if (resolveOptions.isEntry) {
597
+ moduleInfo.moduleSideEffects = true;
598
+ // We must not precede entry proxies with a `\0` as that will mess up relative external resolution
599
+ return resolved.id + ENTRY_SUFFIX;
600
+ }
601
+ if (isCommonJS === IS_WRAPPED_COMMONJS) {
602
+ return { id: wrapId(resolved.id, ES_IMPORT_SUFFIX), meta: { commonjs: { resolved } } };
603
+ }
604
+ }
599
605
  }
600
606
  return resolved;
601
607
  }
@@ -1945,6 +1951,11 @@ function commonjs(options = {}) {
1945
1951
  } = options;
1946
1952
  const extensions = options.extensions || ['.js'];
1947
1953
  const filter = createFilter(options.include, options.exclude);
1954
+ const isPossibleCjsId = (id) => {
1955
+ const extName = extname(id);
1956
+ return extName === '.cjs' || (extensions.includes(extName) && filter(id));
1957
+ };
1958
+
1948
1959
  const { strictRequiresFilter, detectCyclesAndConditional } = getStrictRequiresFilter(options);
1949
1960
 
1950
1961
  const getRequireReturnsDefault =
@@ -1999,7 +2010,7 @@ function commonjs(options = {}) {
1999
2010
  };
2000
2011
  };
2001
2012
 
2002
- const { currentlyResolving, resolveId } = getResolveId(extensions);
2013
+ const { currentlyResolving, resolveId } = getResolveId(extensions, isPossibleCjsId);
2003
2014
 
2004
2015
  const sourceMap = options.sourceMap !== false;
2005
2016
 
@@ -2195,10 +2206,7 @@ function commonjs(options = {}) {
2195
2206
  },
2196
2207
 
2197
2208
  transform(code, id) {
2198
- const extName = extname(id);
2199
- if (extName !== '.cjs' && (!filter(id) || !extensions.includes(extName))) {
2200
- return null;
2201
- }
2209
+ if (!isPossibleCjsId(id)) return null;
2202
2210
 
2203
2211
  try {
2204
2212
  return transformAndCheckExports.call(this, code, id);