rollup-plugin-commonjs
Advanced tools
Comparing version 1.4.0 to 2.0.0
# rollup-plugin-commonjs changelog | ||
## 2.0.0 | ||
* Support for transpiled modules – `exports.default` is used as the default export in place of `module.exports`, if applicable, and `__esModule` is not exported ([#16](https://github.com/rollup/rollup-plugin-commonjs/pull/16)) | ||
## 1.4.0 | ||
@@ -4,0 +8,0 @@ |
@@ -49,2 +49,7 @@ 'use strict'; | ||
var blacklistedExports = { | ||
__esModule: true, | ||
'default': true | ||
}; | ||
function getName(id) { | ||
@@ -127,2 +132,10 @@ var base = path.basename(id); | ||
if (flattened.keypath === 'module.exports' && node.right.type === 'ObjectExpression') { | ||
return node.right.properties.forEach(function (prop) { | ||
if (prop.computed || prop.key.type !== 'Identifier') return; | ||
var name = prop.key.name; | ||
if (name === rollupPluginutils.makeLegalIdentifier(name)) namedExports[name] = true; | ||
}); | ||
} | ||
if (match[1]) namedExports[match[1]] = true; | ||
@@ -174,5 +187,8 @@ | ||
var intro = '\n\nvar ' + name + ' = (function (module' + (usesGlobal ? ', global' : '') + ') {\nvar exports = module.exports;\n'; | ||
var outro = '\nreturn module.exports;\n})({exports:{}}' + (usesGlobal ? ', __commonjs_global' : '') + ');\n\nexport default ' + name + ';\n'; | ||
outro += Object.keys(namedExports).map(function (x) { | ||
var outro = '\nreturn module.exports;\n})({exports:{}}' + (usesGlobal ? ', __commonjs_global' : '') + ');\n\nexport default (' + name + ' && typeof ' + name + ' === \'object\' && \'default\' in ' + name + ' ? ' + name + '[\'default\'] : ' + name + ');\n'; | ||
outro += Object.keys(namedExports).filter(function (key) { | ||
return !blacklistedExports[key]; | ||
}).map(function (x) { | ||
return 'export var ' + x + ' = ' + name + '.' + x + ';'; | ||
@@ -179,0 +195,0 @@ }).join('\n'); |
@@ -45,2 +45,7 @@ import { statSync } from 'fs'; | ||
var blacklistedExports = { | ||
__esModule: true, | ||
'default': true | ||
}; | ||
function getName(id) { | ||
@@ -123,2 +128,10 @@ var base = basename(id); | ||
if (flattened.keypath === 'module.exports' && node.right.type === 'ObjectExpression') { | ||
return node.right.properties.forEach(function (prop) { | ||
if (prop.computed || prop.key.type !== 'Identifier') return; | ||
var name = prop.key.name; | ||
if (name === makeLegalIdentifier(name)) namedExports[name] = true; | ||
}); | ||
} | ||
if (match[1]) namedExports[match[1]] = true; | ||
@@ -170,5 +183,8 @@ | ||
var intro = '\n\nvar ' + name + ' = (function (module' + (usesGlobal ? ', global' : '') + ') {\nvar exports = module.exports;\n'; | ||
var outro = '\nreturn module.exports;\n})({exports:{}}' + (usesGlobal ? ', __commonjs_global' : '') + ');\n\nexport default ' + name + ';\n'; | ||
outro += Object.keys(namedExports).map(function (x) { | ||
var outro = '\nreturn module.exports;\n})({exports:{}}' + (usesGlobal ? ', __commonjs_global' : '') + ');\n\nexport default (' + name + ' && typeof ' + name + ' === \'object\' && \'default\' in ' + name + ' ? ' + name + '[\'default\'] : ' + name + ');\n'; | ||
outro += Object.keys(namedExports).filter(function (key) { | ||
return !blacklistedExports[key]; | ||
}).map(function (x) { | ||
return 'export var ' + x + ' = ' + name + '.' + x + ';'; | ||
@@ -175,0 +191,0 @@ }).join('\n'); |
{ | ||
"name": "rollup-plugin-commonjs", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"description": "Convert CommonJS modules to ES2015", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -34,6 +34,3 @@ # rollup-plugin-commonjs | ||
include: 'node_modules/**', | ||
exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ], | ||
// add this if you want to generate sourcemaps later | ||
sourceMap: true | ||
exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ] | ||
}) | ||
@@ -40,0 +37,0 @@ ] |
@@ -12,2 +12,7 @@ import { statSync } from 'fs'; | ||
var blacklistedExports = { | ||
__esModule: true, | ||
default: true | ||
}; | ||
function getName ( id ) { | ||
@@ -93,2 +98,10 @@ const base = basename( id ); | ||
if ( flattened.keypath === 'module.exports' && node.right.type === 'ObjectExpression' ) { | ||
return node.right.properties.forEach( prop => { | ||
if ( prop.computed || prop.key.type !== 'Identifier' ) return; | ||
const name = prop.key.name; | ||
if ( name === makeLegalIdentifier( name ) ) namedExports[ name ] = true; | ||
}); | ||
} | ||
if ( match[1] ) namedExports[ match[1] ] = true; | ||
@@ -139,7 +152,19 @@ | ||
const intro = `\n\nvar ${name} = (function (module${usesGlobal ? ', global' : ''}) {\nvar exports = module.exports;\n`; | ||
let outro = `\nreturn module.exports;\n})({exports:{}}${usesGlobal ? ', __commonjs_global' : ''});\n\nexport default ${name};\n`; | ||
const intro = ` | ||
outro += Object.keys( namedExports ).map( x => `export var ${x} = ${name}.${x};` ).join( '\n' ); | ||
var ${name} = (function (module${usesGlobal ? ', global' : ''}) { | ||
var exports = module.exports; | ||
`; | ||
let outro = ` | ||
return module.exports; | ||
})({exports:{}}${usesGlobal ? ', __commonjs_global' : ''}); | ||
export default (${name} && typeof ${name} === 'object' && 'default' in ${name} ? ${name}['default'] : ${name});\n`; | ||
outro += Object.keys( namedExports ) | ||
.filter( key => !blacklistedExports[ key ] ) | ||
.map( x => `export var ${x} = ${name}.${x};` ) | ||
.join( '\n' ); | ||
magicString.trim() | ||
@@ -146,0 +171,0 @@ .prepend( importBlock + intro ) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22032
467
44