Skip to content

Commit

Permalink
[ACS-8215] Filter out dependencies of dependencies in licenses.ts script
Browse files Browse the repository at this point in the history
  • Loading branch information
tomson7777 committed Sep 24, 2024
1 parent bed18d8 commit 977118b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/cli/scripts/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface PackageInfo {
name: string;
description: string;
version: string;
dependencies: Record<string, string>;
}

const nonStandardLicenses = {
Expand Down Expand Up @@ -133,6 +134,9 @@ export default function main(_args: string[], workingDir: string) {
exit(1);
}

const packageJson = getPackageFile(packagePath);
const directDependencies = { ...packageJson.dependencies };

return new Promise((resolve, reject) => {
// eslint-disable-next-line no-console
console.info(`Checking ${packagePath}`);
Expand All @@ -148,9 +152,16 @@ export default function main(_args: string[], workingDir: string) {
console.error(err);
reject(err);
} else {
const filteredPackages = Object.keys(packages)
.filter((packageName) => Object.keys(directDependencies).some((dep) => packageName.startsWith(dep)))
.reduce((obj, packageName) => {
obj[packageName] = packages[packageName];
return obj;
}, {});

// eslint-disable-next-line guard-for-in
for (const packageName in packages) {
const pack = packages[packageName];
for (const packageName in filteredPackages) {
const pack = filteredPackages[packageName];
pack['licenseExp'] = pack['licenses']
.toString()
.replace(/\*/g, '')
Expand All @@ -174,12 +185,10 @@ export default function main(_args: string[], workingDir: string) {
}
}

const packageJson: PackageInfo = getPackageFile(packagePath);

ejs.renderFile(
templatePath,
{
packages,
packages: filteredPackages,
projVersion: packageJson.version,
projName: packageJson.name
},
Expand Down

0 comments on commit 977118b

Please sign in to comment.