Skip to content

Commit dcad4d4

Browse files
feat(client): improve compatibility with Bun (#119)
1 parent fa163d7 commit dcad4d4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/_shims/formdata.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
*/
44

55
exports.FormData = FormData;
6-
exports.File = File;
76
exports.Blob = Blob;
7+
exports.File =
8+
typeof File !== 'undefined' ? File : (
9+
// Bun doesn't implement File yet, so just make a shim that throws a helpful error message
10+
class File extends Blob {
11+
constructor() {
12+
throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`);
13+
}
14+
}
15+
);
816

917
exports.isPolyfilled = false;

src/_shims/formdata.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
*/
44

55
const _FormData = FormData;
6-
const _File = File;
76
const _Blob = Blob;
87

8+
const _File =
9+
typeof File !== 'undefined' ? File : (
10+
// Bun doesn't implement File yet, so just make a shim that throws a helpful error message
11+
class File extends Blob {
12+
constructor() {
13+
throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`);
14+
}
15+
}
16+
);
17+
918
export { _FormData as FormData, _File as File, _Blob as Blob };
1019

1120
export const isPolyfilled = false;

0 commit comments

Comments
 (0)