Skip to content

Commit

Permalink
fix: always generate sourceMap
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Nov 25, 2016
1 parent 22cd04f commit d674531
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
27 changes: 11 additions & 16 deletions src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ class LicensePlugin {
prependBanner(code) {
const banner = this._options.banner;
const file = banner ? banner.file : banner;
const result = {code};

// Create a magicString: do not manipulate the string directly since it
// will be used to generate the sourcemap.
const magicString = new MagicString(code);

if (file) {
const filePath = path.resolve(file);
Expand All @@ -148,26 +151,18 @@ class LicensePlugin {
banner = generateBlockComment(banner);
}

// Create a magicString: do not manipulate the string directly since it
// will be used to generate the sourcemap.
const magicString = new MagicString(code);

// Prepend the banner.
magicString.prepend(`${banner}${EOL}`);

// Create the result object.
result.code = magicString.toString();

// Add sourceMap information if it is enabled.
if (this._options.sourceMap !== false) {
result.map = magicString.generateMap({
hires: true,
});
}
}
}

return result;
return {
code: magicString.toString(),
map: magicString.generateMap({
includeContent: true,
hires: true,
}),
};
}

/**
Expand Down
19 changes: 2 additions & 17 deletions test/license-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ describe('LicensePlugin', () => {

expect(result).toBeDefined();
expect(result.code).toBeDefined();
expect(result.map).toBeDefined();
expect(result.code).toBe(code);
});

Expand All @@ -368,6 +369,7 @@ describe('LicensePlugin', () => {

expect(result).toBeDefined();
expect(result.code).toBeDefined();
expect(result.map).toBeDefined();
expect(result.code).toBe(code);
});

Expand Down Expand Up @@ -410,23 +412,6 @@ describe('LicensePlugin', () => {
expect(result.map).toBeDefined();
});

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

const code = 'var foo = 0;';

const result = instance.prependBanner(code);

expect(result).toBeDefined();
expect(result.code).toBeDefined();
expect(result.map).not.toBeDefined();
});

it('should prepend banner and replace moment variables', () => {
const instance = new LicensePlugin({
banner: {
Expand Down

0 comments on commit d674531

Please sign in to comment.