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
70
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 8.4.0 to 8.4.1

6

CHANGELOG.md
# rollup-plugin-commonjs changelog
## 8.4.0
* Better handle non-CJS files that contain CJS keywords ([#285](https://github.com/rollup/rollup-plugin-commonjs/issues/285))
* Use rollup's plugin context`parse` function ([#287](https://github.com/rollup/rollup-plugin-commonjs/issues/287))
* Improve error handling ([#288](https://github.com/rollup/rollup-plugin-commonjs/issues/288))
## 8.3.0

@@ -10,0 +4,0 @@

30

dist/rollup-plugin-commonjs.cjs.js

@@ -8,2 +8,3 @@ 'use strict';

var rollupPluginutils = require('rollup-pluginutils');
var acorn = _interopDefault(require('acorn'));
var estreeWalker = require('estree-walker');

@@ -192,5 +193,9 @@ var MagicString = _interopDefault(require('magic-string'));

function tryParse ( parse, code, id ) {
function tryParse ( code, id ) {
try {
return parse( code, { allowReturnOutsideFunction: true });
return acorn.parse( code, {
ecmaVersion: 8,
sourceType: 'module',
allowReturnOutsideFunction: true
});
} catch ( err ) {

@@ -207,4 +212,4 @@ err.message += " in " + id;

function checkEsModule ( parse, code, id ) {
var ast = tryParse( parse, code, id );
function checkEsModule (code, id) {
var ast = tryParse(code, id);

@@ -226,4 +231,4 @@ // if there are top-level import/export declarations, this is ES not CommonJS

function transformCommonjs ( parse, code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
var ast = astCache || tryParse( parse, code, id );
function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
var ast = astCache || tryParse( code, id );

@@ -769,4 +774,2 @@ var magicString = new MagicString( code );

transform: function transform ( code, id ) {
var this$1 = this;
if ( !filter( id ) ) { return null; }

@@ -776,3 +779,3 @@ if ( extensions.indexOf( path.extname( id ) ) === -1 ) { return null; }

return entryModuleIdsPromise.then( function (entryModuleIds) {
var ref = checkEsModule( this$1.parse, code, id );
var ref = checkEsModule( code, id );
var isEsModule = ref.isEsModule;

@@ -793,12 +796,7 @@ var hasDefaultExport = ref.hasDefaultExport;

var transformed = transformCommonjs( this$1.parse, code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) {
esModulesWithoutDefaultExport.push( id );
return;
}
var transformed = transformCommonjs( code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) { return; }
commonjsModules.set( id, true );
return transformed;
}).catch(function (err) {
this$1.error(err, err.loc);
});

@@ -805,0 +803,0 @@ }

import { statSync } from 'fs';
import { dirname, resolve, basename, extname, sep } from 'path';
import { makeLegalIdentifier, attachScopes, createFilter } from 'rollup-pluginutils';
import acorn from 'acorn';
import { walk } from 'estree-walker';

@@ -187,5 +188,9 @@ import MagicString from 'magic-string';

function tryParse ( parse, code, id ) {
function tryParse ( code, id ) {
try {
return parse( code, { allowReturnOutsideFunction: true });
return acorn.parse( code, {
ecmaVersion: 8,
sourceType: 'module',
allowReturnOutsideFunction: true
});
} catch ( err ) {

@@ -202,4 +207,4 @@ err.message += " in " + id;

function checkEsModule ( parse, code, id ) {
var ast = tryParse( parse, code, id );
function checkEsModule (code, id) {
var ast = tryParse(code, id);

@@ -221,4 +226,4 @@ // if there are top-level import/export declarations, this is ES not CommonJS

function transformCommonjs ( parse, code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
var ast = astCache || tryParse( parse, code, id );
function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
var ast = astCache || tryParse( code, id );

@@ -764,4 +769,2 @@ var magicString = new MagicString( code );

transform: function transform ( code, id ) {
var this$1 = this;
if ( !filter( id ) ) { return null; }

@@ -771,3 +774,3 @@ if ( extensions.indexOf( extname( id ) ) === -1 ) { return null; }

return entryModuleIdsPromise.then( function (entryModuleIds) {
var ref = checkEsModule( this$1.parse, code, id );
var ref = checkEsModule( code, id );
var isEsModule = ref.isEsModule;

@@ -788,12 +791,7 @@ var hasDefaultExport = ref.hasDefaultExport;

var transformed = transformCommonjs( this$1.parse, code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) {
esModulesWithoutDefaultExport.push( id );
return;
}
var transformed = transformCommonjs( code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) { return; }
commonjsModules.set( id, true );
return transformed;
}).catch(function (err) {
this$1.error(err, err.loc);
});

@@ -800,0 +798,0 @@ }

{
"name": "rollup-plugin-commonjs",
"version": "8.4.0",
"version": "8.4.1",
"description": "Convert CommonJS modules to ES2015",

@@ -24,2 +24,3 @@ "main": "dist/rollup-plugin-commonjs.cjs.js",

"dependencies": {
"acorn": "^5.2.1",
"estree-walker": "^0.5.0",

@@ -31,3 +32,2 @@ "magic-string": "^0.22.4",

"devDependencies": {
"acorn": "^5.2.1",
"eslint": "^4.8.0",

@@ -37,3 +37,3 @@ "locate-character": "^2.0.1",

"require-relative": "^0.8.7",
"rollup": "^0.56.3",
"rollup": "^0.55.0",
"rollup-plugin-buble": "^0.16.0",

@@ -40,0 +40,0 @@ "rollup-plugin-node-resolve": "^3.0.0",

@@ -172,3 +172,3 @@ import { statSync } from 'fs';

return entryModuleIdsPromise.then( (entryModuleIds) => {
const {isEsModule, hasDefaultExport, ast} = checkEsModule( this.parse, code, id );
const {isEsModule, hasDefaultExport, ast} = checkEsModule( code, id );
if ( isEsModule ) {

@@ -186,12 +186,7 @@ if ( !hasDefaultExport )

const transformed = transformCommonjs( this.parse, code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) {
esModulesWithoutDefaultExport.push( id );
return;
}
const transformed = transformCommonjs( code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
if ( !transformed ) return;
commonjsModules.set( id, true );
return transformed;
}).catch(err => {
this.error(err, err.loc);
});

@@ -198,0 +193,0 @@ }

@@ -0,1 +1,2 @@

import acorn from 'acorn';
import { walk } from 'estree-walker';

@@ -28,5 +29,9 @@ import MagicString from 'magic-string';

function tryParse ( parse, code, id ) {
function tryParse ( code, id ) {
try {
return parse( code, { allowReturnOutsideFunction: true });
return acorn.parse( code, {
ecmaVersion: 8,
sourceType: 'module',
allowReturnOutsideFunction: true
});
} catch ( err ) {

@@ -43,4 +48,4 @@ err.message += ` in ${id}`;

export function checkEsModule ( parse, code, id ) {
const ast = tryParse( parse, code, id );
export function checkEsModule (code, id) {
const ast = tryParse(code, id);

@@ -60,4 +65,4 @@ // if there are top-level import/export declarations, this is ES not CommonJS

export function transformCommonjs ( parse, code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
const ast = astCache || tryParse( parse, code, id );
export function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
const ast = astCache || tryParse( code, id );

@@ -64,0 +69,0 @@ const magicString = new MagicString( code );

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