Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #151 from Comandeer/t/146
Browse files Browse the repository at this point in the history
Fix for banner outputted twice
  • Loading branch information
Comandeer committed Mar 8, 2019
2 parents 74732ed + 7c914bd commit 0e739ec
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

---

## [8.0.0] – 2019-03-08
### Fixed
* [#146] Banner is outputted twice.

### Changed
* [#146] **BREAKING CHANGE**: bump Rollup dependency to `^1.6.0`.

## [7.0.0] – 2019-01-17
### Added
* [#143] **BREAKING CHANGE**: add support for Rollup `^1.0.0`.
Expand Down Expand Up @@ -164,7 +171,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#138]: https://github.com/Comandeer/rollup-plugin-babel-minify/issues/138
[#143]: https://github.com/Comandeer/rollup-plugin-babel-minify/pull/143
[#144]: https://github.com/Comandeer/rollup-plugin-babel-minify/issues/144
[#146]: https://github.com/Comandeer/rollup-plugin-babel-minify/issues/146

[8.0.0]: https://github.com/Comandeer/rollup-plugin-babel-minify/compare/v7.0.0...v8.0.0
[7.0.0]: https://github.com/Comandeer/rollup-plugin-babel-minify/compare/v6.2.0...v7.0.0
[6.2.0]: https://github.com/Comandeer/rollup-plugin-babel-minify/compare/v6.1.1...v6.2.0
[6.1.1]: https://github.com/Comandeer/rollup-plugin-babel-minify/compare/v6.1.0...v6.1.1
Expand Down
22 changes: 14 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -66,7 +66,7 @@
"scope": "\\S+.*"
},
"peerDependencies": {
"rollup": "^1.0.0"
"rollup": "^1.6.0"
},
"devDependencies": {
"@babel/plugin-syntax-async-generators": "^7.2.0",
Expand All @@ -84,7 +84,7 @@
"mocha": "^6.0.0",
"nyc": "^13.0.1",
"rimraf": "^2.6.2",
"rollup": "^1.0.0",
"rollup": "^1.6.0",
"sourcemap-validator": "^1.0.6"
},
"config": {
Expand Down
13 changes: 12 additions & 1 deletion src/index.js
Expand Up @@ -9,10 +9,21 @@ import { isFn } from './utils.js';
import { isFnOrString } from './utils.js';

function minify( options = {} ) {
let bundleBanner;

return {
name: 'babel-minify',

renderChunk( bundle, chunkInfo, { banner: bundleBanner } ) {
outputOptions( outputOptions ) {
const result = Object.assign( {}, outputOptions );
bundleBanner = result.banner;

delete result.banner;

return result;
},

renderChunk( bundle ) {
const minifyOptions = filterMinifyOptions( options );
const babelConf = {
presets: [ [ minifyPreset, minifyOptions ] ],
Expand Down
26 changes: 26 additions & 0 deletions tests/banner.js
Expand Up @@ -51,6 +51,32 @@ describe( 'banner and comments support', () => {
} );
} );

// #146
it( 'adds banner inherited from bundle.generate only once when comments are enabled', () => {
const rollupOptions = Object.assign( {}, defaultRollupOptions );
// Plugin adding banner dynamically is used to ensure that test passes due to fix,
// not due to the fact that plugin does not insert banner on its own, causing that
// banner is inserted only once (by Rollup).
const bannerPlugin = {
outputOptions( outputOptions ) {
return Object.assign( {}, outputOptions, {
banner: '/* hublabubla */'
} );
}
};

rollupOptions.plugins = [ ... rollupOptions.plugins ];
rollupOptions.plugins.unshift( bannerPlugin );

return createTransformTest( {
rollupOptions,
bundleOptions: defaultBundleOptions
} ).then( ( { bundle } ) => {
expect( bundle.code ).to.match( /^\/\* hublabubla \*\// );
expect( bundle.code ).not.to.match( /^(\/\* hublabubla \*\/\s*){2,}/ );
} );
} );

it( 'adds banner inherited from root configuration', () => {
const bannerOptions = {
output: {
Expand Down
10 changes: 10 additions & 0 deletions tests/cli.js
Expand Up @@ -60,6 +60,16 @@ describe( 'Rollup CLI', () => {
} );
} );

// #146
it( 'banner inherited not outputted twice', () => {
return executeRollupCmd( 'bannerInheritTwice' ).then( () => {
const { [ 'bundle.js' ]: code } = getArtifacts();

expect( code ).to.match( /^\/\* hublabubla \*\// );
expect( code ).not.to.match( /^(\/\* hublabubla \*\/\s*){2,}/ );
} );
} );

// #139
it( 'multiple chunks (dynamic import)', () => {
const artifacts = [
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/simple-project/rollup.config.bannerInheritTwice.js
@@ -0,0 +1,24 @@
import minify from '../../../dist/rollup-plugin-babel-minify.es2015.js';

export default {
input: 'index.js',
plugins: [
// Plugin adding banner dynamically is used to ensure that test passes due to fix,
// not due to the fact that plugin does not insert banner on its own, causing that
// banner is inserted only once (by Rollup).
{
outputOptions( outputOptions ) {
return Object.assign( {}, outputOptions, {
banner: '/* hublabubla */'
} );
}
},

minify()
],
output: {
sourcemap: true,
file: 'bundle.js',
format: 'es'
}
};

0 comments on commit 0e739ec

Please sign in to comment.