PackageExtractorclass

new PackageExtractor({ tree, extensions = DEFAULT_EXTENSIONS, module = new ModuleExtractor(), base }: PackageExtractorOptions)
ParamType
optionsPackageExtractorOptions
Options for a PackageExtractor. required
    .treeTreeElement
Pre-extracted source tree the package.json exports resolve against — typically the result of
IndexExtractor(MergingExtractor(DirectoryExtractor())) over the source root. required readonly
    .extensionsImmutableDictionary<readonly string[]>
Maps an export target file extension (the right-hand side of an exports entry) to the source extensions to look for, in order.
- Bridges built output and source: package.json targets a .js file but the tree holds the .ts source.
- The first source extension that exists in the tree wins; a target extension with no mapping falls back to itself.
- Defaults to { js: ["ts", "tsx", "js", "jsx"] }. readonly
    .moduleModuleExtractor
ModuleExtractor used to build each module element. Defaults to a fresh new ModuleExtractor(). readonly
    .baseAbsolutePath
Absolute base path used to resolve a relative package.json path passed to extract(). readonly
Return
PackageExtractor
Extractor that reads a package.json and produces a flat tree of modules — one kind: "module" DocumentationElement per export entry, in declaration order.

Extractor that reads a package.json and produces a flat tree of modules — one kind: "module"
DocumentationElement per export entry, in declaration order.

  • Static export keys (e.g. "./api", "./firestore/client") become one module each.
  • Wildcard export keys (e.g. "./util/*") expand against the source tree — one module per matching child file or subdirectory.
  • Each export's target extension (e.g. the .js in "./util/*.js") is mapped to source extensions via extensions, so built .js paths resolve to their .ts sources.
  • Each module's title is prefixed with the package name (e.g. uishelving/ui) so listings read as package subpaths.
  • The "." root export is skipped — its content is the root tree element itself.
  • Throws if a static export key has no matching source element in the tree.

Examples

const tree = await new PackageExtractor({ tree: sourceTree }).extract("package.json");