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] Problems with ember addon #1864
Comments
@gossi thanks for making this repro, very helpful! API Extractor understands NPM packages and is designed to be able to analyze an SDK comprised of many packages. You would invoke API Extractor once for each package. (Generally we assume API Extractor's entry point is the default entry point for a To understand why, suppose we are generating an API docs website. We would not want the entire Sometimes people split their project into packages purely for internal organizational purposes, so from a customer's standpoint the API really comes from one master package. For this scenario, the API Extractor has a setting /**
* A list of NPM package names whose exports should be treated as part of this package.
*
* For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
* and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
* of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
* imports library2. To avoid this, we can specify:
*
* "bundledPackages": [ "library2" ],
*
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
* local files for library1.
*/
"bundledPackages": [ "@hokulea/buttons" ], ...then magically all those components will appear in your .api.json file and also in the .d.ts rollup. This might be a solution. However, taking a step back and looking at your project setup, the usage of imports is unconventional and could be improved:
So maybe you just need to straighten out your |
Thanks a lot, very insightful explanations. One more question here: As buttons was just a test, the idea is of course to document all packages in there. What's the best approach for this?
Thing is, I may might want to have one |
The typical model for API Extractor projects would be to break your SDK up into separate NPM packages. A consumer might import them like this: import { Button, AdjacentButton } from "@hokulea/buttons";
import { Panel, ScrollPanel } from "@hokulea/panels";
import { Rectangle, HokuleaConstants } from "@hokulea/core"; Note that with this approach, Typically there is not any "whole library" package. Consumers don't import from Now, continuing my example above, suppose that Sometimes people want to micromanage the bundling, however. In this case, they use "path based imports", which requires consumers to import like this: import { Button } from "@hokulea/buttons/components/button";
import { AdjacentButton } from "@hokulea/buttons/components/adjacent-button";
import { Panel } from "@hokulea/panels/components/panel";
import { Panel, ScrollPanel } from "@hokulea/panels/components/scroll-panel";
import { Rectangle, HokuleaConstants } from "@hokulea/core/utils"; or the all-in-one import { Button } from "@hokulea/sdk/components/button";
import { AdjacentButton } from "@hokulea/sdk/components/adjacent-button";
import { Panel } from "@hokulea/sdk/components/panel";
import { Panel, ScrollPanel } from "@hokulea/sdk/components/scroll-panel";
import { Rectangle, HokuleaConstants } from "@hokulea/sdk/utils"; This micromanagement ensures that Webpack will only process the specific entry points (paths) that the client is using. But it has downsides: Users now need to be aware of a complex tree of file paths. Imports are more verbose. It's difficult to know which file paths are intended to be "public" versus "internal." Today, API Extractor does not support path-based imports. We plan to support it eventually for API Extractor, but this feature hasn't been prioritized because it is not a best practice from an API contract standpoint. Nonetheless there are sometimes valid reasons why people need to use path-based imports. For the API report feature and documentation feature, you can work around it by creating a fake |
Thanks again a thousand times, very insightful! I know how to approach this now. This already makes it a really good Knowledge-Base candidate =) I close it once I'm done. |
I did exactly this! Very, very helpful - thank you so much. Here is the result: Happily closing this |
I'm trying to use api-extractor within an ember addon but the output from api-extractor is "empty".
Ember addons follow the conventions of the ember framework, which is important for their resolver to find the correct files. Most prominent part of the framework are components. These components can appear in template-only or with a backing up class. If there is a class, this is either a JS or TS file and can be documented as usual. Template-only components do not have a backing class, in order to document them, using a
*.d.ts
is one of the arising best practices within the ember community. So there are either*.ts
or*.d.ts
files which I plan to document. Due to embers nature, there is no entrance file, so I created anapi.d.ts
file and re-export everything I planned on documenting (I feel like I did a manual d.ts rollup ?!?).I have a public monorepo in which I want to do it. For testing purposes I started with one package in this repo.
Here is the branch and the package: https://github.com/gossi/hokulea/tree/api-extractor/packages/buttons
The entry file: https://github.com/gossi/hokulea/blob/api-extractor/packages/buttons/addon/api.d.ts
Output
DocModel (at
temp/buttons.api.json
):And
d.ts
rollup from api-extractor (atapi/buttons.d.ts
):I hope you can help me get the content in there. I'm around in gitter, happy to chat on this, too.
Thanks a lot
The text was updated successfully, but these errors were encountered: