Skip to content

Commit b912567

Browse files
authored
fix(#117): duplicates in License Plist metadata output (#129)
* fix(#117): duplicates in License Plist metadata output * fix: broken e2e android test
1 parent 4cc3b14 commit b912567

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

.changeset/smooth-sheep-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@callstack/licenses': patch
3+
---
4+
5+
Exclude duplicated cocoapods license entries from license_plist.yml

examples/bare-example/e2e/checkLicenses/android.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ tags:
5454
text: 'Accept & continue'
5555
file: '../common/acceptChromeTerms-AcceptContinueVariant.yaml'
5656

57-
- assertVisible: A framework for building native applications using React
57+
- assertVisible: react-native
5858
- takeScreenshot: 'e2e_results/github_page'
5959
- back
6060
- stopRecording

packages/licenses-api/src/node/common.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ export function scanDependencies(
215215
return result;
216216
}
217217

218+
const PODSPEC_NAME_REGEX =
219+
/(Pod::Spec\.new\s+do\s+\|(?<specref>.*)\|).*(\k<specref>\.name\s+=\s+(?<quote>["'])(?<specname>[a-zA-Z0-9_\-@]+)\k<quote>)/;
220+
218221
/**
219222
* Generates LicensePlist-compatible metadata for NPM dependencies as a YAML string.
220223
*
@@ -243,9 +246,48 @@ export function generateLicensePlistNPMOutput(licenses: AggregatedLicensesMappin
243246
} as LicensePlistPayload;
244247
});
245248

249+
const excludedEntries = Object.values(licenses).reduce<Array<{ name: string }>>((acc, license) => {
250+
const packageName = license.name;
251+
const localPackageJsonPath = PackageUtils.getPackageJsonPath(packageName);
252+
253+
if (!localPackageJsonPath) {
254+
return acc;
255+
}
256+
257+
const podspecFiles = glob.sync('**.podspec', {
258+
cwd: path.dirname(localPackageJsonPath),
259+
absolute: true,
260+
nocase: true,
261+
nodir: true,
262+
ignore: '**/{__tests__,__fixtures__,__mocks__}/**',
263+
});
264+
265+
if (!podspecFiles) {
266+
return acc;
267+
}
268+
269+
const podspecEntries = podspecFiles.map((podspecFile) => {
270+
const podspecContent = fs.readFileSync(podspecFile, { encoding: 'utf-8' });
271+
const podspecContentShrinked = podspecContent.replace(/\n/g, ' ');
272+
const { specname } = PODSPEC_NAME_REGEX.exec(podspecContentShrinked)?.groups ?? {};
273+
274+
return { name: specname ?? packageName };
275+
});
276+
277+
return [...acc, ...podspecEntries];
278+
}, []);
279+
246280
const yamlDoc = {
247281
...(Object.keys(renames).length > 0 && { rename: renames }),
248282
manual: licenseEntries,
283+
/**
284+
* Adding excludes to prevent duplicates - NPM packages with iOS Podspecs are already
285+
* manually included in the `licenseEntries`. However License Plist is automatically including all
286+
* the entries detected via Pods-<project-name>-acknowledgements.plist, which also
287+
* includes the NPM package with iOS Podspecs - let's filter them out,
288+
* so that only the manual NPM entries are displayed
289+
*/
290+
exclude: excludedEntries,
249291
};
250292

251293
const yamlContent = [

0 commit comments

Comments
 (0)