Log the result of npm pack --json with formatted tarball details and contents
npx @tessl/cli install tessl/npm-lerna--log-packed@6.4.0@lerna/log-packed is a Node.js utility that formats and displays the JSON output from npm pack --json in a human-readable format. It presents tarball information including file listings with sizes, bundled dependencies, and comprehensive package details using formatted columns and Unicode emojis when supported.
npm install @lerna/log-packedconst { logPacked } = require("@lerna/log-packed");For ES modules (requires bundler or loader):
import { logPacked } from "@lerna/log-packed";const execa = require("execa");
const { logPacked } = require("@lerna/log-packed");
// Get npm pack output and format it
execa("npm", ["pack", "--json"]).then(result => {
const tarballs = JSON.parse(result.stdout);
tarballs.forEach(logPacked);
});Formats and logs npm pack JSON output to console with structured, human-readable information.
/**
* Logs formatted npm pack JSON result with tarball details, file contents, and bundled dependencies
* @param {TarballInfo} tarball - Tarball object from npm pack --json output
*/
function logPacked(tarball);Usage Examples:
const { logPacked } = require("@lerna/log-packed");
// Complete tarball info
logPacked({
name: "my-package",
version: "1.0.0",
size: 223,
unpackedSize: 396,
shasum: "8f339308bfabffcddd89e379ab76c8fbbc5c429a",
integrity: "sha512-s+D+5+Kovk2mi2Jg+P6egJ6ZBKzMOdRaWAL5S+a4dWnRa6taym9EeEwpwx5ASF1wbLb0Tduv2XqcwFATxxUGVw==",
filename: "my-package-1.0.0.tgz",
files: [
{ path: "package.json", size: 396, mode: 420 },
{ path: "index.js", size: 1024, mode: 420 }
],
entryCount: 2,
bundled: ["dependency1", "dependency2"]
});
// Minimal tarball info (gracefully handles missing fields)
logPacked({
name: "simple-package",
version: "2.0.0",
filename: "simple-package-2.0.0.tgz"
});The function outputs structured information in up to four sections:
/**
* Tarball information object from npm pack --json output
*/
interface TarballInfo {
/** Package name (required) */
name: string;
/** Package version (required) */
version: string;
/** Array of file objects with path and size properties */
files?: FileInfo[];
/** Array of bundled dependency names */
bundled?: string[];
/** Tarball filename */
filename?: string;
/** Package size in bytes */
size?: number;
/** Unpacked size in bytes */
unpackedSize?: number;
/** SHA sum hash */
shasum?: string;
/** Integrity hash */
integrity?: string;
/** Total number of entries in tarball */
entryCount?: number;
}
/**
* File information within a tarball
*/
interface FileInfo {
/** File path within the package */
path: string;
/** File size in bytes */
size: number;
/** File mode/permissions */
mode?: number;
}The package uses the following external libraries:
The logPacked function is designed to handle incomplete tarball objects gracefully:
The function produces structured console output with:
📦 package-name@version (or package: package-name@version without Unicode)Example output:
📦 my-package@1.0.0
=== Tarball Contents ===
396B package.json
1kB index.js
=== Bundled Dependencies ===
dependency1
dependency2
=== Tarball Details ===
name: my-package
version: 1.0.0
filename: my-package-1.0.0.tgz
package size: 223 B
unpacked size: 396 B
shasum: 8f339308bfabffcddd89e379ab76c8fbbc5c429a
integrity: sha512-s+d+5+kovk2mi[...]XqcwFATxxUGVw==
bundled deps: 2
bundled files: 0
own files: 2
total files: 2