Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the shouldUseGitHubOverride logic for ESM imports #1430

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could avoid the type here - the following would work as well:

Suggested change
const parent: any = undefined
const parent = undefined

but I used what's more consistent with the other test cases.

Let me know if you'd like to drop this any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine :+

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