Skip to content

Commit 5b71ff9

Browse files
authored
fix(mama): include optional deps in pkg json integrity hash (#610)
1 parent e013b49 commit 5b71ff9

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

.changeset/petite-cloths-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/mama": patch
3+
---
4+
5+
fix(mama): include optional deps in pkg json integrity hash

workspaces/mama/src/utils/integrity-hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function packageJSONIntegrityHash(
5050
const object: PackageJSONIntegrityObject = {
5151
name,
5252
version,
53-
dependencies,
53+
dependencies: document?.optionalDependencies ? { ...dependencies, ...document.optionalDependencies } : dependencies,
5454
license,
5555
/**
5656
* Note: NPM registry automatically add `./node_modules/.bin/` to scripts

workspaces/mama/test/packageJSONIntegrityHash.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,30 @@ describe("packageJSONIntegrityHash", () => {
6464
);
6565
}
6666
});
67+
68+
test("should include optional dependencies in the hash when there is some", () => {
69+
const packageJSONWithOptionalDeps = {
70+
...kMinimalPackageJSON,
71+
optionalDependencies: {
72+
canvas: "^2.11.0"
73+
}
74+
};
75+
76+
const expectedObject = {
77+
...kMinimalPackageJSON,
78+
dependencies: {
79+
canvas: "^2.11.0"
80+
},
81+
scripts: {},
82+
license: "NONE"
83+
84+
};
85+
86+
const expectedIntegrity = hash(expectedObject);
87+
88+
const { integrity, object } = packageJSONIntegrityHash(packageJSONWithOptionalDeps, { isFromRemoteRegistry: true });
89+
90+
assert.deepEqual(object, expectedObject);
91+
assert.strictEqual(integrity, expectedIntegrity);
92+
});
6793
});

0 commit comments

Comments
 (0)