Skip to content

Commit 874a28b

Browse files
authored
fix: fetch in cjs runtime (#21)
1 parent 960a258 commit 874a28b

File tree

9 files changed

+21
-38
lines changed

9 files changed

+21
-38
lines changed

.github/workflows/fetch.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
- name: Install
7373
uses: bahmutov/npm-install@v1
7474

75-
- name: Test
75+
- name: Test (ESM)
7676
run: yarn --cwd ${{matrix.project}} test -- --colors
7777

7878
# upload coverage only once
@@ -81,6 +81,9 @@ jobs:
8181
if: matrix.node == '14' && matrix.os == 'ubuntu-latest'
8282
with:
8383
github-token: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Test (CJS)
86+
run: yarn --cwd ${{matrix.project}} test:cjs
8487
publish:
8588
name: Publish
8689
needs:

blob/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"prepare": "npm run build",
4747
"test:es": "uvu test all.spec.js",
4848
"test:web": "playwright-test -r uvu test/web.spec.js",
49-
"test:cjs": "rimraf dist && npm run build && node dist/test/web.spec.cjs",
49+
"test:cjs": "rimraf dist && npm run build && node dist/test/all.spec.cjs",
5050
"test": "npm run test:es && npm run test:cjs",
5151
"precommit": "lint-staged"
5252
},

fetch/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
"node": "^10.17 || >=12.3"
2525
},
2626
"scripts": {
27-
"build": "rollup -c",
27+
"build": "npm run build:cjs && npm run build:types",
2828
"test": "node --experimental-modules ../node_modules/c8/bin/c8 --reporter=html --reporter=lcov --reporter=text --check-coverage node --experimental-modules ../node_modules/mocha/bin/mocha",
29+
"test:cjs": "node ./test/commonjs/test-artifact.js",
2930
"coverage": "c8 report --reporter=text-lcov | coveralls",
3031
"typecheck": "tsc --build",
32+
"build:types": "tsc --build",
33+
"build:cjs": "rollup -c",
3134
"lint": "xo",
32-
"prepublishOnly": "node ./test/commonjs/test-artifact.js && tsc --build"
35+
"prepare": "npm run build"
3336
},
3437
"repository": {
3538
"type": "git",
@@ -76,7 +79,7 @@
7679
"@web-std/form-data": "^2.1.0",
7780
"data-uri-to-buffer": "^3.0.1",
7881
"web-streams-polyfill": "^3.1.1",
79-
"@ssttevee/multipart-parser": "^0.1.9"
82+
"@web3-storage/multipart-parser": "^1.0.0"
8083
},
8184
"esm": {
8285
"sourceMap": true,

fetch/src/utils/form-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {randomBytes} from 'crypto';
2-
import { iterateMultipart } from '@ssttevee/multipart-parser'
2+
import { iterateMultipart } from '@web3-storage/multipart-parser';
33
import {isBlob} from './is.js';
44

55
const carriage = '\r\n';

fetch/test/commonjs/test-artifact.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
// @ts-nocheck
2-
/**
3-
* Rebuild first
4-
*/
5-
const {execFileSync} = require('child_process');
6-
7-
console.log('Building CommonJS version...');
8-
execFileSync('npm', ['run', 'build'], {stdio: 'inherit'});
92

103
const assert = require('assert');
114
const fetch = require('../../');

file/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"prepare": "npm run build",
5151
"test:es": "uvu test all.spec.js",
5252
"test:web": "playwright-test -r uvu test/web.spec.js",
53-
"test:cjs": "rimraf dist && npm run build && node dist/test/web.spec.cjs",
53+
"test:cjs": "rimraf dist && npm run build && node dist/test/all.spec.cjs",
5454
"test": "npm run test:es && npm run test:cjs",
5555
"precommit": "lint-staged"
5656
},

form-data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"prepare": "npm run build",
5252
"test:es": "uvu test all.spec.js",
5353
"test:web": "playwright-test -r uvu test/web.spec.js",
54-
"test:cjs": "rimraf dist && npm run build && node dist/test/web.spec.cjs",
54+
"test:cjs": "rimraf dist && npm run build && node dist/test/all.spec.cjs",
5555
"test": "npm run test:es && npm run test:cjs",
5656
"precommit": "lint-staged"
5757
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"fetch"
88
],
99
"scripts": {
10-
"prepare": "yarn prepare:blob && yarn prepare:file && yarn prepare:form-data",
10+
"prepare": "yarn prepare:blob && yarn prepare:file && yarn prepare:form-data && yarn prepare:fetch",
1111
"prepare:blob": "yarn --cwd blob prepare",
1212
"prepare:file": "yarn --cwd file prepare",
1313
"prepare:form-data": "yarn --cwd form-data prepare",
14+
"prepare:fetch": "yarn --cwd fetch prepare",
1415
"test": "yarn test:blob && yarn test:file && yarn test:form-data && yarn test:fetch",
1516
"test:blob": "yarn --cwd blob test",
1617
"test:file": "yarn --cwd file test",

yarn.lock

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,6 @@
308308
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
309309
integrity sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==
310310

311-
"@ssttevee/multipart-parser@^0.1.9":
312-
version "0.1.9"
313-
resolved "https://registry.yarnpkg.com/@ssttevee/multipart-parser/-/multipart-parser-0.1.9.tgz#972a8bffe7204aa3f519f53bc06adee3498df15b"
314-
integrity sha512-4GmChu029N2VHdi3SEQMlqTctNRisGoE4HOLAsL7p6nrlWHQ63dqVZ2IsnI0HGizzt2/0MLFNlaF7EFBsuXK2g==
315-
dependencies:
316-
"@ssttevee/streamsearch" "~0.3.0"
317-
"@ssttevee/u8-utils" "~0.1.5"
318-
319-
"@ssttevee/streamsearch@~0.3.0":
320-
version "0.3.1"
321-
resolved "https://registry.yarnpkg.com/@ssttevee/streamsearch/-/streamsearch-0.3.1.tgz#7f608ce5a1f77a2ac51e84a5c5a128c62f505828"
322-
integrity sha512-qL6bEa8R1KlN0rcLVWaLZfS+IVi5nw51FlO54p8PbCkspM5G8ssZhcCNJjnPxSPNz1BqIIt0Rm4tALBilYx1dw==
323-
dependencies:
324-
"@ssttevee/u8-utils" "~0.1.5"
325-
326-
"@ssttevee/u8-utils@~0.1.5":
327-
version "0.1.7"
328-
resolved "https://registry.yarnpkg.com/@ssttevee/u8-utils/-/u8-utils-0.1.7.tgz#fb8db35ca9dda860ad3eaf1b557f61e4d43950bc"
329-
integrity sha512-bSD+ocJRyAWiav1w7iQmAJ+ao/DJ5cRLcs2VsFDQeA1pODdF8cVZYy69+/irAeEntYoFbKigID/eM389pZ3vMA==
330-
331311
"@szmarczak/http-timer@^1.1.2":
332312
version "1.1.2"
333313
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
@@ -470,6 +450,11 @@
470450
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
471451
integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==
472452

453+
"@web3-storage/multipart-parser@^1.0.0":
454+
version "1.0.0"
455+
resolved "https://registry.yarnpkg.com/@web3-storage/multipart-parser/-/multipart-parser-1.0.0.tgz#6b69dc2a32a5b207ba43e556c25cc136a56659c4"
456+
integrity sha512-BEO6al7BYqcnfX15W2cnGR+Q566ACXAT9UQykORCWW80lmkpWsnEob6zJS1ZVBKsSJC8+7vJkHwlp+lXG1UCdw==
457+
473458
474459
version "0.9.0"
475460
resolved "https://registry.yarnpkg.com/@zxing/text-encoding/-/text-encoding-0.9.0.tgz#fb50ffabc6c7c66a0c96b4c03e3d9be74864b70b"
@@ -4829,7 +4814,6 @@ readable-stream@^2.0.2, readable-stream@^2.3.3, readable-stream@^2.3.6:
48294814

48304815
readable-stream@^3.4.0, readable-stream@^3.6.0, "readable-stream@https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz":
48314816
version "3.6.0"
4832-
uid "25682c94346526abc8c8b1ece125b52a7247bb2e"
48334817
resolved "https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz#25682c94346526abc8c8b1ece125b52a7247bb2e"
48344818
dependencies:
48354819
browser-util-inspect "^0.2.0"
@@ -5581,7 +5565,6 @@ text-table@^0.2.0:
55815565

55825566
"through2@https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz":
55835567
version "4.0.2"
5584-
uid ea39512757acd2dab1be4ff1eeb1e43708aa7333
55855568
resolved "https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz#ea39512757acd2dab1be4ff1eeb1e43708aa7333"
55865569
dependencies:
55875570
readable-stream "https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz"

0 commit comments

Comments
 (0)