@saucelabs/bin-wrapper
Advanced tools
Comparing version 0.1.2 to 0.2.0
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { HttpOptions } from './index'; | ||
type FileEntry = { | ||
@@ -7,5 +8,5 @@ data: Buffer; | ||
}; | ||
declare function downloadAndUnpack(url: URL, filepath: string, binary: string): Promise<void>; | ||
declare function download(url: URL): Promise<any>; | ||
declare function downloadAndUnpack(url: URL, filepath: string, binary: string, options?: HttpOptions): Promise<void>; | ||
declare function download(url: URL, options: HttpOptions): Promise<any>; | ||
export { downloadAndUnpack, download, FileEntry }; | ||
//# sourceMappingURL=download.d.ts.map |
@@ -13,4 +13,4 @@ "use strict"; | ||
const tar_1 = __importDefault(require("./archive/tar")); | ||
async function downloadAndUnpack(url, filepath, binary) { | ||
const payload = await download(url); | ||
async function downloadAndUnpack(url, filepath, binary, options = {}) { | ||
const payload = await download(url, options); | ||
const files = await extract(payload); | ||
@@ -24,8 +24,9 @@ const found = files.filter(x => x.path == filepath); | ||
exports.downloadAndUnpack = downloadAndUnpack; | ||
async function download(url) { | ||
return await axios_1.default.get(url.toString(), { responseType: 'arraybuffer' }) | ||
.then((res) => { | ||
async function download(url, options) { | ||
return await axios_1.default.get(url.toString(), { | ||
responseType: 'arraybuffer', | ||
headers: options.headers, | ||
}).then((res) => { | ||
return res.data; | ||
}) | ||
.catch((err) => { | ||
}).catch((err) => { | ||
throw new Error(`failed to download: ${err}`); | ||
@@ -32,0 +33,0 @@ }); |
/// <reference types="node" /> | ||
type OS = 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32'; | ||
type Arch = 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x64'; | ||
export type Headers = { | ||
[key: string]: string; | ||
}; | ||
export type HttpOptions = { | ||
headers?: Headers; | ||
}; | ||
export declare class BinWrapper { | ||
@@ -9,2 +15,3 @@ #private; | ||
use(name: string): BinWrapper; | ||
httpOptions(options: HttpOptions): BinWrapper; | ||
install(): Promise<void>; | ||
@@ -11,0 +18,0 @@ run(args: string[]): Promise<number>; |
@@ -16,3 +16,3 @@ "use strict"; | ||
}; | ||
var _BinWrapper_instances, _BinWrapper_sources, _BinWrapper_path, _BinWrapper_name, _BinWrapper_binaryPresent, _BinWrapper_findMatchingPlatform; | ||
var _BinWrapper_instances, _BinWrapper_httpOptions, _BinWrapper_sources, _BinWrapper_path, _BinWrapper_name, _BinWrapper_binaryPresent, _BinWrapper_findMatchingPlatform; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,2 +27,3 @@ exports.BinWrapper = void 0; | ||
_BinWrapper_instances.add(this); | ||
_BinWrapper_httpOptions.set(this, {}); | ||
_BinWrapper_sources.set(this, []); | ||
@@ -44,2 +45,6 @@ _BinWrapper_path.set(this, path_1.default.join(__dirname, 'bin')); | ||
} | ||
httpOptions(options) { | ||
__classPrivateFieldSet(this, _BinWrapper_httpOptions, options, "f"); | ||
return this; | ||
} | ||
async install() { | ||
@@ -50,3 +55,3 @@ if (await __classPrivateFieldGet(this, _BinWrapper_instances, "m", _BinWrapper_binaryPresent).call(this)) { | ||
const downloadUrl = __classPrivateFieldGet(this, _BinWrapper_instances, "m", _BinWrapper_findMatchingPlatform).call(this); | ||
await (0, download_1.downloadAndUnpack)(downloadUrl.path, __classPrivateFieldGet(this, _BinWrapper_name, "f"), path_1.default.join(__classPrivateFieldGet(this, _BinWrapper_path, "f"), __classPrivateFieldGet(this, _BinWrapper_name, "f"))); | ||
await (0, download_1.downloadAndUnpack)(downloadUrl.path, __classPrivateFieldGet(this, _BinWrapper_name, "f"), path_1.default.join(__classPrivateFieldGet(this, _BinWrapper_path, "f"), __classPrivateFieldGet(this, _BinWrapper_name, "f")), __classPrivateFieldGet(this, _BinWrapper_httpOptions, "f")); | ||
} | ||
@@ -62,3 +67,3 @@ async run(args) { | ||
exports.BinWrapper = BinWrapper; | ||
_BinWrapper_sources = new WeakMap(), _BinWrapper_path = new WeakMap(), _BinWrapper_name = new WeakMap(), _BinWrapper_instances = new WeakSet(), _BinWrapper_binaryPresent = async function _BinWrapper_binaryPresent() { | ||
_BinWrapper_httpOptions = new WeakMap(), _BinWrapper_sources = new WeakMap(), _BinWrapper_path = new WeakMap(), _BinWrapper_name = new WeakMap(), _BinWrapper_instances = new WeakSet(), _BinWrapper_binaryPresent = async function _BinWrapper_binaryPresent() { | ||
let st; | ||
@@ -65,0 +70,0 @@ try { |
{ | ||
"name": "@saucelabs/bin-wrapper", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Fetches and runs a binary", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
29693
310