Skip to content

Commit

Permalink
refactor: Give the key variable a better name
Browse files Browse the repository at this point in the history
The "key" within the flatten function in fact is the name and version
string of the currently processed dependency package
  • Loading branch information
RSeidelsohn committed Apr 8, 2023
1 parent 21380e9 commit 622d8b2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,34 @@ function first_or_second(obj1, obj2) {
const flatten = function flatten(options) {
const moduleInfo = { licenses: UNKNOWN };
const { color: colorize, deps: json, unknown } = options;
const key = `${json.name}@${json.version}`;
const currentPackageNameAndVersion = `${json.name}@${json.version}`;
let dirFiles;
let files = [];
let licenseData;
let licenseFile;
let noticeFiles = [];
let readmeFile;
let { data } = options;
let clarification = options.clarifications?.[key];
let clarification = options.clarifications?.[currentPackageNameAndVersion];
let passed_clarification_check = clarification?.checksum ? false : true;

if (json.private) {
moduleInfo.private = true;
}

// If we have processed this key already, just return the data object.
// If we have processed this currentPackageNameAndVersion already, just return the data object.
// This was added so that we don't recurse forever if there was a circular
// dependency in the dependency tree.
/*istanbul ignore next*/
if (data[key]) {
if (data[currentPackageNameAndVersion]) {
return data;
}

if ((options.production && json.extraneous) || (options.development && !json.extraneous && !json.root)) {
return data;
}

data[key] = moduleInfo;
data[currentPackageNameAndVersion] = moduleInfo;

// Include property in output unless custom format has set property to false.
function mustInclude(property) {
Expand Down Expand Up @@ -215,7 +215,7 @@ const flatten = function flatten(options) {
let sha256 = createHash('sha256').update(content).digest('hex');

if (clarification.checksum !== sha256) {
console.error(`Clarification checksum mismatch for ${key} :(\nFile checked: ${licenseFile}`);
console.error(`Clarification checksum mismatch for ${currentPackageNameAndVersion} :(\nFile checked: ${licenseFile}`);
process.exit(1);
} else {
passed_clarification_check = true;
Expand Down Expand Up @@ -343,7 +343,7 @@ const flatten = function flatten(options) {
}

if (!json.name || !json.version) {
delete data[key];
delete data[currentPackageNameAndVersion];
}

/*istanbul ignore next*/
Expand Down

0 comments on commit 622d8b2

Please sign in to comment.