Socket
Socket
Sign inDemoInstall

@rollup/plugin-commonjs

Package Overview
Dependencies
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-commonjs - npm Package Compare versions

Comparing version 12.0.0 to 13.0.0

13

CHANGELOG.md
# @rollup/plugin-commonjs ChangeLog
## v13.0.0
_2020-06-05_
### Breaking Changes
- fix!: remove namedExports from types (#410)
- fix!: do not create fake named exports (#427)
### Bugfixes
- fix: \_\_moduleExports in multi entry + inter dependencies (#415)
## v12.0.0

@@ -4,0 +17,0 @@

32

dist/index.es.js

@@ -485,3 +485,3 @@ import { statSync, existsSync, readFileSync } from 'fs';

function transformCommonjs(parse, code, id, isEntry, isEsModule, ignoreGlobal, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, astCache) {
function transformCommonjs(parse, code, id, isEntry, hasImporters, isEsModule, ignoreGlobal, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, astCache) {
const ast = astCache || tryParse(parse, code, id);

@@ -864,7 +864,3 @@ const magicString = new MagicString(code);

if (!sources.length && !uses.module && !uses.exports && !uses.require && (ignoreGlobal || !uses.global)) {
if (Object.keys(namedExports).length) {
throw new Error(`Custom named exports were specified for ${id} but it does not appear to be a CommonJS module`);
} // not a CommonJS module
// not a CommonJS module
return null;

@@ -890,3 +886,3 @@ } // If `isEsModule` is on, it means it has ES6 import/export statements,

if (!isEntry && !isEsModule) {
if ((!isEntry || hasImporters) && !isEsModule) {
const exportModuleExports = {

@@ -899,13 +895,2 @@ str: `export { ${moduleName} as __moduleExports };`,

const name = getName(id);
function addExport(x) {
const deconflicted = deconflict(scope, globals, name);
const declaration = deconflicted === name ? `export var ${x} = ${moduleName}.${x};` : `var ${deconflicted} = ${moduleName}.${x};\nexport { ${deconflicted} as ${x} };`;
namedExportDeclarations.push({
str: declaration,
name: x
});
}
const defaultExportPropertyAssignments = [];

@@ -968,3 +953,2 @@ let hasDefaultExport = false;

});
delete namedExports[name];
}

@@ -982,3 +966,3 @@

if (!hasDefaultExport && (names.length || !isEntry && !isEsModule)) {
if (!hasDefaultExport && (names.length || (!isEntry || hasImporters) && !isEsModule)) {
wrapperEnd = `\n\nvar ${moduleName} = {\n${names.map(({

@@ -991,8 +975,7 @@ name,

Object.keys(namedExports).filter(key => !blacklist[key]).forEach(addExport);
const defaultExport = /__esModule/.test(code) ? `export default ${HELPERS_NAME}.unwrapExports(${moduleName});` : `export default ${moduleName};`;
const defaultExport = /__esModule/.test(code) ? `export default /*@__PURE__*/${HELPERS_NAME}.unwrapExports(${moduleName});` : `export default ${moduleName};`;
const named = namedExportDeclarations.filter(x => x.name !== 'default' || !hasDefaultExport).map(x => x.str);
const exportBlock = `\n\n${(isEsModule ? [] : [defaultExport]).concat(named).concat(hasDefaultExport ? defaultExportPropertyAssignments : []).join('\n')}`;
magicString.trim().prepend(importBlock + wrapperStart).trim().append(wrapperEnd);
const injectExportBlock = hasDefaultExport || named.length > 0 || shouldWrap || !isEntry;
const injectExportBlock = hasDefaultExport || named.length > 0 || shouldWrap || !isEntry || hasImporters;

@@ -1207,3 +1190,4 @@ if (injectExportBlock) {

const transformed = transformCommonjs(this.parse, code, id, this.getModuleInfo(id).isEntry, isEsModule, ignoreGlobal || isEsModule, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, ast);
const moduleInfo = this.getModuleInfo(id);
const transformed = transformCommonjs(this.parse, code, id, moduleInfo.isEntry, moduleInfo.importers && moduleInfo.importers.length > 0, isEsModule, ignoreGlobal || isEsModule, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, ast);
setIsCjsPromise(id, isEsModule ? false : Boolean(transformed));

@@ -1210,0 +1194,0 @@

@@ -489,3 +489,3 @@ 'use strict';

function transformCommonjs(parse, code, id, isEntry, isEsModule, ignoreGlobal, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, astCache) {
function transformCommonjs(parse, code, id, isEntry, hasImporters, isEsModule, ignoreGlobal, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, astCache) {
const ast = astCache || tryParse(parse, code, id);

@@ -868,7 +868,3 @@ const magicString = new MagicString(code);

if (!sources.length && !uses.module && !uses.exports && !uses.require && (ignoreGlobal || !uses.global)) {
if (Object.keys(namedExports).length) {
throw new Error(`Custom named exports were specified for ${id} but it does not appear to be a CommonJS module`);
} // not a CommonJS module
// not a CommonJS module
return null;

@@ -894,3 +890,3 @@ } // If `isEsModule` is on, it means it has ES6 import/export statements,

if (!isEntry && !isEsModule) {
if ((!isEntry || hasImporters) && !isEsModule) {
const exportModuleExports = {

@@ -903,13 +899,2 @@ str: `export { ${moduleName} as __moduleExports };`,

const name = getName(id);
function addExport(x) {
const deconflicted = deconflict(scope, globals, name);
const declaration = deconflicted === name ? `export var ${x} = ${moduleName}.${x};` : `var ${deconflicted} = ${moduleName}.${x};\nexport { ${deconflicted} as ${x} };`;
namedExportDeclarations.push({
str: declaration,
name: x
});
}
const defaultExportPropertyAssignments = [];

@@ -972,3 +957,2 @@ let hasDefaultExport = false;

});
delete namedExports[name];
}

@@ -986,3 +970,3 @@

if (!hasDefaultExport && (names.length || !isEntry && !isEsModule)) {
if (!hasDefaultExport && (names.length || (!isEntry || hasImporters) && !isEsModule)) {
wrapperEnd = `\n\nvar ${moduleName} = {\n${names.map(({

@@ -995,8 +979,7 @@ name,

Object.keys(namedExports).filter(key => !blacklist[key]).forEach(addExport);
const defaultExport = /__esModule/.test(code) ? `export default ${HELPERS_NAME}.unwrapExports(${moduleName});` : `export default ${moduleName};`;
const defaultExport = /__esModule/.test(code) ? `export default /*@__PURE__*/${HELPERS_NAME}.unwrapExports(${moduleName});` : `export default ${moduleName};`;
const named = namedExportDeclarations.filter(x => x.name !== 'default' || !hasDefaultExport).map(x => x.str);
const exportBlock = `\n\n${(isEsModule ? [] : [defaultExport]).concat(named).concat(hasDefaultExport ? defaultExportPropertyAssignments : []).join('\n')}`;
magicString.trim().prepend(importBlock + wrapperStart).trim().append(wrapperEnd);
const injectExportBlock = hasDefaultExport || named.length > 0 || shouldWrap || !isEntry;
const injectExportBlock = hasDefaultExport || named.length > 0 || shouldWrap || !isEntry || hasImporters;

@@ -1211,3 +1194,4 @@ if (injectExportBlock) {

const transformed = transformCommonjs(this.parse, code, id, this.getModuleInfo(id).isEntry, isEsModule, ignoreGlobal || isEsModule, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, ast);
const moduleInfo = this.getModuleInfo(id);
const transformed = transformCommonjs(this.parse, code, id, moduleInfo.isEntry, moduleInfo.importers && moduleInfo.importers.length > 0, isEsModule, ignoreGlobal || isEsModule, ignoreRequire, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, commonDir, ast);
setIsCjsPromise(id, isEsModule ? false : Boolean(transformed));

@@ -1214,0 +1198,0 @@

{
"name": "@rollup/plugin-commonjs",
"version": "12.0.0",
"version": "13.0.0",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

@@ -39,8 +39,2 @@ import { FilterPattern } from '@rollup/pluginutils';

/**
* explicitly specify unresolvable named exports
* ([see below for more details](https://github.com/rollup/plugins/tree/master/packages/commonjs#named-exports))
* @default undefined
*/
namedExports?: { [package: string]: ReadonlyArray<string> };
/**
* sometimes you have to leave require statements

@@ -47,0 +41,0 @@ * unconverted. Pass an array containing the IDs

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc