Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove path and ref from module args also findBin #457

Closed

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Feb 9, 2020

Since we're not passing modules to .spawn() there's no danger of passing module refs over http, so we can remove the .path and .ref arguments when specifying which ipfs-http-client and ipfs modules to use, instead setting them up when you configure the daemon factory, either in-proc or as a server in an .aegir file.

Also removes the findBin command magic in favour of being explicit about which binary you want the factory to use.

If you need to support env vars like IPFS_GO_EXEC, do that when you set up the factory, for example:

const factory = createFactory({
  ipfsBin: process.env.IPFS_GO_EXEC || require('go-ipfs-dep').path()
})

Also fixes up the examples and upgrades the ipfs dep to run tests against the async/await refactor.

BREAKING CHANGES:

  • .path and .ref args removed from ipfsModule and ipfsHttpModule
  • findBin function removed

Since we're not passing modules to `.spawn()` there's no danger of
passing module refs over http, so we can remove the `.path` and
`.ref` arguments when specifying which `ipfs-http-client` and `ipfs`
modules to use, instead setting them up when you configure the
daemon factory, either in-proc or as a server in an `.aegir` file.

Also removes the `findBin` command magic in favour of being explicit
about which binary you want the factory to use.

If you need to support env vars like `IPFS_GO_EXEC`, do that when
you set up the factory.

BREAKING CHANGES:

- `.path` and `.ref` args removed from `ipfsModule` and `ipfsHttpModule`
- `findBin` function removed
@achingbrain
Copy link
Member Author

Done as a separate branch because js-ipfs master depends on the remove-option-normalisation branch currently.

@hugomrdias
Copy link
Member

given that js-ipfs depends in the target branch how do you want this merged ?

@achingbrain
Copy link
Member Author

achingbrain commented Feb 9, 2020

I would merge the remove-option-normalisation PR into master but not delete the branch, then change the merge base for this PR to be master and merge it.

Next do a release from master and I'll PR js-ipfs to use the release version - once that's merged we can delete the remove-option-normalisation branch from this repo.

achingbrain added a commit to ipfs/js-ipfs that referenced this pull request Feb 10, 2020
Ask the repo if it has been initialised, if so, allow the user to
skip the `.init()` step and move on to `.start()`

Removes the proxy api object in favour of vanilla functions because
it was causing errors to be thrown if you even referenced properties
that were from a different api state.

E.g. with an unitialised repo:

```javascript
const ipfs = await IPFS.create({
  init: false,
  start: false
})

// no invocation, just referencing the property causes an error to be thrown
console.info(ipfs.start)
```

I'd looked at changing the proxy behaviour to return a function that
throws if invoked, but at the time the proxy is called you don't know
what the calling code is going to do with the return value so it's hard
to know if it's accessing a function or a property - the return value is
just put on the stack and interacted with so it seemed simpler to just
pull it out and define the API up front.

A nice future improvement might be to have `.init`, `.start` and `.stop`
export functions that update the API - that way after `.stop` has been
invoked, it could restore the API from the post-`.init` state, but this
can come later.

Also upgrades `ipfsd-ctl` to pass refs only during factory creation.

Depends on:

- [ ] ipfs/js-ipfsd-ctl#457
- [ ] ipfs/js-ipfs-repo#219
- [ ] ipfs-inactive/npm-go-ipfs-dep#40
@hugomrdias hugomrdias changed the base branch from remove-option-normalisation to master February 10, 2020 12:03
@hugomrdias hugomrdias changed the base branch from master to remove-option-normalisation February 10, 2020 12:06
@hugomrdias
Copy link
Member

closing in favor #458

@hugomrdias hugomrdias closed this Feb 10, 2020
achingbrain added a commit to ipfs/js-ipfs that referenced this pull request Feb 13, 2020
Ask the repo if it has been initialised, if so, allow the user to
skip the `.init()` step and move on to `.start()`

Removes the proxy api object in favour of vanilla functions because
it was causing errors to be thrown if you even referenced properties
that were from a different api state.

E.g. with an unitialised repo:

```javascript
const ipfs = await IPFS.create({
  init: false,
  start: false
})

// no invocation, just referencing the property causes an error to be thrown
console.info(ipfs.start)
```

I'd looked at changing the proxy behaviour to return a function that
throws if invoked, but at the time the proxy is called you don't know
what the calling code is going to do with the return value so it's hard
to know if it's accessing a function or a property - the return value is
just put on the stack and interacted with so it seemed simpler to just
pull it out and define the API up front.

A nice future improvement might be to have `.init`, `.start` and `.stop`
export functions that update the API - that way after `.stop` has been
invoked, it could restore the API from the post-`.init` state, but this
can come later.

Also upgrades `ipfsd-ctl` to pass refs only during factory creation.

Depends on:

- [ ] ipfs/js-ipfsd-ctl#457
- [ ] ipfs/js-ipfs-repo#219
- [ ] ipfs-inactive/npm-go-ipfs-dep#40

fix: do not allow parallel init, start or stop

If the user is calling `.init`, `.start` or `.stop` from the code
in multiple places simultaneously, they probably have a bug in
their code and we should let them know instead of masking it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants