{"name":"@publint/pack","version":"0.1.5","keywords":["utilities","pack","unpack","npm"],"author":"Bjorn Lu","license":"MIT","_id":"@publint/pack@0.1.5","maintainers":[{"name":"bluwy","email":"bjornlu.dev@gmail.com"}],"bugs":{"url":"https://github.com/publint/publint/issues"},"dist":{"shasum":"3b87dbcc086560944c3564bf9d05c5a1d115fe85","tarball":"http://registry-npm.ywwl.com/@publint/pack/download/@publint/pack-0.1.5.tgz","fileCount":15,"integrity":"sha512-edgyN2pP07uXiP4tJs0s8KVmU8M8i60YPbbI0/WDeok1mIJHRXz+CgD8I0nelwDkoCh3EWL/G5kGfbuHjsdbvw==","signatures":[{"sig":"MEUCIQCEj+A1nRBrspw+f5smfFj2ab5anUSE7UcQCrP2VyudaQIgSsvNy540z/nVyDgU+/uKQsIENWUT9qw5BAwOOKxKcjg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@publint%2fpack@0.1.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":23576,"size":7249,"noattachment":false,"key":"/@publint/pack/-/@publint/pack-0.1.5.tgz"},"type":"module","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":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:73c98fdb-ec61-4cf2-9dfb-cc9b95148809"}},"repository":{"url":"git+https://github.com/publint/publint.git","type":"git","directory":"packages/pack"},"description":"Utilities for packing and unpacking npm packages","directories":{},"_nodeVersion":"24.16.0","dependencies":{"tinyexec":"^1.2.4"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.1.9","fs-fixture":"^2.14.0"},"_npmOperationalInternal":{"tmp":"tmp/pack_0.1.5_1781679998206_0.22679023320024316","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":1781679998413,"_cnpm_publish_time":1781679998413,"dist-tags":{"latest":"0.1.7"}}