Skip to content

Commit 658a725

Browse files
authored
fix: do not use electron-fetch types (#113)
Use our imaginary native-fetch types instead as they do not require consuming modules to also depend on electron-fetch.
1 parent 53d59cf commit 658a725

File tree

6 files changed

+44
-15
lines changed

6 files changed

+44
-15
lines changed

.aegir.js

+31-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@
22

33
const EchoServer = require('aegir/utils/echo-server')
44
const { format } =require('iso-url')
5+
const path = require('path')
56

6-
let echo = new EchoServer()
7+
/** @type {import('aegir').Options["build"]["config"]} */
8+
const esbuild = {
9+
//inject: [path.join(__dirname, '../../scripts/node-globals.js')],
10+
plugins: [
11+
{
12+
name: 'node built ins',
13+
setup (build) {
14+
build.onResolve({ filter: /^stream$/ }, () => {
15+
return { path: require.resolve('readable-stream') }
16+
})
17+
}
18+
}
19+
]
20+
}
721

822
module.exports = {
9-
hooks: {
10-
pre: async () => {
11-
const server = await echo.start()
12-
const { address, port } = server.server.address()
23+
build: {
24+
config: esbuild
25+
},
26+
test: {
27+
browser: {
28+
config: {
29+
buildConfig: esbuild
30+
}
31+
},
32+
before: async () => {
33+
let echoServer = new EchoServer()
34+
await echoServer.start()
35+
const { address, port } = echoServer.server.address()
1336
return {
37+
echoServer,
1438
env: { ECHO_SERVER : format({ protocol: 'http:', hostname: address, port })}
1539
}
1640
},
17-
post: async () => {
18-
await echo.stop()
41+
async after (options, before) {
42+
await before.echoServer.stop()
1943
}
2044
}
2145
}

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"./src/temp-dir.js": "./src/temp-dir.browser.js",
1717
"./src/path-join.js": "./src/path-join.browser.js",
1818
"./test/files/glob-source.spec.js": false,
19-
"electron-fetch": false
19+
"electron-fetch": false,
20+
"fs-extra": false,
21+
"graceful-fs": false
2022
},
2123
"types": "dist/src/index.d.ts",
2224
"typesVersions": {
@@ -63,13 +65,16 @@
6365
"devDependencies": {
6466
"@types/err-code": "^2.0.0",
6567
"@types/fs-extra": "^9.0.5",
66-
"aegir": "^30.3.0",
68+
"aegir": "^32.2.0",
6769
"delay": "^5.0.0",
70+
"events": "^3.3.0",
6871
"ipfs-unixfs": "^4.0.1",
6972
"it-all": "^1.0.4",
7073
"it-drain": "^1.0.3",
7174
"it-last": "^1.0.4",
72-
"uint8arrays": "^2.0.5"
75+
"readable-stream": "^3.6.0",
76+
"uint8arrays": "^2.0.5",
77+
"util": "^0.12.3"
7378
},
7479
"eslintConfig": {
7580
"extends": "ipfs",

src/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { AbortController } = require('native-abort-controller')
1010
const anySignal = require('any-signal')
1111

1212
/**
13-
* @typedef {import('electron-fetch').Response} Response
13+
* @typedef {import('native-fetch').Response} Response
1414
* @typedef {import('stream').Readable} NodeReadableStream
1515
* @typedef {import('stream').Duplex} NodeDuplexStream
1616
* @typedef {import('./types').HTTPOptions} HTTPOptions

src/http/error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports.AbortError = AbortError
1818

1919
class HTTPError extends Error {
2020
/**
21-
* @param {import('electron-fetch').Response} response
21+
* @param {import('native-fetch').Response} response
2222
*/
2323
constructor (response) {
2424
super(response.statusText)

src/http/fetch.node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { Request, Response, Headers, default: nativeFetch } = require('../fetch')
55
const toStream = require('it-to-stream')
66
const { Buffer } = require('buffer')
77
/**
8-
* @typedef {import('electron-fetch').BodyInit} BodyInit
8+
* @typedef {import('native-fetch').BodyInit} BodyInit
99
* @typedef {import('stream').Readable} NodeReadableStream
1010
*
1111
* @typedef {import('../types').FetchOptions} FetchOptions

src/types.ts src/types.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RequestInit, Response } from 'electron-fetch'
1+
import type { RequestInit, Response } from '../types/native-fetch'
22
interface ProgressStatus {
33
total: number
44
loaded: number
@@ -33,7 +33,7 @@ export interface HTTPOptions extends FetchOptions {
3333
/**
3434
* The base URL to use in case url is a relative URL
3535
*/
36-
base? : string
36+
base?: string
3737
/**
3838
* Throw not ok responses as Errors
3939
*/

0 commit comments

Comments
 (0)