{"name":"@publint/pack","version":"0.1.0","keywords":["utilities","pack","unpack","npm"],"author":{"name":"Bjorn Lu"},"license":"MIT","_id":"@publint/pack@0.1.0","maintainers":[{"name":"bluwy","email":"bjornlu.dev@gmail.com"}],"homepage":"https://github.com/bluwy/publint#readme","bugs":{"url":"https://github.com/bluwy/publint/issues"},"dist":{"shasum":"0cbdfe05f7a930b8eab35e5c228b9eb726cef9c8","tarball":"http://registry-npm.ywwl.com/@publint/pack/download/@publint/pack-0.1.0.tgz","fileCount":14,"integrity":"sha512-NvV5jPAQIMCoHvaJ0ZhfouBJ2woFYYf+o6B7dCHGh/tLKSPVoxhjffi35xPuMHgOv65aTOKUzML5XwQF9EkDAA==","signatures":[{"sig":"MEQCICwjrp/dxqM0fFj/iNuybL4ixBEbHRG8R/VjJIs8FPK9AiBRD8UiRVR4UhNkr7tYJ8lnkybhG+re07bpFEx6psCWwg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@publint%2fpack@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17356,"size":5833,"noattachment":false,"key":"/@publint/pack/-/@publint/pack-0.1.0.tgz"},"type":"module","_from":"file:publint-pack-0.1.0.tgz","engines":{"node":">=18"},"exports":{"types":"./src/index.d.ts","browser":"./src/index-browser.js","default":"./src/index-node.js"},"funding":"https://bjornlu.com/sponsor","scripts":{"test":"vitest run","test-dev":"vitest","typecheck":"tsc","lint-publint":"node ../publint/src/cli.js"},"_npmUser":{"name":"bluwy","email":"bjornlu.dev@gmail.com"},"_resolved":"/tmp/f28fe7f0893914b3c6cb9e1d5457ac7a/publint-pack-0.1.0.tgz","_integrity":"sha512-NvV5jPAQIMCoHvaJ0ZhfouBJ2woFYYf+o6B7dCHGh/tLKSPVoxhjffi35xPuMHgOv65aTOKUzML5XwQF9EkDAA==","repository":{"url":"git+https://github.com/bluwy/publint.git","type":"git","directory":"packages/pack"},"_npmVersion":"10.9.0","description":"Utilities for packing and unpacking npm packages","directories":{},"_nodeVersion":"22.12.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.0.0-beta.3","fs-fixture":"^2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/pack_0.1.0_1736172641822_0.4548597857176153","host":"s3://npm-registry-packages-npm-production"},"readme":"# @publint/pack\n\nZero-dependencies utilities for packing and unpacking npm packages. Supports:\n\n<!-- The list below should sync with the docs at /docs/index.md -->\n\n- npm (v9, v10, v11, v12)\n- yarn (v3, v4)\n- pnpm (v8, v9, v10, v11)\n- bun\n\nOlder versions of these package managers may still work, but they're not officially tested. Yarn 1 is also explicitly not supported.\n\n## API\n\nNOTE: All `pack*` APIs support passing `opts.packageManager` to specify the package manager to use for packing, and `opts.ignoreScripts` to skip running lifecycle scripts.\n\n### `pack()`\n\n- **Type**: `(dir: string, opts?: PackOptions): Promise<string>`\n\nPacks the given directory and returns the packed tarball path. Pass `opts.destination` to change the output directory of the tarball.\n\n```js\nimport { pack } from '@publint/pack'\n\nconst tarballPath = await pack(process.cwd())\nconsole.log(tarballPath)\n// => '/Users/bluwy/project/project-1.0.0.tgz'\n```\n\n### `packAsList()`\n\n- **Type**: `(dir: string, opts?: PackAsListOptions): Promise<string>`\n\nPacks the given directory and returns a list of relative file paths that were packed.\n\nThe relative file paths should be resolved via `getPackDirectory()` if a different packed directory was used.\n\n> [!NOTE]\n> Compared to [`npm-packlist`](https://github.com/npm/npm-packlist), this API works at a higher level by invoking the package manager `pack` command to retrieve the list of files packed. While `npm-packlist` is abstracted away from `npm` to expose a more direct API, unfortunately not all package managers pack files the same way, e.g. the patterns in `\"files\"` may be interpreted differently. Plus, since `npm-packlist` v7, it requires `@npmcli/arborist` to be used together, which is a much larger dependency to include altogether.\n>\n> This package provides an alternative API that works across package managers with a much smaller package size. However, as it executes commands in a child process, it's usually slightly slower (around 200-500ms minimum depending on package manager used and the project size).\n\n```js\nimport { packAsList } from '@publint/pack'\n\nconst files = await packAsList(process.cwd())\nconsole.log(files)\n// => ['src/index.js', 'package.json']\n```\n\n### `packAsJson()`\n\n- **Type**: `(dir: string, opts?: PackAsJsonOptions): Promise<string>`\n\nPacks the given directory with the `--json` flag and returns its stdout as JSON. You can run the `<pm> pack --json` command manually to inspect the output shape.\n\nRelative file paths in the output can be resolved via `getPackDirectory()` if a different packed directory was used.\n\n> [!NOTE]\n> Does not work in pnpm <9.14.1 and bun as they don't support the `--json` flag.\n\n```js\nimport { packAsJson } from '@publint/pack'\n\nconst json = await packAsJson(process.cwd())\nconsole.log(json)\n// => [{ \"id\": \"project@1.0.0\", ...  }]\n```\n\n### `getPackDirectory()`\n\n- **Type**: `(dir: string, packageManager?: PackageManager): Promise<string>`\n\nGets the directory that is being packed by the package manager. Usually this is the same as the input `dir`, but some package managers (like pnpm) allows changing the packed directory via the `publishConfig.directory` field in `package.json`.\n\n```js\nimport { getPackDirectory } from '@publint/pack'\nconst packDir = await getPackDirectory(process.cwd(), 'pnpm')\nconsole.log(packDir)\n// => '<cwd>/dist' (if \"publishConfig.directory\" is set to \"dist\" in package.json)\n```\n\n### `unpack()`\n\n- **Type**: `(tarball: ArrayBuffer | ReadableStream<Uint8Array>): Promise<UnpackResult>`\n\nUnpacks the given tarball buffer (gzip-decompress + untar). It accepts either a `ReadableStream`, `ArrayBuffer`, or `Uint8Array`. In Node.js,`ArrayBuffer` and `Uint8Array` are faster, while in browsers, `ReadableStream` is faster.\n\nFor example, when using `fetch()` in Node.js, use `response.arrayBuffer()` or `response.bytes()`, while in browsers, use `response.body` directly.\n\nIt returns an object with `files`, which is the list of unpacked files, and `rootDir`, which is the shared root directory among all files. (See JSDoc for examples)\n\n```js\nimport { unpack } from '@publint/pack'\n\nconst response = await fetch('https://registry.npmjs.org/mylib/-/mylib-1.0.0.tgz')\nif (!response.body) throw new Error('Failed to fetch tarball')\n\nconst result = await unpack(response.body)\nconsole.log(result)\n// => { files: [...], rootDir: 'package' }\n```\n\n## License\n\nMIT\n","publish_time":1736172642028,"_cnpm_publish_time":1736172642028,"dist-tags":{"latest":"0.1.7"}}