From 839e1908f3c050b45af176883a7e450fb339bef0 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 22 Jan 2021 02:14:49 -0800 Subject: [PATCH] fix: issue with isolateModules flag (#3495) Fixes #3494 Fixes #3498 It appears that `react-scripts` swaps `isolateModules` which [causes problems in webui](https://github.com/ipfs-shipyard/ipfs-webui/pull/1655#issuecomment-763846124) because according to TS: > Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. TS1205 Changes here address that problem as follows: - `export type {...}` is used as per TS error. - `isolateModules` flag is set to `true` so that such issues can be caught locally. - Setting flags seems to have triggered problems in `ipfs-client`, so I had to add some type annotations to fix that. - Added `references` in `ipfs-client/tsconfig.json`, otherwise it does not pick up changes in the dependencies unless they are manually rebuild. --- packages/ipfs-client/package.json | 3 +++ packages/ipfs-client/src/index.js | 8 ++++++++ packages/ipfs-client/tsconfig.json | 8 ++++++++ packages/ipfs-core-types/src/index.ts | 2 +- packages/ipfs-grpc-client/package.json | 3 +++ packages/ipfs-grpc-client/src/index.js | 8 +++++--- tsconfig.json | 1 + 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/ipfs-client/package.json b/packages/ipfs-client/package.json index 21c615af28..87031ab0fe 100644 --- a/packages/ipfs-client/package.json +++ b/packages/ipfs-client/package.json @@ -22,6 +22,9 @@ ] } }, + "eslintConfig": { + "extends": "ipfs" + }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" diff --git a/packages/ipfs-client/src/index.js b/packages/ipfs-client/src/index.js index 4f391e28fa..db02299da2 100644 --- a/packages/ipfs-client/src/index.js +++ b/packages/ipfs-client/src/index.js @@ -4,6 +4,14 @@ const httpClient = require('ipfs-http-client') const grpcClient = require('ipfs-grpc-client') const mergeOptions = require('merge-options') +/** + * @typedef {import('ipfs-http-client/src/lib/core').ClientOptions} HTTPOptions + * @typedef {import('ipfs-grpc-client/src/index').Options} GRPCOptions + * @typedef {string|URL|import('multiaddr')} Address + * @typedef {{http?: Address, grpc?: Address} & Partial} Options + * + * @param {Options} [opts] + */ module.exports = function createClient (opts = {}) { const clients = [] diff --git a/packages/ipfs-client/tsconfig.json b/packages/ipfs-client/tsconfig.json index 979a39adab..b45232f56a 100644 --- a/packages/ipfs-client/tsconfig.json +++ b/packages/ipfs-client/tsconfig.json @@ -3,6 +3,14 @@ "compilerOptions": { "outDir": "dist" }, + "references": [ + { + "path": "../ipfs-http-client" + }, + { + "path": "../ipfs-grpc-client" + } + ], "include": [ "src", "package.json" diff --git a/packages/ipfs-core-types/src/index.ts b/packages/ipfs-core-types/src/index.ts index c9be30e9cc..b1898affd0 100644 --- a/packages/ipfs-core-types/src/index.ts +++ b/packages/ipfs-core-types/src/index.ts @@ -1,7 +1,7 @@ import { RootAPI } from './root' import { AbortOptions, Await, AwaitIterable } from './basic' -export { +export type { RootAPI, AbortOptions, diff --git a/packages/ipfs-grpc-client/package.json b/packages/ipfs-grpc-client/package.json index c4f300d1da..fa94bc7ef9 100644 --- a/packages/ipfs-grpc-client/package.json +++ b/packages/ipfs-grpc-client/package.json @@ -60,5 +60,8 @@ "rimraf": "^3.0.2", "sinon": "^9.0.3", "typescript": "4.0.x" + }, + "eslintConfig": { + "extends": "ipfs" } } diff --git a/packages/ipfs-grpc-client/src/index.js b/packages/ipfs-grpc-client/src/index.js index 4c56164d80..ecfdffec57 100644 --- a/packages/ipfs-grpc-client/src/index.js +++ b/packages/ipfs-grpc-client/src/index.js @@ -23,9 +23,11 @@ function normaliseUrls (opts) { * @typedef {import('http').Agent} HttpAgent * @typedef {import('https').Agent} HttpsAgent * - * @param {object} opts - * @param {string} opts.url - The URL to connect to as a URL or Multiaddr - * @param {HttpAgent|HttpsAgent} [opts.agent] - http.Agent used to control HTTP client behaviour (node.js only) + * @typedef {Object} Options + * @property {string|URL|import('multiaddr')} url - The URL to connect to as a URL or Multiaddr + * @property {HttpAgent|HttpsAgent} [agent] - http.Agent used to control HTTP client behaviour (node.js only) + * + * @param {Options} [opts] */ module.exports = function createClient (opts = { url: '' }) { opts.url = toUrlString(opts.url) diff --git a/tsconfig.json b/tsconfig.json index 8284e1c35e..2c7ec5306b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "stripInternal": true, "resolveJsonModule": true, "incremental": true, + "isolatedModules": true, "baseUrl": ".", "paths": { "interface-ipfs-core/*": [