Skip to content

ipfs-npm = registry-mirror.next() #43

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

Closed
wants to merge 15 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
tests/t-run*
test/t-run*

# Logs
logs
*.log


registry
# Runtime data
pids
*.pid
Expand All @@ -28,3 +27,5 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

flushlog.txt
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
tests/ipfs-repo-tests

coverage
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: node_js

node_js:
- '4'
- '5'
- '6'
- stable

# always use npm latest
Expand All @@ -24,4 +24,7 @@ env:

script:
- npm run lint
- npm test
- npm run coverage

after_success:
- npm run coverage-publish
123 changes: 38 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
registry-mirror
===============
npm on IPFS
===========

> previously known as `registry-mirror`

![](/img/ip-npm-small.png)

Expand All @@ -8,124 +10,75 @@ registry-mirror
[![Dependency Status](https://david-dm.org/diasdavid/registry-mirror.svg?style=flat-square)](https://david-dm.org/diasdavid/registry-mirror)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/coverage-76%25-yellow.svg?style=flat-square)
<!-- While 0.4.0 doesn't get released [![Build Status](https://img.shields.io/travis/diasdavid/registry-mirror/master.svg?style=flat-square)](https://travis-ci.org/diasdavid/registry-mirror) -->
[![Build Status](https://img.shields.io/travis/diasdavid/registry-mirror/master.svg?style=flat-square)](https://travis-ci.org/diasdavid/registry-mirror)

> registry-mirror sets a mirror the the whole NPM registry, using IPFS for the discovery and transport of modules.
> **Install your modules through IPFS!!** This CLI utility enables you to clone the npm registry into IPFS and/or mirror the registry from IPFS.

# Resources

- [Demo video](https://vimeo.com/147968322)
- [Lengthy introduction in a blog post](http://blog.daviddias.me/2015/12/08/stellar-module-management)
- [Node.js Interactive Talk - Stellar Module Management](https://www.youtube.com/watch?v=-S-Tc7Gl8FM)

# Quick setup (probably all that you need)

## Install IPFS dev0.4.0

To install IPFS dev0.4.0, you will need go installed, to install go in your machine, go to https://golang.org/dl and then run:

```bash
$ go get -u github.com/ipfs/go-ipfs
$ ipfs version
ipfs version 0.4.0-dev
```

## Run IPFS daemon
# Installation

```bash
$ ipfs daemon
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.64/tcp/4001
Swarm listening on /ip4/192.168.10.172/tcp/4001
Swarm listening on /ip6/2001:8a0:7ac5:4201:4816:fd56:bea7:eaf3/tcp/4001
Swarm listening on /ip6/2001:8a0:7ac5:4201:ae87:a3ff:fe19:def1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
> npm install ipfs-npm --global
```

## Install registry-mirror

```bash
$ npm i registry-mirror -g
```
This will make the `ipfs-npm` CLI tool available globally and an alias, `ipnpm`. We will use the alias for examples and API documentation, as it is shorter.

# Usage

Wait for the `Updated directory listing` log.

```bash
$ registry-mirror daemon
registry-mirror [info] using output directory /npm-registry/
registry-mirror [info] listening on 127.0.0.1:50321
registry-mirror [info] Cloning NPM OFF
registry-mirror [info] Updated directory listing, good to go :)
```

Port `50321` is default and can be set with `--port`.

## Configure npm

Set up your npm to use `registry-mirror` with the default port through:

```bash
$ npm config set registry http://localhost:50321
```

If you picked another `--port` you need to adjust accordingly.

Good to npm install away! :)
> **WIP**

# Usage
### Examples

## CLI
### API

```bash
$ registry-mirror
Usage: registry-mirror COMMAND [OPTIONS]
#### `ipnpm registry` commands

Available commands:
##### `ipnpm registry clone` - Download and store the entire npm repository into IPFS

daemon Mirror npm registry
ls Check modules available in the mirror
npm publish Publish an IPNS record with your current npm list
npm update Update your npm list of modules from IPNS
```
Downloads the entire npm registry from registry.npmjs.org and stores it on the IPFS node.

## Commands
This command will try to find an IPFS node on the default (`IPFS_PATH`), if none is found, it will start one.

### daemon
**options:**
- `seq-number` - Select the mirror sequence number to start from. Defaults to last, if none, 0.
- `flush` - Write the modules to disk as soon as they are written into IPFS. Defaults to `true`
- `ipfs` - Select an IPFS daemon by passing its API URL. e.g `ipnpm registry clone --ipfs=/ip4/127.0.0.1/tcp/5001`.
- `log` - Sets the log level, default is `module`. Other options are: `[all, module]`. e.g `ipnpm registry clone --log=all`.

> starts the registry-mirror daemon
##### `ipnpm registry index publish` - Publishes the current index we know as an IPNS name

`$ registry-mirror daemon`
This command will try to find an IPFS node on the default (`IPFS_PATH`), if none is found, it will start one.

Options:
- `--clone` - Download the entire npm (Otherwise it just tries to read)
- `--port=<port>` Listen on the specified port
- `--host=<host>` Listen on the specified port
**options:**
- `ipfs` - Select an IPFS daemon by passing its API URL. e.g `ipnpm registry clone --ipfs=/ip4/127.0.0.1/tcp/5001`.

### ls
##### `ipnpm registry index fetch` - Fetches the latest known index from the IPFS network

> lists all the modules available on the IPFS accessible registry and their respective hashes
This command will try to find an IPFS node on the default (`IPFS_PATH`), if none is found, it will start one.

`$ registry-mirror ls`
**options:**
- `ipfs` - Select an IPFS daemon by passing its API URL. e.g `ipnpm registry clone --ipfs=/ip4/127.0.0.1/tcp/5001`.

### npm update
#### `ipnpm daemon` - Starts an ipfs-npm daemon, so that we can point our npm cli to ithttps://www.youtube.com/watch?v=zGjj6Wg8SJA&feature=youtu.be

> update your local registry cache
This command will try to find an IPFS node on the default (`IPFS_PATH`), if none is found, it will start one.

`$ registry npm update`
**options:**
- `ipfs` - Select an IPFS daemon by passing its API URL. e.g `ipnpm registry clone --ipfs=/ip4/127.0.0.1/tcp/5001`.

### npm publish
#### `ipnpm install <module>` - Similar to `npm install`, however it tries first to download the module from npm and then falls back into the regular registry

> publish the version of the cache you have from npm
This command will try to find an IPFS node on the default (`IPFS_PATH`), if none is found, it will start one.

`$ registry npm publish`
**options:**
- `ipfs` - Select an IPFS daemon by passing its API URL. e.g `ipnpm registry clone --ipfs=/ip4/127.0.0.1/tcp/5001`.

## Important
## Important: Getting 502 errors?

If you are on Mac OS X, make sure to increase the limit of files open (with `ulimit -Sn 4096`), otherwise the ipfs daemon will be sad and throw 502 replies.

Expand Down
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
node:
version: stable
70 changes: 39 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,73 @@
{
"name": "registry-mirror",
"name": "ipfs-npm",
"version": "0.6.3",
"description": "Set up a NPM registry mirror, using your favourite storage, IPFS! :D",
"main": "src/index.js",
"bin": {
"registry-mirror": "src/cli/bin.js"
"ipfs-npm": "src/cli/bin.js",
"ipnpm": "src/cli/bin.js"
},
"scripts": {
"test": "mocha tests/test-*/index.js",
"coverage": "istanbul cover --print both -- _mocha tests/test-*/index.js",
"lint": "standard"
"lint": "aegir-lint",
"test": "aegir-test --env node",
"release": "aegir-release --env no-build",
"release-minor": "aegir-release --type minor --env no-build",
"release-major": "aegir-release --type major --env no-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+https://github.com/diasdavid/registry-mirror.git"
"url": "git+https://github.com/diasdavid/ipfs-npm.git"
},
"keywords": [
"IPFS"
"IPFS",
"npm",
"npm-on-ipfs",
"libp2p"
],
"author": "David Dias <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/diasdavid/registry-mirror/issues"
"url": "https://github.com/diasdavid/ipfs-npm/issues"
},
"homepage": "https://github.com/diasdavid/registry-mirror#readme",
"homepage": "https://github.com/diasdavid/ipfs-npm#readme",
"dependencies": {
"async": "^1.5.2",
"async": "^2.1.2",
"debug": "^2.2.0",
"dnscache": "0.0.4",
"express": "^4.12.3",
"follow-registry": "^2.0.0",
"http-https": "^1.0.0",
"ipfs-blob-store": "^0.4.0",
"lru-cache": "^2.5.0",
"express": "^4.14.0",
"follow-registry": "^3.1.0",
"ipfs-api": "^11.0.1",
"ipfs-blob-store": "^1.1.2",
"lru-cache": "^4.0.1",
"multiaddr": "^2.0.3",
"once": "^1.4.0",
"patch-package-json": "0.0.4",
"ronin": "^0.3.11",
"st": "^1.0.0",
"read-pkg-up": "^2.0.0",
"request": "^2.76.0",
"sha": "^2.0.1",
"st": "^1.2.0",
"timethat": "0.0.3",
"ipfs-api": "^3.0.2"
"update-notifier": "^1.0.2",
"yargs": "^6.3.0"
},
"devDependencies": {
"abstract-blob-store": "^3.2.0",
"assert": "^1.3.0",
"aegir": "^9.0.0",
"assert": "^1.4.1",
"chai": "^3.5.0",
"eslint-config-standard-react": "^1.2.1",
"eslint-plugin-react": "^3.9.0",
"http-https": "^1.0.0",
"ipfsd-ctl": "^0.9.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"mockery": "^1.4.0",
"ipfsd-ctl": "^0.17.0",
"mockery": "^2.0.0",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
"pre-commit": "^1.1.3",
"prettysize": "0.0.3",
"request": "^2.54.0",
"rimraf": "^2.3.2",
"standard": "^5.3.1",
"wreck": "^7.0.0"
"rimraf": "^2.5.4",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0"
}
}
23 changes: 17 additions & 6 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#! /usr/bin/env node

var ronin = require('ronin')
'use strict'

var cli = ronin(__dirname)
const yargs = require('yargs')
const updateNotifier = require('update-notifier')
const readPkgUp = require('read-pkg-up')

cli.run()
const pkg = readPkgUp.sync({cwd: __dirname}).pkg
updateNotifier({
pkg,
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
}).notify()

// cli.autoupdate(function () {
// cli.run()
// })
yargs
.commandDir('commands')
.demand(1)
.help()
.version()
.strict()
.completion()
.argv
Loading