Skip to content

Commit

Permalink
fix: node 18 compat issue in the node fetch client
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Sep 5, 2024
1 parent d66f818 commit 2f59cec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"files.insertFinalNewline": false,

"search.exclude": {
"coverage": true,
"coverage": true
}
}
7 changes: 6 additions & 1 deletion src/targets/node/fetch/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export const fetch: Client = {

if (param.fileName) {
includeFS = true;
push(`formData.append('${param.name}', await fs.openAsBlob('${param.fileName}'));`);

// Whenever we drop support for Node 18 we can change this blob work to use
// `fs.openAsBlob('filename')`.
push(
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`,
);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/targets/node/fetch/fixtures/multipart-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';

const formData = new FormData();
formData.append('foo', await fs.openAsBlob('src/fixtures/files/hello.txt'));
formData.append('foo', await new Response(fs.createReadStream('src/fixtures/files/hello.txt')).blob());
formData.append('bar', 'Bonjour le monde');

const url = 'https://httpbin.org/anything';
Expand Down
2 changes: 1 addition & 1 deletion src/targets/node/fetch/fixtures/multipart-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';

const formData = new FormData();
formData.append('foo', await fs.openAsBlob('src/fixtures/files/hello.txt'));
formData.append('foo', await new Response(fs.createReadStream('src/fixtures/files/hello.txt')).blob());

const url = 'https://httpbin.org/anything';
const options = {method: 'POST', body: formData};
Expand Down

0 comments on commit 2f59cec

Please sign in to comment.