From a2021b0b5a1d3a9aac3f1383598697522d125bcf Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 16 Mar 2016 23:43:55 +0100 Subject: [PATCH] fix: Upgrade dependencies, use strict and fix /blocks pathing --- package.json | 31 +++++++++++++++-------------- src/index.js | 4 +++- src/stores/config.js | 12 +++++++----- src/stores/datastore-legacy.js | 14 +++++++------ src/stores/datastore.js | 20 ++++++++++--------- src/stores/index.js | 3 ++- src/stores/keys.js | 4 +++- src/stores/locks.js | 10 ++++++---- src/stores/version.js | 10 ++++++---- tests/browser-tests.js | 4 +++- tests/node-tests.js | 15 ++++++++------ tests/repo-test.js | 36 ++++++++++++++++++---------------- 12 files changed, 93 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index acaf862c..8bbe2881 100644 --- a/package.json +++ b/package.json @@ -24,35 +24,36 @@ "homepage": "https://github.com/ipfs/js-ipfs-repo", "devDependencies": { "async": "^1.5.2", - "bl": "^1.0.0", + "bl": "^1.1.2", "bs58": "^3.0.0", "buffer-loader": "^0.0.1", - "chai": "^3.4.1", + "chai": "^3.5.0", "fs-blob-store": "^5.2.1", "idb-plus-blob-store": "^1.0.0", - "istanbul": "^0.4.1", - "karma": "^0.13.19", + "istanbul": "^0.4.2", + "karma": "^0.13.22", "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.23", + "karma-mocha": "^0.2.2", + "karma-spec-reporter": "0.0.24", "karma-webpack": "^1.7.0", - "local-storage-blob-store": "0.0.2", - "lodash": "^4.0.0", - "mocha": "^2.3.4", + "local-storage-blob-store": "0.0.3", + "lodash": "^4.6.1", + "mocha": "^2.4.5", "ncp": "^2.0.0", - "pre-commit": "^1.1.1", - "rimraf": "^2.4.4", - "standard": "^5.1.1", + "pre-commit": "^1.1.2", + "rimraf": "^2.5.2", + "standard": "^6.0.8", "webpack": "github:diasdavid/webpack#webpack-1" }, "dependencies": { - "bl": "^1.0.0", + "bl": "^1.1.2", "concat-stream": "^1.5.1", - "level-js": "^2.2.2", + "level-js": "^2.2.3", "lockfile": "^1.0.1", "multihashes": "^0.2.0", "xtend": "^4.0.1" - } + }, + "license": "MIT" } diff --git a/src/index.js b/src/index.js index 3f7e9da7..33f6d42b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +'use strict' + const stores = require('./stores') exports = module.exports = Repo @@ -13,7 +15,7 @@ function Repo (repoPath, options) { .locks .setUp(repoPath, options.stores.locks) - this.exists = callback => { + this.exists = (callback) => { this.version.get((err, version) => { if (err) { return callback(new Error('Repo does not exist')) diff --git a/src/stores/config.js b/src/stores/config.js index cd6abe06..8a3c743e 100644 --- a/src/stores/config.js +++ b/src/stores/config.js @@ -1,18 +1,20 @@ -var bl = require('bl') +'use strict' + +const bl = require('bl') exports = module.exports exports.setUp = (basePath, blobStore, locks) => { - var store = blobStore(basePath) + const store = blobStore(basePath) return { - get: callback => { + get: (callback) => { store .createReadStream('config') .pipe(bl((err, config) => { if (err) { return callback(err) } - var result + let result try { result = JSON.parse(config.toString()) } catch (err) { @@ -23,7 +25,7 @@ exports.setUp = (basePath, blobStore, locks) => { }, set: (config, callback) => { - locks.lock(err => { + locks.lock((err) => { if (err) { return callback(err) } diff --git a/src/stores/datastore-legacy.js b/src/stores/datastore-legacy.js index 2edcc126..003383a2 100644 --- a/src/stores/datastore-legacy.js +++ b/src/stores/datastore-legacy.js @@ -1,13 +1,15 @@ +'use strict' + // TODO: This may end up being configurable // TODO: This should belong to the `fs` implementation -var PREFIX_LENGTH = 8 -var multihash = require('multihashes') -var path = require('path') +const PREFIX_LENGTH = 8 +const multihash = require('multihashes') +const path = require('path') -module.exports = store => { +module.exports = (store) => { function hashToPath (hash) { - var folder = hash.slice(0, PREFIX_LENGTH) + const folder = hash.slice(0, PREFIX_LENGTH) return path.join(folder, hash) + '.data' } @@ -17,7 +19,7 @@ module.exports = store => { }, write: (buf, cb) => { - var mh = multihash.encode(buf, 'hex') + const mh = multihash.encode(buf, 'hex') return store.write(hashToPath(mh), buf, cb) } } diff --git a/src/stores/datastore.js b/src/stores/datastore.js index 80455d1f..84dbabfa 100644 --- a/src/stores/datastore.js +++ b/src/stores/datastore.js @@ -1,35 +1,37 @@ +'use strict' + const PREFIX_LENGTH = 8 exports = module.exports exports.setUp = (basePath, blobStore, locks) => { - var store = blobStore(basePath + '/blocks') + const store = blobStore(basePath + '/blocks') return { - createReadStream: multihash => { - var path = multihashToPath(multihash) + createReadStream: (multihash) => { + const path = multihashToPath(multihash) return store.createReadStream(path) }, createWriteStream: (multihash, cb) => { - var path = multihashToPath(multihash) + const path = multihashToPath(multihash) return store.createWriteStream(path, cb) }, exists: (multihash, cb) => { - var path = multihashToPath(multihash) + const path = multihashToPath(multihash) return store.exists(path, cb) }, remove: (multihash, cb) => { - var path = multihashToPath(multihash) + const path = multihashToPath(multihash) return store.remove(path, cb) } } } function multihashToPath (multihash) { - var filename = multihash.toString('hex') + '.data' - var folder = filename.slice(0, PREFIX_LENGTH) - var path = folder + '/' + filename + const filename = multihash.toString('hex') + '.data' + const folder = filename.slice(0, PREFIX_LENGTH) + const path = folder + '/' + filename return path } diff --git a/src/stores/index.js b/src/stores/index.js index a499a085..b7d9eecb 100644 --- a/src/stores/index.js +++ b/src/stores/index.js @@ -1,3 +1,5 @@ +'use strict' + exports = module.exports exports.locks = require('./locks') @@ -7,4 +9,3 @@ exports.keys = require('./keys') exports.datastore = require('./datastore') // exports.datastoreLegacy = require('./datastore-legacy') // exports.logs = require('./logs') - diff --git a/src/stores/keys.js b/src/stores/keys.js index 41e65163..7bf76f86 100644 --- a/src/stores/keys.js +++ b/src/stores/keys.js @@ -1,8 +1,10 @@ +'use strict' + exports = module.exports exports.setUp = (basePath, blobStore, locks, config) => { return { - get: callback => { + get: (callback) => { config.get((err, config) => { if (err) { return callback(err) diff --git a/src/stores/locks.js b/src/stores/locks.js index 27efcec4..52a23a86 100644 --- a/src/stores/locks.js +++ b/src/stores/locks.js @@ -1,8 +1,10 @@ +'use strict' + exports = module.exports exports.setUp = (basePath, blobStore) => { - var store = blobStore(basePath) - var lockFile = 'repo.lock' + const store = blobStore(basePath) + const lockFile = 'repo.lock' return { lock: function (cb) { @@ -31,8 +33,8 @@ exports.setUp = (basePath, blobStore) => { .end() } }, - unlock: cb => { - store.remove(lockFile, err => { + unlock: (cb) => { + store.remove(lockFile, (err) => { if (err) { return cb(err) } store.exists(lockFile, (err, exists) => { if (err) { return cb(err) } diff --git a/src/stores/version.js b/src/stores/version.js index cf166b82..1b422f38 100644 --- a/src/stores/version.js +++ b/src/stores/version.js @@ -1,12 +1,14 @@ -var bl = require('bl') +'use strict' + +const bl = require('bl') exports = module.exports exports.setUp = (basePath, blobStore, locks) => { - var store = blobStore(basePath) + const store = blobStore(basePath) return { - get: callback => { + get: (callback) => { store .createReadStream('version') .pipe(bl((err, version) => { @@ -17,7 +19,7 @@ exports.setUp = (basePath, blobStore, locks) => { })) }, set: (value, callback) => { - locks.lock(err => { + locks.lock((err) => { if (err) { return callback(err) } diff --git a/tests/browser-tests.js b/tests/browser-tests.js index 889c8cc2..92b6d3e5 100644 --- a/tests/browser-tests.js +++ b/tests/browser-tests.js @@ -1,4 +1,6 @@ -/* globals describe, before */ +/* eslint-env mocha */ + +'use strict' const async = require('async') const store = require('idb-plus-blob-store') diff --git a/tests/node-tests.js b/tests/node-tests.js index e3bd9855..0b89de8a 100644 --- a/tests/node-tests.js +++ b/tests/node-tests.js @@ -1,25 +1,28 @@ -/* globals describe, before, after */ +/* eslint-env mocha */ + +'use strict' const expect = require('chai').expect const ncp = require('ncp').ncp const rimraf = require('rimraf') +const path = require('path') const IPFSRepo = require('../src') describe('IPFS Repo Testson on Node.js', () => { - const testRepoPath = __dirname + '/test-repo' + const testRepoPath = path.join(__dirname, 'test-repo') const date = Date.now().toString() const repoPath = testRepoPath + date - before(done => { - ncp(testRepoPath, repoPath, err => { + before((done) => { + ncp(testRepoPath, repoPath, (err) => { expect(err).to.not.exist done() }) }) - after(done => { - rimraf(repoPath, err => { + after((done) => { + rimraf(repoPath, (err) => { expect(err).to.not.exist done() }) diff --git a/tests/repo-test.js b/tests/repo-test.js index ac25e7a6..9a38ede5 100644 --- a/tests/repo-test.js +++ b/tests/repo-test.js @@ -1,4 +1,6 @@ -/* globals describe, it*/ +/* eslint-env mocha */ + +'use strict' const expect = require('chai').expect const base58 = require('bs58') @@ -13,7 +15,7 @@ const fileA = isNode module.exports = function (repo) { describe('IPFS Repo Tests', function () { - it('check if Repo exists', done => { + it('check if Repo exists', (done) => { repo.exists((err, exists) => { expect(err).to.not.exist expect(exists).to.equal(true) @@ -22,29 +24,29 @@ module.exports = function (repo) { }) describe('locks', () => { - it('lock, unlock', done => { - repo.locks.lock(err => { + it('lock, unlock', (done) => { + repo.locks.lock((err) => { expect(err).to.not.exist - repo.locks.unlock(err => { + repo.locks.unlock((err) => { expect(err).to.not.exist done() }) }) }) - it('lock, lock', done => { - repo.locks.lock(err => { + it('lock, lock', (done) => { + repo.locks.lock((err) => { expect(err).to.not.exist - repo.locks.lock(err => { + repo.locks.lock((err) => { expect(err).to.not.exist - repo.locks.unlock(err => { + repo.locks.unlock((err) => { expect(err).to.not.exist done() }) }) setTimeout(() => { - repo.locks.unlock(err => { + repo.locks.unlock((err) => { expect(err).to.not.exist }) }, 500) @@ -53,7 +55,7 @@ module.exports = function (repo) { }) describe('keys', () => { - it('get PrivKey', done => { + it('get PrivKey', (done) => { repo.keys.get((err, privKey) => { expect(err).to.not.exist expect(privKey).to.be.a('string') @@ -63,7 +65,7 @@ module.exports = function (repo) { }) describe('config', () => { - it('get config', done => { + it('get config', (done) => { repo.config.get((err, config) => { expect(err).to.not.exist expect(config).to.be.a('object') @@ -71,8 +73,8 @@ module.exports = function (repo) { }) }) - it('set config', done => { - repo.config.set({a: 'b'}, err => { + it('set config', (done) => { + repo.config.set({a: 'b'}, (err) => { expect(err).to.not.exist repo.config.get((err, config) => { expect(err).to.not.exist @@ -84,7 +86,7 @@ module.exports = function (repo) { }) describe('version', () => { - it('get version', done => { + it('get version', (done) => { repo.version.get((err, version) => { expect(err).to.not.exist expect(version).to.be.a('string') @@ -93,8 +95,8 @@ module.exports = function (repo) { }) }) - it('set version', done => { - repo.version.set('9000', err => { + it('set version', (done) => { + repo.version.set('9000', (err) => { expect(err).to.not.exist repo.version.get((err, version) => { expect(err).to.not.exist