From 766804c0dbe0dddc90c41f932dbf009f40bbb845 Mon Sep 17 00:00:00 2001 From: Christian van der Loo Date: Tue, 16 Aug 2022 21:04:02 -0500 Subject: [PATCH] build: repatched ipfs-utils, added postinstall, externalized electron --- packages/server/project.json | 2 +- packages/server/src/types/express/index.d.ts | 5 +- packages/server/tsconfig.lib.json | 4 ++ patches/ipfs-utils+9.0.7.patch | 55 ++++++++++---------- yarn.lock | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/server/project.json b/packages/server/project.json index 64d5d78..1973d78 100644 --- a/packages/server/project.json +++ b/packages/server/project.json @@ -11,7 +11,7 @@ "outputPath": "dist/packages/server", "main": "packages/server/src/init.ts", "tsConfig": "packages/server/tsconfig.lib.json", - "externalDependencies": "none", + "externalDependencies": ["electron"], "webpackConfig": "packages/server/esbuild-webpack.config.js" } }, diff --git a/packages/server/src/types/express/index.d.ts b/packages/server/src/types/express/index.d.ts index 8f1207e..335e2ef 100644 --- a/packages/server/src/types/express/index.d.ts +++ b/packages/server/src/types/express/index.d.ts @@ -2,9 +2,10 @@ import express from "express" import { DecodedIdToken } from "firebase-admin/auth" declare global { - namespace Express { - interface Request { + declare module Express { + export interface Request { token?: DecodedIdToken + user: string } } } diff --git a/packages/server/tsconfig.lib.json b/packages/server/tsconfig.lib.json index 4ef354b..6e6b96b 100644 --- a/packages/server/tsconfig.lib.json +++ b/packages/server/tsconfig.lib.json @@ -5,8 +5,12 @@ "outDir": "../../dist/out-tsc", "declaration": true, "types": [], + "typeRoots": ["./src/types", "./node_modules/@types"], "esModuleInterop": true }, + "ts-node": { + "transpileOnly": true + }, "include": ["**/*.ts"], "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"] } diff --git a/patches/ipfs-utils+9.0.7.patch b/patches/ipfs-utils+9.0.7.patch index 65a451b..8ad9779 100644 --- a/patches/ipfs-utils+9.0.7.patch +++ b/patches/ipfs-utils+9.0.7.patch @@ -1,31 +1,29 @@ -diff --git a/node_modules/ipfs-utils/src/http.js b/node_modules/ipfs-utils/src/http.js -index 0180fdf..40153f9 100644 ---- a/node_modules/ipfs-utils/src/http.js -+++ b/node_modules/ipfs-utils/src/http.js -@@ -1,7 +1,7 @@ - /* eslint-disable no-undef */ - 'use strict' +diff --git a/node_modules/ipfs-utils/src/fetch.js b/node_modules/ipfs-utils/src/fetch.js +index a941d92..fe4fba4 100644 +--- a/node_modules/ipfs-utils/src/fetch.js ++++ b/node_modules/ipfs-utils/src/fetch.js +@@ -9,10 +9,6 @@ + const { isElectronMain } = require('./env') --const { fetch, Request, Headers } = require('./http/fetch') -+const { Request, Headers } = require('./http/fetch') - const { TimeoutError, HTTPError } = require('./http/error') - const merge = require('merge-options').bind({ ignoreUndefined: true }) - const { URL, URLSearchParams } = require('iso-url') + // use window.fetch if it is available, fall back to node-fetch if not +-let impl = 'native-fetch' +- +-if (isElectronMain) { +- impl = 'electron-fetch' +-} +- +-module.exports = require(impl) ++module.exports = (isElectronMain) ? ++ require('electron-fetch') : ++ require('native-fetch') diff --git a/node_modules/ipfs-utils/src/http/fetch.js b/node_modules/ipfs-utils/src/http/fetch.js -index 1a27129..10010d8 100644 +index 1a27129..1e7e940 100644 --- a/node_modules/ipfs-utils/src/http/fetch.js +++ b/node_modules/ipfs-utils/src/http/fetch.js -@@ -1,22 +1,3 @@ - 'use strict' +@@ -8,15 +8,10 @@ + * @property {globalThis.Headers} fetchImpl.Headers + */ --/** -- * @typedef {object} fetchImpl -- * @property {globalThis.fetch} fetchImpl.fetch -- * @property {globalThis.Request} fetchImpl.Request -- * @property {globalThis.Response} fetchImpl.Response -- * @property {globalThis.Headers} fetchImpl.Headers -- */ -- -let implName = './fetch.node' - -if (typeof XMLHttpRequest === 'function') { @@ -34,8 +32,11 @@ index 1a27129..10010d8 100644 - implName = './fetch.browser' -} - --/** @type {fetchImpl} */ + /** @type {fetchImpl} */ -const fetch = require(implName) -- --module.exports = fetch -+module.exports = require("node-fetch") ++const fetch = ++ (typeof XMLHttpRequest === 'function') ? ++ require('./fetch.browser') : ++ require('./fetch.node') + + module.exports = fetch diff --git a/yarn.lock b/yarn.lock index 86c477a..fee81c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9114,7 +9114,7 @@ ipfs-unixfs@^6.0.0, ipfs-unixfs@^6.0.3, ipfs-unixfs@^6.0.9: err-code "^3.0.1" protobufjs "^6.10.2" -ipfs-utils@9.0.7, ipfs-utils@^9.0.6: +ipfs-utils@9.0.7, ipfs-utils@^9.0.6, ipfs-utils@^9.0.7: version "9.0.7" resolved "https://registry.yarnpkg.com/ipfs-utils/-/ipfs-utils-9.0.7.tgz#b8644b9d053e4dd258f69773b146ac243921aa1f" integrity sha512-Umvb0Zydy2zZiTmQBGLfLISr8vOmXX8cxEIP+N8zGHrtRShG/j32yl1xd/BtS+Hbg0FIbVm3opwvxB2gmta0YA== -- 2.51.2