From 5408a9f2802ae250e85d8cd6bd2f2842ca5b6d46 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Mon, 12 Apr 2021 03:00:32 +0200 Subject: [PATCH] Add typings, add unit tests Move size formatting and pluralization to a shared module. --- .gitignore | 2 + .vscode/settings.json | 11 ++ bin => lib/bin.js | 15 +- help.js => lib/help.js | 0 lib/index.d.ts | 15 ++ index.js => lib/index.js | 11 +- lib/util.js | 11 ++ package.json | 24 ++- pnpm-lock.yaml | 408 +++++++++++++++++++++++++++++++++++++++ test/baretest.txt | 21 ++ test/janadom.txt | 1 + test/test.js | 9 + test/test.txt | 13 ++ 13 files changed, 519 insertions(+), 22 deletions(-) create mode 100644 .vscode/settings.json rename bin => lib/bin.js (80%) rename help.js => lib/help.js (100%) create mode 100644 lib/index.d.ts rename index.js => lib/index.js (96%) mode change 100755 => 100644 create mode 100644 lib/util.js create mode 100644 test/baretest.txt create mode 100644 test/janadom.txt create mode 100644 test/test.js create mode 100644 test/test.txt diff --git a/.gitignore b/.gitignore index f0ad352..e6a73d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store +coverage node_modules pnpm-debug.log +test/actual diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..dea6ce5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "files.exclude": { + "**/.git": true, + "**/.DS_Store": true, + "**/coverage": true, + "**/pnpm-lock.yaml": true + }, + "search.exclude": { + "**/test/actual": true + } +} diff --git a/bin b/lib/bin.js similarity index 80% rename from bin rename to lib/bin.js index 55e0647..b128a93 100755 --- a/bin +++ b/lib/bin.js @@ -23,7 +23,7 @@ for (let i = 2, l = argv.length; i < l; ++i) { verbose = true continue case 'V': case 'version': - console.log(require('./package.json').version) + console.log(require('../package.json').version) process.exit(0) case 'h': case 'help': require('./help')() @@ -40,16 +40,7 @@ if (!refs.length) { } const estimatePkgs = require('.') - -function formatSize(size) { - const kb = size / 1024 - return kb > 0 ? kb > 99 ? `${(size / 1048576).toFixed(2)} MiB` : - `${kb.toFixed(2)} KiB` : `${size} B` -} - -function pluralize(count, singular, plural) { - return count === 1 ? `${count} ${singular}` : `${count} ${plural}` -} +const { formatSize, pluralize } = require('./util') function printProgress({ name, version, tarballSize, unpackedSize, depCount }, { print }) { print(`${name}@${version}: ${pluralize(depCount, 'dependency', 'dependencies')}, ${formatSize(tarballSize)} tarball, ${formatSize(unpackedSize)} unpacked\n`) @@ -61,7 +52,7 @@ function printProgress({ name, version, tarballSize, unpackedSize, depCount }, { const pkgs = await estimatePkgs(refs, { progress, concurrency, verbose }) if (json) console.log(JSON.stringify(pkgs)) } catch (err) { - console.error(err) + console.error(verbose ? err : err.message) process.exitCode = 1 } })() diff --git a/help.js b/lib/help.js similarity index 100% rename from help.js rename to lib/help.js diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..7e6745c --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,15 @@ +export interface Pkg { + name: string + version: string + tarballSize: integer + unpackedSize: integer + depCount: integer +} + +export interface Opts { + progress?: (pkg: Pkg, opts: { print: (text: string) => void }) => void + concurrency?: integer + verbose?: boolean +} + +export default function estimatePkgs(refs: string[], opts?: Opts): Promise diff --git a/index.js b/lib/index.js old mode 100755 new mode 100644 similarity index 96% rename from index.js rename to lib/index.js index e5c090f..8ab88b6 --- a/index.js +++ b/lib/index.js @@ -6,6 +6,7 @@ const https = require('https') const gunzip = require('gunzip-maybe') const tar = require('tar-stream') const { Writable } = require('stream') +const { pluralize } = require('./util') const { keys } = Object const { push } = Array.prototype const print = process.stdout.write.bind(process.stdout) @@ -19,7 +20,9 @@ function log(text) { function loadNpm() { return new Promise((resolve, reject) => { npm.load({ loaded: false }, err => { + /* c8 ignore start */ if (err) reject(err) + /* c8 ignore end */ else resolve() }) }) @@ -53,12 +56,15 @@ function inspectPkg(ref) { function makeRequest(method, url) { return new Promise((resolve, reject) => { log(` ${method} ${url}\n`) + /* c8 ignore start */ const proto = url.startsWith('http:') ? http : https + /* c8 ignore end */ const req = proto .request(url, { method }) .on('response', res => { const { statusCode, statusMessage, headers } = res if (statusCode === 200) resolve(res) + /* c8 ignore start */ else if (statusCode >= 300 && statusCode < 400) { res.resume() makeRequest(method, headers.location, callback).then(resolve, reject) @@ -68,6 +74,7 @@ function makeRequest(method, url) { req.abort() reject(new Error(`${url}: timeout`)) }) + /* c8 ignore end */ .on('error', reject) req.end() }) @@ -155,10 +162,6 @@ function enableOut() { process.stderr.write = writeErr } -function pluralize(count, singular, plural) { - return count === 1 ? `${count} ${singular}` : `${count} ${plural}` -} - async function estimatePkg(ref) { log(` Inspecting ${ref}\n`) const pkg = await inspectPkg(ref) diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..7d5059f --- /dev/null +++ b/lib/util.js @@ -0,0 +1,11 @@ +function formatSize(size) { + const kb = size / 1024 + return kb >= 1 ? kb > 99 ? `${(size / 1048576).toFixed(2)} MiB` : + `${kb.toFixed(2)} KiB` : `${size} B` +} + +function pluralize(count, singular, plural) { + return count === 1 ? `${count} ${singular}` : `${count} ${plural}` +} + +module.exports = { formatSize, pluralize } diff --git a/package.json b/package.json index 901cb78..d527f2d 100644 --- a/package.json +++ b/package.json @@ -26,15 +26,24 @@ "node": ">=12" }, "files": [ - "bin", - "index.js", - "help.js" + "lib" ], "bin": { - "package-cost": "bin" + "package-cost": "lib/bin.js" }, + "main": "lib/index.js", + "types": "lib/index.d.ts", "scripts": { - "test": "node bin" + "test": "mkdir -p test/actual && c8 node lib/bin && c8 --no-clean node lib/bin -V && c8 --no-clean node lib/bin -h && c8 --no-clean node lib/bin -x || c8 --no-clean node lib/bin -c c || c8 --no-clean node lib/bin @prantlf/none || c8 --no-clean node lib/bin -v @prantlf/none || c8 --no-clean node lib/bin janadom@0.1.2 > test/actual/janadom.txt && c8 --no-clean node lib/bin -j -v -c 5 baretest@2.0.0 barecolor@1.0.1 baretest@2.0.0 > test/actual/baretest.txt && c8 --no-clean node lib/bin -v test@0.6.0 > test/actual/test.txt && c8 --no-clean node lib/bin.js janadom@git+https://github.com/prantlf/janadom.git && diff -q test/janadom.txt test/actual/janadom.txt && diff -q test/baretest.txt test/actual/baretest.txt && diff -q test/test.txt test/actual/test.txt && c8 --no-clean node test/test && c8 report -r text && c8 check-coverage" + }, + "c8": { + "reporter": [ + "lcov" + ], + "branches": 100, + "lines": 100, + "functions": 100, + "statements": 100 }, "dependencies": { "gunzip-maybe": "^1.4.2", @@ -49,5 +58,8 @@ "package", "size", "cost" - ] + ], + "devDependencies": { + "c8": "^7.7.1" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 450b73f..5e0eb19 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,7 @@ lockfileVersion: 5.3 specifiers: + c8: ^7.7.1 gunzip-maybe: ^1.4.2 tar-stream: ^2.2.0 @@ -8,10 +9,47 @@ dependencies: gunzip-maybe: 1.4.2 tar-stream: 2.2.0 +devDependencies: + c8: 7.7.1 + packages: + /@bcoe/v8-coverage/0.2.3: + resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} + dev: true + + /@istanbuljs/schema/0.1.3: + resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} + engines: {node: '>=8'} + dev: true + + /@types/is-windows/1.0.0: + resolution: {integrity: sha512-tJ1rq04tGKuIJoWIH0Gyuwv4RQ3+tIu7wQrC0MV47raQ44kIzXSSFKfrxFUOWVRvesoF7mrTqigXmqoZJsXwTg==} + dev: true + + /@types/istanbul-lib-coverage/2.0.3: + resolution: {integrity: sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==} + dev: true + + /ansi-regex/5.0.0: + resolution: {integrity: sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==} + engines: {node: '>=8'} + dev: true + + /ansi-styles/4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + dependencies: + color-convert: 2.0.1 + dev: true + + /balanced-match/1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + dev: true + /base64-js/1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: false /bl/4.1.0: resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==} @@ -19,23 +57,93 @@ packages: buffer: 5.7.1 inherits: 2.0.4 readable-stream: 3.6.0 + dev: false + + /brace-expansion/1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + dev: true /browserify-zlib/0.1.4: resolution: {integrity: sha1-uzX4pRn2AOD6a4SFJByXnQFB+y0=} dependencies: pako: 0.2.9 + dev: false /buffer-from/1.1.1: resolution: {integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==} + dev: false /buffer/5.7.1: resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} dependencies: base64-js: 1.5.1 ieee754: 1.2.1 + dev: false + + /c8/7.7.1: + resolution: {integrity: sha512-OO9KpDGv1iTd/MBNUForJH7vPKt9XnRPWSBKeRJGma4xfTaKBObA0zWAplFpFRuf/qRmATFqGFrzxqDk51LXsw==} + engines: {node: '>=10.12.0'} + hasBin: true + dependencies: + '@bcoe/v8-coverage': 0.2.3 + '@istanbuljs/schema': 0.1.3 + find-up: 5.0.0 + foreground-child: 2.0.0 + furi: 2.0.0 + istanbul-lib-coverage: 3.0.0 + istanbul-lib-report: 3.0.0 + istanbul-reports: 3.0.2 + rimraf: 3.0.2 + test-exclude: 6.0.0 + v8-to-istanbul: 7.1.1 + yargs: 16.2.0 + yargs-parser: 20.2.7 + dev: true + + /cliui/7.0.4: + resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} + dependencies: + string-width: 4.2.2 + strip-ansi: 6.0.0 + wrap-ansi: 7.0.0 + dev: true + + /color-convert/2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + dependencies: + color-name: 1.1.4 + dev: true + + /color-name/1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + dev: true + + /concat-map/0.0.1: + resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + dev: true + + /convert-source-map/1.7.0: + resolution: {integrity: sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==} + dependencies: + safe-buffer: 5.1.2 + dev: true /core-util-is/1.0.2: resolution: {integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=} + dev: false + + /cross-spawn/7.0.3: + resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} + engines: {node: '>= 8'} + dependencies: + path-key: 3.1.1 + shebang-command: 2.0.0 + which: 2.0.2 + dev: true /duplexify/3.7.1: resolution: {integrity: sha512-07z8uv2wMyS51kKhD1KsdXJg5WQ6t93RneqRxUHnskXVtlYYkLqM0gqStQZ3pj073g687jPCHrqNfCzawLYh5g==} @@ -44,14 +152,69 @@ packages: inherits: 2.0.4 readable-stream: 2.3.7 stream-shift: 1.0.1 + dev: false + + /emoji-regex/8.0.0: + resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + dev: true /end-of-stream/1.4.4: resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==} dependencies: once: 1.4.0 + dev: false + + /escalade/3.1.1: + resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} + engines: {node: '>=6'} + dev: true + + /find-up/5.0.0: + resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} + engines: {node: '>=10'} + dependencies: + locate-path: 6.0.0 + path-exists: 4.0.0 + dev: true + + /foreground-child/2.0.0: + resolution: {integrity: sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==} + engines: {node: '>=8.0.0'} + dependencies: + cross-spawn: 7.0.3 + signal-exit: 3.0.3 + dev: true /fs-constants/1.0.0: resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==} + dev: false + + /fs.realpath/1.0.0: + resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=} + dev: true + + /furi/2.0.0: + resolution: {integrity: sha512-uKuNsaU0WVaK/vmvj23wW1bicOFfyqSsAIH71bRZx8kA4Xj+YCHin7CJKJJjkIsmxYaPFLk9ljmjEyB7xF7WvQ==} + dependencies: + '@types/is-windows': 1.0.0 + is-windows: 1.0.2 + dev: true + + /get-caller-file/2.0.5: + resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} + engines: {node: 6.* || 8.* || >= 10.*} + dev: true + + /glob/7.1.6: + resolution: {integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 3.0.4 + once: 1.4.0 + path-is-absolute: 1.0.1 + dev: true /gunzip-maybe/1.4.2: resolution: {integrity: sha512-4haO1M4mLO91PW57BMsDFf75UmwoRX0GkdD+Faw+Lr+r/OZrOCS0pIBwOL1xCKQqnQzbNFGgK2V2CpBUPeFNTw==} @@ -63,30 +226,137 @@ packages: peek-stream: 1.1.3 pumpify: 1.5.1 through2: 2.0.5 + dev: false + + /has-flag/4.0.0: + resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} + engines: {node: '>=8'} + dev: true + + /html-escaper/2.0.2: + resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} + dev: true /ieee754/1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: false + + /inflight/1.0.6: + resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=} + dependencies: + once: 1.4.0 + wrappy: 1.0.2 + dev: true /inherits/2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} /is-deflate/1.0.0: resolution: {integrity: sha1-yGKQHDwWH7CdrHzcfnhPgOmPLxQ=} + dev: false + + /is-fullwidth-code-point/3.0.0: + resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + engines: {node: '>=8'} + dev: true /is-gzip/1.0.0: resolution: {integrity: sha1-bKiwe5nHeZgCWQDlVc7Y7YCHmoM=} engines: {node: '>=0.10.0'} + dev: false + + /is-windows/1.0.2: + resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} + engines: {node: '>=0.10.0'} + dev: true /isarray/1.0.0: resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} + dev: false + + /isexe/2.0.0: + resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} + dev: true + + /istanbul-lib-coverage/3.0.0: + resolution: {integrity: sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==} + engines: {node: '>=8'} + dev: true + + /istanbul-lib-report/3.0.0: + resolution: {integrity: sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==} + engines: {node: '>=8'} + dependencies: + istanbul-lib-coverage: 3.0.0 + make-dir: 3.1.0 + supports-color: 7.2.0 + dev: true + + /istanbul-reports/3.0.2: + resolution: {integrity: sha512-9tZvz7AiR3PEDNGiV9vIouQ/EAcqMXFmkcA1CDFTwOB98OZVDL0PH9glHotf5Ugp6GCOTypfzGWI/OqjWNCRUw==} + engines: {node: '>=8'} + dependencies: + html-escaper: 2.0.2 + istanbul-lib-report: 3.0.0 + dev: true + + /locate-path/6.0.0: + resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} + engines: {node: '>=10'} + dependencies: + p-locate: 5.0.0 + dev: true + + /make-dir/3.1.0: + resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} + engines: {node: '>=8'} + dependencies: + semver: 6.3.0 + dev: true + + /minimatch/3.0.4: + resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} + dependencies: + brace-expansion: 1.1.11 + dev: true /once/1.4.0: resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=} dependencies: wrappy: 1.0.2 + /p-limit/3.1.0: + resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} + engines: {node: '>=10'} + dependencies: + yocto-queue: 0.1.0 + dev: true + + /p-locate/5.0.0: + resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==} + engines: {node: '>=10'} + dependencies: + p-limit: 3.1.0 + dev: true + /pako/0.2.9: resolution: {integrity: sha1-8/dSL073gjSNqBYbrZ7P1Rv4OnU=} + dev: false + + /path-exists/4.0.0: + resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} + engines: {node: '>=8'} + dev: true + + /path-is-absolute/1.0.1: + resolution: {integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18=} + engines: {node: '>=0.10.0'} + dev: true + + /path-key/3.1.1: + resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} + engines: {node: '>=8'} + dev: true /peek-stream/1.1.3: resolution: {integrity: sha512-FhJ+YbOSBb9/rIl2ZeE/QHEsWn7PqNYt8ARAY3kIgNGOk13g9FGyIY6JIl/xB/3TFRVoTv5as0l11weORrTekA==} @@ -94,15 +364,18 @@ packages: buffer-from: 1.1.1 duplexify: 3.7.1 through2: 2.0.5 + dev: false /process-nextick-args/2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + dev: false /pump/2.0.1: resolution: {integrity: sha512-ruPMNRkN3MHP1cWJc9OWr+T/xDP0jhXYCLfJcBuX54hhfIBnaQmAUMfDcG4DM5UMWByBbJY69QSphm3jtDKIkA==} dependencies: end-of-stream: 1.4.4 once: 1.4.0 + dev: false /pumpify/1.5.1: resolution: {integrity: sha512-oClZI37HvuUJJxSKKrC17bZ9Cu0ZYhEAGPsPUy9KlMUmv9dKX2o77RUmq7f3XjIxbwyGwYzbzQ1L2Ks8sIradQ==} @@ -110,6 +383,7 @@ packages: duplexify: 3.7.1 inherits: 2.0.4 pump: 2.0.1 + dev: false /readable-stream/2.3.7: resolution: {integrity: sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==} @@ -121,6 +395,7 @@ packages: safe-buffer: 5.1.2 string_decoder: 1.1.1 util-deprecate: 1.0.2 + dev: false /readable-stream/3.6.0: resolution: {integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==} @@ -129,25 +404,91 @@ packages: inherits: 2.0.4 string_decoder: 1.3.0 util-deprecate: 1.0.2 + dev: false + + /require-directory/2.1.1: + resolution: {integrity: sha1-jGStX9MNqxyXbiNE/+f3kqam30I=} + engines: {node: '>=0.10.0'} + dev: true + + /rimraf/3.0.2: + resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} + hasBin: true + dependencies: + glob: 7.1.6 + dev: true /safe-buffer/5.1.2: resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==} /safe-buffer/5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: false + + /semver/6.3.0: + resolution: {integrity: sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==} + hasBin: true + dev: true + + /shebang-command/2.0.0: + resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} + engines: {node: '>=8'} + dependencies: + shebang-regex: 3.0.0 + dev: true + + /shebang-regex/3.0.0: + resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} + engines: {node: '>=8'} + dev: true + + /signal-exit/3.0.3: + resolution: {integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==} + dev: true + + /source-map/0.7.3: + resolution: {integrity: sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==} + engines: {node: '>= 8'} + dev: true /stream-shift/1.0.1: resolution: {integrity: sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==} + dev: false + + /string-width/4.2.2: + resolution: {integrity: sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==} + engines: {node: '>=8'} + dependencies: + emoji-regex: 8.0.0 + is-fullwidth-code-point: 3.0.0 + strip-ansi: 6.0.0 + dev: true /string_decoder/1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} dependencies: safe-buffer: 5.1.2 + dev: false /string_decoder/1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} dependencies: safe-buffer: 5.2.1 + dev: false + + /strip-ansi/6.0.0: + resolution: {integrity: sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==} + engines: {node: '>=8'} + dependencies: + ansi-regex: 5.0.0 + dev: true + + /supports-color/7.2.0: + resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} + engines: {node: '>=8'} + dependencies: + has-flag: 4.0.0 + dev: true /tar-stream/2.2.0: resolution: {integrity: sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==} @@ -158,15 +499,53 @@ packages: fs-constants: 1.0.0 inherits: 2.0.4 readable-stream: 3.6.0 + dev: false + + /test-exclude/6.0.0: + resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} + engines: {node: '>=8'} + dependencies: + '@istanbuljs/schema': 0.1.3 + glob: 7.1.6 + minimatch: 3.0.4 + dev: true /through2/2.0.5: resolution: {integrity: sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==} dependencies: readable-stream: 2.3.7 xtend: 4.0.2 + dev: false /util-deprecate/1.0.2: resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=} + dev: false + + /v8-to-istanbul/7.1.1: + resolution: {integrity: sha512-p0BB09E5FRjx0ELN6RgusIPsSPhtgexSRcKETybEs6IGOTXJSZqfwxp7r//55nnu0f1AxltY5VvdVqy2vZf9AA==} + engines: {node: '>=10.10.0'} + dependencies: + '@types/istanbul-lib-coverage': 2.0.3 + convert-source-map: 1.7.0 + source-map: 0.7.3 + dev: true + + /which/2.0.2: + resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} + engines: {node: '>= 8'} + hasBin: true + dependencies: + isexe: 2.0.0 + dev: true + + /wrap-ansi/7.0.0: + resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.2 + strip-ansi: 6.0.0 + dev: true /wrappy/1.0.2: resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} @@ -174,3 +553,32 @@ packages: /xtend/4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} + dev: false + + /y18n/5.0.8: + resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} + engines: {node: '>=10'} + dev: true + + /yargs-parser/20.2.7: + resolution: {integrity: sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==} + engines: {node: '>=10'} + dev: true + + /yargs/16.2.0: + resolution: {integrity: sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==} + engines: {node: '>=10'} + dependencies: + cliui: 7.0.4 + escalade: 3.1.1 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + string-width: 4.2.2 + y18n: 5.0.8 + yargs-parser: 20.2.7 + dev: true + + /yocto-queue/0.1.0: + resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} + engines: {node: '>=10'} + dev: true diff --git a/test/baretest.txt b/test/baretest.txt new file mode 100644 index 0000000..d1e682c --- /dev/null +++ b/test/baretest.txt @@ -0,0 +1,21 @@ + Loading npm + Inspecting baretest@2.0.0 + npm v baretest@2.0.0 + Tracking dependencies + npm v barecolor@1.0.1 + Found 1 dependency + Getting tarball sizes + HEAD https://registry.npmjs.org/baretest/-/baretest-2.0.0.tgz + HEAD https://registry.npmjs.org/barecolor/-/barecolor-1.0.1.tgz + Completing unpacked sizes + Inspecting barecolor@1.0.1 + Tracking dependencies + Found 0 dependencies + Getting tarball sizes + Completing unpacked sizes + Inspecting baretest@2.0.0 + Tracking dependencies + Found 1 dependency + Getting tarball sizes + Completing unpacked sizes +[{"name":"baretest","version":"2.0.0","tarballSize":6570,"unpackedSize":14958,"depCount":1},{"name":"barecolor","version":"1.0.1","tarballSize":1777,"unpackedSize":3279,"depCount":0},{"name":"baretest","version":"2.0.0","tarballSize":6570,"unpackedSize":14958,"depCount":1}] diff --git a/test/janadom.txt b/test/janadom.txt new file mode 100644 index 0000000..771d10e --- /dev/null +++ b/test/janadom.txt @@ -0,0 +1 @@ +janadom@0.1.2: 0 dependencies, 12.40 KiB tarball, 63.92 KiB unpacked diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..bdbde67 --- /dev/null +++ b/test/test.js @@ -0,0 +1,9 @@ +const assert = require('assert') +const { formatSize, pluralize } = require('../lib/util') + +assert.strictEqual(formatSize(1), '1 B') +assert.strictEqual(formatSize(1024), '1.00 KiB') +assert.strictEqual(formatSize(1048576), '1.00 MiB') + +assert.strictEqual(pluralize(0, 's', 'p'), '0 p') +assert.strictEqual(pluralize(1, 's', 'p'), '1 s') diff --git a/test/test.txt b/test/test.txt new file mode 100644 index 0000000..0f76569 --- /dev/null +++ b/test/test.txt @@ -0,0 +1,13 @@ + Loading npm + Inspecting test@0.6.0 + npm v test@0.6.0 + Tracking dependencies + npm v ansi-font@0.0.2 + Found 1 dependency + Getting tarball sizes + HEAD https://registry.npmjs.org/test/-/test-0.6.0.tgz + HEAD https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz + Completing unpacked sizes + GET https://registry.npmjs.org/test/-/test-0.6.0.tgz + GET https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz +test@0.6.0: 1 dependency, 0.16 MiB tarball, 1.64 MiB unpacked