Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ export const resolveDependenciesForNpmProject = async (
return;
}

if (exclude.includes(node.pkgid)) {
const packageJson = await readPackageJson(join(node.realpath, "package.json"));

if (
exclude.includes(`${packageJson.name}@${packageJson.version}`) ||
exclude.includes(`${packageJson.name}`)
) {
return;
}

const packageJson = await readPackageJson(join(node.realpath, "package.json"));

const licenseContent = await resolveLicenseContent(node.realpath, packageJson, replacements);

if (licenseContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export const resolveDependenciesForPnpmProject = async (
for (const dependencyPath of dependency.paths) {
const packageJson = await readPackageJson(join(dependencyPath, "package.json"));

const pkgId = `${packageJson.name}@${packageJson.version}`;

if (exclude.includes(pkgId)) {
if (
exclude.includes(`${packageJson.name}@${packageJson.version}`) ||
exclude.includes(`${packageJson.name}`)
) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,37 @@ describe("resolveNpmDependencies", () => {
when(mockedResolveLicenseContent)
.calledWith(child1Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child1LicenseContent);
setUpPackageJson(child1Realpath, { name: child1Name, version: "1.0.0" });
setUpPackageJson(child1Realpath, { name: child1Name, version: child1Version });

when(mockedResolveLicenseContent)
.calledWith(child1_1Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child1_1LicenseContent);
setUpPackageJson(child1_1Realpath, { name: child1_1Name, version: "1.0.0" });
setUpPackageJson(child1_1Realpath, { name: child1_1Name, version: child1_1Version });

when(mockedResolveLicenseContent)
.calledWith(child1_2Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child1_2LicenseContent);
setUpPackageJson(child1_2Realpath, { name: child1_2Name, version: "1.0.0" });
setUpPackageJson(child1_2Realpath, { name: child1_2Name, version: child1_2Version });

when(mockedResolveLicenseContent)
.calledWith(child2Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child2LicenseContent);
setUpPackageJson(child2Realpath, { name: child2Name, version: "1.0.0" });
setUpPackageJson(child2Realpath, { name: child2Name, version: child2Version });

when(mockedResolveLicenseContent)
.calledWith(child2_1Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child2_1LicenseContent);
setUpPackageJson(child2_1Realpath, { name: child2_1Name, version: "1.0.0" });
setUpPackageJson(child2_1Realpath, { name: child2_1Name, version: child2_1Version });

when(mockedResolveLicenseContent)
.calledWith(child3Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child3LicenseContent);
setUpPackageJson(child3Realpath, { name: child3Name, version: "1.0.0" });
setUpPackageJson(child3Realpath, { name: child3Name, version: child3Version });

when(mockedResolveLicenseContent)
.calledWith(child3_1Realpath, expect.anything(), expect.anything())
.mockResolvedValue(child3_1LicenseContent);
setUpPackageJson(child3_1Realpath, { name: child3_1Name, version: "1.0.0" });
setUpPackageJson(child3_1Realpath, { name: child3_1Name, version: child3_1Version });
});

afterAll(() => jest.restoreAllMocks());
Expand Down Expand Up @@ -316,6 +316,23 @@ describe("resolveNpmDependencies", () => {
const child1_2LicenseContentMap = licensesMap.get(child1_2LicenseContent);
expect(child1_2LicenseContentMap?.find(c => c.name === child1_2Name)).toBeDefined();
});

it("should not include the dependency in the result if specified by name only", async () => {
const licensesMap = new Map<LicenseContent, Dependency[]>();

await resolveDependenciesForNpmProject("/some/path/package.json", licensesMap, {
exclude: [`${child1_1Name}`],
});

const child1LicenseContentMap = licensesMap.get(child1LicenseContent);
expect(child1LicenseContentMap?.find(c => c.name === child1Name)).toBeDefined();

const child1_1LicenseContentMap = licensesMap.get(child1_1LicenseContent);
expect(child1_1LicenseContentMap).toBeUndefined();

const child1_2LicenseContentMap = licensesMap.get(child1_2LicenseContent);
expect(child1_2LicenseContentMap?.find(c => c.name === child1_2Name)).toBeDefined();
});
});

const setUpPackageJson = (directory: string, packageJson: PackageJson): void => {
Expand Down