Skip to content

Commit a335efb

Browse files
authored
Replace binary-install with simple-binary-install (#133)
`binary-install` has open CVEs, and `simple-binary-install` seems to do the same thing, but with fewer dependencies.
1 parent 58711be commit a335efb

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

.github/npm/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/package-lock.json
2+
/node_modules/

.github/npm/getBinary.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { Binary } = require('binary-install');
2-
const os = require('os');
1+
import { Binary } from 'simple-binary-install';
2+
import * as os from 'os';
3+
import * as fs from 'fs';
34

45
function getPlatform() {
56
const type = os.type();
@@ -28,13 +29,11 @@ function getPlatform() {
2829
throw new Error(`Unsupported platform: ${type} ${arch}. Please create an issue at https://github.com/coralogix/protofetch/issues`);
2930
}
3031

31-
function getBinary() {
32+
export function getBinary() {
3233
const platform = getPlatform();
33-
const version = require('./package.json').version;
34+
const { version } = JSON.parse(fs.readFileSync('./package.json'));
3435
const url = `https://github.com/coralogix/protofetch/releases/download/v${version}/protofetch_${platform}.tar.gz`;
3536
const name = 'protofetch';
3637

3738
return new Binary(name, url)
3839
}
39-
40-
module.exports = getBinary;

.github/npm/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
"repository": "https://github.com/coralogix/protofetch.git",
66
"homepage": "https://github.com/coralogix/protofetch",
77
"license": "Apache-2.0",
8+
"type": "module",
89
"bin": {
910
"protofetch": "run.js"
1011
},
1112
"scripts": {
1213
"postinstall": "node scripts.js install"
1314
},
1415
"dependencies": {
15-
"binary-install": "^1.0.1"
16-
},
17-
"devDependencies": {
18-
"ncp": "^2.0.0",
19-
"vuepress": "^1.9.7"
16+
"simple-binary-install": "^0.2.1"
2017
},
2118
"keywords": [
2219
"proto",

.github/npm/run.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
const getBinary = require('./getBinary');
2+
import { getBinary } from './getBinary.js';
33

4-
const binary = getBinary();
5-
binary.run();
4+
getBinary().run();

.github/npm/scripts.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
function getBinary({ fatal }) {
2-
try {
3-
return require('./getBinary')();
4-
} catch (err) {
5-
if (fatal) throw err;
6-
}
7-
}
1+
import { getBinary } from './getBinary.js';
82

93
if (process.argv.includes('install')) {
10-
const binary = getBinary({ fatal: true });
11-
if (binary) binary.install();
4+
getBinary().install();
125
}
13-

0 commit comments

Comments
 (0)