Skip to content

[api-extractor]Support multiple modules in the same package #1596

Open
@PissedCapslock

Description

@PissedCapslock

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.

I'm looking for a way to generate documentation for a Typescript library/package which does not have a single input file.
Instead, the package contains of a set of modules where each module exports some classes, interfaces, ... . It is very similar to what Angular has, e.g. if you npm install @angular/router you receive 3 modules in the same npm package:

  • The @angular/router module
  • The @angular/router/upgrade module
  • The @angular/router/testing module

Judging by the documentation, this should be possible using api-extractor:

One significant limitation for .d.ts rollups is the assumption that your package has a single entry point. (If that’s not the case, you probably won’t be able to use this feature of API Extractor, although you can still use the API report and documentation generation features.)

I tried this, but could not get it to work. I have setup a test repository which you can use to reproduce my problem:

git clone https://github.com/PissedCapslock/tsdocexperiment.git
cd tsdocexperiment/
npm install
npm run-script apiextractor
npx api-documenter --input-folder temp --output-folder docs

which results in

Reading firstmodule.api.json
Reading secondmodule.api.json
Error: Another member has already been added with the same name and containerKey

What I do in this repository is the following:

  • The src folder contains a mix of .d.ts files and .ts files. This is probably irrelevant, but mainly done to mimic our current situation where we are migrating a .js codebase Typescript, and have manually created definition files for unported JS code
  • The tsc compiler compiles the src folder, and stores the output in the lib folder.
  • I copy the d.ts files from the src folder into the lib folder as well. That way, the lib folder contains all d.ts files
  • I run the API extractor on all the d.ts files in the lib folder by generating an api-extractor.json file where the entrypoint points to that specific d.ts file, and store that output into the temp folder

This approach results in .api.json files where the module information is gone. I only see the package name. So of course, running api-documenter on it does not work.

Is multiple entry points simply not supported (despite what is mentioned in the documentation), or am I doing something wrong ?
Looking at the documentation of the APIPackage class which has a ReadonlyArray<ApiEntryPoint> property, it certainly looks like multiple entry points are supported.
On the other hand, WorkingPackage.entryPointSourceFile contains the following comment:

  /**
   * The entry point being processed during this invocation of API Extractor.
   *
   * @remarks
   * The working package may have multiple entry points; however, today API Extractor
   * only processes a single entry point during an invocation.  This will be improved
   * in the future.
   */

which sounds less promising.

If supported, I would appreciate it if somebody could point me in the right direction. In return, I would gladly open a PR for the api extractor site with some extra documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThe issue is asking for a new feature or design changeneeds designThe next step is for someone to propose the details of an approach for solving the problemrepro confirmedThe issue comments included repro instructions, and the maintainers reproduced the problem

    Type

    No type

    Projects

    Status

    AE/AD

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions