log-packed.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. const byteSize = require("byte-size");
  3. const columnify = require("columnify");
  4. const hasUnicode = require("has-unicode")();
  5. const log = require("npmlog");
  6. module.exports.logPacked = logPacked;
  7. function logPacked(tarball) {
  8. log.notice("");
  9. log.notice("", `${hasUnicode ? "📦 " : "package:"} ${tarball.name}@${tarball.version}`);
  10. if (tarball.files && tarball.files.length) {
  11. log.notice("=== Tarball Contents ===");
  12. log.notice(
  13. "",
  14. columnify(
  15. tarball.files.map((f) => {
  16. const bytes = byteSize(f.size);
  17. return {
  18. path: f.path,
  19. size: `${bytes.value}${bytes.unit}`,
  20. };
  21. }),
  22. {
  23. include: ["size", "path"],
  24. showHeaders: false,
  25. }
  26. )
  27. );
  28. }
  29. if (tarball.bundled && tarball.bundled.length) {
  30. log.notice("=== Bundled Dependencies ===");
  31. tarball.bundled.forEach((name) => log.notice("", name));
  32. }
  33. log.notice("=== Tarball Details ===");
  34. log.notice(
  35. "",
  36. columnify(
  37. [
  38. { name: "name:", value: tarball.name },
  39. { name: "version:", value: tarball.version },
  40. tarball.filename && { name: "filename:", value: tarball.filename },
  41. tarball.size && { name: "package size:", value: byteSize(tarball.size) },
  42. tarball.unpackedSize && { name: "unpacked size:", value: byteSize(tarball.unpackedSize) },
  43. tarball.shasum && { name: "shasum:", value: tarball.shasum },
  44. tarball.integrity && { name: "integrity:", value: elideIntegrity(tarball.integrity) },
  45. tarball.bundled &&
  46. tarball.bundled.length && {
  47. name: "bundled deps:",
  48. value: tarball.bundled.length,
  49. },
  50. tarball.bundled &&
  51. tarball.bundled.length && {
  52. name: "bundled files:",
  53. value: tarball.entryCount - tarball.files.length,
  54. },
  55. tarball.bundled &&
  56. tarball.bundled.length && {
  57. name: "own files:",
  58. value: tarball.files.length,
  59. },
  60. tarball.entryCount && { name: "total files:", value: tarball.entryCount },
  61. ].filter((x) => x),
  62. {
  63. include: ["name", "value"],
  64. showHeaders: false,
  65. }
  66. )
  67. );
  68. // an empty line
  69. log.notice("", "");
  70. }
  71. function elideIntegrity(integrity) {
  72. const str = integrity.toString();
  73. return `${str.substr(0, 20)}[...]${str.substr(80)}`;
  74. }