Browse Source

Merge branch 'master' into incremental-transform

ghi-672
Rich Harris 9 years ago
parent
commit
ffa49fd9e2
  1. 13
      CHANGELOG.md
  2. 10
      bin/runRollup.js
  3. 3
      package.json
  4. 12
      src/Bundle.js
  5. 8
      src/Declaration.js
  6. 6
      src/Module.js
  7. 2
      src/rollup.js
  8. 2
      src/utils/first.js
  9. 1
      src/utils/fs.js
  10. 2
      src/utils/promise.js
  11. 2
      src/utils/transform.js
  12. 4
      test/cli/multiple-targets/_config.js
  13. 5
      test/cli/multiple-targets/_expected/cjs.js
  14. 3
      test/cli/multiple-targets/_expected/es6.js
  15. 1
      test/cli/multiple-targets/main.js
  16. 13
      test/cli/multiple-targets/rollup.config.js
  17. 1
      test/function/export-default-anonymous-function/_config.js
  18. 1
      test/function/import-chain-as/main.js
  19. 3
      test/function/legal-suggested-names/_config.js
  20. 5
      test/function/legal-suggested-names/bar.js
  21. 5
      test/function/legal-suggested-names/foo.js
  22. 5
      test/function/legal-suggested-names/helpers.js
  23. 8
      test/function/legal-suggested-names/main.js
  24. 2
      test/function/transformer-async/_config.js
  25. 2
      test/sourcemaps/basic-support/_config.js
  26. 38
      test/test.js

13
CHANGELOG.md

@ -1,6 +1,17 @@
# rollup changelog
## 0.27.7
## 0.27.1
* Ensure names exported from a module are not replaced with reserved words ([#696](https://github.com/rollup/rollup/pull/696))
* Revert ([#692](https://github.com/rollup/rollup/pull/692)) – resolved IDs must be strings
## 0.27.0
* Use native promises instead of `es6-promise` ([#689](https://github.com/rollup/rollup/issues/689))
* Support multiple targets in config files ([#655](https://github.com/rollup/rollup/issues/655))
* Allow `resolveId` plugin functions to return non-strings ([#692](https://github.com/rollup/rollup/pull/692))
## 0.26.7
* Distinguish between default and namespace imports of external module ([#637](https://github.com/rollup/rollup/issues/637))
* Add `__esModule` property to named exports in AMD, CJS and UMD modes ([#650](https://github.com/rollup/rollup/issues/650))

10
bin/runRollup.js

@ -143,6 +143,16 @@ function bundle ( options ) {
return bundle.write( options );
}
if ( options.targets ) {
var result = null;
options.targets.forEach( function ( target ) {
result = bundle.write(target);
});
return result;
}
if ( options.sourceMap && options.sourceMap !== 'inline' ) {
handleError({ code: 'MISSING_OUTPUT_OPTION' });
}

3
package.json

@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "0.26.7",
"version": "0.27.1",
"description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js",
"jsnext:main": "src/rollup.js",
@ -45,7 +45,6 @@
"buble": "^0.6.4",
"codecov.io": "^0.1.6",
"console-group": "^0.2.0",
"es6-promise": "^3.0.2",
"eslint": "^2.9.0",
"estree-walker": "^0.2.0",
"istanbul": "^0.4.0",

12
src/Bundle.js

@ -61,7 +61,7 @@ export default class Bundle {
.map( plugin => plugin.transformBundle )
.filter( Boolean );
this.moduleById = blank();
this.moduleById = new Map();
this.modules = [];
this.externalModules = [];
@ -171,8 +171,8 @@ export default class Bundle {
fetchModule ( id, importer ) {
// short-circuit cycles
if ( id in this.moduleById ) return null;
this.moduleById[ id ] = null;
if ( this.moduleById.has( id ) ) return null;
this.moduleById.set( id, null );
return this.load( id )
.catch( err => {
@ -210,7 +210,7 @@ export default class Bundle {
const module = new Module({ id, code, originalCode, ast, sourceMapChain, bundle: this });
this.modules.push( module );
this.moduleById[ id ] = module;
this.moduleById.set( id, module );
return this.fetchAllDependencies( module ).then( () => module );
});
@ -246,10 +246,10 @@ export default class Bundle {
}
module.resolvedIds[ source ] = normalizedExternal;
if ( !this.moduleById[ normalizedExternal ] ) {
if ( !this.moduleById.has( normalizedExternal ) ) {
const module = new ExternalModule( normalizedExternal );
this.externalModules.push( module );
this.moduleById[ normalizedExternal ] = module;
this.moduleById.set( normalizedExternal, module );
}
}

8
src/Declaration.js

@ -1,4 +1,5 @@
import { blank, forOwn, keys } from './utils/object.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import run from './utils/run.js';
import { SyntheticReference } from './Reference.js';
@ -17,7 +18,7 @@ export default class Declaration {
}
this.statement = statement;
this.name = null;
this.name = node.id ? node.id.name : node.name;
this.exportName = null;
this.isParam = isParam;
@ -33,7 +34,10 @@ export default class Declaration {
addReference ( reference ) {
reference.declaration = this;
this.name = reference.name; // TODO handle differences of opinion
if ( reference.name !== this.name ) {
this.name = makeLegalIdentifier( reference.name ); // TODO handle differences of opinion
}
if ( reference.isReassignment ) this.isReassigned = true;
}

6
src/Module.js

@ -224,18 +224,18 @@ export default class Module {
const specifier = specifiers[ name ];
const id = this.resolvedIds[ specifier.source ];
specifier.module = this.bundle.moduleById[ id ];
specifier.module = this.bundle.moduleById.get( id );
});
});
this.exportAllModules = this.exportAllSources.map( source => {
const id = this.resolvedIds[ source ];
return this.bundle.moduleById[ id ];
return this.bundle.moduleById.get( id );
});
this.sources.forEach( source => {
const id = this.resolvedIds[ source ];
const module = this.bundle.moduleById[ id ];
const module = this.bundle.moduleById.get( id );
if ( !module.isExternal ) this.dependencies.push( module );
});

2
src/rollup.js

@ -1,4 +1,3 @@
import Promise from 'es6-promise/lib/es6-promise/promise.js';
import { basename } from './utils/path.js';
import { writeFile } from './utils/fs.js';
import { keys } from './utils/object.js';
@ -27,6 +26,7 @@ const ALLOWED_KEYS = [
'plugins',
'preferConst',
'sourceMap',
'targets',
'treeshake',
'useStrict',
'bundle'

2
src/utils/first.js

@ -1,5 +1,3 @@
import Promise from 'es6-promise/lib/es6-promise/promise.js';
// Return the first non-falsy result from an array of
// maybe-sync, maybe-promise-returning functions
export default function first ( candidates ) {

1
src/utils/fs.js

@ -1,4 +1,3 @@
import Promise from 'es6-promise/lib/es6-promise/promise.js';
import * as fs from 'fs';
import { dirname } from './path.js';

2
src/utils/promise.js

@ -1,5 +1,3 @@
import Promise from 'es6-promise/lib/es6-promise/promise.js';
export function mapSequence ( array, fn ) {
let results = [];
let promise = Promise.resolve();

2
src/utils/transform.js

@ -1,5 +1,3 @@
import Promise from 'es6-promise/lib/es6-promise/promise.js';
export default function transform ( source, id, transformers ) {
let sourceMapChain = [];

4
test/cli/multiple-targets/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'generates multiple output files when multiple targets are specified',
command: 'rollup -c'
};

5
test/cli/multiple-targets/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
var main = 0;
module.exports = main;

3
test/cli/multiple-targets/_expected/es6.js

@ -0,0 +1,3 @@
var main = 0;
export default main;

1
test/cli/multiple-targets/main.js

@ -0,0 +1 @@
export default 0;

13
test/cli/multiple-targets/rollup.config.js

@ -0,0 +1,13 @@
export default {
entry: 'main.js',
targets: [
{
format: 'cjs',
dest: '_actual/cjs.js'
},
{
format: 'es6',
dest: '_actual/es6.js'
}
]
};

1
test/function/export-default-anonymous-function/_config.js

@ -9,7 +9,6 @@ module.exports = {
return path.basename( importee ).replace( /\..+/, '' );
},
load: function ( id ) {
console.log( 'id', id )
return fs.readFileSync( path.join( __dirname, id + '.js' ), 'utf-8' );
}
}]

1
test/function/import-chain-as/main.js

@ -1,5 +1,4 @@
import * as second from './second';
assert.equal( second.first.value, 42 );
console.log( 'second', second )
assert.deepEqual( second, { first: { value: 42 } });

3
test/function/legal-suggested-names/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'illegal name suggestions are ignored'
};

5
test/function/legal-suggested-names/bar.js

@ -0,0 +1,5 @@
import * as helpers from './helpers.js';
export default function bar ( a ) {
return helpers.typeof( a );
}

5
test/function/legal-suggested-names/foo.js

@ -0,0 +1,5 @@
import * as helpers from './helpers.js';
export default function foo ( a ) {
return helpers.typeof( a );
}

5
test/function/legal-suggested-names/helpers.js

@ -0,0 +1,5 @@
var _typeof = function ( thing ) {
return typeof thing;
};
export { _typeof as typeof };

8
test/function/legal-suggested-names/main.js

@ -0,0 +1,8 @@
import * as helpers from './helpers.js';
import foo from './foo.js';
import bar from './bar.js';
assert.equal( helpers.typeof( foo ), 'function' );
assert.equal( helpers.typeof( bar ), 'function' );
assert.equal( foo( 1 ), 'number' );
assert.equal( bar( 2 ), 'number' );

2
test/function/transformer-async/_config.js

@ -1,5 +1,3 @@
var Promise = require( 'es6-promise' ).Promise;
module.exports = {
description: 'transformers can be asynchronous',
options: {

2
test/sourcemaps/basic-support/_config.js

@ -7,7 +7,7 @@ module.exports = {
description: 'basic sourcemap support',
test: function ( code, map ) {
assert.equal( map.version, 3 );
assert.equal( map.file, 'bundle.js' );
assert.ok( /^bundle\.(\w+)\.js/.test( map.file ) );
var smc = new SourceMapConsumer( map );
var generatedLoc, originalLoc;

38
test/test.js

@ -77,7 +77,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () {
throw new Error( 'Missing expected error' );
}, function ( err ) {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, treeshake, useStrict' );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, targets, treeshake, useStrict' );
});
});
});
@ -154,7 +154,6 @@ describe( 'rollup', function () {
// try to generate output
try {
if(config.bundleOptions) { console.log(config.bundleOptions); }
var result = bundle.generate( extend( {}, config.bundleOptions, {
format: 'cjs'
}));
@ -253,7 +252,12 @@ describe( 'rollup', function () {
if ( config.skipIfWindows && process.platform === 'win32' ) return;
var options = extend( {}, config.options, {
entry: FORM + '/' + dir + '/main.js'
entry: FORM + '/' + dir + '/main.js',
onwarn: msg => {
if ( /No name was provided for/.test( msg ) ) return;
if ( /as external dependency/.test( msg ) ) return;
console.error( msg );
}
});
( config.skip ? describe.skip : config.solo ? describe.only : describe)( dir, function () {
@ -309,7 +313,7 @@ describe( 'rollup', function () {
var config = loadConfig( SOURCEMAPS + '/' + dir + '/_config.js' );
var entry = path.resolve( SOURCEMAPS, dir, 'main.js' );
var dest = path.resolve( SOURCEMAPS, dir, '_actual/bundle.js' );
var dest = path.resolve( SOURCEMAPS, dir, '_actual/bundle' );
var options = extend( {}, config.options, {
entry: entry
@ -321,7 +325,7 @@ describe( 'rollup', function () {
var options = extend( {}, {
format: profile.format,
sourceMap: true,
dest: dest
dest: `${dest}.${profile.format}.js`
}, config.options );
bundle.write( options );
@ -354,9 +358,13 @@ describe( 'rollup', function () {
PATH: path.resolve( __dirname, '../bin' ) + path.delimiter + process.env.PATH
}
}, function ( err, code, stderr ) {
if ( err || config.error ) {
config.error( err );
return done();
if ( err ) {
if ( config.error ) {
config.error( err );
return done();
} else {
throw err;
}
}
if ( stderr ) console.error( stderr );
@ -410,6 +418,20 @@ describe( 'rollup', function () {
}
}
else if ( sander.existsSync( '_expected' ) && sander.statSync( '_expected' ).isDirectory() ) {
var error = null;
sander.readdirSync( '_expected' ).forEach( child => {
var expected = sander.readFileSync( path.join( '_expected', child ) ).toString();
var actual = sander.readFileSync( path.join( '_actual', child ) ).toString();
try {
assert.equal( normaliseOutput( actual ), normaliseOutput( expected ) );
} catch ( err ) {
error = err;
}
});
done( error );
}
else {
var expected = sander.readFileSync( '_expected.js' ).toString();
try {

Loading…
Cancel
Save