Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not use electron-fetch types #113

Merged
merged 4 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,44 @@

const EchoServer = require('aegir/utils/echo-server')
const { format } =require('iso-url')
const path = require('path')

let echo = new EchoServer()
/** @type {import('aegir').Options["build"]["config"]} */
const esbuild = {
//inject: [path.join(__dirname, '../../scripts/node-globals.js')],
plugins: [
{
name: 'node built ins',
setup (build) {
build.onResolve({ filter: /^stream$/ }, () => {
return { path: require.resolve('readable-stream') }
})
}
}
]
}

module.exports = {
hooks: {
pre: async () => {
const server = await echo.start()
const { address, port } = server.server.address()
build: {
config: esbuild
},
test: {
browser: {
config: {
buildConfig: esbuild
}
},
before: async () => {
let echoServer = new EchoServer()
await echoServer.start()
const { address, port } = echoServer.server.address()
return {
echoServer,
env: { ECHO_SERVER : format({ protocol: 'http:', hostname: address, port })}
}
},
post: async () => {
await echo.stop()
async after (options, before) {
await before.echoServer.stop()
}
}
}
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"./src/temp-dir.js": "./src/temp-dir.browser.js",
"./src/path-join.js": "./src/path-join.browser.js",
"./test/files/glob-source.spec.js": false,
"electron-fetch": false
"electron-fetch": false,
"fs-extra": false,
"graceful-fs": false
},
"types": "dist/src/index.d.ts",
"typesVersions": {
Expand Down Expand Up @@ -63,13 +65,16 @@
"devDependencies": {
"@types/err-code": "^2.0.0",
"@types/fs-extra": "^9.0.5",
"aegir": "^30.3.0",
"aegir": "^32.2.0",
"delay": "^5.0.0",
"events": "^3.3.0",
"ipfs-unixfs": "^4.0.1",
"it-all": "^1.0.4",
"it-drain": "^1.0.3",
"it-last": "^1.0.4",
"uint8arrays": "^2.0.5"
"readable-stream": "^3.6.0",
"uint8arrays": "^2.0.5",
"util": "^0.12.3"
},
"eslintConfig": {
"extends": "ipfs",
Expand Down
2 changes: 1 addition & 1 deletion src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { AbortController } = require('native-abort-controller')
const anySignal = require('any-signal')

/**
* @typedef {import('electron-fetch').Response} Response
* @typedef {import('native-fetch').Response} Response
* @typedef {import('stream').Readable} NodeReadableStream
* @typedef {import('stream').Duplex} NodeDuplexStream
* @typedef {import('./types').HTTPOptions} HTTPOptions
Expand Down
2 changes: 1 addition & 1 deletion src/http/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.AbortError = AbortError

class HTTPError extends Error {
/**
* @param {import('electron-fetch').Response} response
* @param {import('native-fetch').Response} response
*/
constructor (response) {
super(response.statusText)
Expand Down
2 changes: 1 addition & 1 deletion src/http/fetch.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Request, Response, Headers, default: nativeFetch } = require('../fetch')
const toStream = require('it-to-stream')
const { Buffer } = require('buffer')
/**
* @typedef {import('electron-fetch').BodyInit} BodyInit
* @typedef {import('native-fetch').BodyInit} BodyInit
* @typedef {import('stream').Readable} NodeReadableStream
*
* @typedef {import('../types').FetchOptions} FetchOptions
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts → src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequestInit, Response } from 'electron-fetch'
import type { RequestInit, Response } from '../types/native-fetch'
interface ProgressStatus {
total: number
loaded: number
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface HTTPOptions extends FetchOptions {
/**
* The base URL to use in case url is a relative URL
*/
base? : string
base?: string
/**
* Throw not ok responses as Errors
*/
Expand Down