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

rollup

Package Overview
Dependencies
Maintainers
3
Versions
834
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup - npm Package Compare versions

Comparing version 0.16.1 to 0.16.2

5

CHANGELOG.md
# rollup changelog
## 0.16.2
* Top-level function calls and assignments to globals are treated as side-effects, and always included
* Import files from subdirectories of external packages, e.g. `import mod from 'foo/sub/mod'` ([#126](https://github.com/rollup/rollup/issues/126))
## 0.16.1

@@ -4,0 +9,0 @@

2

package.json
{
"name": "rollup",
"version": "0.16.1",
"version": "0.16.2",
"description": "Next-generation ES6 module bundler",

@@ -5,0 +5,0 @@ "main": "dist/rollup.js",

@@ -36,6 +36,12 @@ import { Promise } from 'sander';

// TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
// Strictly speaking, these globals only apply to non-ES6, non-default-only bundles.
// However, the deconfliction logic is greatly simplified by being the same for all formats.
this.globals.define( 'exports' );
this.scope.bind( 'exports', this.globals.reference( 'exports' ) );
// * CommonJS needs `module` and `exports` ( and `require`? ) to be in scope.
// * SystemJS needs a reference to a function for its `exports`,
// and another one for any `module` it imports. These global names can be reused!
[ 'exports', 'module' ]
.forEach( name => {
this.globals.define( name );
this.scope.bind( name, this.globals.reference( name ) );
});

@@ -53,3 +59,2 @@ // Alias for entryModule.exports.

this.externalModules = [];
this.internalNamespaceModules = [];
}

@@ -65,10 +70,12 @@

entryModule.markAllStatements( true );
this.orderedModules = this.sort();
entryModule.markAllExports();
this.exports.localIds().forEach( ([ , id ]) => {
// If the export is a module (namespace), we need
// all its exports dynamically accessible.
if ( id.module === id ) id.dynamicAccess();
// Include all side-effects
this.modules.forEach( module => {
module.markAllSideEffects();
});
// Sort the modules.
this.orderedModules = this.sort();
// As a last step, deconflict all identifier names, once.

@@ -219,5 +226,7 @@ this.scope.deconflict();

const namespaceBlock = this.internalNamespaceModules.map( module => {
const exports = module.exports.localIds().map( ( [ name, id ] ) =>
`${indentString}get ${name} () { return ${id.name}; }`);
const namespaceBlock = this.modules.filter( module => module.needsDynamicAccess ).map( module => {
const exports = module.exports.getNames().map( name => {
const id = module.exports.lookup( name );
return `${indentString}get ${name} () { return ${id.name}; }`;
});

@@ -224,0 +233,0 @@ return `var ${module.name} = {\n` +

@@ -61,3 +61,3 @@ import { keys } from '../utils/object';

if ( defaultExport ) {
exportBlock += `export default ${ defaultExport.name };`;
exportBlock += `\nexport default ${ defaultExport.name };`;
}

@@ -64,0 +64,0 @@

@@ -29,3 +29,3 @@ import { basename, extname } from './utils/path';

function assign ( target, source ) {
for ( var key in source ) target[ key ] = source[ key ];
for ( let key in source ) target[ key ] = source[ key ];
}

@@ -96,5 +96,5 @@

// ... otherwise search exportAlls
for ( let i = 0; i < this.exportAlls.length; i += 1 ) {
const module = this.exportAlls[i];
// ... otherwise search allExportsFrom
for ( let i = 0; i < this.allExportsFrom.length; i += 1 ) {
const module = this.allExportsFrom[i];
if ( module.exports.inScope( name ) ) {

@@ -112,3 +112,3 @@ return module.exports.reference( name );

return this.exportAlls.some( module => module.exports.inScope( name ) );
return this.allExportsFrom.some( module => module.exports.inScope( name ) );
};

@@ -121,3 +121,5 @@

this.exportAlls = [];
// As far as we know, all our exported bindings have been resolved.
this.allExportsResolved = true;
this.allExportsFrom = [];

@@ -145,6 +147,14 @@ this.reassignments = [];

if ( module.isExternal ) {
throw new Error( `Cannot trace 'export *' references through external modules.` );
let err = new Error( `Cannot trace 'export *' references through external modules.` );
err.file = this.id;
err.loc = getLocation( this.source, node.start );
throw err;
}
this.exportAlls.push( module );
// It seems like we must re-export all exports from another module...
this.allExportsResolved = false;
if ( !~this.allExportsFrom.indexOf( module ) ) {
this.allExportsFrom.push( module );
}
}

@@ -274,2 +284,19 @@

// If all exports aren't resolved, but all our delegate modules are...
if ( !this.allExportsResolved && this.allExportsFrom.every( module => module.allExportsResolved )) {
// .. then all our exports should be as well.
this.allExportsResolved = true;
// For all modules we export all from, iterate through its exported names.
// If we don't already define the binding 'name',
// bind the name to the other module's reference.
this.allExportsFrom.forEach( module => {
module.exports.getNames().forEach( name => {
if ( !this.exports.defines( name ) ) {
this.exports.bind( name, module.exports.reference( name ) );
}
});
});
}
// discover variables that are reassigned inside function

@@ -384,4 +411,8 @@ // bodies, so we can keep bindings live, e.g.

this.locals.getNames().forEach( name => {
const id = this.locals.lookup( name );
// Go through all our local and exported ids and make us depend on
// the defining modules as well as
this.exports.getIds().concat(this.locals.getIds()).forEach( id => {
if ( id.module && !id.module.isExternal ) {
weakDependencies[ id.module.id ] = id.module;
}

@@ -404,22 +435,20 @@ if ( !id.modifierStatements ) return;

// Enforce dynamic access of the module's properties.
dynamicAccess () {
getModule ( source ) {
return this.bundle.moduleById[ this.resolvedIds[ source ] ];
}
// If a module is marked, enforce dynamic access of its properties.
mark () {
if ( this.needsDynamicAccess ) return;
this.needsDynamicAccess = true;
this.markAllExportStatements();
if ( !~this.bundle.internalNamespaceModules.indexOf( this ) ) {
this.bundle.internalNamespaceModules.push( this );
}
this.markAllExports();
}
getModule ( source ) {
return this.bundle.moduleById[ this.resolvedIds[ source ] ];
markAllSideEffects () {
this.statements.forEach( statement => {
statement.markSideEffect();
});
}
mark () {
this.dynamicAccess();
}
markAllStatements ( isEntryModule ) {

@@ -458,6 +487,5 @@ this.statements.forEach( statement => {

markAllExportStatements () {
this.statements.forEach( statement => {
if ( statement.isExportDeclaration ) statement.mark();
});
// Marks all exported identifiers.
markAllExports () {
this.exports.getIds().forEach( id => id.mark() );
}

@@ -633,2 +661,7 @@

else if ( statement.node.type === 'ExportAllDeclaration' ) {
// TODO: remove once `export * from 'external'` is supported.
magicString.remove( statement.start, statement.next );
}
// remove `export` from `export class Foo {...}` or `export default Foo`

@@ -635,0 +668,0 @@ // TODO default exports need different treatment

@@ -121,4 +121,4 @@ import { blank, keys } from './utils/object';

// Returns a list of `[ name, identifier ]` tuples.
localIds () {
return keys( this.names ).map( name => [ name, this.lookup( name ) ] );
getIds () {
return keys( this.names ).map( name => this.lookup( name ) );
}

@@ -125,0 +125,0 @@

@@ -11,2 +11,7 @@ import { blank, keys } from './utils/object';

const modifierNodes = {
AssignmentExpression: 'left',
UpdateExpression: 'argument'
};
function isIife ( node, parent ) {

@@ -210,3 +215,3 @@ return parent && parent.type === 'CallExpression' && node === parent.callee;

// If we can't resolve the name being accessed statically,
// we require the namespace to be dynamically accessible.
// we mark the whole namespace for inclusion in the bundle.
//

@@ -222,3 +227,3 @@ // // resolvable

if ( name === null ) {
namespace.dynamicAccess();
namespace.mark();

@@ -398,2 +403,25 @@ namespace = null;

markSideEffect () {
const statement = this;
walk( this.node, {
enter ( node, parent ) {
if ( /Function/.test( node.type ) && !isIife( node, parent ) ) return this.skip();
// If this is a top-level call expression, or an assignment to a global,
// this statement will need to be marked
if ( node.type === 'CallExpression' ) {
statement.mark();
}
else if ( node.type in modifierNodes ) {
let subject = node[ modifierNodes[ node.type ] ];
while ( subject.type === 'MemberExpression' ) subject = subject.object;
if ( statement.module.bundle.globals.defines( subject.name ) ) statement.mark();
}
}
});
}
replaceIdentifiers ( magicString, names, bundleExports ) {

@@ -400,0 +428,0 @@ const statement = this;

import { absolutePath, dirname, isAbsolute, resolve } from './path';
import { readFileSync } from 'sander';
import { readdirSync, readFileSync } from 'sander';
function dirExists ( dir ) {
try {
readdirSync( dir );
return true;
} catch ( err ) {
return false;
}
}
export function defaultResolver ( importee, importer, options ) {

@@ -13,4 +22,6 @@ // absolute paths are left untouched

if ( importee[0] !== '.' ) {
const [ id ] = importee.split( /[\/\\]/ );
// unless we want to keep it external, that is
if ( ~options.external.indexOf( importee ) ) return null;
if ( ~options.external.indexOf( id ) ) return null;

@@ -28,19 +39,22 @@ return options.resolveExternal( importee, importer, options );

while ( dir !== root && dir !== "." ) {
const pkgPath = resolve( dir, 'node_modules', id, 'package.json' );
let pkgJson;
// `foo` should use jsnext:main, but `foo/src/bar` shouldn't
const parts = id.split( /[\/\\]/ );
try {
pkgJson = readFileSync( pkgPath ).toString();
} catch ( err ) {
// noop
}
while ( dir !== root && dir !== '.' ) {
const modulePath = resolve( dir, 'node_modules', parts[0] );
if ( pkgJson ) {
if ( dirExists( modulePath ) ) {
// `foo/src/bar`
if ( parts.length > 1 ) {
return resolve( modulePath, ...parts.slice( 1 ) ).replace( /\.js$/, '' ) + '.js';
}
// `foo`
const pkgPath = resolve( modulePath, 'package.json' );
let pkg;
try {
pkg = JSON.parse( pkgJson );
pkg = JSON.parse( readFileSync( pkgPath ).toString() );
} catch ( err ) {
throw new Error( `Malformed JSON: ${pkgPath}` );
throw new Error( `Missing or malformed package.json: ${modulePath}` );
}

@@ -51,3 +65,3 @@

if ( !main ) {
throw new Error( `Package ${id} does not have a jsnext:main field, and so cannot be included in your rollup. Try adding it as an external module instead (e.g. options.external = ['${id}']). See https://github.com/rollup/rollup/wiki/jsnext:main for more info` );
throw new Error( `Package ${id} (imported by ${importer}) does not have a jsnext:main field, and so cannot be included in your rollup. Try adding it as an external module instead (e.g. options.external = ['${id}']). See https://github.com/rollup/rollup/wiki/jsnext:main for more info` );
}

@@ -54,0 +68,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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