list-dependents
v2.2.2
Published
Lists all dependents of a project, using npm or ecosyste.ms
Downloads
886
Readme
list-dependents
Lists all dependents of a project, using npm and ecosyste.ms
Usage
Simple
import { fetchEcosystemDependents } from 'list-dependents';
const result = fetchEcosystemDependents(name);
for await (const { downloads, name, pkg } of fetchEcosystemDependents('npm-run-all2')) {
console.log(downloads, name, pkg.description);
}
Advanced
See examples/cli.js
API
fetchEcosystemDependents()
Uses the ecosyste.ms
API to resolve packages of dependents
Syntax
fetchEcosystemDependents(name, [options]) => AsyncGenerator<EcosystemDependentsItem>
Arguments
name
–string
– the name of the package to do the lookup foroptions
–EcosystemDependentsOptions
– optional options
EcosystemDependentsOptions
filter
–(meta: EcosystemDependentsMeta) => boolean
– function givenEcosystemDependentsMeta
and should returntrue
for the package to be includedlogger
–BunyanLite
– a logger instancemaxAge
–number
– the maximum age of latest release to includemaxPages
–number
– the maximum number of source pages to fetch (there areperPage
items per page)minDownloadsLastMonth = 400
–number
– the minimum amount of downloads needed to be returnedperPage = 36
–number
– how many items per page to lookupskipPkg
–boolean
– when set skips resolvingpackage.json
Returns
An AsyncGenerator
that yields EcosystemDependentsItem
objects
fetchEcosystemPackage()
Uses the ecosyste.ms
API to resolve a package
Syntax
fetchEcosystemPackage(name, [options]) => Promise<EcosystemDependentsItem|false|undefined>
Arguments
name
–string
– The name of the package to do the lookup foroptions
–PackageLookupOptions
– optional options
PackageLookupOptions
client
–got
– a client to use for HTTP requestsecosystemsClient
–got
– a client to use for HTTP requests to ecosyste.msdependentOn
–string
– ensure the package depends on this module. Only works whenpackage.json
is fetched.filter
–(meta: EcosystemDependentsMeta) => boolean
– function givenEcosystemDependentsMeta
and should returntrue
for the package to be includedlogger
–BunyanLite
– a logger instanceskipPkg
–boolean | (meta: EcosystemDependentsMeta) => boolean
– whentrue
skips resolvingpackage.json
userAgent
–string
– an additional more specific user agent to preceed the built in one in theUser-Agent
header of requests
Returns
A promise resolving to false
if the package is actively excluded, undefined
if it couldn't be resolved and else EcosystemDependentsItem
createPackageFetchQueue()
Returns a fetchEcosystemPackage
equivalent that enforces a maximum concurrent fetches to npm + shares the back-off between all fetches, respecting the Retry-After
response headers.
Syntax
const fetchPackage = createPackageFetchQueue([queueOptions]);
const package = await fetchPackage(name, [options]);
Arguments
queueOptions
–PackageFetchQueueOptions
– optional options
PackageFetchQueueOptions
client
–got
– a client to use for HTTP requestslogger
–BunyanLite
– a logger instanceuserAgent
–string
– an additional more specific user agent to preceed the built in one in theUser-Agent
header of requests
Returns
A function equal to fetchEcosystemPackage
except that the client
, ecosystemClient
, logger
and userAgent
is overriden by the values sent in when it was created
Types
DependentsMeta
export interface DependentsMeta {
downloads: number;
name: string;
}
DependentsItem
import type { NormalizedPackageJson } from 'read-pkg';
export interface DependentsItem extends DependentsMeta {
pkg?: NormalizedPackageJson | undefined;
targetVersion?: string | undefined,
}
EcosystemDependentsMeta
export interface EcosystemDependentsMeta extends DependentsMeta {
dependentCount: number | undefined,
firstRelease: string | undefined,
latestRelease: string | undefined,
latestVersion: string | undefined,
repositoryUrl: string | undefined;
}
EcosystemDependentsItem
export interface EcosystemDependentsItem extends DependentsItem, EcosystemDependentsMeta {}
Similar modules
dependents
– usesnpm-dependants
together with the npm API and GitHub API to deliver a functionality similar tofetchEcosystemDependents()
/fetchNpmDependents()
list-installed
– sister module to this module – similar API but resolves locally installed modules rather than remote dependentsnpm-dependants
– similar in functionality tofetchNpmDependentList()