From 34a93885587bcdfde493f64bda157276a07a292c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 1 Apr 2021 17:56:30 +0100 Subject: [PATCH 1/4] fix: do not use electron-fetch types Use our imaginary native-fetch types instead as they do not require consuming modules to also depend on electron-fetch. --- src/http.js | 2 +- src/http/error.js | 2 +- src/http/fetch.node.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/http.js b/src/http.js index 880d4ba..8332e7c 100644 --- a/src/http.js +++ b/src/http.js @@ -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 diff --git a/src/http/error.js b/src/http/error.js index 0c61dc9..aa5c9d6 100644 --- a/src/http/error.js +++ b/src/http/error.js @@ -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) diff --git a/src/http/fetch.node.js b/src/http/fetch.node.js index 049b241..27d8ee8 100644 --- a/src/http/fetch.node.js +++ b/src/http/fetch.node.js @@ -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 From 082e3cf4b197ab11da1415f12b7b6cfd7a530dcb Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 1 Apr 2021 18:16:37 +0100 Subject: [PATCH 2/4] chore: upgrade aegir --- .aegir.js | 38 +++++++++++++++++++++++++++++++------- package.json | 11 ++++++++--- src/types.ts | 2 +- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.aegir.js b/.aegir.js index 7733250..e0fddb4 100644 --- a/.aegir.js +++ b/.aegir.js @@ -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() } } } \ No newline at end of file diff --git a/package.json b/package.json index 2aefdf0..78ca7a5 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/src/types.ts b/src/types.ts index 322550e..449f552 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 */ From 41ca09b9f1eea3f59b4774936099062019928470 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 1 Apr 2021 18:22:53 +0100 Subject: [PATCH 3/4] chore: update import in types.d.ts --- src/{types.ts => types.d.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{types.ts => types.d.ts} (95%) diff --git a/src/types.ts b/src/types.d.ts similarity index 95% rename from src/types.ts rename to src/types.d.ts index 449f552..a368750 100644 --- a/src/types.ts +++ b/src/types.d.ts @@ -1,4 +1,4 @@ -import type { RequestInit, Response } from 'electron-fetch' +import type { RequestInit, Response } from 'native-fetch' interface ProgressStatus { total: number loaded: number From fd5768aa47dad7afbc48b7d4f2ead4973279e289 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 1 Apr 2021 18:36:43 +0100 Subject: [PATCH 4/4] chore: update type path --- src/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.d.ts b/src/types.d.ts index a368750..910ec56 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,4 @@ -import type { RequestInit, Response } from 'native-fetch' +import type { RequestInit, Response } from '../types/native-fetch' interface ProgressStatus { total: number loaded: number