From b12cd9fa2941b31d670b8d1570ec13c58fd204d6 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 20 Apr 2016 12:56:20 +0200 Subject: [PATCH 01/10] refactor: use aegir --- .gitignore | 3 ++ .npmignore | 34 ++++++++++++++ .travis.yml | 20 +++++--- README.md | 60 +++++++++++------------ karma.conf.js | 58 ----------------------- package.json | 68 +++++++++++++++------------ src/cli/commands/block/get.js | 2 + src/cli/commands/block/put.js | 2 + src/cli/commands/cat.js | 2 + src/cli/commands/config.js | 2 + src/cli/commands/config/replace.js | 2 + src/cli/commands/config/show.js | 2 + src/cli/commands/dns.js | 2 + src/cli/commands/get.js | 2 + src/cli/commands/id.js | 2 + src/cli/commands/init.js | 11 ++--- src/cli/commands/ls.js | 2 + src/cli/commands/object/data.js | 2 + src/cli/commands/object/get.js | 2 + src/cli/commands/object/links.js | 2 + src/cli/commands/object/new.js | 2 + src/cli/commands/object/put.js | 2 + src/cli/commands/ping.js | 2 + src/cli/commands/repo/gc.js | 2 + src/cli/commands/repo/init.js | 2 + src/cli/commands/repo/version.js | 2 + src/cli/commands/resolve.js | 2 + src/cli/commands/swarm/addrs.js | 2 + src/cli/commands/swarm/addrs/local.js | 2 + src/cli/commands/swarm/connect.js | 2 + src/cli/commands/swarm/disconnect.js | 2 + src/cli/commands/swarm/peers.js | 2 + src/cli/commands/version.js | 2 + src/cli/utils.js | 2 + src/core/default-repo/browser.js | 16 +------ src/core/default-repo/index.js | 2 + src/core/default-repo/node.js | 14 +----- src/core/init.js | 3 ++ src/http-api/resources/bootstrap.js | 2 + src/http-api/resources/id.js | 2 + src/http-api/resources/index.js | 2 + src/http-api/resources/repo.js | 2 + src/http-api/resources/version.js | 2 + src/http-api/routes/block.js | 2 + src/http-api/routes/bootstrap.js | 2 + src/http-api/routes/config.js | 2 + src/http-api/routes/id.js | 2 + src/http-api/routes/index.js | 2 + src/http-api/routes/object.js | 2 + src/http-api/routes/repo.js | 2 + src/http-api/routes/swarm.js | 2 + src/http-api/routes/version.js | 2 + src/index.js | 5 ++ test/browser.js | 3 ++ test/cli-tests/index.js | 1 + test/cli-tests/test-block.js | 1 + test/cli-tests/test-bootstrap.js | 1 + test/cli-tests/test-commands.js | 1 + test/cli-tests/test-config.js | 1 + test/cli-tests/test-id.js | 1 + test/cli-tests/test-init.js | 2 +- test/cli-tests/test-object.js | 1 + test/cli-tests/test-swarm.js | 1 + test/cli-tests/test-version.js | 1 + test/core-tests/browser.js | 3 +- test/core-tests/index.js | 1 + test/core-tests/test-block.js | 1 + test/core-tests/test-bootstrap.js | 1 + test/core-tests/test-config.js | 1 + test/core-tests/test-id.js | 1 + test/core-tests/test-init-node.js | 1 + test/core-tests/test-init.js | 8 ++-- test/core-tests/test-object.js | 2 + test/core-tests/test-swarm-browser.js | 2 + test/core-tests/test-swarm-node.js | 1 + test/core-tests/test-version.js | 1 + test/http-api-tests/index.js | 1 + test/http-api-tests/test-block.js | 1 + test/http-api-tests/test-bootstrap.js | 1 + test/http-api-tests/test-id.js | 1 + test/http-api-tests/test-object.js | 1 + test/http-api-tests/test-repo.js | 2 + test/http-api-tests/test-swarm.js | 1 + test/http-api-tests/test-version.js | 1 + test/node.js | 5 ++ test/utils/temp-node.js | 1 + test/utils/temp-repo.js | 22 +++------ 87 files changed, 272 insertions(+), 178 deletions(-) create mode 100644 .npmignore delete mode 100644 karma.conf.js create mode 100644 src/index.js create mode 100644 test/browser.js create mode 100644 test/node.js diff --git a/.gitignore b/.gitignore index ea440ea6c9..254988dc81 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ build # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules + +lib +dist diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000000..59335fda64 --- /dev/null +++ b/.npmignore @@ -0,0 +1,34 @@ +**/node_modules/ +**/*.log +test/repo-tests* + +# Logs +logs +*.log + +coverage + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +build + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules + +test diff --git a/.travis.yml b/.travis.yml index bcbe5793d3..e1d6320be4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,24 @@ +sudo: false language: node_js node_js: - - "4" - - "5" + - 4 + - 5 +# Make sure we have new NPM. before_install: - - npm i -g npm - # Workaround for a permissions issue with Travis virtual machine images - -addons: - firefox: 'latest' + - npm install -g npm script: + - npm run lint - npm test + - npm run coverage + +addons: + firefox: 'latest' before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + +after_success: + - npm run coverage-publish diff --git a/README.md b/README.md index 36a6210af2..b090b34122 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ IPFS JavaScript Implementation ============================== -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) -[[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/ipfs/js-ipfs.svg?style=flat-square&branch=master)](https://travis-ci.org/ipfs/js-ipfs) -![](https://img.shields.io/badge/coverage-75%25-yellow.svg?style=flat-square) -[![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) -[![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/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) +[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) +[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) +[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfs/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs?branch=master) +[![Travis CI](https://travis-ci.org/ipfs/js-ipfs.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs) +[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs) +[![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) -> IPFS JavaScript implementation. +> IPFS JavaScript implementation. # Description @@ -37,7 +39,7 @@ $ npm i ipfs --save ## Use in Node.js -```JavaScript +```js var IPFS = require('ipfs') var node = new IPFS() @@ -57,7 +59,7 @@ The cli is availble through `jsipfs` in your terminal The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process. -```JavaScript +```js ``` ## Use in a browser using a script tag @@ -100,40 +102,40 @@ IPFS Core is divided into separate subsystems, each of them exist in their own r ▶ ┌───────────────────────────────────────────────────────────────────────────────┐ │ IPFS Core │ │ └───────────────────────────────────────────────────────────────────────────────┘ - │ - │ │ - │ - │ ┌──────────────┬──────────────┼────────────┬─────────────────┐ - │ │ │ │ │ - │ │ │ │ │ │ - ▼ │ ▼ │ ▼ + │ + │ │ + │ + │ ┌──────────────┬──────────────┼────────────┬─────────────────┐ + │ │ │ │ │ + │ │ │ │ │ │ + ▼ │ ▼ │ ▼ │ ┌──────────────────┐ │ ┌──────────────────┐ │ ┌──────────────────┐ │ │ │ │ │ │ │ │ │ │ Block Service │ │ │ DAG Service │ │ │ IPFS Repo │ │ │ │ │ │ │ │ │ │ └──────────────────┘ │ └──────────────────┘ │ └──────────────────┘ - │ │ │ │ - IPFS Core │ ▼ │ ┌────┴────┐ │ - ┌────────┐ │ ▼ ▼ │ - │ │ Block │ │ ┌────────┐┌────────┐ │ - └────────┘ │ │DAG Node││DAG Link│ │ - │ │ └────────┘└────────┘ │ + │ │ │ │ + IPFS Core │ ▼ │ ┌────┴────┐ │ + ┌────────┐ │ ▼ ▼ │ + │ │ Block │ │ ┌────────┐┌────────┐ │ + └────────┘ │ │DAG Node││DAG Link│ │ + │ │ └────────┘└────────┘ │ ┌──────────────────┐ │ │ ┌──────────────────┐ │ │ │ │ │ │ │ │ Bitswap │◀────┤ ├──────▶│ Importer │ │ │ │ │ │ │ │ └──────────────────┘ │ │ └──────────────────┘ - │ │ │ │ - │ │ ┌────┴────┐ - │ │ │ ▼ ▼ + │ │ │ │ + │ │ ┌────┴────┐ + │ │ │ ▼ ▼ │ │ ┌────────┐┌────────┐ │ ┌──────────────────┐ │ │ │ layout ││chunker │ │ │ │ ┌────────────┘ └────────┘└────────┘ - │ │ Files │◀────┘ │ - │ │ │ - │ └──────────────────┘ │ - ▶ │ - ▼ + │ │ Files │◀────┘ │ + │ │ │ + │ └──────────────────┘ │ + ▶ │ + ▼ ┌───────────────────────────────────────────────────────────────────────────────┐ │ │ │ │ diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 1348bc2796..0000000000 --- a/karma.conf.js +++ /dev/null @@ -1,58 +0,0 @@ -module.exports = function (config) { - var path = require('path') - var nodeForgePath = path.resolve(__dirname, 'node_modules/peer-id/vendor/forge.bundle.js') - - config.set({ - basePath: '', - frameworks: ['mocha'], - - files: [ - nodeForgePath, - 'test/core-tests/browser.js' - ], - - preprocessors: { - 'test/core-tests/*': ['webpack'] - }, - - webpack: { - resolve: { - extensions: ['', '.js', '.json'] - }, - externals: { - fs: '{}', - 'node-forge': 'forge', - 'ipfs-data-importing': '{ import: {} }', - 'libp2p-ipfs': {} // to be 'libp2p-ipfs-browser' - }, - node: { - Buffer: true - }, - module: { - loaders: [ - { test: /\.json$/, loader: 'json' } - ], - postLoaders: [{ - test: /\.js$/, - loader: 'transform?brfs', - include: /node_modules\/peer-id/ - }] - } - }, - - webpackMiddleware: { - noInfo: true, - stats: { - colors: true - } - }, - reporters: ['spec'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: false, - browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'], - captureTimeout: 60000, - singleRun: true - }) -} diff --git a/package.json b/package.json index 58d6f0743b..f46f456b71 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,22 @@ "bin": { "jsipfs": "src/cli/bin.js" }, - "main": "src/core/index.js", + "main": "lib/core/index.js", + "jsnext:main": "src/core/index.js", "scripts": { - "lint": "standard --verbose | snazzy", - "coverage": "istanbul cover --print both -- _mocha test/core-tests/index.js", - "coverage:http-api": "istanbul cover --print both -- _mocha test/http-api-tests/index.js", - "test": "npm run test:node && npm run test:browser", - "test:node": "npm run test:node:core && npm run test:node:http-api && npm run test:node:cli", - "test:node:teamcity": "npm run test:node:core:teamcity && npm run test:node:http-api:teamcity && npm run test:node:cli:teamcity", - "test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter test/cli-tests/index.js", - "test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter test/core-tests/index.js", - "test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter test/http-api-tests/index.js", + "lint": "aegir-lint", + "coverage": "aegir-coverage", + "test": "aegir-test", + "test:node": "aegir-test node", + "test:browser": "aegir-test browser", + "build": "aegir-build", + "release": "aegir-release", + "release:minor": "aegir-release minor", + "release:major": "aegir-release major", + "coverage-publish": "aegir-coverage publish", "test:node:cli": "mocha test/cli-tests/index.js", "test:node:core": "mocha test/core-tests/index.js", "test:node:http-api": "mocha test/http-api-tests/index.js", - "test:browser": "karma start karma.conf.js", - "test:browser:teamcity": "karma start --reporters teamcity --colors false karma.conf.js", "test:core": "mocha test/core-tests/index.js", "test:cli": "mocha test/cli-tests/index.js" }, @@ -42,38 +42,25 @@ }, "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { + "aegir": "^2.1.1", "async": "^1.5.2", - "brfs": "^1.4.3", - "buffer-loader": "0.0.1", - "chai": "^3.4.1", + "chai": "^3.5.0", "expose-loader": "^0.7.1", "form-data": "^1.0.0-rc3", "idb-plus-blob-store": "^1.0.0", - "istanbul": "^0.4.1", - "json-loader": "^0.5.4", - "karma": "^0.13.19", - "karma-chrome-launcher": "^0.2.2", - "karma-cli": "^0.1.2", - "karma-firefox-launcher": "^0.1.7", - "karma-mocha": "^0.2.1", - "karma-spec-reporter": "0.0.26", - "karma-teamcity-reporter": "^0.2.2", - "karma-webpack": "^1.7.0", "local-storage-blob-store": "0.0.3", "lodash": "^4.11.1", "mocha": "^2.3.4", - "mocha-teamcity-reporter": "^1.0.0", "ncp": "^2.0.0", "nexpect": "^0.5.0", "pre-commit": "^1.1.2", "rimraf": "^2.4.4", "snazzy": "^3.0.1", - "standard": "^6.0.7", "stream-to-promise": "^1.1.0", - "transform-loader": "^0.2.3", - "webpack": "^2.0.7-beta" + "transform-loader": "^0.2.3" }, "dependencies": { + "babel-runtime": "^6.6.1", "bl": "^1.1.2", "boom": "^3.1.1", "bs58": "^3.0.0", @@ -95,5 +82,28 @@ "peer-info": "^0.6.2", "ronin": "^0.3.11", "temp": "^0.8.3" + }, + "aegir": { + "webpack": { + "resolve": { + "alias": { + "node-forge": "../../../node_modules/peer-id/vendor/forge.bundle.js" + } + }, + "externals": { + "fs": "{}", + "ipfs-data-importing": "{ import: {} }", + "libp2p-ipfs": "{}", + "mkdirp": "{}" + }, + "module": { + "postLoaders": [ + { + "test": "__", + "loader": "transform?brfs" + } + ] + } + } } } diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index ec6baedfcf..9d3d2d97ad 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/block/put.js b/src/cli/commands/block/put.js index 000d043fc3..28be6dfbbc 100644 --- a/src/cli/commands/block/put.js +++ b/src/cli/commands/block/put.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/cat.js b/src/cli/commands/cat.js index 4e829e0c8c..a18480b818 100644 --- a/src/cli/commands/cat.js +++ b/src/cli/commands/cat.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/config.js b/src/cli/commands/config.js index e328fcf14f..68d095f47b 100644 --- a/src/cli/commands/config.js +++ b/src/cli/commands/config.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const get = require('lodash.get') diff --git a/src/cli/commands/config/replace.js b/src/cli/commands/config/replace.js index c9d5672d32..4b156568bb 100644 --- a/src/cli/commands/config/replace.js +++ b/src/cli/commands/config/replace.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const path = require('path') diff --git a/src/cli/commands/config/show.js b/src/cli/commands/config/show.js index 444bd9f71a..5a837bee6f 100644 --- a/src/cli/commands/config/show.js +++ b/src/cli/commands/config/show.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const log = debug('cli:config') diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index 5d59b3e92d..eaa6654b45 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/get.js b/src/cli/commands/get.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/get.js +++ b/src/cli/commands/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 24f32d3d8c..27240aaa91 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const utils = require('../utils') diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index dcde142265..5572bfb623 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const IpfsRepo = require('ipfs-repo') const Ipfs = require('../../core') @@ -30,14 +32,7 @@ module.exports = Command.extend({ const path = utils.getRepoPath() const repo = new IpfsRepo(path, { - stores: { - keys: fsBlobStore, - config: fsBlobStore, - datastore: fsBlobStore, - logs: fsBlobStore, - locks: fsBlobStore, - version: fsBlobStore - } + stores: fsBlobStore }) var ipfs = new Ipfs(repo) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/object/data.js b/src/cli/commands/object/data.js index 1591993c42..f6f32b8051 100644 --- a/src/cli/commands/object/data.js +++ b/src/cli/commands/object/data.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/get.js b/src/cli/commands/object/get.js index 66ecbefd8e..3b85740ff5 100644 --- a/src/cli/commands/object/get.js +++ b/src/cli/commands/object/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/links.js b/src/cli/commands/object/links.js index 7cb20a26f8..e0d16ed4df 100644 --- a/src/cli/commands/object/links.js +++ b/src/cli/commands/object/links.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/new.js b/src/cli/commands/object/new.js index a6df1069a1..58e183cd45 100644 --- a/src/cli/commands/object/new.js +++ b/src/cli/commands/object/new.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/put.js b/src/cli/commands/object/put.js index 792d16fd66..b5aaa1d449 100644 --- a/src/cli/commands/object/put.js +++ b/src/cli/commands/object/put.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/ping.js b/src/cli/commands/ping.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/ping.js +++ b/src/cli/commands/ping.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/gc.js b/src/cli/commands/repo/gc.js index 2228495248..1d7948d62d 100644 --- a/src/cli/commands/repo/gc.js +++ b/src/cli/commands/repo/gc.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/init.js b/src/cli/commands/repo/init.js index 2228495248..1d7948d62d 100644 --- a/src/cli/commands/repo/init.js +++ b/src/cli/commands/repo/init.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/version.js b/src/cli/commands/repo/version.js index 8ce4b4fe8b..7885b99b40 100644 --- a/src/cli/commands/repo/version.js +++ b/src/cli/commands/repo/version.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') diff --git a/src/cli/commands/resolve.js b/src/cli/commands/resolve.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/resolve.js +++ b/src/cli/commands/resolve.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/swarm/addrs.js b/src/cli/commands/swarm/addrs.js index f61f941d9b..aa6802e69f 100644 --- a/src/cli/commands/swarm/addrs.js +++ b/src/cli/commands/swarm/addrs.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/addrs/local.js b/src/cli/commands/swarm/addrs/local.js index 7371267744..2ba6c510a1 100644 --- a/src/cli/commands/swarm/addrs/local.js +++ b/src/cli/commands/swarm/addrs/local.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/connect.js b/src/cli/commands/swarm/connect.js index 95a63aad27..dfa4a0932f 100644 --- a/src/cli/commands/swarm/connect.js +++ b/src/cli/commands/swarm/connect.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/disconnect.js b/src/cli/commands/swarm/disconnect.js index e87f3d54d8..6ce8687868 100644 --- a/src/cli/commands/swarm/disconnect.js +++ b/src/cli/commands/swarm/disconnect.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') // const bs58 = require('bs58') diff --git a/src/cli/commands/swarm/peers.js b/src/cli/commands/swarm/peers.js index 7d18970f08..3e4c890ee7 100644 --- a/src/cli/commands/swarm/peers.js +++ b/src/cli/commands/swarm/peers.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index a206a12ce8..f2708f54d7 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../utils') const debug = require('debug') diff --git a/src/cli/utils.js b/src/cli/utils.js index d714da286b..daf17dc1f5 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -1,3 +1,5 @@ +'use strict' + const fs = require('fs') const os = require('os') const APIctl = require('ipfs-api') diff --git a/src/core/default-repo/browser.js b/src/core/default-repo/browser.js index 42315855cf..ffbc8e3600 100644 --- a/src/core/default-repo/browser.js +++ b/src/core/default-repo/browser.js @@ -1,20 +1,8 @@ 'use strict' -const localStorage = require('idb-plus-blob-store') +const idb = require('idb-plus-blob-store') const IPFSRepo = require('ipfs-repo') -const options = { - stores: { - keys: localStorage, - config: localStorage, - datastore: localStorage, - // datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 - logs: localStorage, - locks: localStorage, - version: localStorage - } -} - module.exports = () => { - return new IPFSRepo('ipfs', options) + return new IPFSRepo('ipfs', {stores: idb}) } diff --git a/src/core/default-repo/index.js b/src/core/default-repo/index.js index 2ad96ecd6c..e4f2aec4cd 100644 --- a/src/core/default-repo/index.js +++ b/src/core/default-repo/index.js @@ -1,3 +1,5 @@ +'use strict' + const isNode = !global.window module.exports = isNode diff --git a/src/core/default-repo/node.js b/src/core/default-repo/node.js index 0c0e22ec50..47fd9563ad 100644 --- a/src/core/default-repo/node.js +++ b/src/core/default-repo/node.js @@ -4,19 +4,7 @@ const os = require('os') const fs = require('fs-blob-store') const IPFSRepo = require('ipfs-repo') -const options = { - stores: { - keys: fs, - config: fs, - datastore: fs, - // datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 - logs: fs, - locks: fs, - version: fs - } -} - module.exports = () => { const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' - return new IPFSRepo(repoPath, options) + return new IPFSRepo(repoPath, {stores: fs}) } diff --git a/src/core/init.js b/src/core/init.js index 9f3ab4416d..363db8c0a3 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -1,3 +1,5 @@ +'use strict' + const peerId = require('peer-id') const IpfsBlocks = require('ipfs-blocks').BlockService const IpfsDagService = require('ipfs-merkle-dag').DAGService @@ -36,6 +38,7 @@ module.exports = (repo, opts, callback) => { function writeVersion () { const version = '3' + repo.version.set(version, (err) => { if (err) { return callback(err) } diff --git a/src/http-api/resources/bootstrap.js b/src/http-api/resources/bootstrap.js index 8cb6c5d439..00d23b5ebd 100644 --- a/src/http-api/resources/bootstrap.js +++ b/src/http-api/resources/bootstrap.js @@ -1,3 +1,5 @@ +'use strict' + const ipfs = require('./../index.js').ipfs const boom = require('boom') diff --git a/src/http-api/resources/id.js b/src/http-api/resources/id.js index 58ed34472b..79b39759e4 100644 --- a/src/http-api/resources/id.js +++ b/src/http-api/resources/id.js @@ -1,3 +1,5 @@ +'use strict' + const ipfs = require('./../index.js').ipfs const boom = require('boom') diff --git a/src/http-api/resources/index.js b/src/http-api/resources/index.js index 4e8af44429..036e09b212 100644 --- a/src/http-api/resources/index.js +++ b/src/http-api/resources/index.js @@ -1,3 +1,5 @@ +'use strict' + exports.version = require('./version') exports.id = require('./id') exports.bootstrap = require('./bootstrap') diff --git a/src/http-api/resources/repo.js b/src/http-api/resources/repo.js index e69de29bb2..b7ff1bce28 100644 --- a/src/http-api/resources/repo.js +++ b/src/http-api/resources/repo.js @@ -0,0 +1,2 @@ +'use strict' + diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js index f863cb117c..059dad31a0 100644 --- a/src/http-api/resources/version.js +++ b/src/http-api/resources/version.js @@ -1,3 +1,5 @@ +'use strict' + const ipfs = require('./../index.js').ipfs const boom = require('boom') diff --git a/src/http-api/routes/block.js b/src/http-api/routes/block.js index 328ac71439..0ee4ca6204 100644 --- a/src/http-api/routes/block.js +++ b/src/http-api/routes/block.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/http-api/routes/bootstrap.js b/src/http-api/routes/bootstrap.js index 7ec21c2e22..5bc0a40ec7 100644 --- a/src/http-api/routes/bootstrap.js +++ b/src/http-api/routes/bootstrap.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') const Joi = require('joi') diff --git a/src/http-api/routes/config.js b/src/http-api/routes/config.js index 7c3ec378b8..452d84ed0b 100644 --- a/src/http-api/routes/config.js +++ b/src/http-api/routes/config.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/http-api/routes/id.js b/src/http-api/routes/id.js index 6ea05d2559..c34e3df8b7 100644 --- a/src/http-api/routes/id.js +++ b/src/http-api/routes/id.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/http-api/routes/index.js b/src/http-api/routes/index.js index 167aa6585b..de8e27bf85 100644 --- a/src/http-api/routes/index.js +++ b/src/http-api/routes/index.js @@ -1,3 +1,5 @@ +'use strict' + module.exports = (server) => { require('./version')(server) require('./id')(server) diff --git a/src/http-api/routes/object.js b/src/http-api/routes/object.js index 463e9c866a..4ca4ee59b3 100644 --- a/src/http-api/routes/object.js +++ b/src/http-api/routes/object.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/http-api/routes/repo.js b/src/http-api/routes/repo.js index 716777bace..6a4511e1f9 100644 --- a/src/http-api/routes/repo.js +++ b/src/http-api/routes/repo.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') // TODO diff --git a/src/http-api/routes/swarm.js b/src/http-api/routes/swarm.js index bfef3f7706..461edeb547 100644 --- a/src/http-api/routes/swarm.js +++ b/src/http-api/routes/swarm.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/http-api/routes/version.js b/src/http-api/routes/version.js index ce15e89a5d..f24485e680 100644 --- a/src/http-api/routes/version.js +++ b/src/http-api/routes/version.js @@ -1,3 +1,5 @@ +'use strict' + const resources = require('./../resources') module.exports = (server) => { diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000000..aec25fb4ae --- /dev/null +++ b/src/index.js @@ -0,0 +1,5 @@ +'use strict' + +const IPFS = require('./core') + +exports = module.exports = IPFS diff --git a/test/browser.js b/test/browser.js new file mode 100644 index 0000000000..fab499f9eb --- /dev/null +++ b/test/browser.js @@ -0,0 +1,3 @@ +'use strict' + +require('./core-tests/browser') diff --git a/test/cli-tests/index.js b/test/cli-tests/index.js index 72626e32c2..6717597ef1 100644 --- a/test/cli-tests/index.js +++ b/test/cli-tests/index.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const fs = require('fs') const ncp = require('ncp').ncp diff --git a/test/cli-tests/test-block.js b/test/cli-tests/test-block.js index 08d02b83d0..f062d4d38b 100644 --- a/test/cli-tests/test-block.js +++ b/test/cli-tests/test-block.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-bootstrap.js b/test/cli-tests/test-bootstrap.js index a059f80b34..4e8117ad52 100644 --- a/test/cli-tests/test-bootstrap.js +++ b/test/cli-tests/test-bootstrap.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-commands.js b/test/cli-tests/test-commands.js index d636d19bcf..aa8da00762 100644 --- a/test/cli-tests/test-commands.js +++ b/test/cli-tests/test-commands.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-config.js b/test/cli-tests/test-config.js index 41fe69300d..13b0ce01fc 100644 --- a/test/cli-tests/test-config.js +++ b/test/cli-tests/test-config.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-id.js b/test/cli-tests/test-id.js index 0eddca0604..bb1595505b 100644 --- a/test/cli-tests/test-id.js +++ b/test/cli-tests/test-id.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-init.js b/test/cli-tests/test-init.js index 2ebdf75523..0d28dab82b 100644 --- a/test/cli-tests/test-init.js +++ b/test/cli-tests/test-init.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') @@ -60,4 +61,3 @@ describe('init', function () { }) }) }) - diff --git a/test/cli-tests/test-object.js b/test/cli-tests/test-object.js index edc825009e..b71aafcacd 100644 --- a/test/cli-tests/test-object.js +++ b/test/cli-tests/test-object.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-swarm.js b/test/cli-tests/test-swarm.js index b1c98d0354..ac5406a8e0 100644 --- a/test/cli-tests/test-swarm.js +++ b/test/cli-tests/test-swarm.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/cli-tests/test-version.js b/test/cli-tests/test-version.js index 821ee19678..52b801842b 100644 --- a/test/cli-tests/test-version.js +++ b/test/cli-tests/test-version.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const nexpect = require('nexpect') diff --git a/test/core-tests/browser.js b/test/core-tests/browser.js index 9befdbf20b..cd9b91b9e9 100644 --- a/test/core-tests/browser.js +++ b/test/core-tests/browser.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const async = require('async') const store = require('idb-plus-blob-store') @@ -43,7 +44,7 @@ describe('IPFS Repo Tests on the Browser', function () { }, done) }) - it('', () => { + it('--', () => { const testsContext = require.context('.', true, /test-*/) testsContext .keys() diff --git a/test/core-tests/index.js b/test/core-tests/index.js index b117395cd0..395e907363 100644 --- a/test/core-tests/index.js +++ b/test/core-tests/index.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const fs = require('fs') const ncp = require('ncp').ncp diff --git a/test/core-tests/test-block.js b/test/core-tests/test-block.js index d4b2c26e0f..b99b221d47 100644 --- a/test/core-tests/test-block.js +++ b/test/core-tests/test-block.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const base58 = require('bs58') diff --git a/test/core-tests/test-bootstrap.js b/test/core-tests/test-bootstrap.js index 7c874f5729..d56d337712 100644 --- a/test/core-tests/test-bootstrap.js +++ b/test/core-tests/test-bootstrap.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect diff --git a/test/core-tests/test-config.js b/test/core-tests/test-config.js index 14b5703a77..f514e876e1 100644 --- a/test/core-tests/test-config.js +++ b/test/core-tests/test-config.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const IPFS = require('../../src/core') diff --git a/test/core-tests/test-id.js b/test/core-tests/test-id.js index 71bc38f56e..766a0e3d13 100644 --- a/test/core-tests/test-id.js +++ b/test/core-tests/test-id.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect diff --git a/test/core-tests/test-init-node.js b/test/core-tests/test-init-node.js index 9b49561ccb..1e05d61b5e 100644 --- a/test/core-tests/test-init-node.js +++ b/test/core-tests/test-init-node.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const IPFS = require('../../src/core') diff --git a/test/core-tests/test-init.js b/test/core-tests/test-init.js index b658f20494..a99ce93f8d 100644 --- a/test/core-tests/test-init.js +++ b/test/core-tests/test-init.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const IPFS = require('../../src/core') @@ -8,8 +9,9 @@ describe('init', function () { this.timeout(10000) it('basic', (done) => { - var repo = createTempRepo() + const repo = createTempRepo() const ipfs = new IPFS(repo) + ipfs.init({ emptyRepo: true }, (err) => { expect(err).to.not.exist @@ -28,8 +30,8 @@ describe('init', function () { }) it('set # of bits in key', (done) => { - var repo1 = createTempRepo() - var repo2 = createTempRepo() + const repo1 = createTempRepo() + const repo2 = createTempRepo() const ipfsShort = new IPFS(repo1) const ipfsLong = new IPFS(repo2) ipfsShort.init({ bits: 128, emptyRepo: true }, (err) => { diff --git a/test/core-tests/test-object.js b/test/core-tests/test-object.js index 1be253b20b..9a9ba51247 100644 --- a/test/core-tests/test-object.js +++ b/test/core-tests/test-object.js @@ -1,3 +1,5 @@ +'use strict' + /* eslint-env mocha */ const expect = require('chai').expect diff --git a/test/core-tests/test-swarm-browser.js b/test/core-tests/test-swarm-browser.js index e69de29bb2..b7ff1bce28 100644 --- a/test/core-tests/test-swarm-browser.js +++ b/test/core-tests/test-swarm-browser.js @@ -0,0 +1,2 @@ +'use strict' + diff --git a/test/core-tests/test-swarm-node.js b/test/core-tests/test-swarm-node.js index 30f7fd5ed3..424e9ad2e0 100644 --- a/test/core-tests/test-swarm-node.js +++ b/test/core-tests/test-swarm-node.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect diff --git a/test/core-tests/test-version.js b/test/core-tests/test-version.js index cb9f964d72..c01d97ce73 100644 --- a/test/core-tests/test-version.js +++ b/test/core-tests/test-version.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect diff --git a/test/http-api-tests/index.js b/test/http-api-tests/index.js index 20834da9bc..980239d40d 100644 --- a/test/http-api-tests/index.js +++ b/test/http-api-tests/index.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const fs = require('fs') const expect = require('chai').expect diff --git a/test/http-api-tests/test-block.js b/test/http-api-tests/test-block.js index cf33426136..83061ff2f2 100644 --- a/test/http-api-tests/test-block.js +++ b/test/http-api-tests/test-block.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/http-api-tests/test-bootstrap.js b/test/http-api-tests/test-bootstrap.js index 7c48f225d0..403991689c 100644 --- a/test/http-api-tests/test-bootstrap.js +++ b/test/http-api-tests/test-bootstrap.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/http-api-tests/test-id.js b/test/http-api-tests/test-id.js index 856ac2b3a9..589d136ec2 100644 --- a/test/http-api-tests/test-id.js +++ b/test/http-api-tests/test-id.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/http-api-tests/test-object.js b/test/http-api-tests/test-object.js index e614c5b9af..5e6628b30d 100644 --- a/test/http-api-tests/test-object.js +++ b/test/http-api-tests/test-object.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/http-api-tests/test-repo.js b/test/http-api-tests/test-repo.js index f98b450fc8..2a02d173af 100644 --- a/test/http-api-tests/test-repo.js +++ b/test/http-api-tests/test-repo.js @@ -1,3 +1,5 @@ +'use strict' + /* eslint-env mocha */ // const expect = require('chai').expect diff --git a/test/http-api-tests/test-swarm.js b/test/http-api-tests/test-swarm.js index a729cdcebb..9f1e45bc39 100644 --- a/test/http-api-tests/test-swarm.js +++ b/test/http-api-tests/test-swarm.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/http-api-tests/test-version.js b/test/http-api-tests/test-version.js index effe5ff9db..b402214e7a 100644 --- a/test/http-api-tests/test-version.js +++ b/test/http-api-tests/test-version.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const APIctl = require('ipfs-api') diff --git a/test/node.js b/test/node.js new file mode 100644 index 0000000000..14ecacfee5 --- /dev/null +++ b/test/node.js @@ -0,0 +1,5 @@ +'use strict' + +require('./core-tests/index') +require('./cli-tests/index') +require('./http-api-tests/index') diff --git a/test/utils/temp-node.js b/test/utils/temp-node.js index 4055a15b62..3ba5692e6c 100644 --- a/test/utils/temp-node.js +++ b/test/utils/temp-node.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect diff --git a/test/utils/temp-repo.js b/test/utils/temp-repo.js index 2be640f6d3..56e89ffa7d 100644 --- a/test/utils/temp-repo.js +++ b/test/utils/temp-repo.js @@ -1,13 +1,14 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect const IPFSRepo = require('ipfs-repo') function createTempRepo () { - const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' + const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) - var store - var teardown + let store + let teardown const isNode = !global.window if (isNode) { @@ -32,19 +33,10 @@ function createTempRepo () { } } - const options = { + var repo = new IPFSRepo(repoPath, { bits: 64, - stores: { - keys: store, - config: store, - datastore: store, - logs: store, - locks: store, - version: store - } - } - - var repo = new IPFSRepo(repoPath, options) + stores: store + }) repo.teardown = teardown From 08482980ca99d6284c52b2dbbb117339c40870f8 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 20 Apr 2016 17:08:51 +0200 Subject: [PATCH 02/10] try to fix process.env and fail --- package.json | 7 ++++++ src/core/default-repo/node.js | 5 ++-- src/core/index.js | 9 ++++--- src/http-api/index.js | 12 +++++---- test/cli-tests/index.js | 38 +++++++++++++++-------------- test/cli-tests/test-block.js | 32 +++++++++++++++++------- test/core-tests/index.js | 37 ++++++++++++++-------------- test/core-tests/test-block.js | 3 ++- test/http-api-tests/index.js | 39 +++++++++++++++++------------- test/http-api-tests/test-config.js | 5 ++-- test/node.js | 5 ---- test/utils/clean.js | 15 ++++++++++++ test/utils/temp-repo.js | 2 +- 13 files changed, 128 insertions(+), 81 deletions(-) delete mode 100644 test/node.js create mode 100644 test/utils/clean.js diff --git a/package.json b/package.json index f46f456b71..5908efa358 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,13 @@ } ] } + }, + "test": { + "node": [ + "test/core-tests/index.js", + "test/http-api-tests/index.js", + "test/cli-tests/index.js" + ] } } } diff --git a/src/core/default-repo/node.js b/src/core/default-repo/node.js index 47fd9563ad..af16b34f07 100644 --- a/src/core/default-repo/node.js +++ b/src/core/default-repo/node.js @@ -3,8 +3,9 @@ const os = require('os') const fs = require('fs-blob-store') const IPFSRepo = require('ipfs-repo') +const path = require('path') -module.exports = () => { - const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' +module.exports = (dir) => { + const repoPath = dir || process.env.IPFS_PATH || path.join(os.homedir(), '.ipfs') return new IPFSRepo(repoPath, {stores: fs}) } diff --git a/src/core/index.js b/src/core/index.js index 66b3bb2160..8a91870c25 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -13,6 +13,7 @@ const multiaddr = require('multiaddr') const importer = require('ipfs-data-importing').import const libp2p = require('libp2p-ipfs') const init = require('./init') +const IPFSRepo = require('ipfs-repo') exports = module.exports = IPFS @@ -21,8 +22,8 @@ function IPFS (repo) { throw new Error('Must be instantiated with new') } - if (!repo) { - repo = defaultRepo() + if (!(repo instanceof IPFSRepo)) { + repo = defaultRepo(repo) } const blockS = new BlockService(repo) @@ -105,7 +106,9 @@ function IPFS (repo) { }) }, - gc: function () {} + gc: function () {}, + + path: () => repo.path } this.init = (opts, callback) => { init(repo, opts, callback) } diff --git a/src/http-api/index.js b/src/http-api/index.js index cdae357ec8..9ddee18323 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -5,6 +5,7 @@ const IPFS = require('../core') const debug = require('debug') const fs = require('fs') const os = require('os') +const path = require('path') const log = debug('api') log.error = debug('api:error') @@ -18,13 +19,14 @@ exports.start = (repo, callback) => { const ipfs = exports.ipfs = new IPFS(repo) ipfs.load(() => { - const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' + const repoPath = ipfs.repo.path() + try { - fs.statSync(repoPath + '/api') + fs.statSync(path.join(repoPath, 'api')) console.log('This repo is currently being used by another daemon') process.exit(1) } catch (err) { - fs.writeFileSync(repoPath + '/api', 'api is on by js-ipfs', {flag: 'w+'}) + fs.writeFileSync(path.join(repoPath, 'api'), 'api is on by js-ipfs', {flag: 'w+'}) } ipfs.config.show((err, config) => { @@ -70,8 +72,8 @@ exports.start = (repo, callback) => { } exports.stop = (callback) => { - const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' - fs.unlinkSync(repoPath + '/api') + const repoPath = exports.ipfs.repo.path() + fs.unlinkSync(path.join(repoPath, 'api')) console.log('->', 'going to stop libp2p') exports.ipfs.libp2p.stop(() => { console.log('->', 'going to stop api server') diff --git a/test/cli-tests/index.js b/test/cli-tests/index.js index 6717597ef1..9779e33da6 100644 --- a/test/cli-tests/index.js +++ b/test/cli-tests/index.js @@ -3,36 +3,38 @@ const fs = require('fs') const ncp = require('ncp').ncp -const rimraf = require('rimraf') const expect = require('chai').expect +const path = require('path') +const clean = require('../utils/clean') describe('cli', () => { - const repoExample = process.cwd() + '/test/go-ipfs-repo' - const repoTests = exports.repoTests = process.cwd() + '/test/repo-tests-run' + const repoExample = path.join(__dirname, '../go-ipfs-repo') + const repoTests = exports.repoTests = path.join(__dirname, '../repo-tests-run-cli') before((done) => { + clean(repoTests) ncp(repoExample, repoTests, (err) => { + expect(err).to.not.exist + process.env.IPFS_PATH = repoTests - expect(err).to.equal(null) done() }) }) - after((done) => { - rimraf(repoTests, (err) => { - expect(err).to.equal(null) - done() - }) + after(() => { + clean(repoTests) }) - const tests = fs.readdirSync(__dirname) - tests.filter((file) => { - if (file === 'index.js' || file === 'api.js') { - return false - } else { - return true - } - }).forEach((file) => { - require('./' + file) + describe('--all', () => { + const tests = fs.readdirSync(__dirname) + tests.filter((file) => { + if (file === 'index.js' || file === 'api.js') { + return false + } else { + return true + } + }).forEach((file) => { + require('./' + file) + }) }) }) diff --git a/test/cli-tests/test-block.js b/test/cli-tests/test-block.js index f062d4d38b..bb83967419 100644 --- a/test/cli-tests/test-block.js +++ b/test/cli-tests/test-block.js @@ -4,12 +4,26 @@ const expect = require('chai').expect const nexpect = require('nexpect') const httpAPI = require('../../src/http-api') +const path = require('path') + +const repoPath = path.join(__dirname, '../repo-tests-run-cli') + +const spawn = (args) => { + const env = process.env + env.IPFS_PATH = repoPath + return nexpect.spawn( + 'node', + [path.join(__dirname, '../../src/cli/bin.js')].concat(args), + {env} + ) +} describe('block', () => { describe('api offline', () => { it('put', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'put', process.cwd() + '/test/test-data/hello']) + spawn(['block', 'put', process.cwd() + '/test/test-data/hello']) .run((err, stdout, exitcode) => { + if (err) throw err expect(err).to.not.exist expect(exitcode).to.equal(0) expect(stdout[0]) @@ -19,7 +33,7 @@ describe('block', () => { }) it('get', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -30,7 +44,7 @@ describe('block', () => { }) it('stat', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -43,7 +57,7 @@ describe('block', () => { }) it('rm', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -56,7 +70,7 @@ describe('block', () => { describe('api running', () => { before((done) => { - httpAPI.start((err) => { + httpAPI.start(repoPath, (err) => { expect(err).to.not.exist done() }) @@ -70,7 +84,7 @@ describe('block', () => { }) it('put', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'put', process.cwd() + '/test/test-data/hello']) + spawn(['block', 'put', process.cwd() + '/test/test-data/hello']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -81,7 +95,7 @@ describe('block', () => { }) it('get', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -92,7 +106,7 @@ describe('block', () => { }) it('stat', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) @@ -105,7 +119,7 @@ describe('block', () => { }) it.skip('rm', (done) => { - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) + spawn(['block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) diff --git a/test/core-tests/index.js b/test/core-tests/index.js index 395e907363..f2d4e1b889 100644 --- a/test/core-tests/index.js +++ b/test/core-tests/index.js @@ -3,14 +3,16 @@ const fs = require('fs') const ncp = require('ncp').ncp -const rimraf = require('rimraf') const expect = require('chai').expect +const path = require('path') +const clean = require('../utils/clean') describe('core', () => { - const repoExample = process.cwd() + '/test/go-ipfs-repo' - const repoTests = process.cwd() + '/test/repo-tests-run' + const repoExample = path.join(__dirname, '../go-ipfs-repo') + const repoTests = path.join(__dirname, '../repo-tests-run') before((done) => { + clean(repoTests) ncp(repoExample, repoTests, (err) => { process.env.IPFS_PATH = repoTests expect(err).to.equal(null) @@ -18,22 +20,21 @@ describe('core', () => { }) }) - after((done) => { - rimraf(repoTests, (err) => { - expect(err).to.equal(null) - done() - }) + after(() => { + clean(repoTests) }) - const tests = fs.readdirSync(__dirname) - tests.filter((file) => { - if (file === 'index.js' || - file.endsWith('browser.js')) { - return false - } else { - return true - } - }).forEach((file) => { - require('./' + file) + describe('--all', () => { + const tests = fs.readdirSync(__dirname) + tests.filter((file) => { + if (file === 'index.js' || + file.endsWith('browser.js')) { + return false + } else { + return true + } + }).forEach((file) => { + require('./' + file) + }) }) }) diff --git a/test/core-tests/test-block.js b/test/core-tests/test-block.js index b99b221d47..965dcac658 100644 --- a/test/core-tests/test-block.js +++ b/test/core-tests/test-block.js @@ -6,11 +6,12 @@ const base58 = require('bs58') const fs = require('fs') const IPFS = require('../../src/core') const Block = require('ipfs-blocks').Block +const path = require('path') const isNode = !global.window const fileA = isNode - ? fs.readFileSync(process.cwd() + '/test/go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') + ? fs.readFileSync(path.join(__dirname, '../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) : require('buffer!./../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') // TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed diff --git a/test/http-api-tests/index.js b/test/http-api-tests/index.js index 980239d40d..6c6733847d 100644 --- a/test/http-api-tests/index.js +++ b/test/http-api-tests/index.js @@ -5,17 +5,22 @@ const fs = require('fs') const expect = require('chai').expect const api = require('../../src/http-api') const ncp = require('ncp').ncp -const rimraf = require('rimraf') +const path = require('path') +const fsStore = require('fs-blob-store') +const IPFSRepo = require('ipfs-repo') +const clean = require('../utils/clean') describe('http api', () => { - const repoExample = process.cwd() + '/test/go-ipfs-repo' - const repoTests = process.cwd() + '/test/repo-tests-run' + const repoExample = path.join(__dirname, '../go-ipfs-repo') + const repoTests = path.join(__dirname, '../repo-tests-run-http') process.env.IPFS_PATH = repoTests before((done) => { + clean(repoTests) ncp(repoExample, repoTests, (err) => { expect(err).to.not.exist - api.start((err) => { + + api.start(repoTests, (err) => { expect(err).to.not.exist done() }) @@ -26,21 +31,21 @@ describe('http api', () => { api.stop((err) => { expect(err).to.not.exist - rimraf(repoTests, (err) => { - expect(err).to.not.exist - done() - }) + clean(repoTests) + done() }) }) - var tests = fs.readdirSync(__dirname) - tests.filter((file) => { - if (file === 'index.js') { - return false - } else { - return true - } - }).forEach((file) => { - require('./' + file) + describe('--all', () => { + var tests = fs.readdirSync(__dirname) + tests.filter((file) => { + if (file === 'index.js') { + return false + } else { + return true + } + }).forEach((file) => { + require('./' + file) + }) }) }) diff --git a/test/http-api-tests/test-config.js b/test/http-api-tests/test-config.js index 3ca1bc214f..634e5fad8c 100644 --- a/test/http-api-tests/test-config.js +++ b/test/http-api-tests/test-config.js @@ -6,10 +6,11 @@ const fs = require('fs') const APIctl = require('ipfs-api') const FormData = require('form-data') const streamToPromise = require('stream-to-promise') +const path = require('path') describe('config', () => { - const configPath = process.cwd() + '/test/repo-tests-run/config' - const originalConfigPath = process.cwd() + '/test/go-ipfs-repo/config' + const configPath = path.join(__dirname, '../repo-tests-run-http/config') + const originalConfigPath = path.join(__dirname, '../go-ipfs-repo/config') const updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8')) const restoreConfig = () => fs.writeFileSync(configPath, fs.readFileSync(originalConfigPath, 'utf8'), 'utf8') diff --git a/test/node.js b/test/node.js deleted file mode 100644 index 14ecacfee5..0000000000 --- a/test/node.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -require('./core-tests/index') -require('./cli-tests/index') -require('./http-api-tests/index') diff --git a/test/utils/clean.js b/test/utils/clean.js new file mode 100644 index 0000000000..13752b594a --- /dev/null +++ b/test/utils/clean.js @@ -0,0 +1,15 @@ +'use strict' + +const rimraf = require('rimraf') +const fs = require('fs') + +module.exports = (dir) => { + try { + fs.accessSync(dir) + } catch (err) { + // Does not exist so all good + return + } + + rimraf.sync(dir) +} diff --git a/test/utils/temp-repo.js b/test/utils/temp-repo.js index 56e89ffa7d..fe669c68d6 100644 --- a/test/utils/temp-repo.js +++ b/test/utils/temp-repo.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const IPFSRepo = require('ipfs-repo') function createTempRepo () { - const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' let store let teardown From b6ce9c74476acb35507ec5b6210237d937914559 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 20 Apr 2016 18:33:41 +0200 Subject: [PATCH 03/10] better.. --- package.json | 18 +++++------- src/cli/utils.js | 9 +++--- src/core/default-repo/node.js | 2 +- src/http-api/index.js | 18 +++++++----- src/http-api/resources/block.js | 3 +- test/cli-tests/index.js | 3 +- test/cli-tests/test-block.js | 41 ++++++++++++++------------- test/cli-tests/test-bootstrap.js | 13 +++++---- test/cli-tests/test-config.js | 46 +++++++++++++++++-------------- test/cli-tests/test-init.js | 18 +++++------- test/cli-tests/test-object.js | 43 +++++++++++++++-------------- test/cli-tests/test-swarm.js | 11 +++++--- test/cli-tests/test-version.js | 7 +++-- test/core-tests/index.js | 3 +- test/core-tests/test-block.js | 2 +- test/core-tests/test-bootstrap.js | 2 +- test/core-tests/test-config.js | 6 ++-- test/core-tests/test-id.js | 2 +- test/core-tests/test-object.js | 2 +- test/core-tests/test-version.js | 2 +- test/http-api-tests/index.js | 5 +--- test/utils/temp-repo.js | 2 +- 22 files changed, 133 insertions(+), 125 deletions(-) diff --git a/package.json b/package.json index 5908efa358..185b4920ae 100644 --- a/package.json +++ b/package.json @@ -10,19 +10,17 @@ "scripts": { "lint": "aegir-lint", "coverage": "aegir-coverage", - "test": "aegir-test", - "test:node": "aegir-test node", + "test": "npm run test:node && npm run test:browser", + "test:node": "npm run test:node:core && npm run test:node:http-api && npm run test:node:cli", + "test:node:core": "aegir-test node", + "test:node:http-api": "mocha test/http-api-tests/index.js", + "test:node:cli": "mocha test/cli-tests/index.js", "test:browser": "aegir-test browser", "build": "aegir-build", "release": "aegir-release", "release:minor": "aegir-release minor", "release:major": "aegir-release major", - "coverage-publish": "aegir-coverage publish", - "test:node:cli": "mocha test/cli-tests/index.js", - "test:node:core": "mocha test/core-tests/index.js", - "test:node:http-api": "mocha test/http-api-tests/index.js", - "test:core": "mocha test/core-tests/index.js", - "test:cli": "mocha test/cli-tests/index.js" + "coverage-publish": "aegir-coverage publish" }, "pre-commit": [ "lint", @@ -107,9 +105,7 @@ }, "test": { "node": [ - "test/core-tests/index.js", - "test/http-api-tests/index.js", - "test/cli-tests/index.js" + "test/core-tests/index.js" ] } } diff --git a/src/cli/utils.js b/src/cli/utils.js index daf17dc1f5..c592734897 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -5,6 +5,7 @@ const os = require('os') const APIctl = require('ipfs-api') const multiaddr = require('multiaddr') const IPFS = require('../core') +const path = require('path') const debug = require('debug') const log = debug('cli') log.error = debug('cli:error') @@ -14,7 +15,7 @@ exports = module.exports exports.isDaemonOn = isDaemonOn function isDaemonOn () { try { - fs.readFileSync(exports.getRepoPath() + '/api') + fs.readFileSync(path.join(exports.getRepoPath(), 'api')) log('daemon is on') return true } catch (err) { @@ -28,14 +29,14 @@ function getAPICtl () { if (!isDaemonOn()) { throw new Error('daemon is not on') } - - const apiAddr = multiaddr(fs.readFileSync(exports.getRepoPath() + '/api').toString()) + const apiPath = path.join(exports.getRepoPath(), 'api') + const apiAddr = multiaddr(fs.readFileSync(apiPath).toString()) return APIctl(apiAddr.toString()) } exports.getIPFS = (callback) => { if (!isDaemonOn()) { - const ipfs = new IPFS() + const ipfs = new IPFS(exports.getRepoPath()) ipfs.load(() => { callback(null, ipfs) }) diff --git a/src/core/default-repo/node.js b/src/core/default-repo/node.js index af16b34f07..8d59a1db50 100644 --- a/src/core/default-repo/node.js +++ b/src/core/default-repo/node.js @@ -6,6 +6,6 @@ const IPFSRepo = require('ipfs-repo') const path = require('path') module.exports = (dir) => { - const repoPath = dir || process.env.IPFS_PATH || path.join(os.homedir(), '.ipfs') + const repoPath = dir || path.join(os.homedir(), '.ipfs') return new IPFSRepo(repoPath, {stores: fs}) } diff --git a/src/http-api/index.js b/src/http-api/index.js index 9ddee18323..cf3adddc94 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -4,7 +4,6 @@ const Hapi = require('hapi') const IPFS = require('../core') const debug = require('debug') const fs = require('fs') -const os = require('os') const path = require('path') const log = debug('api') log.error = debug('api:error') @@ -18,15 +17,17 @@ exports.start = (repo, callback) => { } const ipfs = exports.ipfs = new IPFS(repo) + console.log('Starting at %s', ipfs.repo.path()) ipfs.load(() => { const repoPath = ipfs.repo.path() - + const apiPath = path.join(repoPath, 'api') + console.log('Finished loading') try { - fs.statSync(path.join(repoPath, 'api')) + fs.statSync(apiPath) console.log('This repo is currently being used by another daemon') process.exit(1) } catch (err) { - fs.writeFileSync(path.join(repoPath, 'api'), 'api is on by js-ipfs', {flag: 'w+'}) + fs.writeFileSync(apiPath, 'api is on by js-ipfs', {flag: 'w+'}) } ipfs.config.show((err, config) => { @@ -46,7 +47,7 @@ exports.start = (repo, callback) => { const gateway = config.Addresses.Gateway.split('/') // for the CLI to know the where abouts of the API - fs.writeFileSync(repoPath + '/api', config.Addresses.API) + fs.writeFileSync(apiPath, config.Addresses.API) // select which connection with server.select(