Skip to content

Commit

Permalink
Merge pull request #85 from RSeidelsohn/release_4.2.6
Browse files Browse the repository at this point in the history
Release 4.2.6
  • Loading branch information
RSeidelsohn authored Jun 9, 2023
2 parents f3755fa + 6c7cfbb commit 142ae39
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 173 deletions.
391 changes: 391 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/getLicenseTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ module.exports = function getLicenseTitle(str = 'undefined') {
let version;

try {
// Simply check if the string is a valid SPDX expression:
spdxExpressionParse(str);

// No need for additional parsing efforts:
return str;
} catch (error) {
// Fail silently and continue
// Fail silently and continue with additional parsing efforts:
}

if (str) {
Expand Down
200 changes: 71 additions & 129 deletions lib/index.js

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions lib/indexHelpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fs = require('node:fs');
const path = require('node:path');

/**
* ! This function has a wanted sideeffect, as it modifies the json object that is passed by reference.
*
Expand Down Expand Up @@ -84,10 +87,100 @@ const getLinesWithCopyright = function getLinesWithCopyright(fileContents = '')
});
};

const getOptionArray = (option) => {
if (Array.isArray(option)) {
return option;
}

if (typeof option === 'string') {
return option.split(';');
}

return false;
};

const getCsvData = (sorted, customFormat, csvComponentPrefix) => {
const csvDataArr = [];

Object.entries(sorted).forEach(([key, module]) => {
const dataElements = [];

if (csvComponentPrefix) {
dataElements.push(`"${csvComponentPrefix}"`);
}

// Grab the custom keys from the custom format
if (typeof customFormat === 'object' && Object.keys(customFormat).length > 0) {
dataElements.push(`"${key}"`);

Object.keys(customFormat).forEach((item) => {
dataElements.push(`"${module[item]}"`);
});
} else {
// Be sure to push empty strings for empty values, as this is what CSV expects:
dataElements.push([`"${key}"`, `"${module.licenses || ''}"`, `"${module.repository || ''}"`]);
}

csvDataArr.push(dataElements.join(','));
});

return csvDataArr;
};

const getCsvHeaders = (customFormat, csvComponentPrefix) => {
const prefixName = '"component"';
const entriesArr = [];

if (csvComponentPrefix) {
entriesArr.push(prefixName);
}

if (typeof customFormat === 'object' && Object.keys(customFormat).length > 0) {
entriesArr.push('"module name"');

Object.keys(customFormat).forEach((item) => {
entriesArr.push(`"${item}"`);
});
} else {
entriesArr.push('"module name"', '"license"', '"repository"');
}

return entriesArr.join(',');
};

const getModuleNameForLicenseTextHeader = (moduleName = '') => {
const lastIndexOfAtCharacter = moduleName.lastIndexOf('@');

return `${moduleName.substring(0, lastIndexOfAtCharacter)} ${moduleName.substring(lastIndexOfAtCharacter + 1)}\n`;
};

// Eventually store the contents of the module's README.md in currentExtendedPackageJson.readme:
const storeReadmeInJsonIfExists = (modulePath, currentExtendedPackageJson) => {
if (
typeof modulePath !== 'string' ||
typeof currentExtendedPackageJson !== 'object' ||
modulePath === '' ||
currentExtendedPackageJson?.readme?.toLowerCase()?.indexOf('no readme data found') === -1
) {
return;
}

const readmeFile = path.join(modulePath, 'README.md');

if (fs.existsSync(readmeFile)) {
currentExtendedPackageJson.readme = fs.readFileSync(readmeFile, 'utf8').toString();
}
};

module.exports = {
deleteNonDirectDependenciesFromAllDependencies,
getAuthorDetails,
getCsvData,
getCsvHeaders,
getFirstNotUndefinedOrUndefined,
getLinesWithCopyright,
getModuleNameForLicenseTextHeader,
getOptionArray,
getRepositoryUrl,
storeReadmeInJsonIfExists,
};
4 changes: 2 additions & 2 deletions lib/licenseCheckerHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const filterJson = function filterJson(limitAttributes, json) {
return filteredJson;
};

const getFormattedOutput = function getFormattedOutput(json, args) {
let filteredJson = filterJson(args.limitAttributes, json);
const getFormattedOutput = function getFormattedOutput(modulesWithVersions, args) {
let filteredJson = filterJson(args.limitAttributes, modulesWithVersions);
const jsonCopy = cloneDeep(filteredJson);
filteredJson = null;

Expand Down
62 changes: 31 additions & 31 deletions lib/usageMessage.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
const usageMessage = [
'All options in alphabetical order:',
'',
' --angularCli is just a synonym for --plainVertical',
" --clarificationsFile [filepath] A file that describe the license clarifications for each package, see clarificationExample.json, any field available to the customFormat option can be clarified. Can also be used to specify a subregion of a package's license file (instead reading the entire file).",
' --csv output in csv format.',
' --csvComponentPrefix column prefix for components in csv file',
' --customPath to add a custom Format file in JSON',
' --development only show development dependencies.',
' --direct [boolean|number] look for direct dependencies only if "true" or look for "number" of levels of dependencies',
' --excludeLicenses [list] exclude modules which licenses are in the comma-separated list from the output',
' --excludePackages [list] restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") not in the semicolon-seperated list',
' --excludePackageStartingWith [list] excludes packages starting with anything the comma-separated list',
' --excludePrivatePackages restrict output to not include any package marked as private',
' --failOn [list] fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list',
' --files [path] copy all license files to path and rename them to `module-name`@`version`-LICENSE.txt.',
' --includeLicenses [list] include only modules which licenses are in the comma-separated list from the output',
' --includePackages [list] restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") in the semicolon-seperated list',
' --json output in json format.',
' --limitAttributes [list] limit the attributes to be output.',
' --markdown output in markdown format.',
' --nopeer skip peer dependencies in output.',
' --onlyAllow [list] fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list',
' --onlyunknown only list packages with unknown or guessed licenses.',
' --out [filepath] write the data to a specific file.',
' --plainVertical output in plain vertical format like [Angular CLI does](https://angular.io/3rdpartylicenses.txt)',
' --production only show production dependencies.',
' --relativeLicensePath output the location of the license files as relative paths',
' --relativeModulePath output the location of the module files as relative paths',
' --start [filepath] path of the initial json to look for',
' --summary output a summary of the license usage',
' --unknown report guessed licenses as unknown licenses.',
' --angularCli: is just a synonym for --plainVertical',
" --clarificationsFile [filepath]: A file that describe the license clarifications for each package, see clarificationExample.json, any field available to the customFormat option can be clarified. Can also be used to specify a subregion of a package's license file (instead reading the entire file).",
' --csv: output in csv format.',
' --csvComponentPrefix: column prefix for components in csv file',
' --customPath: to add a custom Format file in JSON',
' --development: only show development dependencies.',
' --direct [boolean|number]: look for direct dependencies only if "true" or look for "number" of levels of dependencies',
' --excludeLicenses [list]: exclude modules which licenses are in the comma-separated list from the output',
' --excludePackages [list]: restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") NOT in the semicolon-seperated list',
' --excludePackagesStartingWith [list]: excludes packages starting with anything the comma-separated list',
' --excludePrivatePackages: restrict output to not include any package marked as private',
' --failOn [list]: fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list',
' --files [path]: copy all license files to path and rename them to `module-name`@`version`-LICENSE.txt.',
' --includeLicenses [list]: restrict output to the packages of which the licenses are included in the comma-separated list from the output',
' --includePackages [list]: restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") in the semicolon-seperated list',
' --json: output in json format.',
' --limitAttributes [list]: limit the attributes to be output.',
' --markdown: output in markdown format.',
' --nopeer: skip peer dependencies in output.',
' --onlyAllow [list]: fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list',
' --onlyunknown: only list packages with unknown or guessed licenses.',
' --out [filepath]: write the data to a specific file.',
' --plainVertical: output in plain vertical format like [Angular CLI does](https://angular.io/3rdpartylicenses.txt)',
' --production: only show production dependencies.',
' --relativeLicensePath: output the location of the license files as relative paths',
' --relativeModulePath: output the location of the module files as relative paths',
' --start [filepath]: path of the initial json to look for',
' --summary: output a summary of the license usage',
' --unknown: report guessed licenses as unknown licenses.',
'',
' --version The current version',
' --help The text you are reading right now :)',
' --version: The current version',
' --help: The text you are reading right now :)',
'',
].join('\n');

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "license-checker-rseidelsohn",
"description": "Extract NPM package licenses - Feature enhanced version of the original license-checker v25.0.1",
"author": "Roman Seidelsohn <[email protected]>",
"version": "4.2.5",
"version": "4.2.6",
"license": "BSD-3-Clause",
"private": false,
"engines": {
Expand Down Expand Up @@ -48,7 +48,7 @@
"exclude": [
"**/tests/*.js"
],
"lines": 90,
"lines": 80,
"statements": 80,
"functions": 80,
"branches": 80
Expand Down Expand Up @@ -130,7 +130,7 @@
"lodash.clonedeep": "^4.5.0",
"mkdirp": "^1.0.4",
"nopt": "^5.0.0",
"read-installed-packages": "^2.0.0",
"read-installed-packages": "^2.0.1",
"semver": "^7.3.5",
"spdx-correct": "^3.1.1",
"spdx-expression-parse": "^3.0.1",
Expand Down

0 comments on commit 142ae39

Please sign in to comment.