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

node-fetch: restore types (for v2), update version, allow agent: false #58693

Conversation

glasser
Copy link
Contributor

@glasser glasser commented Feb 9, 2022

As discussed with @sandersn on #55533, this PR restores previously-deleted types for node-fetch@2. It updates the version from v2.5 to v2.6 and fixes an error in the types where agent: false was not allowed.

The individual commits in the PR have more detailed commit messages.

…ed as of 3.0.0 by @ImRodry"

This reverts commit 4d9b113.

node-fetch@3 makes two major changes: they started shipping TS types
with the package, and they switched it to being an ESM-only module. The
latter means that apps which aren't built in a way that supports ESM (or
other npm modules depending on `node-fetch` which don't want to break
their non-ESM users) need to continue using v2. In fact, the README for
`node-fetch` explicitly states

> If you cannot switch to ESM, please use v2 which remains compatible
> with CommonJS. Critical bug fixes will continue to be published for
> v2.

Stats on npmjs.com show that v2 has 43 times more downloads in the past
7 days than v3.

I applaud node-fetch's forward-thinking approach to ESM, and am not here
to tell them that their choice for v3 is wrong. But practically speaking,
v2 is still heavily used and many projects will not be able to upgrade
to v3 without breaking their own backwards compatibility promises.
So it makes sense to continue to maintain v2-specific node-fetch types
(especially as there are specific issues with the published types,
as the next commit in this PR shows).
v2.6 is the current (and presumably final) minor release of v2.
Apparently these types already included at least one v2.6 feature
(`agent` as a function). So, updating the version as suggested at-rule
DefinitelyTyped#55533 (comment)
The `agent` option is (after checking to see if it's a function, and if
so replacing itself with the return value of calling it) passed directly
to `http.request` (or `https.request`) so we should be able to pass any
type supported there. Notably, `agent: false` is distinct from `agent:
undefined`.

A PR making essentially the same change was merged upstream (the
upstream repo maintains their own types for v3 but not for v2):
node-fetch/node-fetch#1502
@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 9, 2022

@glasser Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

This PR touches some part of DefinitelyTyped infrastructure, so a DT maintainer will need to review it. This is rare — did you mean to do this?

9 packages in this PR (and infra files)

Code Reviews

This PR adds a new definition, so it needs to be reviewed by a DT maintainer before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Only a DT maintainer can approve changes when there are new packages added

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 58693,
  "author": "glasser",
  "headCommitOid": "1ac38913f5fb70f6f7947a58c2f7b9907b594fc6",
  "mergeBaseOid": "7467038c60726c43ccfc0f084cd8d5d8f062d234",
  "lastPushDate": "2022-02-13T21:13:58.000Z",
  "lastActivityDate": "2022-02-14T23:56:44.000Z",
  "mergeOfferDate": "2022-02-13T21:27:27.000Z",
  "mergeRequestDate": "2022-02-14T23:56:44.000Z",
  "mergeRequestUser": "glasser",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": null,
      "kind": "edit",
      "files": [
        {
          "path": "notNeededPackages.json",
          "kind": "infrastructure"
        }
      ],
      "owners": [],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    },
    {
      "name": "file-fetch",
      "kind": "edit",
      "files": [
        {
          "path": "types/file-fetch/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "tpluscode"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "frisby",
      "kind": "edit",
      "files": [
        {
          "path": "types/frisby/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "cwoodland",
        "johnny4753"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "libnpmpublish",
      "kind": "edit",
      "files": [
        {
          "path": "types/libnpmpublish/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "nicolas377",
        "Guy-Adler"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "make-fetch-happen",
      "kind": "edit",
      "files": [
        {
          "path": "types/make-fetch-happen/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "abernix",
        "trevor-scheer"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Popular"
    },
    {
      "name": "node-fetch",
      "kind": "add",
      "files": [
        {
          "path": "types/node-fetch/externals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node-fetch/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node-fetch/node-fetch-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node-fetch/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/node-fetch/tsconfig.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/node-fetch/tslint.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [],
      "addedOwners": [
        "torstenwerner",
        "nikcorg",
        "vinaybedre",
        "kyranet",
        "AndrewLeedham",
        "JasonLi914",
        "southpolesteve",
        "ExE-Boss",
        "alexandrusavin",
        "OmgImAlexis",
        "kbkk",
        "glasser"
      ],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    },
    {
      "name": "npm-registry-fetch",
      "kind": "edit",
      "files": [
        {
          "path": "types/npm-registry-fetch/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "DefinitelyTyped"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Popular"
    },
    {
      "name": "proto-fetch",
      "kind": "edit",
      "files": [
        {
          "path": "types/proto-fetch/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "tpluscode"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "react-native-version-check",
      "kind": "edit",
      "files": [
        {
          "path": "types/react-native-version-check/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "vdelacou",
        "KrishyV"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "zipkin-instrumentation-fetch",
      "kind": "edit",
      "files": [
        {
          "path": "types/zipkin-instrumentation-fetch/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "plantain-00"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "nikcorg",
      "date": "2022-02-14T10:37:40.000Z",
      "isMaintainer": false
    },
    {
      "type": "approved",
      "reviewer": "peterblazejewicz",
      "date": "2022-02-13T21:26:49.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "nicolas377",
      "date": "2022-02-12T15:34:58.000Z",
      "abbrOid": "af88e00"
    },
    {
      "type": "stale",
      "reviewer": "abernix",
      "date": "2022-02-11T08:25:43.000Z",
      "abbrOid": "af88e00"
    },
    {
      "type": "stale",
      "reviewer": "trevor-scheer",
      "date": "2022-02-10T01:05:26.000Z",
      "abbrOid": "af88e00"
    }
  ],
  "mainBotCommentID": 1034320859,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added New Definition This PR creates a new definition package. Critical package Edits Infrastructure Edits multiple packages Check Config Changes a module config files labels Feb 9, 2022
@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Feb 9, 2022
@typescript-bot
Copy link
Contributor

🔔 @tpluscode @cwoodland @johnny4753 @nicolas377 @Guy-Adler @abernix @trevor-scheer @DefinitelyTyped @vdelacou @KrishyV @plantain-00 — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@glasser
Copy link
Contributor Author

glasser commented Feb 9, 2022

When I run npm test node-fetch locally, I get:

glasser@dsg-mbp 0 15:42:46 ~/Projects/Apollo/DefinitelyTyped glasser/restore-node-fetch-v2-and-fix-agent-false u+4 $ npm test node-fetch

> definitely-typed@0.0.3 test
> dtslint types "node-fetch"

Error: /Users/glasser/Projects/Apollo/DefinitelyTyped/node_modules/form-data/index.d.ts:1:1
ERROR: 1:1  no-outside-dependencies  File /Users/glasser/Projects/Apollo/DefinitelyTyped/node_modules/form-data/index.d.ts comes from a `node_modules` but is not declared in this type's `package.json`.  See: https://github.com/Microsoft/dtslint/blob/master/docs/no-outside-dependencies.md

    at testTypesVersion (/Users/glasser/Projects/Apollo/DefinitelyTyped/node_modules/@definitelytyped/dtslint/bin/src/index.js:189:15)
    at async runTests (/Users/glasser/Projects/Apollo/DefinitelyTyped/node_modules/@definitelytyped/dtslint/bin/src/index.js:165:13)
    at async main (/Users/glasser/Projects/Apollo/DefinitelyTyped/node_modules/@definitelytyped/dtslint/bin/src/index.js:77:9)

I'm not sure why: this PR restores node-fetch/package.json which has an explicit dependency on form-data...

But your CI doesn't see that problem, so hopefully all is well.

@DangerBotOSS
Copy link

DangerBotOSS commented Feb 9, 2022

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

frisby (unpkg)

was missing the following properties:

  1. delete

make-fetch-happen (unpkg)

was missing the following properties:

  1. FetchError
  2. Headers
  3. Request
  4. Response

Generated by 🚫 dangerJS against 1ac3891

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Action in New Pull Request Status Board Feb 9, 2022
@glasser
Copy link
Contributor Author

glasser commented Feb 9, 2022

The two packages mentioned by @DangerBotOSS only have dependencies changed in this PR (a revert of the dependency change from #55533).

Copy link
Contributor

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

Reviewed changes post-revert.

I don't understand the versioning situation - should what currently exists be 2.6 or do your changes move us to 2.6? I also need to refamiliarize myself with how versioning is handled in DT (mostly, should we be changing the header manually or is that automated in some way?). I'm guessing you did the right thing, only asking because I don't actually know.

@glasser
Copy link
Contributor Author

glasser commented Feb 10, 2022

I changed the version as suggested by a DT maintainer on #55533. The goal I think is to get the major.minor matching the actual package. The types already had support for "agent that's a function", which was added in 2.6.0

@abernix
Copy link
Contributor

abernix commented Feb 11, 2022

That's my understanding of the goal too. LGTM

@glasser
Copy link
Contributor Author

glasser commented Feb 11, 2022

By the way, if it's helpful, I'd be happy to be a new maintainer on this project.

@nikcorg
Copy link
Contributor

nikcorg commented Feb 12, 2022

@glasser you already are :-)

Copy link
Contributor

@nicolas377 nicolas377 left a comment

Choose a reason for hiding this comment

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

Hopefully this will make the bot happy with the tsconfig

types/node-fetch/tsconfig.json Outdated Show resolved Hide resolved
Co-authored-by: Nicolas Rodriguez <programnicolas@gmail.com>
@glasser
Copy link
Contributor Author

glasser commented Feb 13, 2022

@nicolas377 I'll take your word for it! I guess something about what needs to be in tsconfig.json changed in the last few months?

@typescript-bot typescript-bot removed the Check Config Changes a module config files label Feb 13, 2022
@typescript-bot typescript-bot moved this from Needs Maintainer Action to Waiting for Code Reviews in New Pull Request Status Board Feb 13, 2022
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Action in New Pull Request Status Board Feb 13, 2022
@typescript-bot
Copy link
Contributor

@nicolas377, @abernix, @trevor-scheer Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot moved this from Needs Maintainer Action to Waiting for Code Reviews in New Pull Request Status Board Feb 13, 2022
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Action in New Pull Request Status Board Feb 13, 2022
@typescript-bot
Copy link
Contributor

@peterblazejewicz, @nikcorg, @nicolas377, @abernix, @trevor-scheer Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

Copy link
Member

@peterblazejewicz peterblazejewicz left a comment

Choose a reason for hiding this comment

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

LGTM!
@glasser thanks!
Please stay put in case something gets broken, thx!

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Feb 13, 2022
@typescript-bot typescript-bot moved this from Needs Maintainer Action to Waiting for Author to Merge in New Pull Request Status Board Feb 13, 2022
@glasser
Copy link
Contributor Author

glasser commented Feb 14, 2022

Cool! I'll do so tomorrow when I'm in more "work mode".

@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Feb 14, 2022
@glasser
Copy link
Contributor Author

glasser commented Feb 14, 2022

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Feb 14, 2022
@typescript-bot typescript-bot merged commit 472e88e into DefinitelyTyped:master Feb 14, 2022
@glasser
Copy link
Contributor Author

glasser commented Feb 15, 2022

Thanks everyone! One final question: I see that this published to the latest tag, which previously had v3.0.2. Is that reasonable? (If you're using v3 you should just be using the types that have been bundled in the package itself since v3.0.0, so I think this is ok?)

@trevor-scheer
Copy link
Contributor

It seems like the v3's just ought to be deprecated (it looks like the most recent 3.0.3 actually was)

@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Feb 15, 2022
@distracteddev
Copy link

distracteddev commented Feb 15, 2022

Seems like @types/node-fetch v2.6.0 has broken our latest builds that include @azure/core-http.

The latter requires node-fetch@2.6.x, which pulls in the new published types version. However, the published types appear broken because it cannot find the .d.ts file for the form-data dependency. This manifests in the following error:

node_modules/@types/node-fetch/index.d.ts(19,27): error TS7016: Could not find a declaration file for module 'form-data'. '/x/x/x/node_modules/form-data/lib/form_data.js' implicitly has an 'any' type.

Pinning to the 2.5.x types has resolved the issue for me.

@peterblazejewicz
Copy link
Member

/cc @glasser

peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Feb 15, 2022
v2.6 depends on v2.3 of `form-data`. That verison of `form-data` is not
TS native, requires different dependency

DefinitelyTyped#58693 (comment)

/cc @glasser @distracteddev

Thanks!
@peterblazejewicz
Copy link
Member

PR: #58804

peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Feb 15, 2022
v2.6 depends on v2.3 of `form-data`. That verison of `form-data` is not
TS native, requires different dependency

DefinitelyTyped#58693 (comment)

/cc @glasser @distracteddev

Thanks!
typescript-bot pushed a commit that referenced this pull request Feb 15, 2022
….0.0 by @peterblazejewicz

* fix(node-fetch): swap dependency to @types/form-data

v2.6 depends on v2.3 of `form-data`. That verison of `form-data` is not
TS native, requires different dependency

#58693 (comment)

/cc @glasser @distracteddev

Thanks!

* Update types/node-fetch/package.json

* Update types/node-fetch/package.json

* Update types/node-fetch/package.json

Co-authored-by: David Glasser <glasser@apollographql.com>

Co-authored-by: David Glasser <glasser@apollographql.com>
martin-badin pushed a commit to martin-badin/DefinitelyTyped that referenced this pull request Feb 23, 2022
…update version, allow `agent: false` by @glasser

* Revert "🤖 Merge PR DefinitelyTyped#55533 Remove node-fetch - not needed as of 3.0.0 by @ImRodry"

This reverts commit 4d9b113.

node-fetch@3 makes two major changes: they started shipping TS types
with the package, and they switched it to being an ESM-only module. The
latter means that apps which aren't built in a way that supports ESM (or
other npm modules depending on `node-fetch` which don't want to break
their non-ESM users) need to continue using v2. In fact, the README for
`node-fetch` explicitly states

> If you cannot switch to ESM, please use v2 which remains compatible
> with CommonJS. Critical bug fixes will continue to be published for
> v2.

Stats on npmjs.com show that v2 has 43 times more downloads in the past
7 days than v3.

I applaud node-fetch's forward-thinking approach to ESM, and am not here
to tell them that their choice for v3 is wrong. But practically speaking,
v2 is still heavily used and many projects will not be able to upgrade
to v3 without breaking their own backwards compatibility promises.
So it makes sense to continue to maintain v2-specific node-fetch types
(especially as there are specific issues with the published types,
as the next commit in this PR shows).

* Update tslint.json for change from DefinitelyTyped#57489

* node-fetch: update version to 2.6

v2.6 is the current (and presumably final) minor release of v2.
Apparently these types already included at least one v2.6 feature
(`agent` as a function). So, updating the version as suggested at-rule
DefinitelyTyped#55533 (comment)

* node-fetch: `agent` can be a boolean

The `agent` option is (after checking to see if it's a function, and if
so replacing itself with the return value of calling it) passed directly
to `http.request` (or `https.request`) so we should be able to pass any
type supported there. Notably, `agent: false` is distinct from `agent:
undefined`.

A PR making essentially the same change was merged upstream (the
upstream repo maintains their own types for v3 but not for v2):
node-fetch/node-fetch#1502

* Update types/node-fetch/tsconfig.json

Co-authored-by: Nicolas Rodriguez <programnicolas@gmail.com>

* Update types/node-fetch/index.d.ts

Co-authored-by: Niklas Lindgren <nikc@iki.fi>

* Update types/node-fetch/package.json

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>

Co-authored-by: Nicolas Rodriguez <programnicolas@gmail.com>
Co-authored-by: Niklas Lindgren <nikc@iki.fi>
Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
martin-badin pushed a commit to martin-badin/DefinitelyTyped that referenced this pull request Feb 23, 2022
…ependency to ^3.0.0 by @peterblazejewicz

* fix(node-fetch): swap dependency to @types/form-data

v2.6 depends on v2.3 of `form-data`. That verison of `form-data` is not
TS native, requires different dependency

DefinitelyTyped#58693 (comment)

/cc @glasser @distracteddev

Thanks!

* Update types/node-fetch/package.json

* Update types/node-fetch/package.json

* Update types/node-fetch/package.json

Co-authored-by: David Glasser <glasser@apollographql.com>

Co-authored-by: David Glasser <glasser@apollographql.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Edits Infrastructure Edits multiple packages Maintainer Approved New Definition This PR creates a new definition package. Other Approved This PR was reviewed and signed-off by a community member. Self Merge This PR can now be self-merged by the PR author or an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants