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: switch to cross-fetch from request #7

Merged
merged 5 commits into from
Jul 21, 2022

Conversation

strmer15
Copy link

@strmer15 strmer15 commented Apr 18, 2022

Motivation and Context

This library currently uses the request library for its CLI usage, but request has been deprecated for over 2 years, which means that all projects that depend on it also install request, which includes all users of @stoplight/prism-cli. cross-fetch is an isomorphic implementation of the fetch API that is not deprecated and provides very similar functionality.

Description

I removed the request dependency, added in the cross-fetch dependency, removed yarn.lock and then ran yarn install. I replaced the require('request') with require('node-fetch'), switched the request(...) invocation to fetch(...).then(...).catch(...), and pulled out the common error handling code into a separate function. I uncommented all the CLI tests, fixed them, then ran yarn test to verify they all passed.

How Has This Been Tested?

Ran yarn test to verify everything passed locally, and uncommented the CLI tests to verify they worked.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

@strmer15
Copy link
Author

@chohmann Not sure if you can review or someone else can, this would help resolve a lot of dependency pollution in apps like ours that don't use the request library but have it pulled in by @stoplight/prism-cli.

@strmer15
Copy link
Author

@marbemac Can you review this or do you know who can? Thanks!

@CGiustiniani
Copy link

@marbemac, @wmhilton, @daniel-white, @lottamus, @mmiask Can anybody please review/check this PR as the request package is deprecated for over 2 years now

@daniel-white
Copy link
Member

Should we make this use an isomorphic version to run in the browser?

lib/cli/in.js Outdated
fetch(url)
.then(function (response) {
if (response.status === 200) {
callback(body);
Copy link
Member

Choose a reason for hiding this comment

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

where is body coming from now? we'll need to use the response.text() or equivalent here

Copy link
Author

Choose a reason for hiding this comment

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

Good call - I'll fix that up. I guess I'm too used to Typescript where I would have gotten a type error 😁

Copy link
Author

Choose a reason for hiding this comment

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

Should be fixed now! I also spent a lot of time making sure the unit tests actually worked - they would pass previously but they weren't actually working due to the way stdout and stderr were being passed back in the test helper function. I added in a test express server that would allow us to verify that fetch is bringing back the correct data.

package.json Outdated Show resolved Hide resolved
@strmer15
Copy link
Author

Should we make this use an isomorphic version to run in the browser?

@daniel-white Thanks for reviewing! This is a CLI as far as I can tell, so I don't think it will ever run in a browser. That said, I don't mind using cross-fetch if you think it makes sense.

@daniel-white
Copy link
Member

@strmer15 cross-fetch would be appreciated - internally we do use this in a browser, so the flexibility there would be be appreciated

…eading the request body; use cross-fetch instead of node-fetch; fix the unit tests and add in a test server; remove old stubby config that wasn't used; fix reading from stdin
@strmer15 strmer15 changed the title switch to node-fetch from request, update dependencies switch to cross-fetch from request Jul 20, 2022
@strmer15
Copy link
Author

@strmer15 cross-fetch would be appreciated - internally we do use this in a browser, so the flexibility there would be be appreciated

@daniel-white done! Let me know if you have any other concerns with this PR, thanks for reviewing!

@daniel-white daniel-white changed the title switch to cross-fetch from request fix: switch to cross-fetch from request Jul 21, 2022
@daniel-white daniel-white merged commit 0a85c0e into stoplightio:master Jul 21, 2022
@strmer15 strmer15 deleted the use_node_fetch branch July 21, 2022 13:17
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants