diff --git a/.changeset/metal-rooms-tie.md b/.changeset/metal-rooms-tie.md new file mode 100644 index 00000000..d282f431 --- /dev/null +++ b/.changeset/metal-rooms-tie.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/contact": patch +--- + +Do not throw an Error when using a contact with no 'name' property diff --git a/workspaces/contact/src/UnlitContact.class.ts b/workspaces/contact/src/UnlitContact.class.ts index 840a3f27..c84cb8e4 100644 --- a/workspaces/contact/src/UnlitContact.class.ts +++ b/workspaces/contact/src/UnlitContact.class.ts @@ -14,9 +14,13 @@ export class UnlitContact { public dependencies = new Set(); - constructor(contact: Contact) { + constructor( + contact: Contact + ) { this.illuminated = structuredClone(contact); - this.extendedName = utils.parseRegExp(contact.name); + this.extendedName = typeof contact.name === "string" ? + utils.parseRegExp(contact.name) : + null; } compareTo( diff --git a/workspaces/contact/test/ContactExtractor.spec.ts b/workspaces/contact/test/ContactExtractor.spec.ts index 215117a2..02ee011e 100644 --- a/workspaces/contact/test/ContactExtractor.spec.ts +++ b/workspaces/contact/test/ContactExtractor.spec.ts @@ -13,6 +13,21 @@ import { } from "../src/index.js"; describe("ContactExtractor", () => { + test("Given a contact with no name, it should not throw an Error", () => { + const highlighted: any = { + email: "foobar@gmail.com" + }; + const extractor = new ContactExtractor({ + highlight: [highlighted] + }); + + const dependencies: Record = { + random: fakePackageMetadata() + }; + + extractor.fromDependencies(dependencies); + }); + describe("fromDependencies", () => { test(`Given three dependencies where the Highlighted Contact appears two times, it should successfully scan, extract, and return the contact along with the list of dependencies where it appears.`, () => {