Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mjeanroy/rollup-plugin-license
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.9.0
Choose a base ref
...
head repository: mjeanroy/rollup-plugin-license
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.9.1
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Oct 31, 2022

  1. Copy the full SHA
    0bcc7f1 View commit details
  2. Copy the full SHA
    0719283 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3c6f67e View commit details
  4. release: release version

    mjeanroy committed Oct 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b1d4a26 View commit details
Showing with 182 additions and 158 deletions.
  1. +105 −155 dist/index.js
  2. +2 −1 package.json
  3. +11 −2 src/license-plugin.js
  4. +30 −0 test/integration/bundle-virtual.js
  5. +34 −0 test/integration/it.spec.js
260 changes: 105 additions & 155 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-license",
"version": "2.9.0",
"version": "2.9.1",
"description": "Rollup plugin to add license banner to the final bundle and output third party licenses",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -53,6 +53,7 @@
"@rollup/plugin-babel": "6.0.2",
"@rollup/plugin-commonjs": "23.0.2",
"@rollup/plugin-node-resolve": "15.0.1",
"@rollup/plugin-virtual": "3.0.1",
"@typescript-eslint/eslint-plugin": "5.41.0",
"@typescript-eslint/parser": "5.41.0",
"babel-plugin-add-module-exports": "1.0.4",
13 changes: 11 additions & 2 deletions src/license-plugin.js
Original file line number Diff line number Diff line change
@@ -143,14 +143,21 @@ class LicensePlugin {
this.debug(`scanning internal module ${id}`);
}

if (id.indexOf('virtual:') === 0) {
this.debug(`skipping virtual module: ${id}`);
return;
}

this.debug(`scanning ${id}`);

// Look for the `package.json` file
let dir = path.parse(id).dir;
let dir = path.resolve(path.parse(id).dir);
let pkg = null;

const scannedDirs = [];

this.debug(`iterative over directory tree, starting with: ${dir}`);

while (dir && dir !== this._cwd && !scannedDirs.includes(dir)) {
// Try the cache.
if (_.has(this._cache, dir)) {
@@ -165,6 +172,7 @@ class LicensePlugin {

scannedDirs.push(dir);

this.debug(`looking for package.json file in: ${dir}`);
const pkgPath = path.join(dir, 'package.json');
const exists = fs.existsSync(pkgPath);
if (exists) {
@@ -207,7 +215,8 @@ class LicensePlugin {
}

// Go up in the directory tree.
dir = path.normalize(path.join(dir, '..'));
dir = path.resolve(path.join(dir, '..'));
this.debug(`going up in the directory tree: ${dir}`);
}

// Update the cache
30 changes: 30 additions & 0 deletions test/integration/bundle-virtual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2022 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 reduce from 'lodash/reduce';

// eslint-disable-next-line require-jsdoc
export function sum(array) {
return reduce(array, (acc, x) => acc + x, 0);
}
34 changes: 34 additions & 0 deletions test/integration/it.spec.js
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ import _ from 'lodash';
import * as rollup from 'rollup';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import virtual from '@rollup/plugin-virtual';
import licensePlugin from '../../src/index.js';
import {join} from '../utils/join.js';

@@ -181,6 +182,39 @@ describe('rollup-plugin-license', () => {
});
});

it('should generate bundle with license header ignoring virtual modules', (done) => {
const banner = 'test banner';
const rollupConfig = {
input: path.join(__dirname, 'bundle-virtual.js'),

output: {
file: path.join(tmpDir.name, 'bundle-virtual.js'),
format: 'es',
},

plugins: [
virtual({
'lodash/reduce': `
export default () => {};
`,
}),
licensePlugin({
banner,
}),
],
};

writeBundle(rollupConfig).then(() => {
verifyFile(rollupConfig.output.file, done, (data) => {
expect(data.toString()).toContain(join([
`/**`,
` * ${banner}`,
` */`,
]));
});
});
});

it('should generate bundle with license header from content as a raw string', (done) => {
const content = 'Banner from inline content';
const banner = {content};