npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pkg-entry-points

v1.1.1

Published

Get all entry-points for an npm package. Supports the `exports` field in `package.json`.

Downloads

289,636

Readme

pkg-entry-points

Get all entry-points for an npm package. Supports the exports field to expand subpaths and condition combinations.

Install

npm install pkg-entry-points

Usage

To get all entry-points for a package located at ./node_modules/my-package:

import { getPackageEntryPoints } from 'pkg-entry-points'

const packageExports = 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'],
    ],
    ...,
}
*/

Example: vue - using exports conditions

Entry-points evaluated from the vue package:

{
    ".": [
        [["types"], "./dist/vue.d.ts"],
        [["require"], "./index.js"],
        [["import", "node"], "./index.mjs"],
        [["default", "import"], "./dist/vue.runtime.esm-bundler.js"]
    ],
    "./server-renderer": [
        [["types"], "./server-renderer/index.d.ts"],
        [["import"], "./server-renderer/index.mjs"],
        [["require"], "./server-renderer/index.js"]
    ],
    "./compiler-sfc": [
        [["types"], "./compiler-sfc/index.d.ts"],
        [["import"], "./compiler-sfc/index.mjs"],
        [["require"], "./compiler-sfc/index.js"]
    ],
    "./dist/vue.cjs.js": [
        [["default"], "./dist/vue.cjs.js"]
    ],
    "./dist/vue.cjs.prod.js": [
        [["default"], "./dist/vue.cjs.prod.js"]
    ],
    "./dist/vue.d.ts": [
        [["default"], "./dist/vue.d.ts"]
    ],
    "./dist/vue.esm-browser.js": [
        [["default"], "./dist/vue.esm-browser.js"]
    ],
    "./dist/vue.esm-browser.prod.js": [
        [["default"], "./dist/vue.esm-browser.prod.js"]
    ],
    "./dist/vue.esm-bundler.js": [
        [["default"], "./dist/vue.esm-bundler.js"]
    ],
    "./dist/vue.global.js": [
        [["default"], "./dist/vue.global.js"]
    ],
    "./dist/vue.global.prod.js": [
        [["default"], "./dist/vue.global.prod.js"]
    ],
    "./dist/vue.runtime.esm-browser.js": [
        [["default"], "./dist/vue.runtime.esm-browser.js"]
    ],
    "./dist/vue.runtime.esm-browser.prod.js": [
        [["default"], "./dist/vue.runtime.esm-browser.prod.js"]
    ],
    "./dist/vue.runtime.esm-bundler.js": [
        [["default"], "./dist/vue.runtime.esm-bundler.js"]
    ],
    "./dist/vue.runtime.global.js": [
        [["default"], "./dist/vue.runtime.global.js"]
    ],
    "./dist/vue.runtime.global.prod.js": [
        [["default"], "./dist/vue.runtime.global.prod.js"]
    ],
    "./package.json": [
        [["default"], "./package.json"]
    ],
    "./macros": [
        [["default"], "./macros.d.ts"]
    ],
    "./macros-global": [
        [["default"], "./macros-global.d.ts"]
    ],
    "./ref-macros": [
        [["default"], "./ref-macros.d.ts"]
    ]
}

Example: typescript - no exports (legacy main field, etc.)

Entry-points evaluated from the typescript package:

{
    "./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": [
        [["default"], "./lib/es/diagnosticMessages.generated.json"]
    ],
    "./lib/fr/diagnosticMessages.generated.json": [
        [["default"], "./lib/fr/diagnosticMessages.generated.json"]
    ],
    "./lib/it/diagnosticMessages.generated.json": [
        [["default"], "./lib/it/diagnosticMessages.generated.json"]
    ],
    "./lib/ja/diagnosticMessages.generated.json": [
        [["default"], "./lib/ja/diagnosticMessages.generated.json"]
    ],
    "./lib/ko/diagnosticMessages.generated.json": [
        [["default"], "./lib/ko/diagnosticMessages.generated.json"]
    ],
    "./lib/pl/diagnosticMessages.generated.json": [
        [["default"], "./lib/pl/diagnosticMessages.generated.json"]
    ],
    "./lib/pt-br/diagnosticMessages.generated.json": [
        [["default"], "./lib/pt-br/diagnosticMessages.generated.json"]
    ],
    "./lib/ru/diagnosticMessages.generated.json": [
        [["default"], "./lib/ru/diagnosticMessages.generated.json"]
    ],
    "./lib/tr/diagnosticMessages.generated.json": [
        [["default"], "./lib/tr/diagnosticMessages.generated.json"]
    ],
    "./lib/tsc.js": [
        [["default"], "./lib/tsc.js"]
    ],
    "./lib/tsserver.js": [
        [["default"], "./lib/tsserver.js"]
    ],
    "./lib/tsserverlibrary.js": [
        [["default"], "./lib/tsserverlibrary.js"]
    ],
    "./lib/typesMap.json": [
        [["default"], "./lib/typesMap.json"]
    ],
    "./lib/typescript.js": [
        [["default"], "./lib/typescript.js"]
    ],
    "./lib/typingsInstaller.js": [
        [["default"], "./lib/typingsInstaller.js"]
    ],
    "./lib/watchGuard.js": [
        [["default"], "./lib/watchGuard.js"]
    ],
    "./lib/zh-cn/diagnosticMessages.generated.json": [
        [["default"], "./lib/zh-cn/diagnosticMessages.generated.json"]
    ],
    "./lib/zh-tw/diagnosticMessages.generated.json": [
        [["default"], "./lib/zh-tw/diagnosticMessages.generated.json"]
    ],
    "./package.json": [
        [["default"], "./package.json"]
    ],
    ".": [
        [["default"], "./lib/typescript.js"]
    ]
}

API

getPackageEntryPoints(packagePath, fs?)

Returns: Promise<PackageEntryPoints>

Type definitions:

type PackageEntryPoints = {
    [subpath: string]: ConditionToPath[]
}

type ConditionToPath = [conditions: string[], internalPath: string]

Description

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.

Parameters

  • 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.

Sponsors

Related

resolve-pkg-maps

Utils to resolve package.json subpath & conditional exports/imports maps in resolvers.