From 5261eca1ba8a3d932c6bdc0d3a79901fb914bc50 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 26 Apr 2021 14:33:32 -0600 Subject: [PATCH] chore: include @cloudflare/binary-install directly as source --- npm/binary-install.js | 132 +++++++++++++++++++++++ npm/binary.js | 4 +- npm/npm-shrinkwrap.json | 226 +--------------------------------------- npm/package.json | 4 +- 4 files changed, 138 insertions(+), 228 deletions(-) create mode 100644 npm/binary-install.js diff --git a/npm/binary-install.js b/npm/binary-install.js new file mode 100644 index 000000000..cb84e0aab --- /dev/null +++ b/npm/binary-install.js @@ -0,0 +1,132 @@ +const { existsSync, mkdirSync } = require("fs"); +const { homedir } = require("os"); +const { join } = require("path"); +const { spawnSync } = require("child_process"); + +const axios = require("axios"); +const tar = require("tar"); +const rimraf = require("rimraf"); + +const error = msg => { + console.error(msg); + process.exit(1); +}; + +class Binary { + constructor(url, data) { + if (typeof url !== "string") { + errors.push("url must be a string"); + } else { + try { + new URL(url); + } catch (e) { + errors.push(e); + } + } + let errors = []; + if (data.name && typeof data.name !== "string") { + errors.push("name must be a string"); + } + if (data.installDirectory && typeof data.installDirectory !== "string") { + errors.push("installDirectory must be a string"); + } + if (!data.installDirectory && !data.name) { + errors.push("You must specify either name or installDirectory"); + } + if (errors.length > 0) { + let errorMsg = "Your Binary constructor is invalid:"; + errors.forEach(error => { + errorMsg += error; + }); + error(errorMsg); + } + this.url = url; + this.name = data.name || -1; + this.installDirectory = data.installDirectory || join(__dirname, "bin"); + this.binaryDirectory = -1; + this.binaryPath = -1; + } + + _getInstallDirectory() { + if (!existsSync(this.installDirectory)) { + mkdirSync(this.installDirectory, { recursive: true }); + } + return this.installDirectory; + } + + _getBinaryDirectory() { + const installDirectory = this._getInstallDirectory(); + const binaryDirectory = join(this.installDirectory, "bin"); + if (existsSync(binaryDirectory)) { + this.binaryDirectory = binaryDirectory; + } else { + error(`You have not installed ${this.name ? this.name : "this package"}`); + } + return this.binaryDirectory; + } + + _getBinaryPath() { + if (this.binaryPath === -1) { + const binaryDirectory = this._getBinaryDirectory(); + this.binaryPath = join(binaryDirectory, this.name); + } + + return this.binaryPath; + } + + install() { + const dir = this._getInstallDirectory(); + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true }); + } + + this.binaryDirectory = join(dir, "bin"); + + if (existsSync(this.binaryDirectory)) { + rimraf.sync(this.binaryDirectory); + } + + mkdirSync(this.binaryDirectory, { recursive: true }); + + console.log(`Downloading release from ${this.url}`); + + return axios({ url: this.url, responseType: "stream" }) + .then(res => { + res.data.pipe(tar.x({ strip: 1, C: this.binaryDirectory })); + }) + .then(() => { + console.log( + `${this.name ? this.name : "Your package"} has been installed!` + ); + }) + .catch(e => { + error(`Error fetching release: ${e.message}`); + }); + } + + uninstall() { + if (existsSync(this._getInstallDirectory())) { + rimraf.sync(this.installDirectory); + console.log( + `${this.name ? this.name : "Your package"} has been uninstalled` + ); + } + } + + run() { + const binaryPath = this._getBinaryPath(); + const [, , ...args] = process.argv; + + const options = { cwd: process.cwd(), stdio: "inherit" }; + + const result = spawnSync(binaryPath, args, options); + + if (result.error) { + error(result.error); + } + + process.exit(result.status); + } +} + +module.exports.Binary = Binary; \ No newline at end of file diff --git a/npm/binary.js b/npm/binary.js index 24fc7fbb0..086d639c4 100644 --- a/npm/binary.js +++ b/npm/binary.js @@ -1,4 +1,4 @@ -const { Binary } = require("@cloudflare/binary-install"); +const { Binary } = require("./binary-install"); const os = require("os"); const { join } = require("path"); @@ -59,4 +59,4 @@ module.exports = { install, run, uninstall, -}; +}; \ No newline at end of file diff --git a/npm/npm-shrinkwrap.json b/npm/npm-shrinkwrap.json index 197dc2aa3..b33ccfb3c 100644 --- a/npm/npm-shrinkwrap.json +++ b/npm/npm-shrinkwrap.json @@ -1,233 +1,9 @@ { "name": "@cloudflare/wrangler", "version": "1.16.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "@cloudflare/wrangler", - "version": "1.16.0", - "hasInstallScript": true, - "license": "MIT OR Apache-2.0", - "dependencies": { - "@cloudflare/binary-install": "0.2.0" - }, - "bin": { - "wrangler": "run-wrangler.js" - } - }, - "node_modules/@cloudflare/binary-install": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@cloudflare/binary-install/-/binary-install-0.2.0.tgz", - "integrity": "sha512-54n9ILgln+qUJc0BtbetEIEi1GrIL88p7ZDJy+BV8EsUqA7pMCMHAUOHjDq+YrIoqJHGJktlQJxBYB+4Umf3ww==", - "dependencies": { - "axios": "^0.21.1", - "rimraf": "^3.0.2", - "tar": "^6.0.2" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/axios": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", - "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", - "dependencies": { - "follow-redirects": "^1.10.0" - } - }, - "node_modules/balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/chownr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", - "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", - "engines": { - "node": ">=10" - } - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "node_modules/follow-redirects": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz", - "integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==", - "engines": { - "node": ">=4.0" - } - }, - "node_modules/fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "dependencies": { - "minipass": "^3.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "node_modules/glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - } - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/minipass": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", - "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/minizlib": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", - "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "dependencies": { - "minipass": "^3.0.0", - "yallist": "^4.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, - "node_modules/tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", - "dependencies": { - "chownr": "^2.0.0", - "fs-minipass": "^2.0.0", - "minipass": "^3.0.0", - "minizlib": "^2.1.1", - "mkdirp": "^1.0.3", - "yallist": "^4.0.0" - }, - "engines": { - "node": ">= 10" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - }, - "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - } - }, "dependencies": { - "@cloudflare/binary-install": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@cloudflare/binary-install/-/binary-install-0.2.0.tgz", - "integrity": "sha512-54n9ILgln+qUJc0BtbetEIEi1GrIL88p7ZDJy+BV8EsUqA7pMCMHAUOHjDq+YrIoqJHGJktlQJxBYB+4Umf3ww==", - "requires": { - "axios": "^0.21.1", - "rimraf": "^3.0.2", - "tar": "^6.0.2" - } - }, "axios": { "version": "0.21.1", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", diff --git a/npm/package.json b/npm/package.json index 77bcd4849..c95362700 100644 --- a/npm/package.json +++ b/npm/package.json @@ -42,6 +42,8 @@ "cli" ], "dependencies": { - "@cloudflare/binary-install": "0.2.0" + "axios": "^0.21.1", + "rimraf": "^3.0.2", + "tar": "^6.0.2" } }