Skip to content

Commit bb8c48b

Browse files
committed
Update requires to imports, switch to cli-progress from smooth-progress
1 parent b2cb56a commit bb8c48b

File tree

9 files changed

+42
-31
lines changed

9 files changed

+42
-31
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"async-file": "^2.0.2",
4040
"bytes": "^3.1.2",
4141
"chalk": "^2.4.2",
42+
"cli-progress": "^3.12.0",
4243
"commander": "^2.15.1",
4344
"date-fns": "^2.30.0",
4445
"debug": "4.3.4",
@@ -65,7 +66,6 @@
6566
"semver": "7.6.1",
6667
"shell-escape": "^0.2.0",
6768
"shell-quote": "^1.8.1",
68-
"smooth-progress": "^1.1.0",
6969
"sparkline": "^0.2.0",
7070
"ssh2": "^1.16.0",
7171
"stdout-stderr": "^0.1.13",

packages/cli/src/file.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import * as path from 'path'
33

44
import deps from './deps.js'
55

6-
const debug = require('debug')('heroku-cli:file')
6+
import debug from 'debug'
7+
const fileDebug = debug('heroku-cli:file')
78

89
export function exists(f: string): Promise<boolean> {
910
return deps.fs.pathExists(f)
@@ -14,13 +15,13 @@ export async function stat(file: string): Promise<FS.Stats> {
1415
}
1516

1617
export async function rename(from: string, to: string) {
17-
debug('rename', from, to)
18+
fileDebug('rename', from, to)
1819
return deps.fs.rename(from, to)
1920
}
2021

2122
export async function remove(file: string) {
2223
if (!await exists(file)) return
23-
debug('remove', file)
24+
fileDebug('remove', file)
2425
return deps.fs.remove(file)
2526
}
2627

@@ -46,12 +47,12 @@ export async function removeEmptyDirs(dir: string): Promise<void> {
4647
}
4748

4849
export async function readJSON(file: string) {
49-
debug('readJSON', file)
50+
fileDebug('readJSON', file)
5051
return deps.fs.readJSON(file)
5152
}
5253

5354
export async function outputJSON(file: string, data: any) {
54-
debug('outputJSON', file)
55+
fileDebug('outputJSON', file)
5556
return deps.fs.outputJSON(file, data, {spaces: 2})
5657
}
5758

packages/cli/src/lib/git/git.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import * as fs from 'fs'
55
import {promisify} from 'util'
66
const execFile = promisify(cp.execFile)
77

8-
const debug = require('debug')('git')
8+
import debug from 'debug'
9+
const gitDebug = debug('git')
910

1011
export default class Git {
1112
public async exec(args: string[]): Promise<string> {
12-
debug('exec: git %o', args)
13+
gitDebug('exec: git %o', args)
1314
try {
1415
const {stdout, stderr} = await execFile('git', args)
1516
if (stderr) process.stderr.write(stderr)
@@ -25,7 +26,7 @@ export default class Git {
2526

2627
public spawn(args: string[]) {
2728
return new Promise((resolve, reject) => {
28-
debug('spawn: git %o', args)
29+
gitDebug('spawn: git %o', args)
2930
const s = cp.spawn('git', args, {stdio: [0, 1, 2]})
3031
s.on('error', (err: Error & {code?: string}) => {
3132
if (err.code === 'ENOENT') {

packages/cli/src/lib/pg/download.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
import * as fs from 'fs-extra'
32
import * as Path from 'path'
4-
const https = require('https')
5-
const bytes = require('bytes')
6-
const progress = require('smooth-progress')
3+
import * as https from 'https'
4+
import cliProgress from 'cli-progress'
75

86
type downloadOptions = {
97
progress: boolean
@@ -13,15 +11,19 @@ export default function download(url: string, path: string, opts: downloadOption
1311
const tty = process.stderr.isTTY && process.env.TERM !== 'dumb'
1412

1513
function showProgress(rsp: any) {
16-
const bar = progress({
17-
tmpl: `Downloading ${path}... :bar :percent :eta :data`,
18-
width: 25,
19-
total: Number.parseInt(rsp.headers['content-length'], 10),
14+
const bar = new cliProgress.SingleBar({
15+
format: `Downloading ${path}... |{bar}| {percentage}% | ETA: {eta}s | {value}/{total} bytes`,
16+
barCompleteChar: '\u2588',
17+
barIncompleteChar: '\u2591',
2018
})
19+
bar.start(Number.parseInt(rsp.headers['content-length'], 10), 0)
2120
let total = 0
2221
rsp.on('data', function (chunk: string) {
2322
total += chunk.length
24-
bar.tick(chunk.length, {data: bytes(total, {decimalPlaces: 2, fixedDecimals: 2})})
23+
bar.update(total)
24+
})
25+
rsp.on('end', () => {
26+
bar.stop()
2527
})
2628
}
2729

packages/cli/src/lib/releases/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const got = require('got')
1+
import got from 'got'
22

33
export const stream = function (url: string) {
44
return new Promise(function (resolve, reject) {

packages/cli/src/lib/utils/packageParser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
const {oclif} = require('../../../package.json')
1+
import path from 'node:path'
2+
import * as fs from 'node:fs'
3+
import {fileURLToPath} from 'node:url'
4+
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
7+
const packageJsonPath = path.resolve(__dirname, '../../../package.json')
8+
const pjson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
9+
const { oclif } = pjson
210

311
export function getAllVersionFlags() {
412
return [...oclif.additionalVersionFlags, '--version']

packages/cli/src/oldCommands/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {round, flatten, mean, groupBy, map, sum, sumBy, sortBy, zip} from 'lodas
66
import img from 'term-img'
77
import * as path from 'path'
88
import {execSync} from 'child_process'
9-
const sparkline = require('sparkline')
9+
import sparkline from 'sparkline'
1010
import {ago} from '../lib/time.js'
1111
import {AppErrors} from '../lib/types/app_errors.js'
1212
import * as process from 'process'

packages/cli/src/user-config.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as path from 'path'
44

55
import deps from './deps.js'
66

7+
import debug from 'debug'
8+
const userConfigDebug = debug('heroku:user_config')
9+
710
export interface ConfigJSON {
811
schema: 1;
912
install?: string;
@@ -48,7 +51,7 @@ export default class UserConfig {
4851
if (this._init) return this._init
4952

5053
this._init = (async () => {
51-
this.debug('init')
54+
userConfigDebug('init')
5255
this.body = (await this.read()) || {schema: 1}
5356

5457
if (!this.body.schema) {
@@ -66,10 +69,6 @@ export default class UserConfig {
6669
return this._init
6770
}
6871

69-
private get debug() {
70-
return require('debug')('heroku:user_config')
71-
}
72-
7372
private get file() {
7473
return path.join(this.config.dataDir, 'config.json')
7574
}
@@ -78,7 +77,7 @@ export default class UserConfig {
7877
if (!this.needsSave) return
7978
this.needsSave = false
8079
this.saving = (async () => {
81-
this.debug('saving')
80+
userConfigDebug('saving')
8281
if (!await this.canWrite()) {
8382
throw new Error('file modified, cannot save')
8483
}
@@ -95,15 +94,15 @@ export default class UserConfig {
9594
return body
9695
} catch (error: any) {
9796
if (error.code !== 'ENOENT') throw error
98-
this.debug('not found')
97+
userConfigDebug('not found')
9998
}
10099
}
101100

102101
private async migrate() {
103102
if (await deps.file.exists(this.file)) return
104103
const old = path.join(this.config.configDir, 'config.json')
105104
if (!await deps.file.exists(old)) return
106-
this.debug('moving config into new place')
105+
userConfigDebug('moving config into new place')
107106
await deps.file.rename(old, this.file)
108107
}
109108

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11136,6 +11136,7 @@ __metadata:
1113611136
chai: ^4.4.1
1113711137
chai-as-promised: ^7.1.1
1113811138
chalk: ^2.4.2
11139+
cli-progress: ^3.12.0
1113911140
commander: ^2.15.1
1114011141
date-fns: ^2.30.0
1114111142
debug: 4.3.4
@@ -11173,7 +11174,6 @@ __metadata:
1117311174
shell-escape: ^0.2.0
1117411175
shell-quote: ^1.8.1
1117511176
sinon: ^19.0.2
11176-
smooth-progress: ^1.1.0
1117711177
source-map-support: ^0.5.21
1117811178
sparkline: ^0.2.0
1117911179
ssh2: ^1.16.0
@@ -17272,7 +17272,7 @@ __metadata:
1727217272
languageName: node
1727317273
linkType: hard
1727417274

17275-
"smooth-progress@npm:1.1.0, smooth-progress@npm:^1.1.0":
17275+
"smooth-progress@npm:1.1.0":
1727617276
version: 1.1.0
1727717277
resolution: "smooth-progress@npm:1.1.0"
1727817278
dependencies:

0 commit comments

Comments
 (0)