Parse and resolve the exports field from package.json.
Modern npm packages use the exports field (a.k.a. "export map") to
define entry points and restrict access to internal modules.
Supports:
- String shorthand:
"exports": "./index.js" - Subpath exports:
"exports": { ".": "./index.js", "./utils": "./lib/utils.js" } - Conditional exports:
"exports": { "import": "./esm.js", "require": "./cjs.js" } - Nested conditions:
"exports": { ".": { "import": "./esm.js", "default": "./cjs.js" } }
Summary
Functions
Extracts all conditions used in the export map.
Checks if a subpath is exported by the export map.
Detect whether a package uses ESM (type: "module") or CJS.
Parse the exports field from a package.json map.
Resolve an import path against an export map.
List all exported subpaths from an export map.
Validates that all export paths resolve to existing files.
Types
@type export_map() :: String.t() | %{required(String.t()) => export_map()} | nil
Functions
Extracts all conditions used in the export map.
Checks if a subpath is exported by the export map.
@spec module_type(map()) :: :esm | :cjs
Detect whether a package uses ESM (type: "module") or CJS.
Parse the exports field from a package.json map.
Returns a normalized map of subpath → target mappings, or nil if no exports field.
Resolve an import path against an export map.
Given a subpath (e.g. ".", "./utils") and a list of conditions
(e.g. ["import", "default"]), returns the resolved file path.
List all exported subpaths from an export map.
Validates that all export paths resolve to existing files.