Skip to content

Commit

Permalink
Merge pull request #1430 from mgol/module-github-override-fix
Browse files Browse the repository at this point in the history
Fix the shouldUseGitHubOverride logic for ESM imports
  • Loading branch information
orta authored Apr 16, 2024
2 parents 8371557 + de05921 commit 09cf908
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions source/platforms/github/_tests/_customGitHubRequire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/github/customGitHubRequire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09cf908

Please sign in to comment.