Skip to content

Commit a1bdbea

Browse files
committed
deps: remove byte-size
In its latest release, byte-size dropped support for node versions lower than 14. The cli currently supports node 10 and up. The actual functionality we needed and was using was extremely limited in scope, and didn't warrant an external module. It's just pretty printing a file size, and the files we are dealing with are limited in size so we don't need to support so many suffixes. PR-URL: #3569 Credit: @wraithgar Close: #3569 Reviewed-by: @isaacs
1 parent d1812f1 commit a1bdbea

File tree

11 files changed

+47
-353
lines changed

11 files changed

+47
-353
lines changed

lib/utils/format-bytes.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Convert bytes to printable output, for file reporting in tarballs
2+
// Only supports up to GB because that's way larger than anything the registry
3+
// supports anyways.
4+
5+
const formatBytes = (bytes, space = true) => {
6+
let spacer = ''
7+
if (space)
8+
spacer = ' '
9+
10+
if (bytes < 1000) // B
11+
return `${bytes}${spacer}B`
12+
13+
if (bytes < 1000000) // kB
14+
return `${(bytes / 1000).toFixed(1)}${spacer}kB`
15+
16+
if (bytes < 1000000000) // MB
17+
return `${(bytes / 1000000).toFixed(1)}${spacer}MB`
18+
19+
return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`
20+
}
21+
22+
module.exports = formatBytes

lib/utils/tar.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const tar = require('tar')
22
const ssri = require('ssri')
33
const npmlog = require('npmlog')
4-
const byteSize = require('byte-size')
4+
const formatBytes = require('./format-bytes.js')
55
const columnify = require('columnify')
66

77
const logTar = (tarball, opts = {}) => {
@@ -11,9 +11,9 @@ const logTar = (tarball, opts = {}) => {
1111
log.notice('=== Tarball Contents ===')
1212
if (tarball.files.length) {
1313
log.notice('', columnify(tarball.files.map((f) => {
14-
const bytes = byteSize(f.size)
14+
const bytes = formatBytes(f.size, false)
1515
return (/^node_modules\//.test(f.path)) ? null
16-
: { path: f.path, size: `${bytes.value}${bytes.unit}` }
16+
: { path: f.path, size: `${bytes}` }
1717
}).filter(f => f), {
1818
include: ['size', 'path'],
1919
showHeaders: false,
@@ -28,8 +28,8 @@ const logTar = (tarball, opts = {}) => {
2828
{ name: 'name:', value: tarball.name },
2929
{ name: 'version:', value: tarball.version },
3030
tarball.filename && { name: 'filename:', value: tarball.filename },
31-
{ name: 'package size:', value: byteSize(tarball.size) },
32-
{ name: 'unpacked size:', value: byteSize(tarball.unpackedSize) },
31+
{ name: 'package size:', value: formatBytes(tarball.size) },
32+
{ name: 'unpacked size:', value: formatBytes(tarball.unpackedSize) },
3333
{ name: 'shasum:', value: tarball.shasum },
3434
{
3535
name: 'integrity:',

lib/view.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// npm view [pkg [pkg ...]]
22

3-
const byteSize = require('byte-size')
43
const color = require('ansicolors')
54
const columns = require('cli-columns')
65
const fs = require('fs')
76
const jsonParse = require('json-parse-even-better-errors')
87
const log = require('npmlog')
98
const npa = require('npm-package-arg')
109
const { resolve } = require('path')
10+
const formatBytes = require('./utils/format-bytes.js')
1111
const relativeDate = require('tiny-relative-date')
1212
const semver = require('semver')
1313
const style = require('ansistyles')
@@ -315,7 +315,7 @@ class View extends BaseCommand {
315315
tags.push(`${style.bright(color.green(t))}: ${version}`)
316316
})
317317
const unpackedSize = manifest.dist.unpackedSize &&
318-
byteSize(manifest.dist.unpackedSize)
318+
formatBytes(manifest.dist.unpackedSize, true)
319319
const licenseField = manifest.license || 'Proprietary'
320320
const info = {
321321
name: color.green(manifest.name),
@@ -356,7 +356,7 @@ class View extends BaseCommand {
356356
manifest.dist.integrity && color.yellow(manifest.dist.integrity),
357357
fileCount:
358358
manifest.dist.fileCount && color.yellow(manifest.dist.fileCount),
359-
unpackedSize: unpackedSize && color.yellow(unpackedSize.value) + ' ' + unpackedSize.unit,
359+
unpackedSize: unpackedSize && color.yellow(unpackedSize),
360360
}
361361
if (info.license.toLowerCase().trim() === 'proprietary')
362362
info.license = style.bright(color.red(info.license))

node_modules/byte-size/LICENSE

-21
This file was deleted.

node_modules/byte-size/dist/index.js

-123
This file was deleted.

node_modules/byte-size/index.mjs

-115
This file was deleted.

0 commit comments

Comments
 (0)