Browse Source

Merge pull request #209 from rollup/0.20.0

0.20.0
better-aggressive
Rich Harris 9 years ago
parent
commit
4c7f8ce045
  1. 2
      .travis.yml
  2. 6
      CHANGELOG.md
  3. 2
      package.json
  4. 70
      src/Bundle.js
  5. 4
      src/rollup.js
  6. 28
      src/utils/defaults.js
  7. 5
      src/utils/load.js
  8. 2
      src/utils/path.js
  9. 79
      src/utils/resolveId.js
  10. 6
      test/function/custom-external-resolver-async/_config.js
  11. 6
      test/function/custom-external-resolver-sync/_config.js
  12. 10
      test/function/custom-loaders/_config.js
  13. 2
      test/function/custom-path-resolver-async/_config.js
  14. 2
      test/function/custom-path-resolver-on-entry/_config.js
  15. 16
      test/function/custom-path-resolver-plural-b/_config.js
  16. 16
      test/function/custom-path-resolver-plural/_config.js
  17. 2
      test/function/custom-path-resolver-sync/_config.js
  18. 9
      test/function/does-not-hang-on-missing-module/_config.js
  19. 2
      test/function/export-default-anonymous-function/_config.js
  20. 4
      test/function/import-from-external-subdirectory/_config.js
  21. 5
      test/function/import-from-external-subdirectory/main.js
  22. 14
      test/function/non-js-extensions/_config.js
  23. 3
      test/function/non-js-extensions/info.json
  24. 3
      test/function/non-js-extensions/main.js
  25. 10
      test/function/transformer-multiple/_config.js
  26. 2
      test/function/transformer-single/_config.js
  27. 2
      test/function/uses-supplied-ast/_config.js
  28. 10
      test/sourcemaps/transforms/_config.js
  29. 4
      test/test.js

2
.travis.yml

@ -7,4 +7,4 @@ env:
global: global:
- BUILD_TIMEOUT=10000 - BUILD_TIMEOUT=10000
install: npm install install: npm install
script: npm run ci # script: npm run ci

6
CHANGELOG.md

@ -1,5 +1,11 @@
# rollup changelog # rollup changelog
## 0.20.0
* Support for [plugins](https://github.com/rollup/rollup/wiki/Plugins) ([#207](https://github.com/rollup/rollup/pulls/207))
* BREAKING – `options.transform`, `options.load`, `options.resolveId`, `options.resolveExternal` and `options.external` are no longer supported, and should be handled by plugins. [More info](https://github.com/rollup/rollup/wiki/Plugins)
* BREAKING – the .js extension is only added if it looks like there's no extension, allowing e.g. `import data from 'data.json'` (with the appropriate transformer). For safety, always include the file extension – import `./foo.js`, not `./foo`
## 0.19.2 ## 0.19.2
* Fix exporting namespaces to include all of their exports ([#204](https://github.com/rollup/rollup/issues/204)) * Fix exporting namespaces to include all of their exports ([#204](https://github.com/rollup/rollup/issues/204))

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "rollup", "name": "rollup",
"version": "0.19.2", "version": "0.20.0",
"description": "Next-generation ES6 module bundler", "description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js", "main": "dist/rollup.js",
"jsnext:main": "src/rollup.js", "jsnext:main": "src/rollup.js",

70
src/Bundle.js

@ -6,8 +6,7 @@ import Module from './Module';
import ExternalModule from './ExternalModule'; import ExternalModule from './ExternalModule';
import finalisers from './finalisers/index'; import finalisers from './finalisers/index';
import ensureArray from './utils/ensureArray'; import ensureArray from './utils/ensureArray';
import { defaultResolver, defaultExternalResolver } from './utils/resolveId'; import { load, onwarn, resolveId } from './utils/defaults';
import { defaultLoader } from './utils/load';
import getExportMode from './utils/getExportMode'; import getExportMode from './utils/getExportMode';
import getIndentString from './utils/getIndentString'; import getIndentString from './utils/getIndentString';
import { unixizePath } from './utils/normalizePlatform.js'; import { unixizePath } from './utils/normalizePlatform.js';
@ -19,16 +18,25 @@ export default class Bundle {
this.entry = options.entry; this.entry = options.entry;
this.entryModule = null; this.entryModule = null;
this.resolveId = first( ensureArray( options.resolveId ).concat( defaultResolver ) ); this.plugins = ensureArray( options.plugins );
this.load = first( ensureArray( options.load ).concat( defaultLoader ) );
this.resolveOptions = { this.resolveId = first(
external: ensureArray( options.external ), this.plugins
resolveExternal: first( ensureArray( options.resolveExternal ).concat( defaultExternalResolver ) ) .map( plugin => plugin.resolveId )
}; .filter( Boolean )
.concat( resolveId )
);
this.loadOptions = {}; this.load = first(
this.transformers = ensureArray( options.transform ); this.plugins
.map( plugin => plugin.load )
.filter( Boolean )
.concat( load )
);
this.transformers = this.plugins
.map( plugin => plugin.transform )
.filter( Boolean );
this.pending = blank(); this.pending = blank();
this.moduleById = blank(); this.moduleById = blank();
@ -39,13 +47,16 @@ export default class Bundle {
this.assumedGlobals = blank(); this.assumedGlobals = blank();
this.external = options.external || [];
this.onwarn = options.onwarn || onwarn;
// TODO strictly speaking, this only applies with non-ES6, non-default-only bundles // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
[ 'module', 'exports' ].forEach( global => this.assumedGlobals[ global ] = true ); [ 'module', 'exports' ].forEach( global => this.assumedGlobals[ global ] = true );
} }
build () { build () {
return Promise.resolve( this.resolveId( this.entry, undefined, this.resolveOptions ) ) return Promise.resolve( this.resolveId( this.entry, undefined ) )
.then( id => this.fetchModule( id ) ) .then( id => this.fetchModule( id, undefined ) )
.then( entryModule => { .then( entryModule => {
this.entryModule = entryModule; this.entryModule = entryModule;
@ -107,12 +118,19 @@ export default class Bundle {
}); });
} }
fetchModule ( id ) { fetchModule ( id, importer ) {
// short-circuit cycles // short-circuit cycles
if ( this.pending[ id ] ) return null; if ( this.pending[ id ] ) return null;
this.pending[ id ] = true; this.pending[ id ] = true;
return Promise.resolve( this.load( id, this.loadOptions ) ) return Promise.resolve( this.load( id ) )
.catch( err => {
let msg = `Could not load ${id}`;
if ( importer ) msg += ` (imported by ${importer})`;
msg += `: ${err.message}`;
throw new Error( msg );
})
.then( source => transform( source, id, this.transformers ) ) .then( source => transform( source, id, this.transformers ) )
.then( source => { .then( source => {
const { code, originalCode, ast, sourceMapChain } = source; const { code, originalCode, ast, sourceMapChain } = source;
@ -128,12 +146,12 @@ export default class Bundle {
fetchAllDependencies ( module ) { fetchAllDependencies ( module ) {
const promises = module.dependencies.map( source => { const promises = module.dependencies.map( source => {
return Promise.resolve( this.resolveId( source, module.id, this.resolveOptions ) ) return Promise.resolve( this.resolveId( source, module.id ) )
.then( resolvedId => { .then( resolvedId => {
module.resolvedIds[ source ] = resolvedId || source;
// external module
if ( !resolvedId ) { if ( !resolvedId ) {
if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` );
module.resolvedIds[ source ] = source;
if ( !this.moduleById[ source ] ) { if ( !this.moduleById[ source ] ) {
const module = new ExternalModule( source ); const module = new ExternalModule( source );
this.externalModules.push( module ); this.externalModules.push( module );
@ -141,12 +159,13 @@ export default class Bundle {
} }
} }
else if ( resolvedId === module.id ) { else {
if ( resolvedId === module.id ) {
throw new Error( `A module cannot import itself (${resolvedId})` ); throw new Error( `A module cannot import itself (${resolvedId})` );
} }
else { module.resolvedIds[ source ] = resolvedId;
return this.fetchModule( resolvedId ); return this.fetchModule( resolvedId, module.id );
} }
}); });
}); });
@ -171,7 +190,14 @@ export default class Bundle {
} }
}); });
if ( options.intro ) magicString.prepend( options.intro + '\n' ); const intro = [ options.intro ]
.concat(
this.plugins.map( plugin => plugin.intro && plugin.intro() )
)
.filter( Boolean )
.join( '\n\n' );
if ( intro ) magicString.prepend( intro + '\n' );
if ( options.outro ) magicString.append( '\n' + options.outro ); if ( options.outro ) magicString.append( '\n' + options.outro );
const indentString = getIndentString( magicString, options ); const indentString = getIndentString( magicString, options );

4
src/rollup.js

@ -11,6 +11,10 @@ export function rollup ( options ) {
throw new Error( 'You must supply options.entry to rollup' ); throw new Error( 'You must supply options.entry to rollup' );
} }
if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
throw new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' );
}
const bundle = new Bundle( options ); const bundle = new Bundle( options );
return bundle.build().then( () => { return bundle.build().then( () => {

28
src/utils/defaults.js

@ -0,0 +1,28 @@
import { readFileSync } from './fs';
import { dirname, extname, isAbsolute, resolve } from './path';
export function load ( id ) {
return readFileSync( id, 'utf-8' );
}
function addExt ( id ) {
if ( !extname( id ) ) id += '.js';
return id;
}
export function resolveId ( importee, importer ) {
// absolute paths are left untouched
if ( isAbsolute( importee ) ) return addExt( importee );
// if this is the entry point, resolve against cwd
if ( importer === undefined ) return resolve( process.cwd(), addExt( importee ) );
// external modules are skipped at this stage
if ( importee[0] !== '.' ) return null;
return resolve( dirname( importer ), addExt( importee ) );
}
export function onwarn ( msg ) {
console.error( msg );
}

5
src/utils/load.js

@ -1,5 +0,0 @@
import { readFileSync } from './fs';
export function defaultLoader ( id ) {
return readFileSync( id, 'utf-8' );
}

2
src/utils/path.js

@ -21,7 +21,7 @@ export function dirname ( path ) {
} }
export function extname ( path ) { export function extname ( path ) {
const match = /\.[^\.]+$/.exec( path ); const match = /\.[^\.]+$/.exec( basename( path ) );
if ( !match ) return ''; if ( !match ) return '';
return match[0]; return match[0];
} }

79
src/utils/resolveId.js

@ -1,79 +0,0 @@
import { absolutePath, dirname, isAbsolute, resolve } from './path';
import { readdirSync, readFileSync } from './fs';
function dirExists ( dir ) {
try {
readdirSync( dir );
return true;
} catch ( err ) {
return false;
}
}
export function defaultResolver ( importee, importer, options ) {
// absolute paths are left untouched
if ( isAbsolute( importee ) ) return importee;
// if this is the entry point, resolve against cwd
if ( importer === undefined ) return resolve( process.cwd(), importee );
// we try to resolve external modules
if ( importee[0] !== '.' ) {
const [ id ] = importee.split( /[\/\\]/ );
// unless we want to keep it external, that is
if ( ~options.external.indexOf( id ) ) return null;
return options.resolveExternal( importee, importer, options );
}
return resolve( dirname( importer ), importee ).replace( /\.js$/, '' ) + '.js';
}
export function defaultExternalResolver ( id, importer ) {
// for now, only node_modules is supported, and only jsnext:main
const root = absolutePath.exec( importer )[0];
let dir = dirname( importer );
// `foo` should use jsnext:main, but `foo/src/bar` shouldn't
const parts = id.split( /[\/\\]/ );
// npm scoped packages – @user/package
if ( parts[0][0] === '@' && parts[1] ) {
var user = parts.shift();
parts[0] = user + '/' + parts[0];
}
while ( dir !== root && dir !== '.' ) {
const modulePath = resolve( dir, 'node_modules', parts[0] );
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( readFileSync( pkgPath, 'utf-8' ) );
} catch ( err ) {
throw new Error( `Missing or malformed package.json: ${modulePath}` );
}
const main = pkg[ 'jsnext:main' ];
if ( !main ) {
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` );
}
return resolve( dirname( pkgPath ), main ).replace( /\.js$/, '' ) + '.js';
}
dir = dirname( dir );
}
throw new Error( `Could not find package ${id} (required by ${importer})` );
}

6
test/function/custom-external-resolver-async/_config.js

@ -5,9 +5,11 @@ var Promise = require( 'sander' ).Promise;
module.exports = { module.exports = {
description: 'uses a custom external path resolver (asynchronous)', description: 'uses a custom external path resolver (asynchronous)',
options: { options: {
resolveExternal: function ( id, importer, options ) { plugins: [{
return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) ); resolveId: function ( id, importer ) {
if ( importer && id[0] !== '.' ) return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.ok( exports.success ); assert.ok( exports.success );

6
test/function/custom-external-resolver-sync/_config.js

@ -4,9 +4,11 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom external path resolver (synchronous)', description: 'uses a custom external path resolver (synchronous)',
options: { options: {
resolveExternal: function ( id, importer, options ) { plugins: [{
return path.resolve( __dirname, 'js_modules', id + '.js' ); resolveId: function ( id, importer ) {
if ( importer && id[0] !== '.' ) return path.resolve( __dirname, 'js_modules', id + '.js' );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.ok( exports.success ); assert.ok( exports.success );

10
test/function/custom-loaders/_config.js

@ -3,17 +3,21 @@ var fs = require( 'fs' );
module.exports = { module.exports = {
description: 'uses custom loaders, falling back to default', description: 'uses custom loaders, falling back to default',
options: { options: {
load: [ plugins: [
function ( id ) { {
load: function ( id ) {
if ( /foo\.js/.test( id ) ) { if ( /foo\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 ); return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 );
} }
}
}, },
function ( id ) { {
load: function ( id ) {
if ( /bar\.js/.test( id ) ) { if ( /bar\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 ); return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 );
} }
} }
}
] ]
} }
}; };

2
test/function/custom-path-resolver-async/_config.js

@ -4,6 +4,7 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom path resolver (asynchronous)', description: 'uses a custom path resolver (asynchronous)',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
var Promise = require( 'sander' ).Promise; var Promise = require( 'sander' ).Promise;
var resolved; var resolved;
@ -18,6 +19,7 @@ module.exports = {
return Promise.resolve( resolved ); return Promise.resolve( resolved );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) ); assert.strictEqual( exports.path, require( 'path' ) );

2
test/function/custom-path-resolver-on-entry/_config.js

@ -10,6 +10,7 @@ module.exports = {
description: 'applies custom resolver to entry point', description: 'applies custom resolver to entry point',
//solo: true, //solo: true,
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( importer === undefined ) { if ( importer === undefined ) {
return '@' + path.relative( __dirname, importee ); return '@' + path.relative( __dirname, importee );
@ -26,6 +27,7 @@ module.exports = {
return fs.readFileSync( moduleId, 'utf-8' ); return fs.readFileSync( moduleId, 'utf-8' );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.equal( exports, 42 ); assert.equal( exports, 42 );

16
test/function/custom-path-resolver-plural-b/_config.js

@ -3,18 +3,22 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'resolver error is not caught', description: 'resolver error is not caught',
options: { options: {
resolveId: [ plugins: [
function () { {
resolveId: function () {
throw new Error( 'nope' ); throw new Error( 'nope' );
}, },
function ( importee, importer ) {
return 'main';
}
],
load: function ( id ) { load: function ( id ) {
if ( id === 'main' ) return 'assert.ok( false );' if ( id === 'main' ) return 'assert.ok( false );'
} }
}, },
{
resolveId: function ( importee, importer ) {
return 'main';
}
}
]
},
error: function ( err ) { error: function ( err ) {
assert.equal( err.message, 'nope' ); assert.equal( err.message, 'nope' );
} }

16
test/function/custom-path-resolver-plural/_config.js

@ -4,19 +4,23 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses custom path resolvers (plural)', description: 'uses custom path resolvers (plural)',
options: { options: {
resolveId: [ plugins: [
function ( importee ) { {
resolveId: function ( importee ) {
if ( importee[0] === '@' ) if ( importee[0] === '@' )
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' ); return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' );
}, },
function ( importee ) {
if ( importee[0] === '!' ) return '<empty>';
}
],
load: function ( id ) { load: function ( id ) {
if ( id === '<empty>' ) return ''; if ( id === '<empty>' ) return '';
} }
}, },
{
resolveId: function ( importee ) {
if ( importee[0] === '!' ) return '<empty>';
}
}
]
},
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.res, 0 ); assert.strictEqual( exports.res, 0 );
} }

2
test/function/custom-path-resolver-sync/_config.js

@ -4,12 +4,14 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom path resolver (synchronous)', description: 'uses a custom path resolver (synchronous)',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee; if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee;
if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' ); if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' );
return false; return false;
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) ); assert.strictEqual( exports.path, require( 'path' ) );

9
test/function/does-not-hang-on-missing-module/_config.js

@ -2,7 +2,12 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'does not hang on missing module (#53)', description: 'does not hang on missing module (#53)',
error: function ( error ) { options: {
assert.ok( /Could not find package unlessYouCreatedThisFileForSomeReason/.test( error.message ) ); onwarn: function ( msg ) {
assert.equal( "Treating 'unlessYouCreatedThisFileForSomeReason' as external dependency", msg );
}
},
runtimeError: function ( error ) {
assert.equal( "Cannot find module 'unlessYouCreatedThisFileForSomeReason'", error.message );
} }
}; };

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

@ -4,6 +4,7 @@ var path = require( 'path' );
module.exports = { module.exports = {
description: 'exports an anonymous function with custom ID resolver', // yeah, this is a real edge case description: 'exports an anonymous function with custom ID resolver', // yeah, this is a real edge case
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
return path.basename( importee ).replace( /\..+/, '' ); return path.basename( importee ).replace( /\..+/, '' );
}, },
@ -11,5 +12,6 @@ module.exports = {
console.log( 'id', id ) console.log( 'id', id )
return fs.readFileSync( path.join( __dirname, id + '.js' ), 'utf-8' ); return fs.readFileSync( path.join( __dirname, id + '.js' ), 'utf-8' );
} }
}]
} }
}; };

4
test/function/import-from-external-subdirectory/_config.js

@ -1,4 +0,0 @@
module.exports = {
description: 'default resolver imports from a subdirectory of an external module',
babel: true
};

5
test/function/import-from-external-subdirectory/main.js

@ -1,5 +0,0 @@
// this test is brittle, it relies on this dependency continuing
// to be structured in a certain way
import btoa from 'magic-string/src/utils/btoa';
assert.equal( btoa( 'it works' ), new Buffer( 'it works' ).toString( 'base64' ) );

14
test/function/non-js-extensions/_config.js

@ -0,0 +1,14 @@
var path = require( 'path' );
module.exports = {
description: 'non .js extensions are preserved',
options: {
plugins: [{
transform: function ( code, id ) {
if ( path.extname( id ) === '.json' ) {
return 'export default ' + code;
}
}
}]
}
};

3
test/function/non-js-extensions/info.json

@ -0,0 +1,3 @@
{
"answer": 42
}

3
test/function/non-js-extensions/main.js

@ -0,0 +1,3 @@
import info from './info.json';
assert.equal( info.answer, 42 );

10
test/function/transformer-multiple/_config.js

@ -3,16 +3,20 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'accepts multiple transformer functions', description: 'accepts multiple transformer functions',
options: { options: {
transform: [ plugins: [
function ( code, path ) { {
transform: function ( code, path ) {
return code.replace( /MAGIC_NUMBER/g, 3 ); return code.replace( /MAGIC_NUMBER/g, 3 );
}
}, },
function ( code, path ) { {
transform: function ( code, path ) {
return code.replace( /\d+/g, function ( match ) { return code.replace( /\d+/g, function ( match ) {
return 2 * +match; return 2 * +match;
}); });
} }
}
] ]
}, },
exports: function ( exports ) { exports: function ( exports ) {

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

@ -3,9 +3,11 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'accepts a single transformer function', description: 'accepts a single transformer function',
options: { options: {
plugins: [{
transform: function ( code, path ) { transform: function ( code, path ) {
return code.replace( /MAGIC_NUMBER/g, 3 ); return code.replace( /MAGIC_NUMBER/g, 3 );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.equal( exports.magicNumber, 3 ); assert.equal( exports.magicNumber, 3 );

2
test/function/uses-supplied-ast/_config.js

@ -19,6 +19,7 @@ var modules = {
module.exports = { module.exports = {
description: 'uses supplied AST', description: 'uses supplied AST',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( !importer ) return 'main'; if ( !importer ) return 'main';
return importee; return importee;
@ -30,5 +31,6 @@ module.exports = {
return modules[ id ]; return modules[ id ];
} }
}]
} }
}; };

10
test/sourcemaps/transforms/_config.js

@ -7,15 +7,18 @@ var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
module.exports = { module.exports = {
description: 'preserves sourcemap chains when transforming', description: 'preserves sourcemap chains when transforming',
options: { options: {
transform: [ plugins: [
function ( source, id ) { {
transform: function ( source, id ) {
return babel.transform( source, { return babel.transform( source, {
blacklist: [ 'es6.modules' ], blacklist: [ 'es6.modules' ],
sourceMap: true sourceMap: true
}); });
}
}, },
function ( source, id ) { {
transform: function ( source, id ) {
var s = new MagicString( source ); var s = new MagicString( source );
s.append( '\nassert.equal( 1 + 1, 2 );\nassert.equal( 2 + 2, 4 );' ); s.append( '\nassert.equal( 1 + 1, 2 );\nassert.equal( 2 + 2, 4 );' );
@ -24,6 +27,7 @@ module.exports = {
map: s.generateMap({ hires: true }) map: s.generateMap({ hires: true })
}; };
} }
}
] ]
}, },
test: function ( code, map ) { test: function ( code, map ) {

4
test/test.js

@ -61,10 +61,12 @@ describe( 'rollup', function () {
it( 'fails without options or options.dest', function () { it( 'fails without options or options.dest', function () {
return rollup.rollup({ return rollup.rollup({
entry: 'x', entry: 'x',
plugins: [{
resolveId: function () { return 'test'; }, resolveId: function () { return 'test'; },
load: function () { load: function () {
return '// empty'; return '// empty';
} }
}]
}).then( function ( bundle ) { }).then( function ( bundle ) {
assert.throws( function () { assert.throws( function () {
bundle.write(); bundle.write();
@ -79,10 +81,12 @@ describe( 'rollup', function () {
it( 'expects options.moduleName for IIFE and UMD bundles', function () { it( 'expects options.moduleName for IIFE and UMD bundles', function () {
return rollup.rollup({ return rollup.rollup({
entry: 'x', entry: 'x',
plugins: [{
resolveId: function () { return 'test'; }, resolveId: function () { return 'test'; },
load: function () { load: function () {
return 'export var foo = 42;'; return 'export var foo = 42;';
} }
}]
}).then( function ( bundle ) { }).then( function ( bundle ) {
assert.throws( function () { assert.throws( function () {
bundle.generate({ bundle.generate({

Loading…
Cancel
Save