From 5dd50d7378a3d421e15c97def13a5bfeaabeb93e Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Mar 2024 15:00:43 +0530 Subject: [PATCH] chore(deps): remove `cli-progress` --- lib/findpath.js | 2 +- lib/install.js | 60 +++++++++++++++++++++-------------------------- package-lock.json | 12 ---------- package.json | 1 - 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/lib/findpath.js b/lib/findpath.js index 78c9fe4..03e4e56 100644 --- a/lib/findpath.js +++ b/lib/findpath.js @@ -1,5 +1,5 @@ -import process from 'node:process'; import path from 'node:path'; +import process from 'node:process'; import url from 'node:url'; /** diff --git a/lib/install.js b/lib/install.js index 5f74593..6aba039 100755 --- a/lib/install.js +++ b/lib/install.js @@ -1,17 +1,15 @@ -import { createWriteStream, existsSync } from 'node:fs'; -import { rename, rm, symlink } from 'node:fs/promises'; -import { get } from 'node:https'; -import { dirname, resolve } from 'node:path'; -import { arch, env, platform, exit } from 'node:process'; -import { URL, fileURLToPath } from 'node:url'; +import fs from 'node:fs'; +import https from 'node:https'; +import path from 'node:path'; +import process from 'node:process'; +import url from 'node:url'; import compressing from 'compressing'; -import { SingleBar, Presets } from 'cli-progress'; -import { parse } from 'semver'; +import semver from 'semver'; import manifest from '../package.json' assert { type: 'json' }; -const __dirname = dirname(fileURLToPath(import.meta.url)); +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); install() .catch((error) => { @@ -46,19 +44,19 @@ async function install() { * * @type {string} */ - let urlBase = env.npm_config_nwjs_urlbase || env.NWJS_URLBASE || 'https://dl.nwjs.io/v'; + let urlBase = process.env.npm_config_nwjs_urlbase || process.env.NWJS_URLBASE || 'https://dl.nwjs.io/v'; /** * NW.js build flavor * * @type {'sdk' | 'normal'} */ - let buildType = env.npm_config_nwjs_build_type || env.NWJS_BUILD_TYPE || 'normal'; + let buildType = process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal'; /** * Parsed string version to Semver version object */ - let parsedVersion = parse(manifest.version); + let parsedVersion = semver.parse(manifest.version); /** * Version string of the format `X.Y.Z-pre`. @@ -77,14 +75,14 @@ async function install() { * * @type {NodeJS.Platform | 'osx' | 'win'} */ - let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform; + let hostOs = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform; /** * Host architecture * * @type {NodeJS.Architecture} */ - let hostArch = env.npm_config_nwjs_process_arch || arch; + let hostArch = process.env.npm_config_nwjs_process_arch || process.arch; /** * Path to the decompressed folder. @@ -112,7 +110,7 @@ async function install() { * * @type {string} */ - let nwDir = resolve(__dirname, '..', 'nwjs'); + let nwDir = path.resolve(__dirname, '..', 'nwjs'); // Check if version is a prelease. if (typeof parsedVersion?.prerelease?.[0] === 'string') { @@ -147,7 +145,7 @@ async function install() { nwCache = [nwFile, nwExt].join(''); - url = [ + uri = [ urlBase, versionString, '/', @@ -156,7 +154,7 @@ async function install() { if (!PLATFORM_KV[hostOs] || !ARCH_KV[hostArch]) { console.error('[ ERROR ] Could not find a compatible version of nw.js to download for your platform.'); - exit(1); + process.exit(1); } /** @@ -164,7 +162,7 @@ async function install() { * * @type {URL} */ - let parsedUrl = new URL(url); + let parsedUrl = new url.URL(uri); /** * Request download from server. @@ -174,30 +172,26 @@ async function install() { let request = null; if (parsedUrl.protocol === 'file:') { - nwCache = resolve(decodeURIComponent(url.slice('file://'.length))); - if (existsSync(nwCache) === false) { + nwCache = path.resolve(decodeURIComponent(uri.slice('file://'.length))); + if (fs.existsSync(nwCache) === false) { console.error('[ ERROR ] Could not find ' + nwCache); - exit(1); + process.exit(1); } } - if (existsSync(nwCache) === false) { - const bar = new SingleBar({}, Presets.rect); + if (fs.existsSync(nwCache) === false) { - const stream = createWriteStream(nwCache); + const stream = fs.createWriteStream(nwCache); request = new Promise((res, rej) => { - get(url, (response) => { + https.get(uri, (response) => { let chunks = 0; - bar.start(Number(response.headers['content-length']), 0); response.on('data', async (chunk) => { chunks += chunk.length; - bar.increment(); - bar.update(chunks); }); response.on('error', async () => { - await rm(nwCache, { force: true }); + await fs.promises.rm(nwCache, { force: true }); rej(); }); @@ -213,19 +207,19 @@ async function install() { if (request !== null) { await request; } - await rm(nwDir, { + await fs.promises.rm(nwDir, { recursive: true, force: true, }); - await compressing[platform === 'linux' ? 'tgz' : 'zip'] + await compressing[process.platform === 'linux' ? 'tgz' : 'zip'] .uncompress(nwCache, '.'); - await rename( + await fs.promises.rename( nwFile, nwDir ); // This allows nw-builder to treat ./node_modules/nw as cacheDir and access the downloaded binary. - await symlink(nwDir, nwFile); + await fs.promises.symlink(nwDir, nwFile); return; } diff --git a/package-lock.json b/package-lock.json index 4b77794..10c4493 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "cli-progress": "^3.12.0", "compressing": "^1.10.0", "semver": "^7.5.4", "yargs": "^17.7.2" @@ -86,17 +85,6 @@ "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", "integrity": "sha512-T7zexNBwiiaCOGDg9xNX9PBmjrubblRkENuptryuI64URkXDFum9il/JGL8Lm8wYfAXpredVXXZz7eMHilimiQ==" }, - "node_modules/cli-progress": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.12.0.tgz", - "integrity": "sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==", - "dependencies": { - "string-width": "^4.2.3" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", diff --git a/package.json b/package.json index 03de621..d14d19a 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ ], "license": "MIT", "dependencies": { - "cli-progress": "^3.12.0", "compressing": "^1.10.0", "semver": "^7.5.4", "yargs": "^17.7.2"