-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-extractor]Support multiple modules in the same package #1596
Comments
Notes for getting this repro to run correctly:
|
@PissedCapslock I'm impressed you actually got fairly far with this. 😊 The crash is happening because when you invoke api-extractor on a secondary entry point, it produces an .api.json file with the same package name as before: {
"metadata": {
"toolPackage": "@microsoft/api-extractor",
"toolVersion": "7.5.1",
"schemaVersion": 1003,
"oldestForwardsCompatibleVersion": 1001
},
"kind": "Package",
"canonicalReference": "tsdocexperiment!",
"docComment": "",
"name": "tsdocexperiment", // <==============
"members": [ ...and then API Documenter is complaining because it doesn't expect to load two different definitions for the same package. |
One possible workaround would be to generate the // Run the API Extractor command-line
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(tempApiExtractorConfigFile); ...with this: // Run the API Extractor command-line
const configFile: IConfigFile = ExtractorConfig.loadFile(tempApiExtractorConfigFile);
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
configObject: configFile,
configObjectFullPath: path.resolve(tempApiExtractorConfigFile),
packageJson: {
name: path.basename(definitionFile).replace('.d.ts','')
},
packageJsonFullPath: path.resolve("package.json")
}); But I'd like to think about this a little more and see if we can maybe support it at least partially. Frankly I've never really attempted it. |
This issue is a dupe of #664 |
@PissedCapslock The difficulty of implementing this feature breaks down into 3 levels:
To understand the hard case, suppose we have two API entry points src/simple.ts (entry point) import { BaseControl } from './common';
/** @public */
export class Button extends BaseControl { } src/containers.ts (entry point) import { BaseControl } from './common';
/** @public */
export class TabPanel extends BaseControl { } src/common.ts (NOT a public entry point) /** @public */
export class BaseControl {
private _name: string;
} When we create the two .d.ts rollups, where do we put Instead, API Extractor would need to collect any symbols that get exported by more than one entry point, and move them into a synthetic There's also a puzzle of how to represent this on the documentation website. Presumably the table of contents would show something like this:
And what if src/simple.ts and src/containers.ts both export the
The design of the full-blown feature is fairly clear, but as you can see there's a fair amount of plumbing involved. Whereas, if you only need the partial "Support for documentation and API reports" from my list above, then it might be a lot less work. |
I'm also very interested in this feature as some libraries I maintain have(will have) multiple entry points. I'm glad that you think it's easy to add support for documentation and API reports which , I think, are most important to most people. For types and sharing types, we can just use the ones generated by tsc. @octogonz Have you started working on this? If not, would you accept contribution? I'd like to give it a shot at the documentation and api report part. |
Nope!
Absolutely! 😁
There's some onboarding docs here: https://api-extractor.com/pages/contributing/building/ Also I'm usually reachable on Gitter for specific questions. |
This includes a workaround for microsoft/rushstack#1596
This includes a workaround for microsoft/rushstack#1596
Is this a feature or a 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 samenpm
package:@angular/router
module@angular/router/upgrade
module@angular/router/testing
moduleJudging by the documentation, this should be possible using
api-extractor
:I tried this, but could not get it to work. I have setup a test repository which you can use to reproduce my problem:
which results in
What I do in this repository is the following:
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 codetsc
compiler compiles thesrc
folder, and stores the output in thelib
folder.d.ts
files from thesrc
folder into thelib
folder as well. That way, thelib
folder contains alld.ts
filesd.ts
files in the lib folder by generating anapi-extractor.json
file where the entrypoint points to that specificd.ts
file, and store that output into thetemp
folderThis approach results in
.api.json
files where the module information is gone. I only see the package name. So of course, runningapi-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: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.
The text was updated successfully, but these errors were encountered: