Skip to content

Commit

Permalink
chore(deps): remove cli-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Mar 9, 2024
1 parent e30db9a commit 5dd50d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/findpath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from 'node:process';
import path from 'node:path';
import process from 'node:process';
import url from 'node:url';

/**
Expand Down
60 changes: 27 additions & 33 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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`.
Expand All @@ -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.
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -147,7 +145,7 @@ async function install() {

nwCache = [nwFile, nwExt].join('');

url = [
uri = [
urlBase,
versionString,
'/',
Expand All @@ -156,15 +154,15 @@ 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);
}

/**
* Parsed URL.
*
* @type {URL}
*/
let parsedUrl = new URL(url);
let parsedUrl = new url.URL(uri);

/**
* Request download from server.
Expand All @@ -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();
});

Expand All @@ -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;
}
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
],
"license": "MIT",
"dependencies": {
"cli-progress": "^3.12.0",
"compressing": "^1.10.0",
"semver": "^7.5.4",
"yargs": "^17.7.2"
Expand Down

0 comments on commit 5dd50d7

Please sign in to comment.