diff --git a/.aegir.js b/.aegir.js index 6e6ba9aa..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: '930kB' }, + bundlesize: { maxSize: '35kB' }, karma: { files: [{ pattern: 'test/fixtures/**/*', @@ -16,5 +16,12 @@ module.exports = { hooks: { pre: () => server.start(), post: () => server.stop() + }, + webpack: process.env.NODE_ENV === 'test' ? undefined : { + externals: { + ipfs: 'ipfs', + 'ipfs-http-client': 'ipfs-http-client', + 'go-ipfs-dep': 'go-ipfs-dep' + } } } diff --git a/.travis.yml b/.travis.yml index c3ac7371..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,9 +36,6 @@ jobs: addons: chrome: stable script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - npx aegir test -t browser -t webworker --bail --timeout 60000 - stage: test @@ -52,27 +43,18 @@ jobs: addons: firefox: latest script: - - npm install ipfs - - npm install ipfs-http-client - - npm install go-ipfs-dep - 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 \ No newline at end of file + email: false diff --git a/package.json b/package.json index 2971dfc6..8cc3c367 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "execa": "^4.0.0", "fs-extra": "^8.1.0", "ipfs-utils": "^0.7.1", - "ky": "^0.16.1", + "ky": "^0.15.0", "ky-universal": "^0.3.0", "merge-options": "^2.0.0", "multiaddr": "^7.2.1", @@ -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": "^0.40.0", + "ipfs-http-client": "^42.0.0-pre.0", "lint-staged": "^10.0.2" }, "peerDependencies": { diff --git a/src/factory.js b/src/factory.js index d44e3525..ace1370e 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 @@ -51,14 +46,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 = [] } @@ -87,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, @@ -116,16 +124,39 @@ 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 specified + 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('ipfs') + } + } + + // 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') + } + } + + // find ipfs binary if not specified + if (opts.type !== 'proc' && !opts.ipfsBin) { + opts.ipfsBin = findBin(opts.type, true) + } + // IPFS options defaults const ipfsOptions = merge( {