From 3a7322499035b0d030e38f7a4fca8eb38cc3a94c Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 18 Sep 2016 12:24:17 -0400 Subject: [PATCH] =?UTF-8?q?ensure=20bundle=20ends=20with=20newline=20?= =?UTF-8?q?=E2=80=93=20fixes=20#958?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Bundle.js | 1 + src/rollup.js | 2 +- test/test.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Bundle.js b/src/Bundle.js index d56f4a5..a4e8c53 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -431,6 +431,7 @@ export default class Bundle { timeEnd( 'sourceMap' ); } + if ( code[ code.length - 1 ] !== '\n' ) code += '\n'; return { code, map }; } diff --git a/src/rollup.js b/src/rollup.js index be39d0b..0868960 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -108,7 +108,7 @@ export function rollup ( options ) { promises.push( writeFile( dest + '.map', map.toString() ) ); } - code += `\n//# ${SOURCEMAPPING_URL}=${url}\n`; + code += `//# ${SOURCEMAPPING_URL}=${url}\n`; } promises.push( writeFile( dest, code ) ); diff --git a/test/test.js b/test/test.js index 5876435..52cc00e 100644 --- a/test/test.js +++ b/test/test.js @@ -102,6 +102,16 @@ describe( 'rollup', function () { plugins: [ loader({ x: `var a = null; a = 'a string';` }) ] }); }); + + it( 'includes a newline at the end of the bundle', () => { + return rollup.rollup({ + entry: 'x', + plugins: [ loader({ x: `console.log( 42 );` }) ] + }).then( bundle => { + const { code } = bundle.generate({ format: 'iife' }); + assert.ok( code[ code.length - 1 ] === '\n' ); + }); + }); }); describe( 'bundle.write()', () => {