From 3a0f870483112e51adba0ccc163d171d3841bac7 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 16:25:07 +0000 Subject: [PATCH 01/17] fix: only require http api client if it has not been specified If we configure which http api module to use, don't try to require `ipfs-http-client`, because that then means the containing project needs to specify a dependency on `ipfs-http-client` when the containing project might actually be `ipfs-http-client`... --- src/factory.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/factory.js b/src/factory.js index d44e3525..801420e0 100644 --- a/src/factory.js +++ b/src/factory.js @@ -21,11 +21,6 @@ const defaults = { type: 'go', env: {}, args: [], - ipfsHttpModule: { - path: require.resolve('ipfs-http-client'), - ref: require('ipfs-http-client') - }, - ipfsModule: {}, ipfsOptions: {}, forceKill: true, forceKillTimeout: 5000 @@ -126,6 +121,16 @@ class Factory { options ) + // only include the http api client if it has not been specified as an option + // for example if we are testing the http api client itself we should not try + // to require 'ipfs-http-client' + if (!opts.ipfsHttpModule) { + opts.ipfsHttpModule = { + path: require.resolve('ipfs-http-client'), + ref: require('ipfs-http-client') + } + } + // IPFS options defaults const ipfsOptions = merge( { From ad2e60d857f6cf0687b28af2984b23ab43d7d95f Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 16:46:38 +0000 Subject: [PATCH 02/17] chore: update bundle size No idea why this is necessary --- .aegir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.aegir.js b/.aegir.js index 6e6ba9aa..d2320439 100644 --- a/.aegir.js +++ b/.aegir.js @@ -4,7 +4,7 @@ const createServer = require('./src').createServer const server = createServer() // using defaults module.exports = { - bundlesize: { maxSize: '930kB' }, + bundlesize: { maxSize: '940kB' }, karma: { files: [{ pattern: 'test/fixtures/**/*', From 1fd7dcb61d2f1cf649f048559844a4dd969dbc43 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 17:19:25 +0000 Subject: [PATCH 03/17] fix: restore ipfs module default --- src/factory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/factory.js b/src/factory.js index 801420e0..e01798f6 100644 --- a/src/factory.js +++ b/src/factory.js @@ -21,6 +21,7 @@ const defaults = { type: 'go', env: {}, args: [], + ipfsModule: {}, ipfsOptions: {}, forceKill: true, forceKillTimeout: 5000 From da43d037049876b9a6f14bd516f803fe966097e1 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 17:27:19 +0000 Subject: [PATCH 04/17] fix: specify peer deps as externals to not bundle them --- .aegir.js | 7 +++++++ .travis.yml | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.aegir.js b/.aegir.js index d2320439..2e9eaadf 100644 --- a/.aegir.js +++ b/.aegir.js @@ -16,5 +16,12 @@ module.exports = { hooks: { pre: () => server.start(), post: () => server.stop() + }, + webpack: { + externals: { + ipfs: 'ipfs', + 'ipfs-http-client': 'ipfs-http-client', + 'go-ipfs-dep': 'go-ifps-dep' + } } } diff --git a/.travis.yml b/.travis.yml index c3ac7371..5249a029 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,7 @@ jobs: - npm install ipfs - npm install ipfs-http-client - npm install go-ipfs-dep + - npm run build - npx aegir test -t browser -t webworker --bail --timeout 60000 - stage: test @@ -55,6 +56,7 @@ jobs: - npm install ipfs - npm install ipfs-http-client - npm install go-ipfs-dep + - npm run build - npx aegir test -t browser -t webworker --bail --timeout 60000 -- --browsers FirefoxHeadless - stage: test @@ -75,4 +77,4 @@ jobs: - npm install go-ipfs-dep - npx aegir test -t electron-renderer --bail --timeout 60000 notifications: - email: false \ No newline at end of file + email: false From f010017c8ad1e1aa5526a44340d923034bec50a0 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 23:19:26 +0000 Subject: [PATCH 05/17] fix: add ipfs to dev deps to fix tests --- .aegir.js | 4 ++-- package.json | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.aegir.js b/.aegir.js index 2e9eaadf..53d4c575 100644 --- a/.aegir.js +++ b/.aegir.js @@ -17,11 +17,11 @@ module.exports = { pre: () => server.start(), post: () => server.stop() }, - webpack: { + webpack: process.env.NODE_ENV === 'test' ? undefined : { externals: { ipfs: 'ipfs', 'ipfs-http-client': 'ipfs-http-client', - 'go-ipfs-dep': 'go-ifps-dep' + 'go-ipfs-dep': 'go-ipfs-dep' } } } diff --git a/package.json b/package.json index 2971dfc6..142c198c 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,10 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "dirty-chai": "^2.0.1", + "go-ipfs-dep": "^0.4.22", "husky": "^4.0.10", + "ipfs": "github:ipfs/js-ipfs#master", + "ipfs-http-client": "^42.0.0-pre.0", "lint-staged": "^10.0.2" }, "peerDependencies": { From 43e01d86f4d998cc673847d87e86d5019f2138ca Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 23:21:17 +0000 Subject: [PATCH 06/17] fix: rmeove extra installs as ipfs is now a dev dep --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5249a029..4924bc91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,6 @@ os: - windows script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - npx nyc -s npm run test:node -- --timeout 60000 after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov @@ -29,9 +26,6 @@ jobs: include: - stage: check script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - npx aegir build --bundlesize - npx aegir commitlint --travis - npx aegir dep-check @@ -42,10 +36,6 @@ jobs: addons: chrome: stable script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - - npm run build - npx aegir test -t browser -t webworker --bail --timeout 60000 - stage: test @@ -53,28 +43,18 @@ jobs: addons: firefox: latest script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - - npm run build - npx aegir test -t browser -t webworker --bail --timeout 60000 -- --browsers FirefoxHeadless - stage: test name: electron-main os: osx script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - npx aegir test -t electron-main --bail --timeout 60000 - stage: test name: electron-renderer os: osx script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - npx aegir test -t electron-renderer --bail --timeout 60000 notifications: email: false From 13ced9c86d52e6b40833d7df2b2f7fb524edf0ae Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 07:10:59 +0000 Subject: [PATCH 07/17] fix: only require if module has not been specified as option --- src/factory.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/factory.js b/src/factory.js index e01798f6..8ef36941 100644 --- a/src/factory.js +++ b/src/factory.js @@ -112,16 +112,24 @@ class Factory { const type = options.type || this.opts.type const opts = merge( this.overrides[type], - // conditionally include ipfs based on which type of daemon we will spawn when none has been specifed - (type === 'js' || type === 'proc') ? { - ipfsModule: { - path: require.resolve('ipfs'), - ref: require('ipfs') - } - } : {}, options ) + // conditionally include ipfs based on which type of daemon we will spawn when none has been specifed + if ((opts.type === 'js' || opts.type === 'proc') && !opts.ipfsModule) { + opts.ipfsModule = {} + } + + if (opts.ipfsModule) { + if (!opts.ipfsModule.path) { + opts.ipfsModule.path = require.resolve('ipfs') + } + + if (!opts.ipfsModule.ref) { + opts.ipfsModule.ref = require(opts.ipfsModule.path) + } + } + // only include the http api client if it has not been specified as an option // for example if we are testing the http api client itself we should not try // to require 'ipfs-http-client' From 2fe63c28ae3f9978ebdb6257d18125410255e289 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 07:26:02 +0000 Subject: [PATCH 08/17] fix: typo --- src/factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factory.js b/src/factory.js index 8ef36941..a5a183d7 100644 --- a/src/factory.js +++ b/src/factory.js @@ -115,7 +115,7 @@ class Factory { options ) - // conditionally include ipfs based on which type of daemon we will spawn when none has been specifed + // conditionally include ipfs based on which type of daemon we will spawn when none has been specified if ((opts.type === 'js' || opts.type === 'proc') && !opts.ipfsModule) { opts.ipfsModule = {} } From 784bccd4788f82e319da18a860f49906b321933e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 07:30:15 +0000 Subject: [PATCH 09/17] fix: use module name as that is what is overridden by webpack --- src/factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factory.js b/src/factory.js index a5a183d7..06a57b9c 100644 --- a/src/factory.js +++ b/src/factory.js @@ -126,7 +126,7 @@ class Factory { } if (!opts.ipfsModule.ref) { - opts.ipfsModule.ref = require(opts.ipfsModule.path) + opts.ipfsModule.ref = require('ipfs') } } From 3d813a02f4914d5327c011864b4cd2ab0d360b26 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 08:40:05 +0000 Subject: [PATCH 10/17] fix: defer finding binary until spawn time --- src/factory.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/factory.js b/src/factory.js index 06a57b9c..f36a9ff7 100644 --- a/src/factory.js +++ b/src/factory.js @@ -47,14 +47,6 @@ class Factory { proc: merge(this.opts, { type: 'proc' }) }, overrides) - if (!this.overrides.js.ipfsBin) { - this.overrides.js.ipfsBin = findBin('js', this.opts.type === 'js') - } - - if (!this.overrides.go.ipfsBin) { - this.overrides.go.ipfsBin = findBin('go', this.opts.type === 'go') - } - /** @type ControllerDaemon[] */ this.controllers = [] } @@ -140,6 +132,16 @@ class Factory { } } + // find ipfs binary if not specified + if (!opts.ipfsBin && opts.type === 'js') { + opts.ipfsBin = findBin('js', true) + } + + // find ipfs binary if not specified + if (!opts.ipfsBin && opts.type === 'go') { + opts.ipfsBin = findBin('go', true) + } + // IPFS options defaults const ipfsOptions = merge( { From 21bd28fbc7fe23bf733874649b848a4a22f1c709 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 08:41:56 +0000 Subject: [PATCH 11/17] fix: spin clause round and remove duplication --- src/factory.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/factory.js b/src/factory.js index f36a9ff7..78ad8204 100644 --- a/src/factory.js +++ b/src/factory.js @@ -133,13 +133,8 @@ class Factory { } // find ipfs binary if not specified - if (!opts.ipfsBin && opts.type === 'js') { - opts.ipfsBin = findBin('js', true) - } - - // find ipfs binary if not specified - if (!opts.ipfsBin && opts.type === 'go') { - opts.ipfsBin = findBin('go', true) + if (opts.type !== 'proc' && !opts.ipfsBin) { + opts.ipfsBin = findBin(opts.type, true) } // IPFS options defaults From 5d77e03ea2a3c441167ac0221334dd060fb33d7e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 09:40:29 +0000 Subject: [PATCH 12/17] fix: start with this.opts, then overrides, then options --- src/factory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/factory.js b/src/factory.js index 78ad8204..3ab1d92e 100644 --- a/src/factory.js +++ b/src/factory.js @@ -103,6 +103,7 @@ class Factory { async spawn (options = { }) { const type = options.type || this.opts.type const opts = merge( + this.opts, this.overrides[type], options ) From be018b544b045e5c479755902411a48b50490f52 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 11:40:36 +0000 Subject: [PATCH 13/17] chore: revert merging opts --- src/factory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/factory.js b/src/factory.js index 3ab1d92e..78ad8204 100644 --- a/src/factory.js +++ b/src/factory.js @@ -103,7 +103,6 @@ class Factory { async spawn (options = { }) { const type = options.type || this.opts.type const opts = merge( - this.opts, this.overrides[type], options ) From 769d6245ead32052250138cbb7626db51d25e6c7 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 15:36:14 +0000 Subject: [PATCH 14/17] fix: remove default ipfsModule because it triggers requiring ipfs --- src/factory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/factory.js b/src/factory.js index 78ad8204..f6db4cb0 100644 --- a/src/factory.js +++ b/src/factory.js @@ -21,7 +21,6 @@ const defaults = { type: 'go', env: {}, args: [], - ipfsModule: {}, ipfsOptions: {}, forceKill: true, forceKillTimeout: 5000 From 21fc98ebc3987270cfcf3cca39ec836a832c5202 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 16:04:11 +0000 Subject: [PATCH 15/17] fix: do not send empty ipfsModule object to web api --- package.json | 2 +- src/factory.js | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 142c198c..68583346 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "dirty-chai": "^2.0.1", "go-ipfs-dep": "^0.4.22", "husky": "^4.0.10", - "ipfs": "github:ipfs/js-ipfs#master", + "ipfs": "^0.40.0", "ipfs-http-client": "^42.0.0-pre.0", "lint-staged": "^10.0.2" }, diff --git a/src/factory.js b/src/factory.js index f6db4cb0..ace1370e 100644 --- a/src/factory.js +++ b/src/factory.js @@ -74,18 +74,39 @@ class Factory { } async _spawnRemote (options) { - const res = await ky.post( - `${options.endpoint}/spawn`, - { - json: { - ...options, - // avoid recursive spawning - remote: false, - // do not send code refs over http - ipfsModule: { ...options.ipfsModule, ref: undefined }, - ipfsHttpModule: { ...options.ipfsHttpModule, ref: undefined } + const opts = { + json: { + ...options, + // avoid recursive spawning + remote: false + } + } + + if (options.ipfsModule) { + delete opts.ipfsModule + + if (options.ipfsModule.path) { + opts.ipfsModule = { + path: options.ipfsModule.path + // n.b. no ref property - do not send code refs over http + } + } + } + + if (options.ipfsHttpModule) { + delete opts.ipfsHttpModule + + if (options.ipfsHttpModule.path) { + opts.ipfsHttpModule = { + path: options.ipfsHttpModule.path + // n.b. no ref property - do not send code refs over http } } + } + + const res = await ky.post( + `${options.endpoint}/spawn`, + opts ).json() return new ControllerRemote( options.endpoint, From f92aaf2fde4a05c5d176787b1344776b612b2e8e Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 30 Jan 2020 16:37:13 +0000 Subject: [PATCH 16/17] chore: update .aegir.js Co-Authored-By: Hugo Dias --- .aegir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.aegir.js b/.aegir.js index 53d4c575..31235b7c 100644 --- a/.aegir.js +++ b/.aegir.js @@ -4,7 +4,7 @@ const createServer = require('./src').createServer const server = createServer() // using defaults module.exports = { - bundlesize: { maxSize: '940kB' }, + bundlesize: { maxSize: '35kB' }, karma: { files: [{ pattern: 'test/fixtures/**/*', From e46948ed87ca8b20d54d4e94040b69a3963a82d4 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 11:02:58 +0000 Subject: [PATCH 17/17] fix: set up correct module properties --- src/factory.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/factory.js b/src/factory.js index ace1370e..561a9656 100644 --- a/src/factory.js +++ b/src/factory.js @@ -77,30 +77,24 @@ class Factory { const opts = { json: { ...options, + ipfsModule: undefined, + ipfsHttpModule: undefined, // avoid recursive spawning remote: false } } - if (options.ipfsModule) { - delete opts.ipfsModule - - if (options.ipfsModule.path) { - opts.ipfsModule = { - path: options.ipfsModule.path - // n.b. no ref property - do not send code refs over http - } + if (options.ipfsModule && options.ipfsModule.path) { + opts.json.ipfsModule = { + path: options.ipfsModule.path + // n.b. no ref property - do not send code refs over http } } - if (options.ipfsHttpModule) { - delete opts.ipfsHttpModule - - if (options.ipfsHttpModule.path) { - opts.ipfsHttpModule = { - path: options.ipfsHttpModule.path - // n.b. no ref property - do not send code refs over http - } + if (options.ipfsHttpModule && options.ipfsHttpModule.path) { + opts.json.ipfsHttpModule = { + path: options.ipfsHttpModule.path + // n.b. no ref property - do not send code refs over http } }