Skip to content

Conversation

@septs
Copy link

@septs septs commented Jan 5, 2021

fix #107

@septs septs mentioned this pull request Jan 5, 2021
@philsturgeon
Copy link
Member

Conceptually this seems like a good idea, but a few things:

Firstly, is there any documentation required to fully solve #107, does the user need to change anything or is it just magic?

Secondly. another attempt was made to fix #107 by using request in #108, and that was closed as it doesn't work in the browser. fetch() does work in the browser ofc, but we might need to do a little more work to make sure node-fetch is only loaded in node and normal fetch is available in the browser.

@P0lip I'd appreciate your input here on the second thing, because this will effect @stoplightio stuff, probably for the better.

@septs
Copy link
Author

septs commented Jan 6, 2021

Secondly. another attempt was made to fix #107 by using request in #108, and that was closed as it doesn't work in the browser. fetch() does work in the browser ofc, but we might need to do a little more work to make sure node-fetch is only loaded in node and normal fetch is available in the browser.

support via browser field in package.json on browser downgrade to native fetch

see https://github.com/node-fetch/node-fetch/blob/2.x/package.json#L6
see https://github.com/node-fetch/node-fetch/blob/2.x/browser.js
see https://github.com/defunctzombie/package-browser-field-spec

Copy link
Member

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
I'm very supportive when it comes to getting rid of http and https. It's a step in good direction since this makes the integration of json-schema-ref-parser in browser environment much easier.
There are a few comments left to address, however.
Let me know if anything needs further clarification. Happy to help getting this PR over the finish line.

@septs septs requested a review from P0lip January 8, 2021 21:20
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, Request does not support timeout.
You need to use AbortController.
There is a neat usage example included in the link above.

Copy link
Author

Choose a reason for hiding this comment

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

see https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal

i think, remove timeout option may be better.

Copy link
Author

@septs septs Jan 9, 2021

Choose a reason for hiding this comment

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

if so, need to add extra library, https://npm.im/abort-controller (over 2 year, no any update)

Copy link
Member

Choose a reason for hiding this comment

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

Let's add the library. The fact the last release took place 2 years is nothing wrong. The spec has simply not changed since then, so there was no need to introduce any change.
I had a chance to utilize that library in the past and I can say it's solid.

@philsturgeon philsturgeon changed the title use node-fetch simplify http resolver use isomorphic-fetch simplify http resolver Jan 11, 2021
@philsturgeon
Copy link
Member

I think removing timeouts and redirect logic is a little nuclear here, as there are alternative approaches.

To get timeouts working with abort controller: https://dmitripavlutin.com/timeout-fetch-request/

There's some stuff on google about follow redirects being built in https://stackoverflow.com/questions/39735496/redirect-after-a-fetch-post-call#39739894 but im not sure if thats going to work for this specific implementation.

Anyhow, if we remove these that's probably a major release, and it's not a great sales pitch to just say there's less functionality now.

@philsturgeon
Copy link
Member

Btw I appreciate your work on this! Sorry if that doesn't come across, I write a little too quickly sometimes, never mean to sound rude! 😅

@septs
Copy link
Author

septs commented Jan 11, 2021

i planning use typescript design a new library.

@septs septs closed this Jan 11, 2021
@philsturgeon
Copy link
Member

@septs I don't understand. You had almost finished this feature and instead something something now you're doing a new one in TypeScript?

There's already a TypeScript rewrite of this library that's coming along quite nicely, and it does a lot more than just switch to TS. There's years of domain knowledge built up in this codebase and that one. Would you like to work together instead of duplicating efforts?

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

Labels

None yet

3 participants