Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

install-bin

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

install-bin - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/logger.d.ts

4

lib/installer.d.ts
import { Binary } from './binary';
import { LogLevelFilterString } from './logger';
export interface MakeInstallerParams {
root: string;
binary: Binary;
logLevel?: LogLevelFilterString;
}
export declare const makeInstaller: ({ root, binary }: MakeInstallerParams) => {
export declare const makeInstaller: ({ root, binary, logLevel, }: MakeInstallerParams) => {
install: () => Promise<void>;
binaryPath: string;
};

@@ -21,23 +21,33 @@ "use strict";

const tar_1 = __importDefault(require("tar"));
const makeInstaller = ({ root, binary }) => {
const logger_1 = require("./logger");
const makeInstaller = ({ root, binary, logLevel = 'info', }) => {
const logger = new logger_1.Logger(logLevel);
const installDirectory = node_path_1.default.join(root, 'node_modules', '.bin');
const binaryPath = node_path_1.default.join(installDirectory, binary.name);
const install = () => __awaiter(void 0, void 0, void 0, function* () {
logger.trace({ installDirectory, binaryPath });
if ((0, node_fs_1.existsSync)(binaryPath)) {
logger.info(`${binary.name} already installed, skipping installation.`);
return;
}
if ((0, node_fs_1.existsSync)(installDirectory)) {
logger.debug(`Installation directory already exists, purging directory`);
yield promises_1.default.rm(installDirectory, { recursive: true, force: true });
}
yield promises_1.default.mkdir(installDirectory, { recursive: true });
console.log(`Downloading ${binary.url}`);
const res = yield axios_1.default.get(binary.url, { responseType: 'stream' });
yield new Promise((resolve, reject) => {
res.data
.pipe(tar_1.default.extract({ strip: 0, cwd: installDirectory }))
.on('finish', resolve)
.on('error', reject);
}).catch(err => {
console.error(`Failed to download: ${err}`);
});
logger.info(`Downloading ${binary.url}`);
try {
const res = yield axios_1.default.get(binary.url, { responseType: 'stream' });
yield new Promise((resolve, reject) => {
res.data
.pipe(tar_1.default.extract({ strip: 0, cwd: installDirectory }))
.on('finish', resolve)
.on('error', reject);
});
}
catch (err) {
const message = err instanceof Error ? err.message : 'An unknown error occurred.';
logger.error(`Binary download failed: ${message}`);
process.exit(1);
}
});

@@ -44,0 +54,0 @@ return { install, binaryPath };

@@ -15,4 +15,7 @@ "use strict";

const installer_1 = require("./installer");
const logger_1 = require("./logger");
const hideBin = (argv) => argv.slice(2);
const run = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const logger = new logger_1.Logger((_a = params.logLevel) !== null && _a !== void 0 ? _a : 'info');
const { install, binaryPath } = (0, installer_1.makeInstaller)(params);

@@ -25,3 +28,3 @@ yield install();

if (result.error) {
console.error(result.error);
logger.error(result.error);
return process.exit(1);

@@ -28,0 +31,0 @@ }

{
"name": "install-bin",
"version": "0.1.0",
"version": "0.2.0",
"repository": "git@github.com:maxdeviant/install-bin.git",

@@ -5,0 +5,0 @@ "author": "Marshall Bowers <elliott.codes@gmail.com>",

# install-bin
[![npm](https://img.shields.io/npm/v/install-bin.svg?maxAge=3600)](https://www.npmjs.com/package/install-bin)
Install binaries from npm
## Installation
#### Yarn
```sh
yarn add install-bin
```
#### npm
```sh
npm install install-bin
```

@@ -7,2 +7,3 @@ import axios from 'axios';

import { Binary } from './binary';
import { Logger, LogLevelFilterString } from './logger';

@@ -12,5 +13,12 @@ export interface MakeInstallerParams {

binary: Binary;
logLevel?: LogLevelFilterString;
}
export const makeInstaller = ({ root, binary }: MakeInstallerParams) => {
export const makeInstaller = ({
root,
binary,
logLevel = 'info',
}: MakeInstallerParams) => {
const logger = new Logger(logLevel);
const installDirectory = path.join(root, 'node_modules', '.bin');

@@ -20,3 +28,6 @@ const binaryPath = path.join(installDirectory, binary.name);

const install = async () => {
logger.trace({ installDirectory, binaryPath });
if (existsSync(binaryPath)) {
logger.info(`${binary.name} already installed, skipping installation.`);
return;

@@ -26,2 +37,3 @@ }

if (existsSync(installDirectory)) {
logger.debug(`Installation directory already exists, purging directory`);
await fs.rm(installDirectory, { recursive: true, force: true });

@@ -32,14 +44,20 @@ }

console.log(`Downloading ${binary.url}`);
logger.info(`Downloading ${binary.url}`);
const res = await axios.get(binary.url, { responseType: 'stream' });
try {
const res = await axios.get(binary.url, { responseType: 'stream' });
await new Promise((resolve, reject) => {
res.data
.pipe(tar.extract({ strip: 0, cwd: installDirectory }))
.on('finish', resolve)
.on('error', reject);
}).catch(err => {
console.error(`Failed to download: ${err}`);
});
await new Promise((resolve, reject) => {
res.data
.pipe(tar.extract({ strip: 0, cwd: installDirectory }))
.on('finish', resolve)
.on('error', reject);
});
} catch (err: unknown) {
const message =
err instanceof Error ? err.message : 'An unknown error occurred.';
logger.error(`Binary download failed: ${message}`);
process.exit(1);
}
};

@@ -46,0 +64,0 @@

import { spawnSync } from 'child_process';
import { makeInstaller, MakeInstallerParams } from './installer';
import { Logger } from './logger';

@@ -7,2 +8,4 @@ const hideBin = (argv: string[]) => argv.slice(2);

export const run = async (params: MakeInstallerParams) => {
const logger = new Logger(params.logLevel ?? 'info');
const { install, binaryPath } = makeInstaller(params);

@@ -17,3 +20,3 @@

if (result.error) {
console.error(result.error);
logger.error(result.error);
return process.exit(1);

@@ -20,0 +23,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc