diff --git a/source/platforms/github/_tests/_customGitHubRequire.test.ts b/source/platforms/github/_tests/_customGitHubRequire.test.ts index 8bdb9fc86..7bcc6c0ed 100644 --- a/source/platforms/github/_tests/_customGitHubRequire.test.ts +++ b/source/platforms/github/_tests/_customGitHubRequire.test.ts @@ -31,6 +31,12 @@ describe("shouldUseGitHubOverride", () => { const parent: any = { filename: dangerPrefix + "./my-import" } expect(shouldUseGitHubOverride(module, parent)).toBeTruthy() }) + + it("ignores modules without a parent", () => { + const module = "./peril" + const parent: any = undefined + expect(shouldUseGitHubOverride(module, parent)).toBeFalsy() + }) }) describe("customGitHubResolveRequest", () => { diff --git a/source/platforms/github/customGitHubRequire.ts b/source/platforms/github/customGitHubRequire.ts index 106851e48..5f6b4c134 100644 --- a/source/platforms/github/customGitHubRequire.ts +++ b/source/platforms/github/customGitHubRequire.ts @@ -86,9 +86,9 @@ export async function getGitHubFileContents( // Setup a callback used to determine whether a specific `require` invocation // needs to be overridden. -export const shouldUseGitHubOverride = (request: string, parent: NodeModule): boolean => { +export const shouldUseGitHubOverride = (request: string, parent?: NodeModule): boolean => { // Is it a from a file we're handling, and is it relative? - if (parent.filename.startsWith(dangerPrefix) && request.startsWith(".")) { + if (parent?.filename.startsWith(dangerPrefix) && request.startsWith(".")) { return true } // Basically any import that's not a relative import from a Dangerfile