Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rollup/plugin-commonjs

Package Overview
Dependencies
Maintainers
4
Versions
73
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 18.0.0-0 to 18.0.0-1

116

dist/index.es.js

@@ -12,3 +12,3 @@ import { basename, extname, dirname, sep, join, resolve } from 'path';

var peerDependencies = {
rollup: "^2.38.0"
rollup: "^2.38.3"
};

@@ -323,19 +323,5 @@

function deconflict(scope, globals, identifier) {
function deconflict(scopes, globals, identifier) {
let i = 1;
let deconflicted = makeLegalIdentifier(identifier);
while (scope.contains(deconflicted) || globals.has(deconflicted)) {
deconflicted = makeLegalIdentifier(`${identifier}_${i}`);
i += 1;
}
// eslint-disable-next-line no-param-reassign
scope.declarations[deconflicted] = true;
return deconflicted;
}
function deconflictScopes(scopes, globals, identifier) {
let i = 1;
let deconflicted = makeLegalIdentifier(identifier);
const hasConflicts = () =>

@@ -773,13 +759,2 @@ scopes.some((scope) => scope.contains(deconflicted)) || globals.has(deconflicted);

function isLocallyShadowed(name, scope) {
while (scope.parent) {
if (scope.declarations[name]) {
return true;
}
// eslint-disable-next-line no-param-reassign
scope = scope.parent;
}
return false;
}
function isShorthandProperty(parent) {

@@ -829,2 +804,3 @@ return parent && parent.type === 'Property' && parent.shorthand;

exports,
exportDeclarations,
moduleExportsAssignments,

@@ -837,9 +813,3 @@ firstTopLevelModuleExportsAssignment,

if (wrapped) {
getExportsWhenWrapping(
exports,
exportDeclarations,
exportsName,
detectWrappedDefault,
HELPERS_NAME
);
getExportsWhenWrapping(exportDeclarations, exportsName, detectWrappedDefault, HELPERS_NAME);
} else {

@@ -871,2 +841,3 @@ getExports(

exports,
exportDeclarations,
moduleExportsAssignments,

@@ -880,7 +851,7 @@ firstTopLevelModuleExportsAssignment,

magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, 'var ');
exports.push(`${exportsName} as __moduleExports`, `${exportsName} as default`);
exports.push(`${exportsName} as __moduleExports`);
exportDeclarations.push(`export default ${exportsName};`);
}
function getExportsWhenWrapping(
exports,
exportDeclarations,

@@ -891,9 +862,9 @@ exportsName,

) {
if (detectWrappedDefault) {
exportDeclarations.push(
`export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
);
} else {
exports.push(`${exportsName} as default`);
}
exportDeclarations.push(
`export default ${
detectWrappedDefault
? `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName})`
: exportsName
};`
);
}

@@ -961,3 +932,3 @@

} else {
exports.push(`${exportsName} as default`);
exportDeclarations.push(`export default ${exportsName};`);
}

@@ -1088,7 +1059,2 @@ }

) {
const removedDeclarators = getDeclaratorsReplacedByImportsAndSetImportNames(
topLevelRequireDeclarators,
requiredByNode,
reassignedNames
);
setRemainingImportNamesAndRewriteRequires(

@@ -1099,3 +1065,2 @@ requireExpressionsWithUsedReturnValue,

);
removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString);
const imports = [];

@@ -1138,26 +1103,2 @@ imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);

function getDeclaratorsReplacedByImportsAndSetImportNames(
topLevelRequireDeclarators,
requiredByNode,
reassignedNames
) {
const removedDeclarators = new Set();
for (const declarator of topLevelRequireDeclarators) {
const { required } = requiredByNode.get(declarator.init);
if (!required.name) {
const potentialName = declarator.id.name;
if (
!reassignedNames.has(potentialName) &&
!required.nodesUsingRequired.some((node) =>
isLocallyShadowed(potentialName, requiredByNode.get(node).scope)
)
) {
required.name = potentialName;
removedDeclarators.add(declarator);
}
}
}
return removedDeclarators;
}
function setRemainingImportNamesAndRewriteRequires(

@@ -1184,21 +1125,2 @@ requireExpressionsWithUsedReturnValue,

function removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString) {
for (const declaration of topLevelDeclarations) {
let keepDeclaration = false;
let [{ start }] = declaration.declarations;
for (const declarator of declaration.declarations) {
if (removedDeclarators.has(declarator)) {
magicString.remove(start, declarator.end);
} else if (!keepDeclaration) {
magicString.remove(start, declarator.start);
keepDeclaration = true;
}
start = declarator.end;
}
if (!keepDeclaration) {
magicString.remove(declaration.start, declaration.end);
}
}
}
/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */

@@ -1245,3 +1167,3 @@

// TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers');
const HELPERS_NAME = deconflict([scope], globals, 'commonjsHelpers');
const dynamicRegisterSources = new Set();

@@ -1589,7 +1511,7 @@ let hasRemovedRequire = false;

const nameBase = getName(id);
const exportsName = deconflictScopes([...exportsAccessScopes], globals, nameBase);
const moduleName = deconflictScopes([...moduleAccessScopes], globals, `${nameBase}Module`);
const exportsName = deconflict([...exportsAccessScopes], globals, nameBase);
const moduleName = deconflict([...moduleAccessScopes], globals, `${nameBase}Module`);
const deconflictedExportNames = Object.create(null);
for (const [exportName, { scopes }] of exportsAssignmentsByName) {
deconflictedExportNames[exportName] = deconflictScopes([...scopes], globals, exportName);
deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
}

@@ -1596,0 +1518,0 @@

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

var peerDependencies = {
rollup: "^2.38.0"
rollup: "^2.38.3"
};

@@ -332,19 +332,5 @@

function deconflict(scope, globals, identifier) {
function deconflict(scopes, globals, identifier) {
let i = 1;
let deconflicted = pluginutils.makeLegalIdentifier(identifier);
while (scope.contains(deconflicted) || globals.has(deconflicted)) {
deconflicted = pluginutils.makeLegalIdentifier(`${identifier}_${i}`);
i += 1;
}
// eslint-disable-next-line no-param-reassign
scope.declarations[deconflicted] = true;
return deconflicted;
}
function deconflictScopes(scopes, globals, identifier) {
let i = 1;
let deconflicted = pluginutils.makeLegalIdentifier(identifier);
const hasConflicts = () =>

@@ -782,13 +768,2 @@ scopes.some((scope) => scope.contains(deconflicted)) || globals.has(deconflicted);

function isLocallyShadowed(name, scope) {
while (scope.parent) {
if (scope.declarations[name]) {
return true;
}
// eslint-disable-next-line no-param-reassign
scope = scope.parent;
}
return false;
}
function isShorthandProperty(parent) {

@@ -838,2 +813,3 @@ return parent && parent.type === 'Property' && parent.shorthand;

exports,
exportDeclarations,
moduleExportsAssignments,

@@ -846,9 +822,3 @@ firstTopLevelModuleExportsAssignment,

if (wrapped) {
getExportsWhenWrapping(
exports,
exportDeclarations,
exportsName,
detectWrappedDefault,
HELPERS_NAME
);
getExportsWhenWrapping(exportDeclarations, exportsName, detectWrappedDefault, HELPERS_NAME);
} else {

@@ -880,2 +850,3 @@ getExports(

exports,
exportDeclarations,
moduleExportsAssignments,

@@ -889,7 +860,7 @@ firstTopLevelModuleExportsAssignment,

magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, 'var ');
exports.push(`${exportsName} as __moduleExports`, `${exportsName} as default`);
exports.push(`${exportsName} as __moduleExports`);
exportDeclarations.push(`export default ${exportsName};`);
}
function getExportsWhenWrapping(
exports,
exportDeclarations,

@@ -900,9 +871,9 @@ exportsName,

) {
if (detectWrappedDefault) {
exportDeclarations.push(
`export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
);
} else {
exports.push(`${exportsName} as default`);
}
exportDeclarations.push(
`export default ${
detectWrappedDefault
? `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName})`
: exportsName
};`
);
}

@@ -970,3 +941,3 @@

} else {
exports.push(`${exportsName} as default`);
exportDeclarations.push(`export default ${exportsName};`);
}

@@ -1097,7 +1068,2 @@ }

) {
const removedDeclarators = getDeclaratorsReplacedByImportsAndSetImportNames(
topLevelRequireDeclarators,
requiredByNode,
reassignedNames
);
setRemainingImportNamesAndRewriteRequires(

@@ -1108,3 +1074,2 @@ requireExpressionsWithUsedReturnValue,

);
removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString);
const imports = [];

@@ -1147,26 +1112,2 @@ imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);

function getDeclaratorsReplacedByImportsAndSetImportNames(
topLevelRequireDeclarators,
requiredByNode,
reassignedNames
) {
const removedDeclarators = new Set();
for (const declarator of topLevelRequireDeclarators) {
const { required } = requiredByNode.get(declarator.init);
if (!required.name) {
const potentialName = declarator.id.name;
if (
!reassignedNames.has(potentialName) &&
!required.nodesUsingRequired.some((node) =>
isLocallyShadowed(potentialName, requiredByNode.get(node).scope)
)
) {
required.name = potentialName;
removedDeclarators.add(declarator);
}
}
}
return removedDeclarators;
}
function setRemainingImportNamesAndRewriteRequires(

@@ -1193,21 +1134,2 @@ requireExpressionsWithUsedReturnValue,

function removeDeclaratorsFromDeclarations(topLevelDeclarations, removedDeclarators, magicString) {
for (const declaration of topLevelDeclarations) {
let keepDeclaration = false;
let [{ start }] = declaration.declarations;
for (const declarator of declaration.declarations) {
if (removedDeclarators.has(declarator)) {
magicString.remove(start, declarator.end);
} else if (!keepDeclaration) {
magicString.remove(start, declarator.start);
keepDeclaration = true;
}
start = declarator.end;
}
if (!keepDeclaration) {
magicString.remove(declaration.start, declaration.end);
}
}
}
/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */

@@ -1254,3 +1176,3 @@

// TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers');
const HELPERS_NAME = deconflict([scope], globals, 'commonjsHelpers');
const dynamicRegisterSources = new Set();

@@ -1598,7 +1520,7 @@ let hasRemovedRequire = false;

const nameBase = getName(id);
const exportsName = deconflictScopes([...exportsAccessScopes], globals, nameBase);
const moduleName = deconflictScopes([...moduleAccessScopes], globals, `${nameBase}Module`);
const exportsName = deconflict([...exportsAccessScopes], globals, nameBase);
const moduleName = deconflict([...moduleAccessScopes], globals, `${nameBase}Module`);
const deconflictedExportNames = Object.create(null);
for (const [exportName, { scopes }] of exportsAssignmentsByName) {
deconflictedExportNames[exportName] = deconflictScopes([...scopes], globals, exportName);
deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
}

@@ -1605,0 +1527,0 @@

6

package.json
{
"name": "@rollup/plugin-commonjs",
"version": "18.0.0-0",
"version": "18.0.0-1",
"publishConfig": {

@@ -50,3 +50,3 @@ "access": "public"

"peerDependencies": {
"rollup": "^2.38.0"
"rollup": "^2.38.3"
},

@@ -67,3 +67,3 @@ "dependencies": {

"require-relative": "^0.8.7",
"rollup": "^2.38.0",
"rollup": "^2.38.3",
"shx": "^0.3.2",

@@ -70,0 +70,0 @@ "source-map": "^0.7.3",

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