go-ipfs-dep
Advanced tools
Comparing version 0.4.23 to 0.5.0
@@ -0,1 +1,11 @@ | ||
<a name="0.5.0"></a> | ||
# [0.5.0](https://github.com/ipfs/npm-go-ipfs-dep/compare/v0.4.23...v0.5.0) (2020-04-28) | ||
### Features | ||
* add .path and .path.silent functions to detect binary ([#40](https://github.com/ipfs/npm-go-ipfs-dep/issues/40)) ([c48958d](https://github.com/ipfs/npm-go-ipfs-dep/commit/c48958d)), closes [#25](https://github.com/ipfs/npm-go-ipfs-dep/issues/25) | ||
<a name="0.4.23"></a> | ||
@@ -2,0 +12,0 @@ ## [0.4.23](https://github.com/ipfs/npm-go-ipfs-dep/compare/v0.4.23-2...v0.4.23) (2020-01-30) |
{ | ||
"name": "go-ipfs-dep", | ||
"version": "0.4.23", | ||
"version": "0.5.0", | ||
"description": "Install the latest go-ipfs binary", | ||
@@ -53,2 +53,3 @@ "main": "src/index.js", | ||
"Harlan T Wood <harlantwood@users.noreply.github.com>", | ||
"Hector Sanjuan <code@hector.link>", | ||
"Henrique Dias <hacdias@gmail.com>", | ||
@@ -55,0 +56,0 @@ "Oli Evans <oli@tableflip.io>", |
@@ -26,2 +26,18 @@ # go-ipfs-dep | ||
After downloading you can find out the path of the installed binary by calling the `path` function exported by this module: | ||
```javascript | ||
const { path } = require('go-ipfs-dep') | ||
console.info('go-ipfs is installed at', path()) | ||
``` | ||
An error will be thrown if the path to the binary cannot be resolved - if you do not wish this to happen, call `path.silent()`: | ||
```javascript | ||
const { path: silent } = require('go-ipfs-dep') | ||
console.info('go-ipfs may installed at', silent()) | ||
``` | ||
### Overriding the go-ipfs version | ||
@@ -28,0 +44,0 @@ |
@@ -19,2 +19,10 @@ #!/usr/bin/env node | ||
const existingPath = download.path.silent() | ||
if (existingPath) { | ||
process.stdout.write(`Detected existing binary at ${existingPath}\n`) | ||
process.stdout.write(`Skipping download\n`) | ||
process.exit(0) | ||
} | ||
// First param is the target version | ||
@@ -21,0 +29,0 @@ // Second param is the target platform |
@@ -30,2 +30,3 @@ 'use strict' | ||
const pkg = require('./../package.json') | ||
const fs = require('fs') | ||
@@ -119,1 +120,24 @@ function unpack ({ url, installPath, stream }) { | ||
} | ||
module.exports.path = function () { | ||
const paths = [ | ||
path.resolve(path.join(__dirname, '..', 'go-ipfs', 'ipfs')), | ||
path.resolve(path.join(__dirname, '..', 'go-ipfs', 'ipfs.exe')) | ||
] | ||
for (const bin of paths) { | ||
if (fs.existsSync(bin)) { | ||
return bin | ||
} | ||
} | ||
throw new Error('go-ipfs binary not found, it may not be installed or an error may have occured during installation') | ||
} | ||
module.exports.path.silent = function () { | ||
try { | ||
return module.exports.path() | ||
} catch (err) { | ||
// ignore | ||
} | ||
} |
@@ -42,3 +42,3 @@ 'use strict' | ||
test('Ensure ipfs gets downloaded (current version and platform)', (t) => { | ||
t.plan(5) | ||
t.plan(7) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
@@ -56,2 +56,7 @@ rimraf.sync(dir) | ||
t.ok(stats, 'go-ipfs was downloaded') | ||
// Check detected path | ||
fs.stat(Download.path(), (err3, stats3) => { | ||
t.error(err3, 'detected binary path should stat without error') | ||
t.ok(stats3.mode, 'downloaded binary was detected') | ||
}) | ||
}) | ||
@@ -62,3 +67,3 @@ }) | ||
test('Ensure Windows version gets downloaded', (t) => { | ||
t.plan(7) | ||
t.plan(9) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
@@ -78,2 +83,7 @@ rimraf.sync(dir) | ||
t.ok(stats2, 'windows bin was downloaded') | ||
// Check detected path | ||
fs.stat(Download.path(), (err3, stats3) => { | ||
t.error(err3, 'detected binary path should stat without error') | ||
t.ok(stats3.mode, 'downloaded binary was detected') | ||
}) | ||
}) | ||
@@ -85,3 +95,3 @@ }) | ||
test('Ensure Linux version gets downloaded', (t) => { | ||
t.plan(7) | ||
t.plan(9) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
@@ -101,2 +111,7 @@ rimraf.sync(dir) | ||
t.ok(stats2, 'linux bin was downloaded') | ||
// Check detected path | ||
fs.stat(Download.path(), (err3, stats3) => { | ||
t.error(err3, 'detected binary path should stat without error') | ||
t.ok(stats3.mode, 'downloaded binary was detected') | ||
}) | ||
}) | ||
@@ -108,3 +123,3 @@ }) | ||
test('Ensure OSX version gets downloaded', (t) => { | ||
t.plan(7) | ||
t.plan(9) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
@@ -124,2 +139,7 @@ rimraf.sync(dir) | ||
t.ok(stats2, 'OSX bin was downloaded') | ||
// Check detected path | ||
fs.stat(Download.path(), (err3, stats3) => { | ||
t.error(err3, 'detected binary path should stat without error') | ||
t.ok(stats3.mode, 'downloaded binary was detected') | ||
}) | ||
}) | ||
@@ -131,3 +151,3 @@ }) | ||
test('Ensure TARGET_OS, TARGET_VERSION and TARGET_ARCH version gets downloaded', (t) => { | ||
t.plan(7) | ||
t.plan(9) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
@@ -154,5 +174,10 @@ rimraf.sync(dir) | ||
t.ok(stats2, 'windows bin was downloaded') | ||
delete process.env.TARGET_OS | ||
delete process.env.TARGET_VERSION | ||
delete process.env.TARGET_ARCH | ||
// Check detected path | ||
fs.stat(Download.path(), (err3, stats3) => { | ||
t.error(err3, 'detected binary path should stat without error') | ||
t.ok(stats3.mode, 'downloaded binary was detected') | ||
delete process.env.TARGET_OS | ||
delete process.env.TARGET_VERSION | ||
delete process.env.TARGET_ARCH | ||
}) | ||
}) | ||
@@ -184,1 +209,16 @@ }) | ||
}) | ||
test('Path returns undefined when no binary has been downloaded', (t) => { | ||
t.plan(1) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
rimraf.sync(dir) | ||
t.ok(Download.path.silent() === undefined, 'Path is undefined before installation') | ||
}) | ||
test('Path returns undefined when no binary has been downloaded', (t) => { | ||
t.plan(1) | ||
const dir = path.resolve(__dirname, '../go-ipfs') | ||
rimraf.sync(dir) | ||
t.throws(Download.path, /not found/, 'Path throws if binary is not installed') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30945
17
365
125
19
4