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: fix exports for node #205

Closed
wants to merge 1 commit into from
Closed

fix: fix exports for node #205

wants to merge 1 commit into from

Conversation

nozomuikuta
Copy link
Member

@nozomuikuta nozomuikuta commented Jan 30, 2023

Resolves #198

I tested this PR in the following way:

  • Copy files from Stackblitz reproduction link to my local (ofetch.create is not a function #198 (comment))
  • Modify node_modules as this PR
  • Confirm the bug is fixed in my local in 3 ways:
    • With require('ofetch') (from exports["."]["node"]["require"] in package.json
    • With require('ofetch') (from exports["default"]["require"] in package.json (with . subpath deleted in the file for fallback to work)
    • With require('ofetch/node') (from exports["./node"]["require"] in package.json

@nozomuikuta nozomuikuta requested a review from pi0 January 30, 2023 02:26
@nozomuikuta nozomuikuta self-assigned this Jan 30, 2023
@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Merging #205 (3701a1b) into main (5943c5f) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #205   +/-   ##
=======================================
  Coverage   85.75%   85.75%           
=======================================
  Files           5        5           
  Lines         323      323           
  Branches       59       59           
=======================================
  Hits          277      277           
  Misses         46       46           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines +7 to +10
exports.ofetch.create = defaultOptions => getExport("ofetch").then($fetch => $fetch.create(defaultOptions));
exports.ofetch.raw = (input, init) => getExport("ofetch").then($fetch => $fetch.raw(input, init));
exports.ofetch.native = (input, init) => getExport("ofetch").then($fetch => $fetch.native(input, init));

Copy link
Member Author

Choose a reason for hiding this comment

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

Since ofetch is actually $fetch, I added these exports.

export const $fetch = ofetch;

exports.ofetch = createCaller("ofetch");
exports.ofetch.create = defaultOptions => getExport("ofetch").then($fetch => $fetch.create(defaultOptions));
Copy link
Member

Choose a reason for hiding this comment

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

We need to return a sync version of fetch that itself has raw/native/etc

@pi0
Copy link
Member

pi0 commented Jan 30, 2023

Thanks for the PR dear @nozomuikuta. Since issues with CJS support is now resolved using node-fetch-native with CJS support, i'm thinking to completely drop this stub.

@nozomuikuta
Copy link
Member Author

Oh, I see then let me close this PR. 🙆‍♂️

@nozomuikuta nozomuikuta deleted the fix/node-exports branch January 31, 2023 01:33
@markbrouch
Copy link

@pi0 - "Since issues with CJS support is now resolved using node-fetch-native with CJS support", what do you mean here - is a fix forthcoming? I'm just trying to track the issue reported in #198 since that's preventing me from using .create() in my project.

@pi0
Copy link
Member

pi0 commented Feb 16, 2023

~> #211

@markbrouch
Copy link

Great work! fixed the issue for me, thanks.

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.

ofetch.create is not a function
3 participants