@saucelabs/bin-wrapper
Advanced tools
Comparing version 0.4.0 to 1.0.0
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _BinWrapper_instances, _BinWrapper_httpOptions, _BinWrapper_sources, _BinWrapper_path, _BinWrapper_name, _BinWrapper_binaryPresent, _BinWrapper_findMatchingPlatform; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,60 +12,58 @@ exports.BinWrapper = void 0; | ||
class BinWrapper { | ||
constructor() { | ||
_BinWrapper_instances.add(this); | ||
_BinWrapper_httpOptions.set(this, {}); | ||
_BinWrapper_sources.set(this, []); | ||
_BinWrapper_path.set(this, path_1.default.join(__dirname, 'bin')); | ||
_BinWrapper_name.set(this, 'bin'); | ||
} | ||
#httpOptions = {}; | ||
#sources = []; | ||
#path = path_1.default.join(__dirname, 'bin'); | ||
#name = 'bin'; | ||
src(path, os, arch) { | ||
__classPrivateFieldGet(this, _BinWrapper_sources, "f").push({ os: os, arch: arch, path: path }); | ||
this.#sources.push({ os: os, arch: arch, path: path }); | ||
return this; | ||
} | ||
dest(path) { | ||
__classPrivateFieldSet(this, _BinWrapper_path, path, "f"); | ||
this.#path = path; | ||
return this; | ||
} | ||
use(name) { | ||
__classPrivateFieldSet(this, _BinWrapper_name, name, "f"); | ||
this.#name = name; | ||
return this; | ||
} | ||
httpOptions(options) { | ||
__classPrivateFieldSet(this, _BinWrapper_httpOptions, options, "f"); | ||
this.#httpOptions = options; | ||
return this; | ||
} | ||
async install() { | ||
if (await __classPrivateFieldGet(this, _BinWrapper_instances, "m", _BinWrapper_binaryPresent).call(this)) { | ||
if (await this.#binaryPresent()) { | ||
return; | ||
} | ||
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")), __classPrivateFieldGet(this, _BinWrapper_httpOptions, "f")); | ||
const downloadUrl = this.#findMatchingPlatform(); | ||
await (0, download_1.downloadAndUnpack)(downloadUrl.path, this.#name, path_1.default.join(this.#path, this.#name), this.#httpOptions); | ||
} | ||
async run(args, stdio) { | ||
await this.install(); | ||
return await (0, run_1.run)(path_1.default.join(__classPrivateFieldGet(this, _BinWrapper_path, "f"), __classPrivateFieldGet(this, _BinWrapper_name, "f")), args, stdio); | ||
return await (0, run_1.run)(path_1.default.join(this.#path, this.#name), args, stdio); | ||
} | ||
async #binaryPresent() { | ||
let st; | ||
try { | ||
st = await promises_1.default.stat(this.path()); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
if (!st.isFile()) { | ||
throw new Error(`${this.path()} exists but is not a file`); | ||
} | ||
return true; | ||
} | ||
#findMatchingPlatform() { | ||
const matches = this.#sources.filter(x => x.arch === process.arch && x.os === process.platform); | ||
if (matches.length == 0) { | ||
throw new Error(`no package found for ${process.platform}_${process.arch}`); | ||
} | ||
return matches[0]; | ||
} | ||
path() { | ||
return path_1.default.join(__classPrivateFieldGet(this, _BinWrapper_path, "f"), __classPrivateFieldGet(this, _BinWrapper_name, "f")); | ||
return path_1.default.join(this.#path, this.#name); | ||
} | ||
} | ||
exports.BinWrapper = BinWrapper; | ||
_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; | ||
try { | ||
st = await promises_1.default.stat(this.path()); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
if (!st.isFile()) { | ||
throw new Error(`${this.path()} exists but is not a file`); | ||
} | ||
return true; | ||
}, _BinWrapper_findMatchingPlatform = function _BinWrapper_findMatchingPlatform() { | ||
const matches = __classPrivateFieldGet(this, _BinWrapper_sources, "f").filter(x => x.arch === process.arch && x.os === process.platform); | ||
if (matches.length == 0) { | ||
throw new Error(`no package found for ${process.platform}_${process.arch}`); | ||
} | ||
return matches[0]; | ||
}; | ||
exports.default = BinWrapper; |
{ | ||
"name": "@saucelabs/bin-wrapper", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"description": "Fetches and runs a binary", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"build": "rimraf ./build && tsc", | ||
"lint": "eslint src/ test/", | ||
"lint": "eslint src/ tests/", | ||
"prepare": "husky install", | ||
@@ -39,26 +39,26 @@ "test": "jest --coverage", | ||
"homepage": "https://github.com/saucelabs/bin-wrapper#readme", | ||
"dependencies": { | ||
"adm-zip": "^0.5.10", | ||
"axios": "^1.5.1", | ||
"tar-stream": "^3.1.6", | ||
"https-proxy-agent": "^7.0.2" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.3.1", | ||
"@tsconfig/node16": "^1.0.3", | ||
"@types/adm-zip": "^0.5.0", | ||
"@types/jest": "^29.2.5", | ||
"@types/node": "^18.11.18", | ||
"@types/tar-stream": "^2.2.2", | ||
"eslint": "^8.32.0", | ||
"eslint-config-typescript": "^3.0.0", | ||
"@jest/globals": "^29.7.0", | ||
"@tsconfig/node20": "^20.1.2", | ||
"@types/adm-zip": "^0.5.2", | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^20.8.4", | ||
"@types/tar-stream": "^3.1.1", | ||
"@typescript-eslint/eslint-plugin": "^6.7.5", | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"eslint": "^8.51.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.3.1", | ||
"release-it": "^15.6.0", | ||
"rimraf": "^4.1.0", | ||
"spawk": "^1.8.0", | ||
"ts-jest": "^29.0.5", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"adm-zip": "^0.5.10", | ||
"axios": "^1.2.2", | ||
"tar-stream": "^3.0.0", | ||
"https-proxy-agent": "^5.0.1" | ||
"jest": "^29.7.0", | ||
"release-it": "^16.2.1", | ||
"rimraf": "^5.0.5", | ||
"spawk": "^1.8.1", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
# bin-wrapper | ||
:warning: This package is a non-official and not a supported product. | ||
:warning: This package is not an official Sauce Labs product and is not supported by Sauce Labs. | ||
@@ -101,2 +101,2 @@ ## Install | ||
Returns the path to the binary. | ||
Returns the path to the binary. |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
102
28669
323
+ Addedagent-base@7.1.1(transitive)
+ Addedhttps-proxy-agent@7.0.5(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
Updatedaxios@^1.5.1
Updatedhttps-proxy-agent@^7.0.2
Updatedtar-stream@^3.1.6