Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: remove byte-size #3569

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are actually used anywhere because byteSize would be returning an object here not a string.

{ 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