From d9d49887112a3a7acdfc4f29381c112f1b3dae7d Mon Sep 17 00:00:00 2001 From: Mickael Jeanroy Date: Sun, 5 Apr 2020 22:07:05 +0200 Subject: [PATCH] chore: remove deprecated options and remove support of rollup < 1.x.x --- .DS_Store | Bin 0 -> 6148 bytes src/index-rollup-legacy.js | 103 ------- src/index-rollup-stable.js | 77 ------ src/index.js | 58 +++- src/license-plugin-option.js | 143 +--------- test/index-rollup-legacy.spec.js | 255 ------------------ ...ex-rollup-stable.spec.js => index.spec.js} | 42 +-- test/integration/it.spec.js | 28 -- test/license-plugin-option.spec.js | 193 ------------- test/license-plugin.spec.js | 75 ------ 10 files changed, 63 insertions(+), 911 deletions(-) create mode 100644 .DS_Store delete mode 100644 src/index-rollup-legacy.js delete mode 100644 src/index-rollup-stable.js delete mode 100644 test/index-rollup-legacy.spec.js rename test/{index-rollup-stable.spec.js => index.spec.js} (85%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..28591eab897e700a9c08732cd246384c180c6547 GIT binary patch literal 6148 zcmeHKF;2ul47A}SPNLvS%KZXASe=f7nh$WvAqpY|3DKwH*)X#= 0.48 replace `sourceMap` with `sourcemap`. - // If `sourcemap` is disabled globally, disable it on the plugin. - if (opts.sourceMap === false || opts.sourcemap === false) { - plugin.disableSourceMap(); - } - }, - - /** - * Function called by rollup when the final bundle is generated: it is used - * to prepend the banner file on the generated bundle. - * - * @param {string} code Bundle content. - * @param {Object} outputOptions The options for this output. - * @return {void} - */ - transformBundle(code, outputOptions = {}) { - const sourcemap = outputOptions.sourcemap !== false || outputOptions.sourceMap !== false; - return plugin.prependBanner(code, sourcemap); - }, - - /** - * Function called by rollup when the final bundle will be written on disk: it - * is used to generate a file containing a summary of all third-party dependencies - * with license information. - * - * @return {void} - */ - ongenerate() { - plugin.scanThirdParties(); - }, - }; -} diff --git a/src/index-rollup-stable.js b/src/index-rollup-stable.js deleted file mode 100644 index bff7940d..00000000 --- a/src/index-rollup-stable.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016-2020 Mickael Jeanroy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import _ from 'lodash'; -import {licensePlugin} from './license-plugin.js'; - -/** - * Create rollup plugin compatible with rollup >= 1.0.0 - * - * @param {Object} options Plugin options. - * @return {Object} Plugin instance. - */ -export function licensePluginStable(options = {}) { - const plugin = licensePlugin(options); - - return { - /** - * Name of the plugin, used automatically by rollup. - * @type {string} - */ - name: plugin.name, - - /** - * Function called by rollup when the final bundle is generated: it is used - * to prepend the banner file on the generated bundle. - * - * @param {string} code Bundle content. - * @param {Object} chunk The chunk being generated. - * @param {Object} outputOptions The options for the generated output. - * @return {void} - */ - renderChunk(code, chunk, outputOptions = {}) { - plugin.scanDependencies( - _.chain(chunk.modules) - .toPairs() - .reject((mod) => mod[1].isAsset) - .filter((mod) => mod[1].renderedLength > 0) - .map((mod) => mod[0]) - .value() - ); - - return plugin.prependBanner(code, outputOptions.sourcemap !== false); - }, - - /** - * Function called by rollup when the final bundle will be written on disk: it - * is used to generate a file containing a summary of all third-party dependencies - * with license information. - * - * @return {void} - */ - generateBundle() { - plugin.scanThirdParties(); - }, - }; -} diff --git a/src/index.js b/src/index.js index ecc7511b..0c7ac88c 100644 --- a/src/index.js +++ b/src/index.js @@ -22,14 +22,56 @@ * SOFTWARE. */ +import _ from 'lodash'; +import {licensePlugin} from './license-plugin.js'; -import * as rollup from 'rollup'; -import {licensePluginLegacy} from './index-rollup-legacy'; -import {licensePluginStable} from './index-rollup-stable'; +/** + * Create rollup plugin compatible with rollup >= 1.0.0 + * + * @param {Object} options Plugin options. + * @return {Object} Plugin instance. + */ +export default function rollupPluginLicense(options = {}) { + const plugin = licensePlugin(options); + + return { + /** + * Name of the plugin, used automatically by rollup. + * @type {string} + */ + name: plugin.name, + + /** + * Function called by rollup when the final bundle is generated: it is used + * to prepend the banner file on the generated bundle. + * + * @param {string} code Bundle content. + * @param {Object} chunk The chunk being generated. + * @param {Object} outputOptions The options for the generated output. + * @return {void} + */ + renderChunk(code, chunk, outputOptions = {}) { + plugin.scanDependencies( + _.chain(chunk.modules) + .toPairs() + .reject((mod) => mod[1].isAsset) + .filter((mod) => mod[1].renderedLength > 0) + .map((mod) => mod[0]) + .value() + ); -const VERSION = rollup.VERSION; -const MAJOR_VERSION = VERSION ? Number(VERSION.split('.')[0]) : 0; -const IS_ROLLUP_LEGACY = MAJOR_VERSION === 0; -const plugin = IS_ROLLUP_LEGACY ? licensePluginLegacy : licensePluginStable; + return plugin.prependBanner(code, outputOptions.sourcemap !== false); + }, -export default plugin; + /** + * Function called by rollup when the final bundle will be written on disk: it + * is used to generate a file containing a summary of all third-party dependencies + * with license information. + * + * @return {void} + */ + generateBundle() { + plugin.scanThirdParties(); + }, + }; +} diff --git a/src/license-plugin-option.js b/src/license-plugin-option.js index a3ac59dc..c723c13b 100644 --- a/src/license-plugin-option.js +++ b/src/license-plugin-option.js @@ -116,142 +116,6 @@ function warn(msg) { console.warn(`[${PLUGIN_NAME}] -- ${msg}`); } -/** - * Print a warning related to deprecated property. - * - * @param {string} deprecatedName The deprecated property name. - * @param {*} name The new, non deprecated, name. - * @return {void} - */ -function warnDeprecated(deprecatedName, name) { - warn( - `"${deprecatedName}" has been deprecated and will be removed in a future version, please use "${name}" instead.` - ); -} - -/** - * Fix option object, replace `sourceMap` with `sourcemap` if needed. - * - * Rollup <= 0.48 used `sourceMap` in camelcase, so this plugin used - * this convention at the beginning. - * Now, the `sourcemap` key should be used, but legacy version should still - * be able to use the `sourceMap` key. - * - * @param {Object} options Original option object. - * @return {Object} The new fixed option object. - */ -function fixSourceMapOptions(options) { - if (!_.hasIn(options, 'sourceMap')) { - return options; - } - - // Print a warning to inform consumers that this option has been deprecated. - warnDeprecated('sourceMap', 'sourcemap'); - - // Create new options object without the deprecated `sourceMap` entry. - const newOptions = _.omitBy(options, (value, key) => ( - key === 'sourceMap' - )); - - // If the old `sourceMap` key is used, set it to `sourcemap` key. - // Be careful, do not override `sourcemap` if it already exists. - if (!_.hasIn(newOptions, 'sourcemap')) { - newOptions.sourcemap = options.sourceMap; - } - - return newOptions; -} - -/** - * Fix option object, replace `banner.file` with `banner.content.file` - * and `banner.encoding` with `banner.content.encoding` if needed. - * - * @param {Object} options Original option object. - * @return {Object} The new fixed option object. - */ -function fixBannerOptions(options) { - if (!_.hasIn(options, 'banner')) { - return options; - } - - const banner = options.banner; - const containsDeprecatedFile = _.hasIn(banner, 'file'); - const containsDeprecatedEncoding = _.hasIn(banner, 'encoding'); - - // No need to do anything. - if (!containsDeprecatedFile && !containsDeprecatedEncoding) { - return options; - } - - // Print a warning to inform consumers that this option has been deprecated. - if (containsDeprecatedFile) { - warnDeprecated('banner.file', 'banner.content.file'); - } - - // Print a warning to inform consumers that this option has been deprecated. - if (containsDeprecatedEncoding) { - warnDeprecated('banner.encoding', 'banner.content.encoding'); - } - - // Create new banner object without deprecated entries. - const newBanner = _.omitBy(banner, (value, key) => ( - key === 'file' || key === 'encoding' - )); - - // Migrate deprecated properties to their new versions. - if (!_.hasIn(newBanner, 'content')) { - newBanner.content = _.pick(banner, ['file', 'encoding']); - } - - return _.extend({}, options, { - banner: newBanner, - }); -} - -/** - * Fix option object, replace `thirdParty.encoding` with `thirdParty.output.encoding`. - * - * @param {Object} options Original option object. - * @return {Object} The new fixed option object. - */ -function fixThirdPartyOptions(options) { - if (!_.hasIn(options, 'thirdParty')) { - return options; - } - - const thirdParty = options.thirdParty; - if (!_.hasIn(thirdParty, 'encoding')) { - return options; - } - - warnDeprecated('thirdParty.encoding', 'thirdParty.output.encoding'); - - const newThirdParty = _.omitBy(thirdParty, (value, key) => ( - key === 'encoding' - )); - - if (_.isString(thirdParty.output)) { - newThirdParty.output = { - file: thirdParty.output, - encoding: thirdParty.encoding, - }; - } - - return _.extend({}, options, { - thirdParty: newThirdParty, - }); -} - -/** - * Normalize option object by removing deprecated options and migrate these to the new version. - * - * @param {Object} options Option object. - * @return {Object} Normalized option object. - */ -function normalizeOptions(options) { - return _.reduce([fixSourceMapOptions, fixBannerOptions, fixThirdPartyOptions], (acc, fn) => fn(acc), options); -} - /** * Validate given option object. * @@ -298,9 +162,6 @@ function validateOptions(options) { * @return {Object} New normalized options. */ export function licensePluginOptions(options) { - const normalizedOptions = normalizeOptions(options); - - validateOptions(normalizedOptions); - - return normalizedOptions; + validateOptions(options); + return options; } diff --git a/test/index-rollup-legacy.spec.js b/test/index-rollup-legacy.spec.js deleted file mode 100644 index c4655d15..00000000 --- a/test/index-rollup-legacy.spec.js +++ /dev/null @@ -1,255 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016-2020 Mickael Jeanroy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import path from 'path'; -import fs from 'fs'; -import tmp from 'tmp'; -import {licensePluginLegacy} from '../src/index-rollup-legacy.js'; -import {join} from './utils/join.js'; - -describe('rollup-plugin-license [rollup legacy]', () => { - let tmpDir; - - beforeEach(() => { - tmpDir = tmp.dirSync({ - unsafeCleanup: true, - }); - }); - - afterEach(() => { - tmpDir.removeCallback(); - }); - - it('should return new plugin instance', () => { - const instance = licensePluginLegacy(); - expect(instance.name).toBe('rollup-plugin-license'); - }); - - it('should enable sourceMap if `options.sourceMap` (camelcase) is true', () => { - const instance = licensePluginLegacy(); - const sourceMap = true; - instance.options({sourceMap}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).toBeDefined(); - }); - - it('should enable sourceMap if `options.sourcemap` (lowercase) is true', () => { - const instance = licensePluginLegacy(); - const sourcemap = true; - instance.options({sourcemap}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).toBeDefined(); - }); - - it('should not enable sourceMap if `options.sourceMap` (camelcase) is false', () => { - const instance = licensePluginLegacy(); - const sourceMap = false; - instance.options({sourceMap}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).not.toBeDefined(); - }); - - it('should not enable sourceMap if options.sourcemap (lowercase) is false', () => { - const instance = licensePluginLegacy(); - const sourcemap = false; - instance.options({sourcemap}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).not.toBeDefined(); - }); - - it('should not try to disable sourceMap if `sourceMap` (camelcase) is set in plugin options', () => { - const instance = licensePluginLegacy({ - sourcemap: true, - }); - - instance.options({ - sourceMap: false, - }); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).toBeDefined(); - }); - - it('should not try to disable sourceMap if sourcemap (lowercase) is set in plugin options', () => { - const instance = licensePluginLegacy({ - sourcemap: true, - }); - - instance.options({ - sourcemap: false, - }); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).toBeDefined(); - }); - - it('should enable sourceMap by default', () => { - const instance = licensePluginLegacy(); - - instance.options({}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).toBeDefined(); - }); - - it('should disable sourcemap (lowercase) in plugin options', () => { - const instance = licensePluginLegacy({ - sourcemap: false, - }); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).not.toBeDefined(); - }); - - it('should disable sourceMap (camelcase) in plugin options', () => { - const warn = spyOn(console, 'warn'); - const instance = licensePluginLegacy({ - sourceMap: false, - }); - - const code = 'var foo = 0;'; - const outputOptions = {}; - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).not.toBeDefined(); - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "sourceMap" has been deprecated and will be removed in a future version, ' + - 'please use "sourcemap" instead.' - ); - }); - - it('should scan dependency on load', (done) => { - const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt'); - const instance = licensePluginLegacy({ - thirdParty: { - includePrivate: true, - output: thirdPartyOutput, - }, - }); - - const id = path.join(__dirname, 'fixtures', 'fake-package-1', 'src', 'index.js'); - - instance.load(id); - instance.ongenerate(); - - fs.readFile(thirdPartyOutput, 'utf8', (err, data) => { - if (err) { - done.fail(err); - } - - const content = data.toString(); - expect(content).toBeDefined(); - expect(content).toContain('fake-package'); - done(); - }); - }); - - it('should prepend banner when bundle is transformed', () => { - const banner = 'test banner'; - const instance = licensePluginLegacy({banner}); - - const code = 'var foo = 0;'; - const outputOptions = {}; - - const result = instance.transformBundle(code, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.code).toBe(join([ - '/**', - ' * test banner', - ' */', - '', - 'var foo = 0;', - ])); - }); - - it('should create third-parties file when bundle is generated', (done) => { - const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt'); - const instance = licensePluginLegacy({ - thirdParty: { - output: thirdPartyOutput, - }, - }); - - instance.ongenerate(); - - fs.readFile(thirdPartyOutput, 'utf8', (err, data) => { - if (err) { - done.fail(err); - } - - const content = data.toString(); - expect(content).toBeDefined(); - expect(content.length).not.toBe(0); - done(); - }); - }); -}); diff --git a/test/index-rollup-stable.spec.js b/test/index.spec.js similarity index 85% rename from test/index-rollup-stable.spec.js rename to test/index.spec.js index 4c29e4f3..f50dc990 100644 --- a/test/index-rollup-stable.spec.js +++ b/test/index.spec.js @@ -25,10 +25,10 @@ import path from 'path'; import fs from 'fs'; import tmp from 'tmp'; -import {licensePluginStable} from '../src/index-rollup-stable.js'; +import rollupPluginLicense from '../src/index.js'; import {join} from './utils/join.js'; -describe('rollup-plugin-license [rollup stable]', () => { +describe('rollup-plugin-license', () => { let tmpDir; beforeEach(() => { @@ -42,13 +42,13 @@ describe('rollup-plugin-license [rollup stable]', () => { }); it('should return new plugin instance', () => { - const instance = licensePluginStable(); + const instance = rollupPluginLicense(); expect(instance.name).toBe('rollup-plugin-license'); }); it('should scan dependencies when chunk is rendered', (done) => { const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt'); - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ thirdParty: { includePrivate: true, output: thirdPartyOutput, @@ -86,7 +86,7 @@ describe('rollup-plugin-license [rollup stable]', () => { it('should scan dependencies when chunk is rendered and skip tree-shaken modules', (done) => { const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt'); - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ thirdParty: { includePrivate: true, output: thirdPartyOutput, @@ -134,7 +134,7 @@ describe('rollup-plugin-license [rollup stable]', () => { it('should prepend banner when bundle is transformed', () => { const banner = 'test banner'; - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ banner, }); @@ -157,7 +157,7 @@ describe('rollup-plugin-license [rollup stable]', () => { it('should create third-parties file when bundle is generated', (done) => { const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt'); - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ thirdParty: { output: thirdPartyOutput, }, @@ -193,7 +193,7 @@ describe('rollup-plugin-license [rollup stable]', () => { }); it('should initialize plugin with sourcemap option', () => { - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ sourcemap: true, }); @@ -209,7 +209,7 @@ describe('rollup-plugin-license [rollup stable]', () => { }); it('should enable sourcemap by default', () => { - const instance = licensePluginStable(); + const instance = rollupPluginLicense(); const code = 'var foo = 0;'; const chunk = {}; @@ -223,7 +223,7 @@ describe('rollup-plugin-license [rollup stable]', () => { }); it('should disbable sourcemap (lowercase) in plugin options', () => { - const instance = licensePluginStable({ + const instance = rollupPluginLicense({ sourcemap: false, }); @@ -238,28 +238,8 @@ describe('rollup-plugin-license [rollup stable]', () => { expect(result.map).not.toBeDefined(); }); - it('should disable sourceMap (camelcase) in plugin options', () => { - const warn = spyOn(console, 'warn'); - const instance = licensePluginStable({ - sourceMap: false, - }); - - const code = 'var foo = 0;'; - const chunk = {}; - const outputOptions = {}; - const result = instance.renderChunk(code, chunk, outputOptions); - - expect(result).toBeDefined(); - expect(result.code).toBeDefined(); - expect(result.map).not.toBeDefined(); - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "sourceMap" has been deprecated and will be removed in a future version, ' + - 'please use "sourcemap" instead.' - ); - }); - it('should disable sourcemap using output options', () => { - const instance = licensePluginStable(); + const instance = rollupPluginLicense(); const code = 'var foo = 0;'; const chunk = {}; diff --git a/test/integration/it.spec.js b/test/integration/it.spec.js index a62c8af4..ac751767 100644 --- a/test/integration/it.spec.js +++ b/test/integration/it.spec.js @@ -181,34 +181,6 @@ describe('rollup-plugin-license', () => { }); }); - it('should generate bundle with license header from given file', (done) => { - const banner = { - file: path.join(__dirname, '..', 'fixtures', 'banner.txt'), - encoding: 'utf-8', - }; - - const rollupConfig = createRollupConfig({ - banner, - }); - - writeBundle(rollupConfig).then(() => { - verifyFile(rollupConfig.output.file, done, (data) => { - expect(data.toString()).toContain(join([ - '/**', - ' * Test banner.', - ' *', - ' * With a second line.', - ' */', - ])); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.file" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.file" instead.' - ); - }); - }); - }); - it('should generate bundle with license header from content as a raw string', (done) => { const content = 'Banner from inline content'; const banner = {content}; diff --git a/test/license-plugin-option.spec.js b/test/license-plugin-option.spec.js index 3ead1178..edbf8a71 100644 --- a/test/license-plugin-option.spec.js +++ b/test/license-plugin-option.spec.js @@ -97,199 +97,6 @@ describe('licensePluginOptions', () => { expect(warn).not.toHaveBeenCalledWith(); }); - it('should normalize option object and fix deprecated "sourceMap" entry', () => { - const warn = spyOn(console, 'warn'); - const options = { - sourceMap: true, - }; - - const result = licensePluginOptions(options); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "sourceMap" has been deprecated and will be removed in a future version, ' + - 'please use "sourcemap" instead.' - ); - - expect(result).toEqual({ - sourcemap: true, - }); - }); - - it('should normalize option object and fix deprecated "banner.file" entry', () => { - const warn = spyOn(console, 'warn'); - const options = { - banner: { - file: 'LICENSE.md', - }, - }; - - const result = licensePluginOptions(options); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.file" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.file" instead.' - ); - - expect(result).toEqual({ - banner: { - content: { - file: 'LICENSE.md', - }, - }, - }); - - // Ensure original option object has not changed - expect(options).toEqual({ - banner: { - file: 'LICENSE.md', - }, - }); - }); - - it('should normalize option object and fix deprecated "thirdParty.encoding" entry', () => { - const warn = spyOn(console, 'warn'); - const options = { - thirdParty: { - output: 'ThirdParty.txt', - encoding: 'utf-16', - }, - }; - - const result = licensePluginOptions(options); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "thirdParty.encoding" has been deprecated and will be removed in a future version, ' + - 'please use "thirdParty.output.encoding" instead.' - ); - - expect(result).toEqual({ - thirdParty: { - output: { - file: 'ThirdParty.txt', - encoding: 'utf-16', - }, - }, - }); - - // Ensure original option object has not changed - expect(options).toEqual({ - thirdParty: { - output: 'ThirdParty.txt', - encoding: 'utf-16', - }, - }); - }); - - it('should normalize option object and fix deprecated "banner.encoding" entry', () => { - const warn = spyOn(console, 'warn'); - const options = { - banner: { - encoding: 'utf-16', - }, - }; - - const result = licensePluginOptions(options); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.encoding" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.encoding" instead.' - ); - - expect(result).toEqual({ - banner: { - content: { - encoding: 'utf-16', - }, - }, - }); - - // Ensure original option object has not changed - expect(options).toEqual({ - banner: { - encoding: 'utf-16', - }, - }); - }); - - it('should normalize option object, fix and warn about all deprecated properties', () => { - const warn = spyOn(console, 'warn'); - const options = { - sourceMap: true, - cwd: '.', - debug: true, - - banner: { - file: 'LICENSE.md', - encoding: 'utf-16', - commentStyle: 'regular', - }, - - thirdParty: { - output: 'ThirdParty.txt', - encoding: 'utf-8', - }, - }; - - const result = licensePluginOptions(options); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "sourceMap" has been deprecated and will be removed in a future version, ' + - 'please use "sourcemap" instead.' - ); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.file" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.file" instead.' - ); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.encoding" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.encoding" instead.' - ); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "thirdParty.encoding" has been deprecated and will be removed in a future version, ' + - 'please use "thirdParty.output.encoding" instead.' - ); - - expect(result).toEqual({ - sourcemap: true, - cwd: '.', - debug: true, - - banner: { - commentStyle: 'regular', - content: { - file: 'LICENSE.md', - encoding: 'utf-16', - }, - }, - - thirdParty: { - output: { - file: 'ThirdParty.txt', - encoding: 'utf-8', - }, - }, - }); - - // Ensure original option object has not changed - expect(options).toEqual({ - sourceMap: true, - cwd: '.', - debug: true, - banner: { - file: 'LICENSE.md', - encoding: 'utf-16', - commentStyle: 'regular', - }, - thirdParty: { - output: 'ThirdParty.txt', - encoding: 'utf-8', - }, - }); - }); - it('should validate option object when output is an array', () => { const options = { thirdParty: { diff --git a/test/license-plugin.spec.js b/test/license-plugin.spec.js index 9ccc9255..815a9777 100644 --- a/test/license-plugin.spec.js +++ b/test/license-plugin.spec.js @@ -72,19 +72,6 @@ describe('LicensePlugin', () => { expect(plugin._dependencies).toEqual({}); }); - it('should print warning when plugin is used with sourceMap (camelcase)', () => { - const warn = spyOn(console, 'warn'); - - licensePlugin({ - sourceMap: false, - }); - - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "sourceMap" has been deprecated and will be removed in a future version, ' + - 'please use "sourcemap" instead.' - ); - }); - it('should print warning with unknown options', () => { const warn = spyOn(console, 'warn'); @@ -436,13 +423,11 @@ describe('LicensePlugin', () => { }); describe('with banner option', () => { - let warn; let code; let bannerJs; let bannerTxt; beforeEach(() => { - warn = spyOn(console, 'warn'); code = 'var foo = 0;'; bannerJs = path.join(__dirname, 'fixtures', 'banner.js'); bannerTxt = path.join(__dirname, 'fixtures', 'banner.txt'); @@ -480,43 +465,6 @@ describe('LicensePlugin', () => { expect(readFileSync).toHaveBeenCalledWith(jasmine.any(String), encoding); }); - it('should prepend banner to bundle from (deprecated) file option', () => { - const instance = licensePlugin({ - banner: { - file: bannerJs, - }, - }); - - const result = instance.prependBanner(code); - - verifyResult(result); - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.file" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.file" instead.' - ); - }); - - - it('should prepend banner to bundle with (deprecated) custom encoding option', () => { - const readFileSync = spyOn(fs, 'readFileSync').and.callThrough(); - const encoding = 'ascii'; - const instance = licensePlugin({ - banner: { - file: bannerJs, - encoding, - }, - }); - - const result = instance.prependBanner(code); - - verifyResult(result); - expect(readFileSync).toHaveBeenCalledWith(jasmine.any(String), encoding); - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "banner.file" has been deprecated and will be removed in a future version, ' + - 'please use "banner.content.file" instead.' - ); - }); - it('should fail to prepend banner without any content', () => { const instance = licensePlugin({ banner: { @@ -951,29 +899,6 @@ describe('LicensePlugin', () => { }); }); - it('should export list of dependencies with (deprecated) custom encoding to given file', (done) => { - const warn = spyOn(console, 'warn'); - const output = path.join(tmpDir.name, 'third-party.txt'); - const encoding = 'base64'; - const instance = licensePlugin({ - thirdParty: { - output, - encoding, - }, - }); - - instance.addDependency(pkg1); - instance.scanThirdParties(); - - verifyFileWithEncoding(output, encoding, done, (content) => { - expect(content).toContain('foo'); - expect(warn).toHaveBeenCalledWith( - '[rollup-plugin-license] -- "thirdParty.encoding" has been deprecated and will be removed in a future version, ' + - 'please use "thirdParty.output.encoding" instead.' - ); - }); - }); - it('should export default message without any dependencies', (done) => { const file = path.join(tmpDir.name, 'third-party.txt'); const instance = licensePlugin({