PackageExtractorclass
new PackageExtractor({ tree, extensions = DEFAULT_EXTENSIONS, module = new ModuleExtractor(), base }: PackageExtractorOptions)| Param | Type | |
|---|---|---|
options | PackageExtractorOptions | Options for a PackageExtractor. required |
.tree | TreeElement | Pre-extracted source tree the package.json exports resolve against — typically the result ofIndexExtractor(MergingExtractor(DirectoryExtractor())) over the source root. required readonly |
.extensions | ImmutableDictionary<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 |
.module | ModuleExtractor | ModuleExtractor used to build each module element. Defaults to a fresh new ModuleExtractor(). readonly |
.base | AbsolutePath |
| 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
.jsin"./util/*.js") is mapped to source extensions viaextensions, so built.jspaths resolve to their.tssources. - Each module's
titleis prefixed with the packagename(e.g.ui→shelving/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");