Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*',
Expand All @@ -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'
}
}
}
20 changes: 1 addition & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ 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

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
Expand All @@ -42,37 +36,25 @@ 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
name: firefox
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
email: false
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Comment thread
hugomrdias marked this conversation as resolved.
Expand Down
91 changes: 61 additions & 30 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
}
Expand Down Expand Up @@ -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
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need all this haven't we already done this below? we just need to remove refs like in the previous version of this block.

Plus its deleting and setting opts.ipfsModule where it should be opts.json.ipfsModule and same for opts.ipfsHttpModule, so if this code made some use case work it wasn't because of this logic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was resulting in ipfsModule: {} being sent over the http api which was then getting fleshed out to ipfsModule: { path: require.resolve('ipfs'), ref: require('ipfs') } which breaks under js-ipfs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these if clauses are very hard to track and error prone because of all the combinations available in ctl

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point about the deletion of the wrong property though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these if clauses are very hard to track and error prone because of all the combinations available in ctl

You are quite right. Here, look - I've removed them: #454


const res = await ky.post(
`${options.endpoint}/spawn`,
opts
).json()
return new ControllerRemote(
options.endpoint,
Expand All @@ -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(
{
Expand Down