diff --git a/src/index.js b/src/index.js index b3e565ec..4c904b79 100644 --- a/src/index.js +++ b/src/index.js @@ -60,8 +60,9 @@ module.exports = (options = {}) => { } // Rollup >= 0.48 replace `sourceMap` with `sourcemap`. - if (opts.sourceMap || opts.sourcemap) { - plugin.enableSourceMap(); + // If `sourcemap` is disabled globally, disable it on the plugin. + if (opts.sourceMap === false || opts.sourcemap === false) { + plugin.disableSourceMap(); } }, diff --git a/src/license-plugin.js b/src/license-plugin.js index 99c52332..0c20d8a6 100644 --- a/src/license-plugin.js +++ b/src/license-plugin.js @@ -48,7 +48,7 @@ class LicensePlugin { this.name = 'rollup-plugin-license'; this._options = options; - this._sourceMap = false; + this._sourceMap = true; this._cwd = process.cwd(); this._dependencies = {}; this._pkg = require(path.join(this._cwd, 'package.json')); @@ -65,8 +65,8 @@ class LicensePlugin { * * @return {void} */ - enableSourceMap() { - this._sourceMap = true; + disableSourceMap() { + this._sourceMap = false; } /** diff --git a/test/index.spec.js b/test/index.spec.js index 9a464d21..73a2a949 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -45,7 +45,7 @@ describe('rollup-plugin-license', () => { }); it('should enable sourceMap if options.sourceMap is true', () => { - spyOn(LicensePlugin.prototype, 'enableSourceMap').and.callThrough(); + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); const instance = plugin(); const result = instance.options({ @@ -53,11 +53,11 @@ describe('rollup-plugin-license', () => { }); expect(result).not.toBeDefined(); - expect(LicensePlugin.prototype.enableSourceMap).toHaveBeenCalledWith(); + expect(LicensePlugin.prototype.disableSourceMap).not.toHaveBeenCalled(); }); it('should enable sourceMap if options.sourcemap (lowercase) is true', () => { - spyOn(LicensePlugin.prototype, 'enableSourceMap').and.callThrough(); + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); const instance = plugin(); const result = instance.options({ @@ -65,11 +65,11 @@ describe('rollup-plugin-license', () => { }); expect(result).not.toBeDefined(); - expect(LicensePlugin.prototype.enableSourceMap).toHaveBeenCalledWith(); + expect(LicensePlugin.prototype.disableSourceMap).not.toHaveBeenCalled(); }); it('should not enable sourceMap if options.sourceMap is false', () => { - spyOn(LicensePlugin.prototype, 'enableSourceMap').and.callThrough(); + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); const instance = plugin(); const result = instance.options({ @@ -77,27 +77,39 @@ describe('rollup-plugin-license', () => { }); expect(result).not.toBeDefined(); - expect(LicensePlugin.prototype.enableSourceMap).not.toHaveBeenCalled(); + expect(LicensePlugin.prototype.disableSourceMap).toHaveBeenCalledWith(); }); - it('should not enable sourceMap by default', () => { - spyOn(LicensePlugin.prototype, 'enableSourceMap').and.callThrough(); + it('should not enable sourceMap if options.sourcemap (lowercase) is false', () => { + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); + + const instance = plugin(); + const result = instance.options({ + sourcemap: false, + }); + + expect(result).not.toBeDefined(); + expect(LicensePlugin.prototype.disableSourceMap).toHaveBeenCalledWith(); + }); + + it('should enable sourceMap by default', () => { + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); const instance = plugin(); const result = instance.options({}); expect(result).not.toBeDefined(); - expect(LicensePlugin.prototype.enableSourceMap).not.toHaveBeenCalled(); + expect(LicensePlugin.prototype.disableSourceMap).not.toHaveBeenCalled(); }); - it('should not enable sourceMap if options is not set', () => { - spyOn(LicensePlugin.prototype, 'enableSourceMap').and.callThrough(); + it('should enable sourceMap if options is not set', () => { + spyOn(LicensePlugin.prototype, 'disableSourceMap').and.callThrough(); const instance = plugin(); const result = instance.options(); expect(result).not.toBeDefined(); - expect(LicensePlugin.prototype.enableSourceMap).not.toHaveBeenCalled(); + expect(LicensePlugin.prototype.disableSourceMap).not.toHaveBeenCalled(); }); it('should prepend banner when bundle is transformed', () => { diff --git a/test/license-plugin.spec.js b/test/license-plugin.spec.js index fa4b882d..cb6e35e9 100644 --- a/test/license-plugin.spec.js +++ b/test/license-plugin.spec.js @@ -42,16 +42,16 @@ describe('LicensePlugin', () => { const plugin = new LicensePlugin(); expect(plugin._cwd).toBeDefined(); expect(plugin._pkg).toBeDefined(); - expect(plugin._sourceMap).toBe(false); + expect(plugin._sourceMap).toBe(true); expect(plugin._dependencies).toEqual({}); }); - it('should enable source map', () => { + it('should disable source map', () => { const plugin = new LicensePlugin(); - expect(plugin._sourceMap).toBe(false); - - plugin.enableSourceMap(); expect(plugin._sourceMap).toBe(true); + + plugin.disableSourceMap(); + expect(plugin._sourceMap).toBe(false); }); it('should load pkg', () => { @@ -341,7 +341,7 @@ describe('LicensePlugin', () => { const result = instance.prependBanner(code); expect(result).toBeDefined(); - expect(result.map).not.toBeDefined(); + expect(result.map).toBeDefined(); expect(result.code).toEqual( `/**\n` + ` * Test banner.\n` + @@ -365,7 +365,7 @@ describe('LicensePlugin', () => { const result = instance.prependBanner(code); expect(result).toBeDefined(); - expect(result.map).not.toBeDefined(); + expect(result.map).toBeDefined(); expect(result.code).toEqual( `/**\n` + ` * Test banner.\n` + @@ -394,7 +394,7 @@ describe('LicensePlugin', () => { expect(fs.readFileSync).toHaveBeenCalledWith(jasmine.any(String), encoding); expect(result).toBeDefined(); - expect(result.map).not.toBeDefined(); + expect(result.map).toBeDefined(); expect(result.code).toEqual( `/**\n` + ` * Test banner.\n` + @@ -406,20 +406,20 @@ describe('LicensePlugin', () => { ); }); - it('should prepend banner to bundle with source map', () => { + it('should prepend banner to bundle without source map', () => { const instance = new LicensePlugin({ banner: { file: path.join(__dirname, 'fixtures', 'banner.js'), }, }); - instance.enableSourceMap(); + instance.disableSourceMap(); const code = 'var foo = 0;'; const result = instance.prependBanner(code); expect(result).toBeDefined(); - expect(result.map).toBeDefined(); + expect(result.map).not.toBeDefined(); expect(result.code).toEqual( `/**\n` + ` * Test banner.\n` + @@ -433,7 +433,6 @@ describe('LicensePlugin', () => { it('should not prepend default banner to bundle', () => { const instance = new LicensePlugin(); - instance.enableSourceMap(); const code = 'var foo = 0;'; const result = instance.prependBanner(code); @@ -451,8 +450,6 @@ describe('LicensePlugin', () => { }, }); - instance.enableSourceMap(); - const code = 'var foo = 0;'; const result = instance.prependBanner(code); @@ -492,8 +489,6 @@ describe('LicensePlugin', () => { }, }); - instance.enableSourceMap(); - const code = 'var foo = 0;'; const result = instance.prependBanner(code);