Skip to content

Commit

Permalink
feat: move ipfs to peer deps (#446)
Browse files Browse the repository at this point in the history
Doing this reduced the size of `node_modules` in the js-IPFS module
for me by about 300MB.

BREAKING CHANGE: This package now requires 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.
  • Loading branch information
achingbrain authored and hugomrdias committed Jan 28, 2020
1 parent e616b0f commit 236c935
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
21 changes: 20 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ os:
- osx
- windows

script: npx nyc -s npm run test:node -- --timeout 60000
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 @@ -35,25 +42,37 @@ 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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ Version 1.0.0 changed a bit the api and the options methods take so please read
npm install --save ipfsd-ctl
```

Please ensure your project also has dependencies on `ipfs`, `ipfs-http-client` and `go-ipfs-dep`.

```sh
npm install --save ipfs
npm install --save ipfs-http-client
npm install --save go-ipfs-dep
```

If you are only going to use the `go` implementation of IPFS, you can skip installing the `js` implementation and vice versa, though both will require the `ipfs-http-client` module.

If you are only using the `proc` type in-process IPFS node, you can skip installing `go-ipfs-dep` and `ipfs-http-client`.

## Usage

### Spawning a single IPFS controller: `createController`
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"debug": "^4.1.1",
"execa": "^4.0.0",
"fs-extra": "^8.1.0",
"go-ipfs-dep": "~0.4.22",
"ipfs": "0.40.0",
"ipfs-http-client": "^41.0.0",
"ipfs-utils": "^0.7.1",
"ky": "^0.16.1",
"ky-universal": "^0.3.0",
Expand All @@ -77,6 +74,11 @@
"husky": "^4.0.10",
"lint-staged": "^10.0.2"
},
"peerDependencies": {
"go-ipfs-dep": "*",
"ipfs": "*",
"ipfs-http-client": "*"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-ipfsd-ctl.git"
Expand Down
19 changes: 11 additions & 8 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const defaults = {
path: require.resolve('ipfs-http-client'),
ref: require('ipfs-http-client')
},
ipfsModule: {
path: require.resolve('ipfs'),
ref: require('ipfs')
},
ipfsBin: findBin('go'),
ipfsOptions: {}
}

Expand All @@ -48,9 +43,9 @@ class Factory {

/** @type ControllerOptionsOverrides */
this.overrides = merge({
js: merge(this.opts, { type: 'js', ipfsBin: findBin('js') }),
go: this.opts,
proc: merge(this.opts, { type: 'proc', ipfsBin: findBin('js') })
js: merge(this.opts, { type: 'js', ipfsBin: findBin('js', this.opts.type === 'js') }),
go: merge(this.opts, { type: 'go', ipfsBin: findBin('go', this.opts.type === 'go') }),
proc: merge(this.opts, { type: 'proc', ipfsBin: findBin('js', this.opts.type === 'proc') })
}, overrides)

/** @type ControllerDaemon[] */
Expand Down Expand Up @@ -105,6 +100,14 @@ class Factory {
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 = {
path: require.resolve('ipfs'),
ref: require('ipfs')
}
}

// IPFS options defaults
const ipfsOptions = merge(
{
Expand Down
8 changes: 5 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ const checkForRunningApi = (repoPath) => {
return api ? api.toString() : null
}

const findBin = (type) => {
const findBin = (type, required) => {
const resolve = required ? resolveCwd : resolveCwd.silent

if (type === 'js') {
return process.env.IPFS_JS_EXEC || resolveCwd('ipfs/src/cli/bin.js')
return process.env.IPFS_JS_EXEC || resolve('ipfs/src/cli/bin.js')
}

return process.env.IPFS_GO_EXEC || resolveCwd(`go-ipfs-dep/go-ipfs/${isWindows ? 'ipfs.exe' : 'ipfs'}`)
return process.env.IPFS_GO_EXEC || resolve(`go-ipfs-dep/go-ipfs/${isWindows ? 'ipfs.exe' : 'ipfs'}`)
}

const tmpDir = (type = '') => {
Expand Down

0 comments on commit 236c935

Please sign in to comment.