Installations
npm install pacote
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
^20.17.0 || >=22.9.0
Node Version
22.11.0
NPM Version
10.9.1
Score
66.1
Supply Chain
96.7
Quality
86.8
Maintenance
100
Vulnerability
97.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
npm
Download Statistics
Total Downloads
1,316,645,597
Last Day
1,443,969
Last Week
6,507,189
Last Month
28,853,661
Last Year
374,264,916
GitHub Statistics
363 Stars
1,127 Commits
48 Forks
17 Watching
6 Branches
109 Contributors
Package Meta Information
Latest Version
21.0.0
Package Id
pacote@21.0.0
Unpacked Size
72.02 kB
Size
22.72 kB
File Count
18
NPM Version
10.9.1
Node Version
22.11.0
Publised On
25 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
1,316,645,597
Last day
-3.2%
1,443,969
Compared to previous day
Last week
-13.8%
6,507,189
Compared to previous week
Last month
1.8%
28,853,661
Compared to previous month
Last year
22%
374,264,916
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
17
pacote
Fetches package manifests and tarballs from the npm registry.
USAGE
1const pacote = require('pacote') 2 3// get a package manifest 4pacote.manifest('foo@1.x').then(manifest => console.log('got it', manifest)) 5 6// extract a package into a folder 7pacote.extract('github:npm/cli', 'some/path', options) 8 .then(({from, resolved, integrity}) => { 9 console.log('extracted!', from, resolved, integrity) 10 }) 11 12pacote.tarball('https://server.com/package.tgz').then(data => { 13 console.log('got ' + data.length + ' bytes of tarball data') 14})
pacote
works with any kind of package specifier that npm can install. If
you can pass it to the npm CLI, you can pass it to pacote. (In fact, that's
exactly what the npm CLI does.)
Anything that you can do with one kind of package, you can do with another.
Data that isn't relevant (like a packument for a tarball) will be simulated.
prepare
scripts will be run when generating tarballs from git
and
directory
locations, to simulate what would be published to the
registry, so that you get a working package instead of just raw source
code that might need to be transpiled.
CLI
This module exports a command line interface that can do most of what is
described below. Run pacote -h
to learn more.
Pacote - The JavaScript Package Handler, v10.1.1
Usage:
pacote resolve <spec>
Resolve a specifier and output the fully resolved target
Returns integrity and from if '--long' flag is set.
pacote manifest <spec>
Fetch a manifest and print to stdout
pacote packument <spec>
Fetch a full packument and print to stdout
pacote tarball <spec> [<filename>]
Fetch a package tarball and save to <filename>
If <filename> is missing or '-', the tarball will be streamed to stdout.
pacote extract <spec> <folder>
Extract a package to the destination folder.
Configuration values all match the names of configs passed to npm, or
options passed to Pacote. Additional flags for this executable:
--long Print an object from 'resolve', including integrity and spec.
--json Print result objects as JSON rather than node's default.
(This is the default if stdout is not a TTY.)
--help -h Print this helpful text.
For example '--cache=/path/to/folder' will use that folder as the cache.
API
The spec
refers to any kind of package specifier that npm can install.
If you can pass it to the npm CLI, you can pass it to pacote. (In fact,
that's exactly what the npm CLI does.)
See below for valid opts
values.
-
pacote.resolve(spec, opts)
Resolve a specifier likefoo@latest
orgithub:user/project
all the way to a tarball url, tarball file, or git repo with commit hash. -
pacote.extract(spec, dest, opts)
Extract a package's tarball into a destination folder. Returns a promise that resolves to the{from,resolved,integrity}
of the extracted package. -
pacote.manifest(spec, opts)
Fetch (or simulate) a package's manifest (basically, thepackage.json
file, plus a bit of metadata). See below for more on manifests and packuments. Returns a Promise that resolves to the manifest object. -
pacote.packument(spec, opts)
Fetch (or simulate) a package's packument (basically, the top-level package document listing all the manifests that the registry returns). See below for more on manifests and packuments. Returns a Promise that resolves to the packument object. -
pacote.tarball(spec, opts)
Get a package tarball data as a buffer in memory. Returns a Promise that resolves to the tarball data Buffer, withfrom
,resolved
, andintegrity
fields attached. -
pacote.tarball.file(spec, dest, opts)
Save a package tarball data to a file on disk. Returns a Promise that resolves to{from,integrity,resolved}
of the fetched tarball. -
pacote.tarball.stream(spec, streamHandler, opts)
Fetch a tarball and make the stream available to thestreamHandler
function.This is mostly an internal function, but it is exposed because it does provide some functionality that may be difficult to achieve otherwise.
The
streamHandler
function MUST return a Promise that resolves when the stream (and all associated work) is ended, or rejects if the stream has an error.The
streamHandler
function MAY be called multiple times, as Pacote retries requests in some scenarios, such as cache corruption or retriable network failures.
Options
Options are passed to
npm-registry-fetch
and
cacache
, so in addition to these, anything for
those modules can be given to pacote as well.
Options object is cloned, and mutated along the way to add integrity, resolved, and other properties, as they are determined.
cache
Where to store cache entries and temp files. Passed tocacache
. Defaults to the same cache directory that npm will use by default, based on platform and environment.where
Base folder for resolving relativefile:
dependencies.resolved
Shortcut for looking up resolved values. Should be specified if known.integrity
Expected integrity of fetched package tarball. If specified, tarballs with mismatched integrity values will raise anEINTEGRITY
error.umask
Permission mode mask for extracted files and directories. Defaults to0o22
. See "Extracted File Modes" below.fmode
Minimum permission mode for extracted files. Defaults to0o666
. See "Extracted File Modes" below.dmode
Minimum permission mode for extracted directories. Defaults to0o777
. See "Extracted File Modes" below.preferOnline
Prefer to revalidate cache entries, even when it would not be strictly necessary. Defaultfalse
.before
When picking a manifest from a packument, only consider packages published before the specified date. Defaultnull
.defaultTag
The defaultdist-tag
to use when choosing a manifest from a packument. Defaults tolatest
.registry
The npm registry to use by default. Defaults tohttps://registry.npmjs.org/
.fullMetadata
Fetch the full metadata from the registry for packuments, including information not strictly required for installation (author, description, etc.) Defaults totrue
whenbefore
is set, since the version publish time is part of the extended packument metadata.fullReadJson
Use the slowerread-package-json
package insted ofread-package-json-fast
in order to include extra fields like "readme" in the manifest. Defaults tofalse
.packumentCache
For registry packuments only, you may provide aMap
object which will be used to cache packument requests between pacote calls. This allows you to easily avoid hitting the registry multiple times (even just to validate the cache) for a given packument, since it is unlikely to change in the span of a single command.verifySignatures
A boolean that will make pacote verify the integrity signature of a manifest, if present. There must be a configured_keys
entry in the config that is scoped to the registry the manifest is being fetched from.verifyAttestations
A boolean that will make pacote verify Sigstore attestations, if present. There must be a configured_keys
entry in the config that is scoped to the registry the manifest is being fetched from.tufCache
Where to store metadata/target files when retrieving the package attestation key material via TUF. Defaults to the same cache directory that npm will use by default, based on platform and environment.
Advanced API
Each different type of fetcher is exposed for more advanced usage such as using helper methods from this classes:
DirFetcher
FileFetcher
GitFetcher
RegistryFetcher
RemoteFetcher
Extracted File Modes
Files are extracted with a mode matching the following formula:
( (tarball entry mode value) | (minimum mode option) ) ~ (umask)
This is in order to prevent unreadable files or unlistable directories from
cluttering a project's node_modules
folder, even if the package tarball
specifies that the file should be inaccessible.
It also prevents files from being group- or world-writable without explicit
opt-in by the user, because all file and directory modes are masked against
the umask
value.
So, a file which is 0o771
in the tarball, using the default fmode
of
0o666
and umask
of 0o22
, will result in a file mode of 0o755
:
(0o771 | 0o666) => 0o777
(0o777 ~ 0o22) => 0o755
In almost every case, the defaults are appropriate. To respect exactly
what is in the package tarball (even if this makes an unusable system), set
both dmode
and fmode
options to 0
. Otherwise, the umask
config
should be used in most cases where file mode modifications are required,
and this functions more or less the same as the umask
value in most Unix
systems.
Extracted File Ownership
When running as root
on Unix systems, all extracted files and folders
will have their owning uid
and gid
values set to match the ownership
of the containing folder.
This prevents root
-owned files showing up in a project's node_modules
folder when a user runs sudo npm install
.
Manifests
A manifest
is similar to a package.json
file. However, it has a few
pieces of extra metadata, and sometimes lacks metadata that is inessential
to package installation.
In addition to the common package.json
fields, manifests include:
-
manifest._resolved
The tarball url or file path where the package artifact can be found. -
manifest._from
A normalized form of the spec passed in as an argument. -
manifest._integrity
The integrity value for the package artifact. -
manifest._id
The canonical spec of this package version: name@version. -
manifest.dist
Registry manifests (those included in a packument) have adist
object. Onlytarball
is required, though at least one ofshasum
orintegrity
is almost always present.tarball
The url to the associated package artifact. (Copied by Pacote tomanifest._resolved
.)integrity
The integrity SRI string for the artifact. This may not be present for older packages on the npm registry. (Copied by Pacote tomanifest._integrity
.)shasum
Legacy integrity value. Hexadecimal-encoded sha1 hash. (Converted to an SRI string and copied by Pacote tomanifest._integrity
whendist.integrity
is not present.)fileCount
Number of files in the tarball.unpackedSize
Size on disk of the package when unpacked.signatures
Signatures of the shasum. Includes the keyid that correlates to akey from the npm registry
Packuments
A packument is the top-level package document that lists the set of manifests for available versions for a package.
When a packument is fetched with accept: application/vnd.npm.install-v1+json
in the HTTP headers, only the most
minimum necessary metadata is returned. Additional metadata is returned
when fetched with only accept: application/json
.
For Pacote's purposes, the following fields are relevant:
versions
An object where each key is a version, and each value is the manifest for that version.dist-tags
An object mapping dist-tags to version numbers. This is howfoo@latest
gets turned intofoo@1.2.3
.time
In the full packument, an object mapping version numbers to publication times, for theopts.before
functionality.
Pacote adds the following field, regardless of the accept header:
_contentLength
The size of the packument.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 24 commits out of 29 are checked with a SAST tool
Reason
Found 8/9 approved changesets -- score normalized to 8
Reason
7 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 6
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/audit.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/audit.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/audit.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/audit.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-release.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:106: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:122: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-release.yml:138: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:89: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/post-dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/post-dependabot.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/post-dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull-request.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/pull-request.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull-request.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/pull-request.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-integration.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release-integration.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-integration.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release-integration.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:199: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:218: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:236: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:274: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:283: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:303: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:110: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:119: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:136: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:162: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/pacote/release.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/audit.yml:38
- Warn: npmCommand not pinned by hash: .github/workflows/ci-release.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:42
- Warn: npmCommand not pinned by hash: .github/workflows/post-dependabot.yml:39
- Warn: npmCommand not pinned by hash: .github/workflows/pull-request.yml:42
- Warn: npmCommand not pinned by hash: .github/workflows/release-integration.yml:52
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:50
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:130
- Info: 0 out of 26 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 12 third-party GitHubAction dependencies pinned
- Info: 0 out of 8 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:21
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:22
- Warn: no topLevel permission defined: .github/workflows/audit.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci-release.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/post-dependabot.yml:8
- Warn: no topLevel permission defined: .github/workflows/pull-request.yml:1
- Warn: no topLevel permission defined: .github/workflows/release-integration.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yml:11
- Warn: topLevel 'checks' permission set to 'write': .github/workflows/release.yml:13
- Info: no jobLevel write permissions found
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More