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: use ipfs-provider #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ As the largest software registry in the world, [npm](https://www.npmjs.com) is a
The result is npm-on-ipfs: a module that wraps your package manager of choice (npm or yarn) in configuration to use [IPFS](https://ipfs.io/), not HTTP, to retrieve your dependencies from the central npm registry. It's still a work in progress, but we think you'll find it useful and awesome for the following reasons:

- Having dependencies on the distributed web makes development **more available** because multiple nodes supplying tarballs means no panic if a single source goes dark
- It can also be **faster and cheaper** — if dependencies are already being hosted on your local network, this means lower bandwidth cost and higher speed
- It can also be **faster and cheaper** — if dependencies are already being hosted on your local network, this means lower bandwidth cost and higher speed
- If enough dependencies are hosted on your local network (think enterprise or community development settings), that network can operate **offline-first**: Take your team on a remote mountain retreat and hack away!

## Install & use
Expand Down Expand Up @@ -85,6 +85,8 @@ Options:
timing out [default: 5000]
--ipfs-mfs-prefix Which mfs prefix to use
[default: "/npm-registry"]
--ipfs-disable-providers Wether to disable the search for running nodes

Choose a reason for hiding this comment

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

Typo: Wether -> Whether

[default: false]
--ipfs-node "proc" to start an in-process IPFS node,
"disposable" to start an in-process disposable
node, "go" or "js" to spawn an IPFS node as a
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"express": "^4.16.4",
"express-http-proxy": "^1.5.1",
"ipfs": "^0.36.3",
"ipfs-http-client": "^32.0.1",
"ipfs-provider": "^0.2.1",
Copy link
Member

Choose a reason for hiding this comment

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

Cool module!

Copy link
Member

@daviddias daviddias Sep 14, 2019

Choose a reason for hiding this comment

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

This will pick up if I'm running IPFS Desktop, correct? 👌🏽

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct 👍

"ipfs-registry-mirror-common": "^1.0.13",
"ipfsd-ctl": "~0.42.2",
"once": "^1.4.0",
Expand Down
5 changes: 5 additions & 0 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ yargs.command('$0', 'Installs your js dependencies using IPFS', (yargs) => { //
describe: 'Which mfs prefix to use',
default: '/npm-registry'
})
.option('ipfs-disable-providers', {
describe: 'Whether to disable the search for running nodes',
type: 'boolean',
default: false
})
.option('ipfs-node', {
describe: '"proc" to start an in-process IPFS node, "disposable" to start an in-process disposable node, "go" or "js" to spawn an IPFS node as a separate process or a multiaddr that resolves to a running node',
default: 'proc'
Expand Down
30 changes: 28 additions & 2 deletions src/core/commands/start-ipfs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const IpfsApi = require('ipfs-http-client')
const ipfsdCtrl = require('ipfsd-ctl')
const getIpfs = require('ipfs-provider')
const which = require('which-promise')
const promisify = require('util').promisify
const request = require('ipfs-registry-mirror-common/utils/retry-request')
Expand Down Expand Up @@ -36,6 +36,26 @@ const spawn = (createArgs, spawnArgs = { init: true }) => {
}

const startIpfs = async (config) => {
if (!config.ipfs.disableProviders) {
console.info('🔎 Searching for a running node') // eslint-disable-line no-console

try {
const provider = await getIpfs({
tryWebExt: false,
tryWindow: false
})

console.info(`😈 Connecting to an ${provider.provider} node`) // eslint-disable-line no-console

return {
api: provider.ipfs,
stop: (cb) => cb()
}
} catch (e) {
console.info('💥 Couldn\'t find an available node') // eslint-disable-line no-console
}
}

if (config.ipfs.node === 'proc') {
console.info(`😈 Spawning an in-process IPFS node using repo at ${config.ipfs.repo}`) // eslint-disable-line no-console

Expand Down Expand Up @@ -82,8 +102,14 @@ const startIpfs = async (config) => {

console.info(`😈 Connecting to a remote IPFS node at ${config.ipfs.node}`) // eslint-disable-line no-console

const provider = await getIpfs({
tryWebExt: false,
tryWindow: false,
apiAddress: config.ipfs.node
})

return {
api: new IpfsApi(config.ipfs.node),
api: provider.ipfs,
stop: (cb) => cb()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = (overrides = {}) => {
ipfs: {
host: option(process.env.IPFS_HOST, overrides.ipfsHost),
port: option(Number(process.env.IPFS_PORT), overrides.ipfsPort),
disableProviders: option(process.env.IPFS_DISABLE_PROVIDERS, overrides.ipfsDisableProviders),
node: option(process.env.IPFS_NODE, overrides.ipfsNode),
prefix: option(process.env.IPFS_MFS_PREFIX, overrides.ipfsMfsPrefix),
flush: option(process.env.IPFS_FLUSH, overrides.ipfsFlush),
Expand Down