Skip to content

Commit

Permalink
Merge pull request #258 from TobyAndToby/ts/no-peer-deps
Browse files Browse the repository at this point in the history
Ensure peer dependencies don't show in results
  • Loading branch information
tobybessant committed Dec 12, 2023
2 parents c343f1d + 2c9bcdb commit fa40a2a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const resolveDependenciesForNpmProject = async (
const topNode = await arborist.loadActual();

const parseNode = async (node: Node | Link) => {
if (node.dev) {
if (node.dev || node.peer) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ describe("resolveNpmDependencies", () => {
const child2_1Realpath = "/some/path/child2.1";
const child2_1LicenseContent = "license contents for child2.1";

const child3Pkgid = "child3";
const child3Realpath = "/some/path/child3";
const child3LicenseContent = "license contents for child3";

const child3_1Pkgid = "child3.1";
const child3_1Realpath = "/some/path/child3.1";
const child3_1LicenseContent = "license contents for child3.1";

// A node tree where:
// - child1 is a 'normal' dependency
// - It has two 'normal' dependencies
// - child2 is a dev dependency
// - It has one 'normal' dependency (but it won't show in results because it's parent is a dev dependency)
// - child3 is a peer dependency
// - It has one 'normal' dependency (but it won't show in results because it's parent is a peer dependency)
const topNode: Arborist.Node = {
children: new Map([
[
Expand All @@ -48,6 +63,7 @@ describe("resolveNpmDependencies", () => {
realpath: child1_1Realpath,
children: new Map(),
dev: false,
peer: false,
},
],
[
Expand All @@ -57,10 +73,12 @@ describe("resolveNpmDependencies", () => {
realpath: child1_2Realpath,
children: new Map(),
dev: false,
peer: false,
},
],
]),
dev: false,
peer: false,
},
],
[
Expand All @@ -76,10 +94,33 @@ describe("resolveNpmDependencies", () => {
realpath: child2_1Realpath,
children: new Map(),
dev: false,
peer: false,
},
],
]),
dev: true,
peer: false,
},
],
[
"child3",
{
pkgid: child3Pkgid,
realpath: child3Realpath,
children: new Map([
[
"child3.1",
{
pkgid: child3_1Pkgid,
realpath: child3_1Realpath,
children: new Map(),
dev: false,
peer: false,
},
],
]),
dev: false,
peer: true,
},
],
]),
Expand Down Expand Up @@ -117,6 +158,14 @@ describe("resolveNpmDependencies", () => {
when(mockedResolveLicenseContent)
.calledWith(child2_1Realpath, expect.anything())
.mockResolvedValue(child2_1LicenseContent);

when(mockedResolveLicenseContent)
.calledWith(child3Realpath, expect.anything())
.mockResolvedValue(child3LicenseContent);

when(mockedResolveLicenseContent)
.calledWith(child3_1Realpath, expect.anything())
.mockResolvedValue(child3_1LicenseContent);
});

afterAll(() => jest.restoreAllMocks());
Expand Down Expand Up @@ -167,6 +216,18 @@ describe("resolveNpmDependencies", () => {
const child2_1LicenseContentMap = licensesMap.get(child2_1LicenseContent);
expect(child2_1LicenseContentMap).toBeUndefined();
});

it("should not include peer dependencies in the result", async () => {
const licensesMap = new Map<string, Set<string>>();

await resolveDependenciesForNpmProject("/some/path/package.json", licensesMap);

const child3LicenseContentMap = licensesMap.get(child3LicenseContent);
expect(child3LicenseContentMap).toBeUndefined();

const child3_1LicenseContentMap = licensesMap.get(child3_1LicenseContent);
expect(child3_1LicenseContentMap).toBeUndefined();
});
});

describe("when a dependency is in the exclude list", () => {
Expand Down

0 comments on commit fa40a2a

Please sign in to comment.