diff options
author | 2023-08-06 20:39:40 -0700 | |
---|---|---|
committer | 2023-08-06 20:39:40 -0700 | |
commit | 0665733b0302ac7e743e4c131c7697741fa923a5 (patch) | |
tree | 2609e7055acbb308ddd52b45393a9b61fdc397bf /src/js | |
parent | 70c3371b14293e18a5e0470e8b8cd4c04259a606 (diff) | |
download | bun-0665733b0302ac7e743e4c131c7697741fa923a5.tar.gz bun-0665733b0302ac7e743e4c131c7697741fa923a5.tar.zst bun-0665733b0302ac7e743e4c131c7697741fa923a5.zip |
Fixes #4029 and fixes #4022 (#4032)
* Fixes #4029 and Fixes #4022
Fixes #4029
Fixes #4022
* Add test for all the fetches
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/out/InternalModuleRegistryConstants.h | 12 | ||||
-rw-r--r-- | src/js/thirdparty/isomorphic-fetch.js | 6 | ||||
-rw-r--r-- | src/js/thirdparty/node-fetch.js | 1 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h index 5cd010c12..0ad5c4c97 100644 --- a/src/js/out/InternalModuleRegistryConstants.h +++ b/src/js/out/InternalModuleRegistryConstants.h @@ -209,11 +209,11 @@ static constexpr ASCIILiteral ThirdpartyDetectLibcLinuxCode = "(function (){\"us // // -static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";return globalThis.fetch})\n"_s; +static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";const bunFetch=Bun.fetch,fetch=(...args)=>bunFetch(...args);return fetch.default=fetch,fetch.fetch=fetch,fetch})\n"_s; // // -static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch})})\n"_s; +static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch,default:fetch})})\n"_s; // // @@ -434,11 +434,11 @@ static constexpr ASCIILiteral ThirdpartyDetectLibcLinuxCode = "(function (){\"us // // -static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";return globalThis.fetch})\n"_s; +static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";const bunFetch=Bun.fetch,fetch=(...args)=>bunFetch(...args);return fetch.default=fetch,fetch.fetch=fetch,fetch})\n"_s; // // -static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch})})\n"_s; +static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch,default:fetch})})\n"_s; // // @@ -660,11 +660,11 @@ static constexpr ASCIILiteral ThirdpartyDetectLibcLinuxCode = "(function (){\"us // // -static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";return globalThis.fetch})\n"_s; +static constexpr ASCIILiteral ThirdpartyIsomorphicFetchCode = "(function (){\"use strict\";const bunFetch=Bun.fetch,fetch=(...args)=>bunFetch(...args);return fetch.default=fetch,fetch.fetch=fetch,fetch})\n"_s; // // -static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch})})\n"_s; +static constexpr ASCIILiteral ThirdpartyNodeFetchCode = "(function (){\"use strict\";const{Headers,Request,Response,Blob,File=Blob,FormData}=globalThis,realFetch=Bun.fetch;function fetch(...args){return realFetch(...args)}class AbortError extends DOMException{constructor(message){super(message,\"AbortError\")}}class FetchBaseError extends Error{constructor(message,type){super(message);this.type=type}}class FetchError extends FetchBaseError{constructor(message,type,systemError){super(message,type);this.code=systemError\?.code}}function blobFrom(path,options){return Promise.resolve(Bun.file(data))}function blobFromSync(path,options){return Bun.file(data)}var fileFrom=blobFrom,fileFromSync=blobFromSync;function isRedirect(code){return code===301||code===302||code===303||code===307||code===308}return Object.assign(fetch,{AbortError,Blob,FetchBaseError,FetchError,File,FormData,Headers,Request,Response,blobFrom,blobFromSync,fileFrom,fileFromSync,isRedirect,fetch,default:fetch})})\n"_s; // // diff --git a/src/js/thirdparty/isomorphic-fetch.js b/src/js/thirdparty/isomorphic-fetch.js index 7b36684e2..59c8a6d06 100644 --- a/src/js/thirdparty/isomorphic-fetch.js +++ b/src/js/thirdparty/isomorphic-fetch.js @@ -1 +1,5 @@ -export default globalThis.fetch; +const bunFetch = Bun.fetch; +const fetch = (...args) => bunFetch(...args); +fetch.default = fetch; +fetch.fetch = fetch; +export default fetch; diff --git a/src/js/thirdparty/node-fetch.js b/src/js/thirdparty/node-fetch.js index 899536d9b..f8bc9e3cd 100644 --- a/src/js/thirdparty/node-fetch.js +++ b/src/js/thirdparty/node-fetch.js @@ -60,4 +60,5 @@ export default Object.assign(fetch, { fileFromSync, isRedirect, fetch, + default: fetch, }); |