Skip to content

Commit

Permalink
chore: remove deprecated options and remove support of rollup < 1.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Apr 5, 2020
1 parent 266ab96 commit d9d4988
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 911 deletions.
Binary file added .DS_Store
Binary file not shown.
103 changes: 0 additions & 103 deletions src/index-rollup-legacy.js

This file was deleted.

77 changes: 0 additions & 77 deletions src/index-rollup-stable.js

This file was deleted.

58 changes: 50 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
};
}
Loading

0 comments on commit d9d4988

Please sign in to comment.