Skip to content

Commit

Permalink
refactor: banner file option is inside a banner field
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Nov 24, 2016
1 parent 2fec575 commit ebbff0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class LicensePlugin {
* @return {Object} The result containing the code and, optionnally, the source map.
*/
transformBundle(code) {
const file = this._options.file;
const banner = this._options.banner;
const file = banner ? banner.file : banner;
const result = {code};

if (file) {
Expand Down
32 changes: 24 additions & 8 deletions test/license-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ describe('LicensePlugin', () => {

it('should prepend banner to bundle', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner.js'),
},
});

const code = 'var foo = 0;';
Expand Down Expand Up @@ -355,7 +357,9 @@ describe('LicensePlugin', () => {

it('should not fail if banner file does not exist', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'dummy'),
banner: {
file: path.join(__dirname, 'fixtures', 'dummy'),
},
});

const code = 'var foo = 0;';
Expand All @@ -369,7 +373,9 @@ describe('LicensePlugin', () => {

it('should prepend banner and create block comment', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner.txt'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner.txt'),
},
});

const code = 'var foo = 0;';
Expand All @@ -390,7 +396,9 @@ describe('LicensePlugin', () => {

it('should prepend banner to bundle and create sourceMap', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner.js'),
},
});

const code = 'var foo = 0;';
Expand All @@ -405,7 +413,9 @@ describe('LicensePlugin', () => {
it('should prepend banner to bundle and do not create sourceMap', () => {
const instance = new LicensePlugin({
sourceMap: false,
file: path.join(__dirname, 'fixtures', 'banner.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner.js'),
},
});

const code = 'var foo = 0;';
Expand All @@ -419,7 +429,9 @@ describe('LicensePlugin', () => {

it('should prepend banner and replace moment variables', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner-with-moment.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner-with-moment.js'),
},
});

const code = 'var foo = 0;';
Expand All @@ -438,7 +450,9 @@ describe('LicensePlugin', () => {

it('should prepend banner and replace package variables', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner-with-pkg.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner-with-pkg.js'),
},
});

const code = 'var foo = 0;';
Expand All @@ -457,7 +471,9 @@ describe('LicensePlugin', () => {

it('should prepend banner and replace dependencies placeholders', () => {
const instance = new LicensePlugin({
file: path.join(__dirname, 'fixtures', 'banner-with-dependencies.js'),
banner: {
file: path.join(__dirname, 'fixtures', 'banner-with-dependencies.js'),
},
});

// Load a dependency
Expand Down

0 comments on commit ebbff0a

Please sign in to comment.