From 5e93d2f5d185b7e64ab74baf9018c607539bebd5 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 26 Jan 2018 13:37:39 -0500 Subject: [PATCH 1/8] update version call so that it doesn't freak out w/ an uninitialized repo. --- src/cli/commands/version.js | 8 ++++---- src/core/components/repo.js | 18 +++++++++++++++++- src/core/components/version.js | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index dc322616e0..3507a52cb2 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -32,22 +32,22 @@ module.exports = { }, handler (argv) { - argv.ipfs.version((err, ipfs) => { + argv.ipfs.version((err, data) => { if (err) { throw err } const withCommit = argv.all || argv.commit - const parsedVersion = `${ipfs.version}${withCommit ? `-${ipfs.commit}` : ''}` + const parsedVersion = `${data.version}${withCommit ? `-${data.commit}` : ''}` if (argv.repo) { // go-ipfs prints only the number, even without the --number flag. - print(ipfs.repo) + print(data.repo) } else if (argv.number) { print(parsedVersion) } else if (argv.all) { print(`js-ipfs version: ${parsedVersion}`) - print(`Repo version: ${ipfs.repo}`) + print(`Repo version: ${data.repo}`) } else { print(`js-ipfs version: ${parsedVersion}`) } diff --git a/src/core/components/repo.js b/src/core/components/repo.js index eb488346a9..414c68f109 100644 --- a/src/core/components/repo.js +++ b/src/core/components/repo.js @@ -1,13 +1,29 @@ 'use strict' +const repoVersion = require('ipfs-repo').repoVersion + module.exports = function repo (self) { return { init: (bits, empty, callback) => { // 1. check if repo already exists }, + /** + * If the repo has been initialized, report the current version. + * Otherwise report the version that would be initialized. + */ version: (callback) => { - self._repo.version.get(callback) + self._repo._isInitialized(err => { + if (err) { + if (/ENOENT|not yet initialized/.test(err.message)) { + // this repo has not been initialized + return callback(null, repoVersion) + } + return callback(err) + } + + self._repo.version.get(callback) + }) }, gc: function () {}, diff --git a/src/core/components/version.js b/src/core/components/version.js index 0f3fa2c1e1..1afbc7a7fb 100644 --- a/src/core/components/version.js +++ b/src/core/components/version.js @@ -13,7 +13,7 @@ module.exports = function version (self) { self.repo.version((err, repoVersion) => { if (err) { - throw err + callback(err) } callback(null, { From ff27f7e8237008e478c8db42a0e8c0a4a3f887d6 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 26 Jan 2018 13:38:25 -0500 Subject: [PATCH 2/8] update sharness tests. I've not been able to run the sharness tests successfully but got to go so will push this for now --- test/sharness/t0010-basic-commands.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sharness/t0010-basic-commands.sh b/test/sharness/t0010-basic-commands.sh index 402485051b..8660c17515 100755 --- a/test/sharness/t0010-basic-commands.sh +++ b/test/sharness/t0010-basic-commands.sh @@ -28,7 +28,8 @@ test_expect_success "ipfs version output looks good" ' test_expect_success "ipfs version --all has all required fields" ' ipfs version --all > version_all.txt && - grep "js-ipfs version" version_all.txt + grep "js-ipfs version" version_all.txt && + grep "Repo version" version_all.txt ' test_expect_success "ipfs help succeeds" ' From 1075a8c388fc4f5a4a010f6866f5121db0b076f0 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 26 Jan 2018 14:02:28 -0500 Subject: [PATCH 3/8] update test to use ipfs-repo.version. --- test/cli/repo.js | 9 ++------- test/cli/version.js | 8 +------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/test/cli/repo.js b/test/cli/repo.js index dd1e29533d..903ceba68a 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -4,20 +4,15 @@ const fs = require('fs') const path = require('path') const expect = require('chai').expect -const runOnAndOff = require('../utils/on-and-off') +const repoVersion = require('ipfs-repo').repoVersion -function getRepoVersion (repoPath) { - const versionPath = path.join(repoPath, 'version') - return String(fs.readFileSync(versionPath)) -} +const runOnAndOff = require('../utils/on-and-off') describe('repo', () => runOnAndOff((thing) => { let ipfs - let repoVersion before(() => { ipfs = thing.ipfs - repoVersion = getRepoVersion(ipfs.repoPath) }) it('get the repo version', () => { diff --git a/test/cli/version.js b/test/cli/version.js index ba86356088..dfbdcbc51d 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -4,21 +4,15 @@ const fs = require('fs') const path = require('path') const expect = require('chai').expect +const repoVersion = require('ipfs-repo').repoVersion const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') -function getRepoVersion (repoPath) { - const versionPath = path.join(repoPath, 'version') - return String(fs.readFileSync(versionPath)) -} - describe('version', () => runOnAndOff((thing) => { let ipfs - let repoVersion before(() => { ipfs = thing.ipfs - repoVersion = getRepoVersion(ipfs.repoPath) }) it('get the version', () => { From 54299dae2f86c10cf539e0ccb404ba3ebb0cf767 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 26 Jan 2018 16:30:51 -0500 Subject: [PATCH 4/8] impl printing and tests for system and node.js versions. --- src/cli/commands/version.js | 3 ++ test/cli/version.js | 57 ++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 3507a52cb2..6bb8447a2f 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -1,5 +1,6 @@ 'use strict' +const os = require('os') const print = require('../utils').print module.exports = { @@ -48,6 +49,8 @@ module.exports = { } else if (argv.all) { print(`js-ipfs version: ${parsedVersion}`) print(`Repo version: ${data.repo}`) + print(`System version: ${os.arch()}/${os.platform()}`) + print(`Node.js version: ${process.version}`) } else { print(`js-ipfs version: ${parsedVersion}`) } diff --git a/test/cli/version.js b/test/cli/version.js index dfbdcbc51d..8189ce2a4c 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -2,6 +2,7 @@ 'use strict' const fs = require('fs') +const os = require('os') const path = require('path') const expect = require('chai').expect const repoVersion = require('ipfs-repo').repoVersion @@ -15,39 +16,55 @@ describe('version', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('get the version', () => { - return ipfs('version').then((out) => { + it('get the version', () => + ipfs('version').then(out => expect(out).to.eql( `js-ipfs version: ${pkgversion}\n` ) - }) - }) + ) + ) - it('handles --number', () => { - return ipfs('version --number').then(out => + it('handles --number', () => + ipfs('version --number').then(out => expect(out).to.eql(`${pkgversion}\n`) ) - }) + ) - it('handles --commit', () => { - return ipfs('version --commit').then(out => + it('handles --commit', () => + ipfs('version --commit').then(out => expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`) ) - }) + ) - it('handles --all', () => { - return ipfs('version --all').then(out => - expect(out).to.include( - `js-ipfs version: ${pkgversion}- -Repo version: ${repoVersion} -` + describe('handles --all', function() { + it('prints js-ipfs version', () => + ipfs('version --all').then(out => + expect(out).to.include(`js-ipfs version: ${pkgversion}`) + ) + ) + + it('prints repo version', () => + ipfs('version --all').then(out => + expect(out).to.include(`Repo version: ${repoVersion}`) + ) + ) + + it('prints arch/platform', () => + ipfs('version --all').then(out => + expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`) + ) + ) + + it('prints Node.js version', () => + ipfs('version --all').then(out => + expect(out).to.include(`Node.js version: ${process.version}`) ) ) }) - it('handles --repo', () => { - return ipfs('version --repo').then(out => { + it('handles --repo', () => + ipfs('version --repo').then(out => expect(out).to.eql(`${repoVersion}\n`) - }) - }) + ) + ) })) From c738c76da9e942b61ca5950055d8ec309800bf81 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 30 Jan 2018 13:19:42 -0500 Subject: [PATCH 5/8] update sharness expects after adding System and Node.js version to --all --- test/sharness/t0010-basic-commands.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/sharness/t0010-basic-commands.sh b/test/sharness/t0010-basic-commands.sh index 8660c17515..92f4354fdd 100755 --- a/test/sharness/t0010-basic-commands.sh +++ b/test/sharness/t0010-basic-commands.sh @@ -29,7 +29,9 @@ test_expect_success "ipfs version output looks good" ' test_expect_success "ipfs version --all has all required fields" ' ipfs version --all > version_all.txt && grep "js-ipfs version" version_all.txt && - grep "Repo version" version_all.txt + grep "Repo version" version_all.txt && + grep "System version" version_all.txt && + grep "Node.js version" version_all.txt ' test_expect_success "ipfs help succeeds" ' From 8ea55778ae1f73e14f9ecc7ac552f70048c316bf Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 30 Jan 2018 13:28:51 -0500 Subject: [PATCH 6/8] update ipfs-repo version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db2bdac274..921d20b18d 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "ipfs-block": "~0.6.1", "ipfs-block-service": "~0.13.0", "ipfs-multipart": "~0.1.0", - "ipfs-repo": "~0.18.5", + "ipfs-repo": "^0.18.6", "ipfs-unixfs": "~0.1.14", "ipfs-unixfs-engine": "~0.24.2", "ipld-resolver": "~0.14.1", From 27722217791f3790f51d775fecb6f05149b0bb4e Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 30 Jan 2018 13:48:25 -0500 Subject: [PATCH 7/8] lint/doc --- src/core/components/repo.js | 3 +++ test/cli/files.js | 2 +- test/cli/repo.js | 2 -- test/cli/version.js | 4 +--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/components/repo.js b/src/core/components/repo.js index 414c68f109..d163fcc8b5 100644 --- a/src/core/components/repo.js +++ b/src/core/components/repo.js @@ -11,6 +11,9 @@ module.exports = function repo (self) { /** * If the repo has been initialized, report the current version. * Otherwise report the version that would be initialized. + * + * @param {function(Error, Number)} [callback] + * @returns {undefined} */ version: (callback) => { self._repo._isInitialized(err => { diff --git a/test/cli/files.js b/test/cli/files.js index 5a36f52a4e..f3ca0d501b 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect const fs = require('fs') +const expect = require('chai').expect const path = require('path') const compareDir = require('dir-compare').compareSync const rimraf = require('rimraf').sync diff --git a/test/cli/repo.js b/test/cli/repo.js index 903ceba68a..17c04aaaa3 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -1,8 +1,6 @@ /* eslint-env mocha */ 'use strict' -const fs = require('fs') -const path = require('path') const expect = require('chai').expect const repoVersion = require('ipfs-repo').repoVersion diff --git a/test/cli/version.js b/test/cli/version.js index 8189ce2a4c..cee869fc20 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -1,9 +1,7 @@ /* eslint-env mocha */ 'use strict' -const fs = require('fs') const os = require('os') -const path = require('path') const expect = require('chai').expect const repoVersion = require('ipfs-repo').repoVersion const pkgversion = require('../../package.json').version @@ -36,7 +34,7 @@ describe('version', () => runOnAndOff((thing) => { ) ) - describe('handles --all', function() { + describe('handles --all', function () { it('prints js-ipfs version', () => ipfs('version --all').then(out => expect(out).to.include(`js-ipfs version: ${pkgversion}`) From 21a7f29b92a6a949fe4557719e1f884e81903ad7 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 30 Jan 2018 15:40:47 -0500 Subject: [PATCH 8/8] ask eslint to expand the depths of acceptable callback hell --- test/cli/version.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/cli/version.js b/test/cli/version.js index cee869fc20..5bf740eb15 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -1,3 +1,4 @@ +/* eslint max-nested-callbacks: ["error", 5] */ /* eslint-env mocha */ 'use strict' @@ -36,27 +37,27 @@ describe('version', () => runOnAndOff((thing) => { describe('handles --all', function () { it('prints js-ipfs version', () => - ipfs('version --all').then(out => + ipfs('version --all').then(out => { expect(out).to.include(`js-ipfs version: ${pkgversion}`) - ) + }) ) it('prints repo version', () => - ipfs('version --all').then(out => + ipfs('version --all').then(out => { expect(out).to.include(`Repo version: ${repoVersion}`) - ) + }) ) it('prints arch/platform', () => - ipfs('version --all').then(out => + ipfs('version --all').then(out => { expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`) - ) + }) ) it('prints Node.js version', () => - ipfs('version --all').then(out => + ipfs('version --all').then(out => { expect(out).to.include(`Node.js version: ${process.version}`) - ) + }) ) })