Skip to content

Conversation

lencioni
Copy link
Contributor

@lencioni lencioni commented May 8, 2025

Node added fetch in v17.5, and we don't support anything older than Node
18, so we should be able to remove this dependency now without any
issues.

FormData is also available in Node 18, so we should be good to go on
that front.

@lencioni lencioni requested a review from trotzig May 8, 2025 19:37
@lencioni lencioni requested a review from Copilot May 8, 2025 19:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the dependency on node-fetch by switching to the built-in fetch available from Node 18+, cleaning up both production and test code.

  • Removed node-fetch imports from production files and tests
  • Updated tests to spy on global.fetch and added afterEach hooks to restore mocks
  • Removed node-fetch from package.json

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/postGithubComment-test.js Replaced node-fetch mocks with global.fetch spy and ensured restoration of mocks after tests.
test/loadUserConfig-test.js Removed node-fetch and replaced with a global.fetch spy, though some fetch mocking remains inconsistent.
test/fetchPng-test.js Updated fetch mocking to use global.fetch consistently.
src/postGithubComment.js Removed node-fetch import in favor of built-in fetch.
src/makeRequest.js Removed node-fetch import and dependency.
src/loadUserConfig.js Removed node-fetch import.
src/loadCSSFile.js Removed node-fetch import.
src/fetchPng.js Removed node-fetch import in favor of built-in fetch.
package.json Removed the node-fetch dependency.
Comments suppressed due to low confidence (1)

test/loadUserConfig-test.js:115

  • [nitpick] After switching to using jest.spyOn(global, 'fetch'), consider replacing 'fetch.mockImplementation' with 'global.fetch.mockImplementation' for consistency with other tests.
fetch.mockImplementation(() => Promise.resolve({ ok: true, json: () => ({ secret: 'yay' }) }));

Node added fetch in v17.5, and we don't support anything older than Node
18, so we should be able to remove this dependency now without any
issues.

FormData is also available in Node 18, so we should be good to go on
that front.
@lencioni lencioni changed the title Replace node-fetch with built-in fetch Replace node-fetch and form-data with built-in fetch and FormData May 8, 2025
@lencioni lencioni requested a review from Copilot May 8, 2025 21:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the node-fetch and form-data dependencies by replacing them with built-in fetch and FormData in Node 18+.

  • Removed node-fetch and form-data imports and their related mocks in tests
  • Updated tests to use global.fetch with proper mock cleanup
  • Modified FormData usage in makeRequest to use Blob for form fields

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/postGithubComment-test.js Updated fetch mocking to use global.fetch and added cleanup in afterEach
test/loadUserConfig-test.js Replaced node-fetch mocking with global.fetch spy; slight inconsistency in fetch reference
test/fetchPng-test.js Updated fetch mocking to rely on global.fetch and adjusted header assertions for consistency
src/postGithubComment.js Removed node-fetch dependency
src/makeRequest.js Removed FormData dependency and adapted to built-in FormData using Blob for values
src/loadUserConfig.js Removed node-fetch dependency
src/loadCSSFile.js Removed node-fetch dependency
src/fetchPng.js Replaced node-fetch with built-in fetch and updated stream conversion using Readable.fromWeb
package.json Removed node-fetch and form-data dependencies

info,
}));

jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true }));
Copy link

Copilot AI May 8, 2025

Choose a reason for hiding this comment

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

The test sets up a global.fetch spy but later calls fetch.mockImplementation. For clarity and consistency, update all references to use global.fetch explicitly.

Suggested change
jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true }));
jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true }));
global.fetch.mockImplementation(() => ({ ok: true }));

Copilot uses AI. Check for mistakes.

Comment on lines 17 to +18
} else {
form.append(key, value);
form.append(key, new Blob([value]));
Copy link

Copilot AI May 8, 2025

Choose a reason for hiding this comment

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

[nitpick] Wrapping non-file values in a Blob may alter their type; verify that converting simple form values to Blob objects is the intended behavior for the built-in FormData implementation.

Copilot uses AI. Check for mistakes.

@lencioni
Copy link
Contributor Author

lencioni commented May 8, 2025

Oh rats, we are using the agent argument in node-fetch, which doesn't seem to have a direct replacement in the built-in fetch implementation. I think I'll back out of this change for now.

@lencioni lencioni closed this May 8, 2025
@lencioni
Copy link
Contributor Author

lencioni commented May 9, 2025

Looks like this is coming to Node's fetch soon nodejs/node#57165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant