Skip to content

Commit f1c38d6

Browse files
committed
fix: issue with cloning bodies
chore: updated packages to @remix-run/web
1 parent 799a790 commit f1c38d6

File tree

13 files changed

+79
-72
lines changed

13 files changed

+79
-72
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
path: packages/${{ matrix.package }}
5555
token: ${{ secrets.GITHUB_TOKEN }}
5656
release-type: node
57-
package-name: "@web-std/${{ matrix.package }}"
57+
package-name: "@remix-run/web-${{ matrix.package }}"
5858
monorepo-tags: true
5959
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"refactor","section":"Changes","hidden":false},{"type":"chore","section":"Changes","hidden":false}]'
6060
command: release-pr
@@ -73,7 +73,7 @@ jobs:
7373
path: packages/${{ matrix.package }}
7474
token: ${{ secrets.GITHUB_TOKEN }}
7575
release-type: node
76-
package-name: "@web-std/${{ matrix.package }}"
76+
package-name: "@remix-run/web-${{ matrix.package }}"
7777
monorepo-tags: true
7878
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"refactor","section":"Changes","hidden":false},{"type":"chore","section":"Changes","hidden":false}]'
7979
command: github-release

packages/blob/Readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @web-std/blob
1+
# @remix-run/web-blob
22

33
[![ci][ci.icon]][ci.url]
44
[![package][version.icon] ![downloads][downloads.icon]][package.url]
@@ -14,7 +14,7 @@ The reason this library exists is because [fetch-blob][] chooses to compromise
1414
Web API compatibility of [`blob.stream()`][w3c blob.stream] by using nodejs
1515
native [Readable][] stream. We found this to be problematic when sharing code
1616
across nodejs and browser runtimes. Instead this library stays true to the
17-
specification by using [ReadableStream][] implementation from [@web-std/stream][]
17+
specification by using [ReadableStream][] implementation from [@remix-run/web-stream][]
1818
library even if that is less convenient in nodejs context.
1919

2020
> Note: Both node [Readable][] streams and web [ReadableStream][] implement
@@ -35,7 +35,7 @@ to do with [node-fetch][].
3535
### Usage
3636

3737
```js
38-
import { Blob } from "@web-std/blob"
38+
import { Blob } from "@remix-run/web-blob"
3939
const blob = new Blob(["hello", new TextEncoder().encode("world")])
4040
for await (const chunk of blob.stream()) {
4141
console.log(chunk)
@@ -50,23 +50,23 @@ be able to get all the type inference out of the box.
5050

5151
## Install
5252

53-
npm install @web-std/blob
53+
npm install @remix-run/web-blob
5454

5555
[ci.icon]: https://github.com/web-std/io/workflows/blob/badge.svg
5656
[ci.url]: https://github.com/web-std/io/actions/workflows/blob.yml
57-
[version.icon]: https://img.shields.io/npm/v/@web-std/blob.svg
58-
[downloads.icon]: https://img.shields.io/npm/dm/@web-std/blob.svg
59-
[package.url]: https://npmjs.org/package/@web-std/blob
60-
[downloads.image]: https://img.shields.io/npm/dm/@web-std/blob.svg
61-
[downloads.url]: https://npmjs.org/package/@web-std/blob
57+
[version.icon]: https://img.shields.io/npm/v/@remix-run/web-blob.svg
58+
[downloads.icon]: https://img.shields.io/npm/dm/@remix-run/web-blob.svg
59+
[package.url]: https://npmjs.org/package/@remix-run/web-blob
60+
[downloads.image]: https://img.shields.io/npm/dm/@remix-run/web-blob.svg
61+
[downloads.url]: https://npmjs.org/package/@remix-run/web-blob
6262
[prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg
6363
[prettier.url]: https://github.com/prettier/prettier
6464
[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob
6565
[fetch-blob]: https://github.com/node-fetch/fetch-blob
6666
[readablestream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
6767
[readable]: https://nodejs.org/api/stream.html#stream_readable_streams
6868
[w3c blob.stream]: https://w3c.github.io/FileAPI/#dom-blob-stream
69-
[@web-std/stream]: https://github.com/web-std/io/tree/main/stream
69+
[@remix-run/web-stream]: https://github.com/web-std/io/tree/main/stream
7070
[for await]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
7171
[buffer]: https://nodejs.org/api/buffer.html
7272
[weakmap]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap

packages/blob/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
},
2727
"dependencies": {
2828
"web-encoding": "1.1.5",
29-
"@remix-run/web-stream": "^1.0.0"
29+
"@remix-run/web-stream": "^1.0.3"
3030
},
3131
"author": "Irakli Gozalishvili <[email protected]> (https://gozala.io)",
3232
"repository": "https://github.com/remix-run/web-std-io",
3333
"license": "MIT",
3434
"devDependencies": {
3535
"@types/node": "15.0.2",
36-
"@web-std/fetch": "^3.0.0",
36+
"@remix-run/web-fetch": "^4.1.1",
3737
"git-validate": "2.2.4",
3838
"husky": "^6.0.0",
3939
"lint-staged": "^11.0.0",

packages/fetch/Readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @web-std/fetch
1+
# @remix-run/web-fetch
22

33
[![ci][ci.icon]][ci.url]
44
[![package][version.icon] ![downloads][downloads.icon]][package.url]
@@ -19,25 +19,25 @@ they put it is:
1919
>
2020
2121
We found these incompatibility to be really problematic when sharing code
22-
across nodejs and browser rutimes. This library uses [@web-std/stream][] instead.
22+
across nodejs and browser rutimes. This library uses [@remix-run/web-stream][] instead.
2323

2424

2525

2626
[ci.icon]: https://github.com/web-std/io/workflows/fetch/badge.svg
2727
[ci.url]: https://github.com/web-std/io/actions/workflows/fetch.yml
28-
[version.icon]: https://img.shields.io/npm/v/@web-std/fetch.svg
29-
[downloads.icon]: https://img.shields.io/npm/dm/@web-std/fetch.svg
30-
[package.url]: https://npmjs.org/package/@web-std/fetch
31-
[downloads.image]: https://img.shields.io/npm/dm/@web-std/fetch.svg
32-
[downloads.url]: https://npmjs.org/package/@web-std/fetch
28+
[version.icon]: https://img.shields.io/npm/v/@remix-run/web-fetch.svg
29+
[downloads.icon]: https://img.shields.io/npm/dm/@remix-run/web-fetch.svg
30+
[package.url]: https://npmjs.org/package/@remix-run/web-fetch
31+
[downloads.image]: https://img.shields.io/npm/dm/@remix-run/web-fetch.svg
32+
[downloads.url]: https://npmjs.org/package/@remix-run/web-fetch
3333
[prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg
3434
[prettier.url]: https://github.com/prettier/prettier
3535
[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob
3636
[fetch-blob]: https://github.com/node-fetch/fetch-blob
3737
[readablestream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
3838
[readable]: https://nodejs.org/api/stream.html#stream_readable_streams
3939
[w3c blob.stream]: https://w3c.github.io/FileAPI/#dom-blob-stream
40-
[@web-std/stream]:https://github.com/web-std/io/tree/main/stream
40+
[@remix-run/web-stream]:https://github.com/web-std/io/tree/main/stream
4141
[Uint8Array]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
4242
[node-fetch]:https://github.com/node-fetch/
4343
[fetch api]:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

packages/fetch/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@
9797
"typescript": "^4.4.4"
9898
},
9999
"dependencies": {
100-
"@remix-run/web-blob": "^3.0.3",
100+
"@remix-run/web-blob": "^3.0.4",
101101
"@remix-run/web-form-data": "^3.0.2",
102-
"@remix-run/web-stream": "^1.0.1",
102+
"@remix-run/web-stream": "^1.0.3",
103103
"data-uri-to-buffer": "^3.0.1",
104104
"mrmime": "^1.0.0",
105105
"@web3-storage/multipart-parser": "^1.0.0"

packages/fetch/src/body.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ export default class Body {
175175
/**
176176
* @returns {Promise<FormData>}
177177
*/
178-
179178
async formData() {
180179
return toFormData(this)
181180
}
@@ -425,7 +424,6 @@ const fromBytes = bytes => new ReadableStream({
425424
* @returns {ReadableStream<Uint8Array>}
426425
*/
427426
export const fromAsyncIterable = content =>
428-
// @ts-ignore
429427
new ReadableStream(new AsyncIterablePump(content));
430428

431429
/**
@@ -451,7 +449,11 @@ class AsyncIterablePump {
451449
controller.close();
452450
break;
453451
} else {
454-
controller.enqueue(next.value);
452+
if (typeof next.value === 'string') {
453+
controller.enqueue(new TextEncoder().encode(next.value));
454+
} else {
455+
controller.enqueue(next.value);
456+
}
455457
}
456458
}
457459
} catch (error) {

packages/fetch/test/request.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {Blob} from '@remix-run/web-fetch';
88
import { ReadableStream } from '@remix-run/web-fetch';
99

1010
import TestServer from './utils/server.js';
11-
import {Request} from '@remix-run/web-fetch';
11+
import {Request,FormData as WebFormData} from '@remix-run/web-fetch';
12+
import {File} from '@remix-run/web-file';
1213

1314
const {expect} = chai;
1415

@@ -19,6 +20,7 @@ describe('Request', () => {
1920
before(async () => {
2021
await local.start();
2122
base = `http://${local.hostname}:${local.port}/`;
23+
global.File = File;
2224
});
2325

2426
after(async () => {
@@ -269,4 +271,24 @@ describe('Request', () => {
269271
expect(result).to.equal('a=1');
270272
});
271273
});
274+
275+
it.only('should read formData after clone with FormData body',async () => {
276+
const ogFormData = new WebFormData();
277+
ogFormData.append('a', 1);
278+
ogFormData.append('b', 2);
279+
ogFormData.append('file', new File(['content'], 'file.txt'));
280+
281+
const request = new Request(base, {
282+
method: 'POST',
283+
body: ogFormData,
284+
});
285+
const clonedRequest = request.clone();
286+
287+
return clonedRequest.formData().then(clonedFormData => {
288+
expect(clonedFormData.get('a')).to.equal("1");
289+
expect(clonedFormData.get('b')).to.equal("2");
290+
const file = clonedFormData.get('file')
291+
expect(typeof file).to.equal("object");
292+
});
293+
});
272294
});

packages/file/Readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Web API compatible [File][] for nodejs.
99
### Usage
1010

1111
```js
12-
import { File, Blob } from "@web-std/file"
12+
import { File, Blob } from "@remix-run/web-file"
1313
const file = new File(["hello", new TextEncoder().encode("world")], "hello")
1414
for await (const chunk of blob.stream()) {
1515
console.log(chunk)
@@ -24,15 +24,15 @@ be able to get all the type innference out of the box.
2424

2525
## Install
2626

27-
npm install @web-std/file
27+
npm install @remix-run/web-file
2828

2929
[ci.icon]: https://github.com/web-std/io/workflows/file/badge.svg
3030
[ci.url]: https://github.com/web-std/io/actions/workflows/file.yml
31-
[version.icon]: https://img.shields.io/npm/v/@web-std/file.svg
32-
[downloads.icon]: https://img.shields.io/npm/dm/@web-std/file.svg
33-
[package.url]: https://npmjs.org/package/@web-std/file
34-
[downloads.image]: https://img.shields.io/npm/dm/@web-std/file.svg
35-
[downloads.url]: https://npmjs.org/package/@web-std/file
31+
[version.icon]: https://img.shields.io/npm/v/@remix-run/web-file.svg
32+
[downloads.icon]: https://img.shields.io/npm/dm/@remix-run/web-file.svg
33+
[package.url]: https://npmjs.org/package/@remix-run/web-file
34+
[downloads.image]: https://img.shields.io/npm/dm/@remix-run/web-file.svg
35+
[downloads.url]: https://npmjs.org/package/@remix-run/web-file
3636
[prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg
3737
[prettier.url]: https://github.com/prettier/prettier
3838
[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob

packages/file/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
},
3030
"types": "./dist/src/lib.d.ts",
3131
"dependencies": {
32-
"@remix-run/web-blob": "^3.0.3"
32+
"@remix-run/web-blob": "^3.0.4"
3333
},
3434
"author": "Irakli Gozalishvili <[email protected]> (https://gozala.io)",
3535
"repository": "https://github.com/remix-run/web-std-io",
3636
"license": "MIT",
3737
"devDependencies": {
3838
"@types/node": "15.0.2",
39-
"@web-std/fetch": "^3.0.0",
39+
"@remix-run/web-fetch": "^4.1.1",
4040
"git-validate": "2.2.4",
4141
"husky": "^6.0.0",
4242
"lint-staged": "^11.0.0",

packages/form-data/Readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @web-std/form-data
1+
# @remix-run/web-form-data
22

33
[![ci][ci.icon]][ci.url]
44
[![package][version.icon] ![downloads][downloads.icon]][package.url]
@@ -9,16 +9,16 @@ Web API compatible [FormData][] for nodejs.
99
## Install
1010

1111
```sh
12-
npm install @web-std/form-data
12+
npm install @remix-run/web-form-data
1313
```
1414

1515
[ci.icon]: https://github.com/web-std/io/workflows/form-data/badge.svg
1616
[ci.url]: https://github.com/web-std/io/actions/workflows/form-data.yml
17-
[version.icon]: https://img.shields.io/npm/v/@web-std/form-data.svg
18-
[downloads.icon]: https://img.shields.io/npm/dm/@web-std/form-data.svg
19-
[package.url]: https://npmjs.org/package/@web-std/form-data
20-
[downloads.image]: https://img.shields.io/npm/dm/@web-std/form-data.svg
21-
[downloads.url]: https://npmjs.org/package/@web-std/form-data
17+
[version.icon]: https://img.shields.io/npm/v/@remix-run/web-form-data.svg
18+
[downloads.icon]: https://img.shields.io/npm/dm/@remix-run/web-form-data.svg
19+
[package.url]: https://npmjs.org/package/@remix-run/web-form-data
20+
[downloads.image]: https://img.shields.io/npm/dm/@remix-run/web-form-data.svg
21+
[downloads.url]: https://npmjs.org/package/@remix-run/web-form-data
2222
[prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg
2323
[prettier.url]: https://github.com/prettier/prettier
2424
[formdata]: https://developer.mozilla.org/en-US/docs/Web/API/FormData

0 commit comments

Comments
 (0)