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

feat: move ipfs to peer deps #446

Merged
merged 6 commits into from
Jan 28, 2020
Merged

feat: move ipfs to peer deps #446

merged 6 commits into from
Jan 28, 2020

Conversation

achingbrain
Copy link
Member

Doing this reduced the size of node_modules in the js-IPFS module for me by about 300MB and should result in a faster CI run for js-IPFS since it doesn't need to install itself.

Does require the user to bring their own version, but they can also skip installing go-IPFS if, for example, they are only going to use js-IPFS.

Doing this reduced the size of `node_modules` in the js-IPFS module
for me by about 300MB.

Does require the user to bring their own version, but they can
also skip installing go-IPFS if, for example, they are only going
to use js-IPFS.
"peerDependencies": {
"go-ipfs-dep": "*",
"ipfs": "*",
"ipfs-http-client": "*"
Copy link
Member

Choose a reason for hiding this comment

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

...but I think you'll have to install all of these even if you use only 1 because the calls to require will fail? Do we need try/catches?

Copy link
Member Author

Choose a reason for hiding this comment

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

Quite right. I think you'll need ipfs-http-client all the time, even the proc factory type needs it because it checks to see if another ipfs process has opened the repo, if it has then it uses the http client to connect to it.

I've pushed a change that only requires ipfs if we're going to use it. go-ipfs-dep isn't required directly, instead the findBin function in utils.js tries to pull the binary path out of the module so I've made that fail silently if the factory type is not 'go'.

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

🚀 this will be great for saving disk space but also for install times in CI. No more installing a previous version of IPFS that is not used.

BTW, it also needs a BREAKING CHANGE commit message.

src/factory.js Outdated
@@ -46,11 +41,19 @@ class Factory {
/** @type ControllerOptions */
this.opts = merge(defaults, options)

// conditionally include ipfs based on which type of daemon we will spawn
if (this.opts.type === 'js' || this.opts.type === 'proc') {
this.opts.ipfsModule = {
Copy link
Member

Choose a reason for hiding this comment

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

This will overwrite ipfsModule that the user has passed in. We should only set this if this.opts.ipfsModule is not yet set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good shout, have pushed a fix

Copy link
Member

Choose a reason for hiding this comment

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

this is just to avoid throwing when spawning go controllers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, when your project is only going to use go-IPFS there's not much point installing js-IPFS as well.

Copy link
Member

Choose a reason for hiding this comment

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

this still fails when bundling (or at least warns depending on the bundler) and if the user wants to use js or proc they are forced to specify it in the factory constructor or else they get an error when calling .spawn({type:'proc'})

Copy link
Member Author

Choose a reason for hiding this comment

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

I've moved that clause to .spawn so it's run against the merged options

script:
- npm install ipfs
- npm install ipfs-http-client
- npm install go-ipfs-dep
Copy link
Member

Choose a reason for hiding this comment

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

For discussion: we should install the versions this module depends on otherwise updating them may cause the tests for this module to break.

Copy link
Member Author

@achingbrain achingbrain Jan 27, 2020

Choose a reason for hiding this comment

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

Can do, though this module depends on * so it already does install the version this module depends on, for better or for worse :trollface:

We could change it to be an actual version, but that would imply we require a certain version.

On that, looking through the code quickly, the API methods we call are:

ipfs.id
ipfs.version
ipfs.init
ipfs.start
ipfs.stop

I guess it's feasible that we could refactor those, but they are pretty low-churn.

The .id invocation looks a bit weird to me - it's used to set a peerId property on a node which is then used by the tests so we could probably remove it (in another PR).

We could probably remove .version too, as the caller can just invoke the API method themselves.

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

LGTM, still needs a BREAKING CHANGE message but I guess @hugomrdias can add on squashmerge.

src/factory.js Outdated
@@ -46,11 +41,19 @@ class Factory {
/** @type ControllerOptions */
this.opts = merge(defaults, options)

// conditionally include ipfs based on which type of daemon we will spawn
if (this.opts.type === 'js' || this.opts.type === 'proc') {
this.opts.ipfsModule = {
Copy link
Member

Choose a reason for hiding this comment

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

this is just to avoid throwing when spawning go controllers?

src/factory.js Outdated
@@ -46,11 +41,19 @@ class Factory {
/** @type ControllerOptions */
this.opts = merge(defaults, options)

// conditionally include ipfs based on which type of daemon we will spawn
if (this.opts.type === 'js' || this.opts.type === 'proc') {
this.opts.ipfsModule = {
Copy link
Member

Choose a reason for hiding this comment

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

this still fails when bundling (or at least warns depending on the bundler) and if the user wants to use js or proc they are forced to specify it in the factory constructor or else they get an error when calling .spawn({type:'proc'})

@achingbrain
Copy link
Member Author

@hugomrdias I think I've addressed everything - is this good to go?

@hugomrdias hugomrdias changed the title Move ipfs to peer deps feat: move ipfs to peer deps Jan 28, 2020
@hugomrdias hugomrdias merged commit 236c935 into master Jan 28, 2020
@hugomrdias hugomrdias deleted the move-ipfs-to-peer-deps branch January 28, 2020 17:51
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.

3 participants