Skip to content

Commit

Permalink
deps: remove byte-size
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wraithgar committed Aug 11, 2021
1 parent d1812f1 commit a1bdbea
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 353 deletions.
22 changes: 22 additions & 0 deletions lib/utils/format-bytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Convert bytes to printable output, for file reporting in tarballs
// Only supports up to GB because that's way larger than anything the registry
// supports anyways.

const formatBytes = (bytes, space = true) => {
let spacer = ''
if (space)
spacer = ' '

if (bytes < 1000) // B
return `${bytes}${spacer}B`

if (bytes < 1000000) // kB
return `${(bytes / 1000).toFixed(1)}${spacer}kB`

if (bytes < 1000000000) // MB
return `${(bytes / 1000000).toFixed(1)}${spacer}MB`

return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`
}

module.exports = formatBytes
10 changes: 5 additions & 5 deletions lib/utils/tar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tar = require('tar')
const ssri = require('ssri')
const npmlog = require('npmlog')
const byteSize = require('byte-size')
const formatBytes = require('./format-bytes.js')
const columnify = require('columnify')

const logTar = (tarball, opts = {}) => {
Expand All @@ -11,9 +11,9 @@ const logTar = (tarball, opts = {}) => {
log.notice('=== Tarball Contents ===')
if (tarball.files.length) {
log.notice('', columnify(tarball.files.map((f) => {
const bytes = byteSize(f.size)
const bytes = formatBytes(f.size, false)
return (/^node_modules\//.test(f.path)) ? null
: { path: f.path, size: `${bytes.value}${bytes.unit}` }
: { path: f.path, size: `${bytes}` }
}).filter(f => f), {
include: ['size', 'path'],
showHeaders: false,
Expand All @@ -28,8 +28,8 @@ const logTar = (tarball, opts = {}) => {
{ name: 'name:', value: tarball.name },
{ name: 'version:', value: tarball.version },
tarball.filename && { name: 'filename:', value: tarball.filename },
{ name: 'package size:', value: byteSize(tarball.size) },
{ name: 'unpacked size:', value: byteSize(tarball.unpackedSize) },
{ name: 'package size:', value: formatBytes(tarball.size) },
{ name: 'unpacked size:', value: formatBytes(tarball.unpackedSize) },
{ name: 'shasum:', value: tarball.shasum },
{
name: 'integrity:',
Expand Down
6 changes: 3 additions & 3 deletions lib/view.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// npm view [pkg [pkg ...]]

const byteSize = require('byte-size')
const color = require('ansicolors')
const columns = require('cli-columns')
const fs = require('fs')
const jsonParse = require('json-parse-even-better-errors')
const log = require('npmlog')
const npa = require('npm-package-arg')
const { resolve } = require('path')
const formatBytes = require('./utils/format-bytes.js')
const relativeDate = require('tiny-relative-date')
const semver = require('semver')
const style = require('ansistyles')
Expand Down Expand Up @@ -315,7 +315,7 @@ class View extends BaseCommand {
tags.push(`${style.bright(color.green(t))}: ${version}`)
})
const unpackedSize = manifest.dist.unpackedSize &&
byteSize(manifest.dist.unpackedSize)
formatBytes(manifest.dist.unpackedSize, true)
const licenseField = manifest.license || 'Proprietary'
const info = {
name: color.green(manifest.name),
Expand Down Expand Up @@ -356,7 +356,7 @@ class View extends BaseCommand {
manifest.dist.integrity && color.yellow(manifest.dist.integrity),
fileCount:
manifest.dist.fileCount && color.yellow(manifest.dist.fileCount),
unpackedSize: unpackedSize && color.yellow(unpackedSize.value) + ' ' + unpackedSize.unit,
unpackedSize: unpackedSize && color.yellow(unpackedSize),
}
if (info.license.toLowerCase().trim() === 'proprietary')
info.license = style.bright(color.red(info.license))
Expand Down
21 changes: 0 additions & 21 deletions node_modules/byte-size/LICENSE

This file was deleted.

123 changes: 0 additions & 123 deletions node_modules/byte-size/dist/index.js

This file was deleted.

115 changes: 0 additions & 115 deletions node_modules/byte-size/index.mjs

This file was deleted.

Loading

0 comments on commit a1bdbea

Please sign in to comment.