package
Get all entry-points for an npm package. Supports the `exports` field in `package.json`.
npm install pkg-entry-pointsGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
25.6 kB
Includes dependencies.
Get all entry-points for an npm package. Supports the exports field to expand subpaths and condition combinations.
Already a sponsor? Join the discussion in the Development repo!
npm install pkg-entry-pointsTo get all entry-points for a package located at ./node_modules/my-package:
import { getPackageEntryPoints, type PackageEntryPoints } from 'pkg-entry-points'
const packageExports: PackageEntryPoints = await getPackageEntryPoints('./node_modules/my-package')
console.log(packageExports)
/*
{
'.': [
[conditions, internalPath],
],
'./entry-file': [
[['types'], './dist/entry-file.d.ts'],
[['import'], './dist/entry-file.mjs'],
[['require'], './dist/entry-file.js'],
],
...,
}
*/vue - using exports conditionsEntry-points evaluated from the vue package:
vue entry-points{
".": [
[
[
"types",
],
"./dist/vue.d.ts",
],
[
[
"require",
],
"./index.js",
],
[
[
"import",
"node",
],
"./index.mjs",
],
[
[
"default",
"import",
],
"./dist/vue.runtime.esm-bundler.js",
typescript - no exports (legacy main field, etc.)Entry-points evaluated from the typescript package:
typescript entry-points{
"./lib/cancellationToken.js": [
[
[
"default",
],
"./lib/cancellationToken.js",
],
],
"./lib/cs/diagnosticMessages.generated.json": [
[
[
"default",
],
"./lib/cs/diagnosticMessages.generated.json",
],
],
"./lib/de/diagnosticMessages.generated.json": [
[
[
"default",
],
"./lib/de/diagnosticMessages.generated.json",
],
],
"./lib/es/diagnosticMessages.generated.json": [
Returns: Promise<PackageEntryPoints>
Type definitions (both PackageEntryPoints and ConditionToPath are exported):
type PackageEntryPoints = {
[subpath: string]: ConditionToPath[]
}
type ConditionToPath = [conditions: string[], internalPath: string]Returns all possible entry-points of an npm package.
If the package has a package.json#exports property, it will return an object where the keys are expanded subpaths and the values are arrays of tuples containing an array of possible import combinations paired with the internal file path it resolves to.
If the package does not have an exports property, it will return an object where the keys are the internal file paths, mapping to arrays of possible import combinations.
packagePath
Type: string
Required
The path to the package to get the exports for.
fs
Type: typeof import('fs/promises')
Optional
Default: fs.promises
The file-system to use. Defaults to Node.js's fs/promises module.
Utils to resolve package.json subpath & conditional exports/imports maps in resolvers.