Browse Source

Merge pull request #1223 from rollup/gh-986

Populate file property of sourcemaps when plugins are involved
gh-1187
Rich Harris 8 years ago
committed by GitHub
parent
commit
46f5dbf67c
  1. 2
      src/Bundle.js
  2. 4
      src/utils/collapseSourcemaps.js
  3. 15
      test/sourcemaps/sourcemap-file/_config.js
  4. 1
      test/sourcemaps/sourcemap-file/main.js
  5. 2
      test/test.js

2
src/Bundle.js

@ -515,7 +515,7 @@ export default class Bundle {
if ( file ) file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file ); if ( file ) file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file );
if ( this.hasLoaders || find( this.plugins, plugin => plugin.transform || plugin.transformBundle ) ) { if ( this.hasLoaders || find( this.plugins, plugin => plugin.transform || plugin.transformBundle ) ) {
map = magicString.generateMap( {} ); map = magicString.generateMap({});
if ( typeof map.mappings === 'string' ) { if ( typeof map.mappings === 'string' ) {
map.mappings = decode( map.mappings ); map.mappings = decode( map.mappings );
} }

4
src/utils/collapseSourcemaps.js

@ -1,6 +1,6 @@
import { encode } from 'sourcemap-codec'; import { encode } from 'sourcemap-codec';
import error from './error.js'; import error from './error.js';
import { dirname, relative, resolve } from './path.js'; import { basename, dirname, relative, resolve } from './path.js';
class Source { class Source {
constructor ( filename, content ) { constructor ( filename, content ) {
@ -159,6 +159,8 @@ export default function collapseSourcemaps ( bundle, file, map, modules, bundleS
if ( file ) { if ( file ) {
const directory = dirname( file ); const directory = dirname( file );
sources = sources.map( source => relative( directory, source ) ); sources = sources.map( source => relative( directory, source ) );
map.file = basename( file );
} }
// we re-use the `map` object because it has convenient toString/toURL methods // we re-use the `map` object because it has convenient toString/toURL methods

15
test/sourcemaps/sourcemap-file/_config.js

@ -0,0 +1,15 @@
const assert = require( 'assert' );
module.exports = {
description: 'populates file property of sourcemap when plugins are used (#986)',
options: {
plugins: [
{
transform () {}
}
]
},
test: ( code, map, profile ) => {
assert.equal( map.file, `bundle.${profile.format}.js` );
}
};

1
test/sourcemaps/sourcemap-file/main.js

@ -0,0 +1 @@
console.log( 42 );

2
test/test.js

@ -461,7 +461,7 @@ describe( 'rollup', function () {
if ( config.test ) { if ( config.test ) {
const { code, map } = bundle.generate( options ); const { code, map } = bundle.generate( options );
config.test( code, map ); config.test( code, map, profile );
} }
if ( config.warnings ) { if ( config.warnings ) {

Loading…
Cancel
Save