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: v3.5.1
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: v3.5.2
Choose a head ref
  • 6 commits
  • 7 files changed
  • 2 contributors

Commits on Jun 23, 2024

  1. Copy the full SHA
    12f9c0c View commit details

Commits on Jun 26, 2024

  1. chore(deps-dev): bump the typescript-eslint group with 2 updates (#1752)

    Bumps the typescript-eslint group with 2 updates: [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) and [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser).
    
    
    Updates `@typescript-eslint/eslint-plugin` from 7.13.1 to 7.14.1
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.14.1/packages/eslint-plugin)
    
    Updates `@typescript-eslint/parser` from 7.13.1 to 7.14.1
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.14.1/packages/parser)
    
    ---
    updated-dependencies:
    - dependency-name: "@typescript-eslint/eslint-plugin"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: typescript-eslint
    - dependency-name: "@typescript-eslint/parser"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: typescript-eslint
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 26, 2024
    Copy the full SHA
    c905ef6 View commit details

Commits on Jul 2, 2024

  1. chore(deps-dev): bump the typescript-eslint group with 2 updates (#1754)

    Bumps the typescript-eslint group with 2 updates: [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) and [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser).
    
    
    Updates `@typescript-eslint/eslint-plugin` from 7.14.1 to 7.15.0
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.15.0/packages/eslint-plugin)
    
    Updates `@typescript-eslint/parser` from 7.14.1 to 7.15.0
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.15.0/packages/parser)
    
    ---
    updated-dependencies:
    - dependency-name: "@typescript-eslint/eslint-plugin"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: typescript-eslint
    - dependency-name: "@typescript-eslint/parser"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: typescript-eslint
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 2, 2024
    Copy the full SHA
    e8bdc59 View commit details

Commits on Jul 4, 2024

  1. chore(deps-dev): bump typescript from 5.5.2 to 5.5.3 (#1755)

    Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.5.2 to 5.5.3.
    - [Release notes](https://github.com/Microsoft/TypeScript/releases)
    - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
    - [Commits](microsoft/TypeScript@v5.5.2...v5.5.3)
    
    ---
    updated-dependencies:
    - dependency-name: typescript
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 4, 2024
    Copy the full SHA
    0454c64 View commit details
  2. fix: fix regression where files like 'license-*' are not matched

    mjeanroy committed Jul 4, 2024
    Copy the full SHA
    4f7b0be View commit details
  3. release: release version

    mjeanroy committed Jul 4, 2024
    Copy the full SHA
    623496c View commit details
Showing with 146 additions and 23 deletions.
  1. +47 −10 dist/index.js
  2. +4 −4 package.json
  3. +39 −9 src/read-file.js
  4. +1 −0 test/fixtures/fake-package-12/LICENSE-MIT
  5. +15 −0 test/fixtures/fake-package-12/package.json
  6. +25 −0 test/fixtures/fake-package-12/src/index.js
  7. +15 −0 test/license-plugin.spec.js
57 changes: 47 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -686,16 +686,6 @@ const licenseValidator = {
isValid,
};

const pathsMatch = (target) => {
const targetLower = target.toLowerCase();
return (p) => {
const pLower = p.toLowerCase();
return (
pLower === targetLower ||
pLower.slice(0, pLower.lastIndexOf(".")) === targetLower
);
};
};
/**
* Find file and returns its content if file exists.
*
@@ -727,6 +717,53 @@ function readFile(dir, names) {
return null;
}

/**
* Returns a predicate function that returns `true` if the given path matches the target path.
*
* @param {string} target Target path.
* @returns {function(*): boolean} Predicate function.
*/
function pathsMatch(target) {
const targetRegExp = generatePattern(target);
return (p) => targetRegExp.test(p);
}

/**
* Generate a pattern where all regexp special characters are escaped.
* @param {string} input Input.
* @returns {string} Escaped input.
*/
function escapeRegExp(input) {
return input.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
const FILE_FORBIDDEN_CHARACTERS = [
"#",
"%",
"&",
"*",
":",
"<",
">",
"?",
"/",
path.sep,
"{",
"|",
"}",
].map((c) => escapeRegExp(c));
const FILE_SUFFIX_PTN = `[^${FILE_FORBIDDEN_CHARACTERS.join("")}]`;

/**
* Generate filename pattern for the given input: the generated regexp will match any file
* starting with `input` (case insensitively).
*
* @param {string} input Input.
* @returns {RegExp} Generated pattern.
*/
function generatePattern(input) {
return new RegExp(`^${input}(${FILE_SUFFIX_PTN})*$`, "i");
}

/**
* Pre-Defined comment style:
*
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-license",
"version": "3.5.1",
"version": "3.5.2",
"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",
@@ -54,8 +54,8 @@
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-virtual": "3.0.2",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"ansi-colors": "4.1.3",
"babel-plugin-add-module-exports": "1.0.4",
"eslint": "8.57.0",
@@ -75,7 +75,7 @@
"rollup-plugin-prettier": "4.1.1",
"rollup-plugin-strip-banner": "3.1.0",
"tmp": "0.2.3",
"typescript": "5.5.2"
"typescript": "5.5.3"
},
"engines": {
"node": ">=14.0.0"
48 changes: 39 additions & 9 deletions src/read-file.js
Original file line number Diff line number Diff line change
@@ -27,15 +27,6 @@ import fs from 'fs';
import _ from 'lodash';
import { fdir } from 'fdir';

const pathsMatch = (target) => {
const targetLower = target.toLowerCase();

return (p) => {
const pLower = p.toLowerCase();
return pLower === targetLower ||
pLower.slice(0, pLower.lastIndexOf('.')) === targetLower;
};
};
/**
* Find file and returns its content if file exists.
*
@@ -70,3 +61,42 @@ export function readFile(dir, names) {

return null;
}

/**
* Returns a predicate function that returns `true` if the given path matches the target path.
*
* @param {string} target Target path.
* @returns {function(*): boolean} Predicate function.
*/
function pathsMatch(target) {
const targetRegExp = generatePattern(target);
return (p) => (
targetRegExp.test(p)
);
}

/**
* Generate a pattern where all regexp special characters are escaped.
* @param {string} input Input.
* @returns {string} Escaped input.
*/
function escapeRegExp(input) {
return input.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

const FILE_FORBIDDEN_CHARACTERS = ['#', '%', '&', '*', ':', '<', '>', '?', '/', path.sep, '{', '|', '}'].map((c) => (
escapeRegExp(c)
));

const FILE_SUFFIX_PTN = `[^${FILE_FORBIDDEN_CHARACTERS.join('')}]`;

/**
* Generate filename pattern for the given input: the generated regexp will match any file
* starting with `input` (case insensitively).
*
* @param {string} input Input.
* @returns {RegExp} Generated pattern.
*/
function generatePattern(input) {
return new RegExp(`^${input}(${FILE_SUFFIX_PTN})*$`, 'i');
}
1 change: 1 addition & 0 deletions test/fixtures/fake-package-12/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LICENSE-MIT file
15 changes: 15 additions & 0 deletions test/fixtures/fake-package-12/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "fake-package",
"version": "1.0.0",
"description": "Fake package used in unit tests",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mickael Jeanroy <mickael.jeanroy@gmail.com>",
"license": "MIT",
"private": true,
"dependencies": {
"lodash": "*"
}
}
25 changes: 25 additions & 0 deletions test/fixtures/fake-package-12/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 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.
*/

console.log('fake-package');
15 changes: 15 additions & 0 deletions test/license-plugin.spec.js
Original file line number Diff line number Diff line change
@@ -443,6 +443,21 @@ describe('LicensePlugin', () => {

plugin.scanDependency(id);
});

it('should load pkg including license text from LICENSE-* file', () => {
const id = path.join(__dirname, 'fixtures', 'fake-package-12', 'src', 'index.js');

plugin.scanDependency(id);

expect(addDependency).toHaveBeenCalled();
expect(plugin._dependencies.size).toBe(1);
expect(plugin._dependencies.has('fake-package')).toBe(true);
expect(plugin._dependencies.get('fake-package')).toEqual({
...fakePackage,
self: false,
licenseText: 'LICENSE-MIT file',
});
});
});

describe('when adding dependencies', () => {