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

Removed node-fetch package and used native fetch #619

Closed
wants to merge 3 commits into from

Conversation

theothirteen
Copy link

@theothirteen theothirteen commented May 6, 2023

Fixes #589 Issue. Option 4 Suboption 1.

  • Tests pass
  • Appropriate changes to README are included in the PR
  • Types updated

Changes

  • Remove node-fetch dependency
  • Removed DOM lib from tsconfig
  • Added @types/node-fetch as dev dependencies to get the updated types for fetch

@antongolub
Copy link
Collaborator

I'd suggest smth like "engines": { "node": ">= 18.0.0" } instead of all these node version checks and err notices.

@theothirteen
Copy link
Author

@antongolub Thank you for the review. Please correct me If I am wrong. Once I upgrade the node engine field then test cases will work without any node version check but in the case of the Fetch function if a user tries to run the zx with node 16 then we have to print the error(#589 (comment)) message that fetch is not supported so don't we need a check there?

@antonmedv
Copy link
Collaborator

About "engines": { "node": ">= 18.0.0" }, this will prevent installing zx on node16. What if somebody not using fetch? Just $?

src/goods.ts Outdated
$.log({ kind: 'fetch', url, init })
return nodeFetch(url, init)
export async function globalFetch(url: RequestInfo, init?: RequestInit) {
if (isNodeEighteenOrGreaterThanEighteen) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of checking version, why not just check if fetch exists?

if ('fetch' in globalThis) or if (globalThis.fetch)

Copy link
Author

Choose a reason for hiding this comment

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

@midzelis Thank you for the feedback. Updated that condition. Please take a look and let me know if you have any doubts.

@theothirteen theothirteen force-pushed the removed-node-fetch branch 2 times, most recently from 90ff479 to 5701517 Compare June 24, 2023 09:32
@njfamirm
Copy link

Thank you @theothirteen !
Considering that node native fetch doesn't need any package to work, even in types, you can generally remove @types/node-fetch and use nodejs types,

I'm do this in this branch and create pr in your repo: theothirteen#1
You can include my changes in this pr by merging that!

Chnges:

  • add DOM as lib into tsconfig
  • fully remove node-fetch type

@theothirteen
Copy link
Author

theothirteen commented Sep 18, 2023

Thank you @theothirteen ! Considering that node native fetch doesn't need any package to work, even in types, you can generally remove @types/node-fetch and use nodejs types,

I'm do this in this branch and create pr in your repo: theothirteen#1 You can include my changes in this pr by merging that!

Chnges:

  • add DOM as lib into tsconfig
  • fully remove node-fetch type

Hello @njfamirm Thank you for the PR and suggestions.

The reason why I have added @types/node-fetch is to use types. Currently RequestInfo and RequestInit types are not available in @types/node so just for the types and for a better development experience keep the types. Also as it's a dev dependency so does not affect bundle size. Please let me know if you have alternate solutions for that issue.

Furthermore, as node-fetch is dependent on the DOM lib and currently we are not using it so removed it.

@njfamirm
Copy link

njfamirm commented Sep 18, 2023

Thanks for your review @theothirteen

The reason why I have added @types/node-fetch is to use types. Currently RequestInfo and RequestInit types are not available in @types/node so just for the types and for a better development experience keep the types. Also as it's a dev dependency so does not affect bundle size. Please let me know if you have alternate solutions for that issue.

but RequestInfo & RequestInit is built-in in typescript. (you can see this with vscode autocomplete and following type definition)

2
1

Also if this types not exists, we have build error, but current have no error.
I think it is a mistake to use node-fetch types for native fetch.

Furthermore, as node-fetch is dependent on the DOM lib and currently we are not using it so removed it.

if we want to use fetch on typescript, we must add DOM lib.

@njfamirm
Copy link

njfamirm commented Sep 18, 2023

I'm update my pr and resolve conflicts, so ready for rereview

@antonmedv antonmedv requested review from antonmedv and removed request for midzelis September 18, 2023 08:22
@theothirteen
Copy link
Author

Thanks for your review @theothirteen

The reason why I have added @types/node-fetch is to use types. Currently RequestInfo and RequestInit types are not available in @types/node so just for the types and for a better development experience keep the types. Also as it's a dev dependency so does not affect bundle size. Please let me know if you have alternate solutions for that issue.

but RequestInfo & RequestInit is built-in in typescript. (you can see this with vscode autocomplete and following type definition)

2 1

Also if this types not exists, we have build error, but current have no error. I think it is a mistake to use node-fetch types for native fetch.

Furthermore, as node-fetch is dependent on the DOM lib and currently we are not using it so removed it.

if we want to use fetch on typescript, we must add DOM lib.

@njfamirm Totally agree with you but in the initial requirement, it is mentioned that we can drop the DOM lib if we go with the native fetch. That is the reason I have removed the DOM lib. @antonmedv Could you please provide your inputs if we want to keep the DOM lib or not?

@njfamirm
Copy link

@njfamirm Totally agree with you but in the initial requirement, it is mentioned that we can drop the DOM lib if we go with the native fetch. That is the reason I have removed the DOM lib. @antonmedv Could you please provide your inputs if we want to keep the DOM lib or not?

@theothirteen Yes you are right 👍🏻
But the problem is that fetch actually needs DOM in typescript, but we solve this problem by using any type, which of course cannot be called solving! just ignoring 🫠

@antonmedv
Copy link
Collaborator

I'd like to drop DOM

@theothirteen theothirteen force-pushed the removed-node-fetch branch 2 times, most recently from 0d4fec9 to 963a5bc Compare October 2, 2023 19:02
@njfamirm
Copy link

Whats up?

@theothirteen theothirteen force-pushed the removed-node-fetch branch 2 times, most recently from 7bf67b1 to 1d37b70 Compare January 1, 2024 17:20
antongolub added a commit to antongolub/zx that referenced this pull request Mar 17, 2024
antongolub added a commit to antongolub/zx that referenced this pull request Mar 17, 2024
antonmedv pushed a commit that referenced this pull request Mar 17, 2024
@antonmedv antonmedv closed this Mar 18, 2024
@antongolub
Copy link
Collaborator

Resolved in #722

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.

Plan for v8
5 participants