Skip to content

[api-extractor] Improve namespace support #773

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

Merged
merged 4 commits into from
Aug 21, 2018

Conversation

adventure-yunfei
Copy link
Contributor

@adventure-yunfei adventure-yunfei commented Aug 15, 2018

Fix Cases:

Currently this case won't work:

import { sub } from './sub';

// case 1: directly export "sub" module content
export { sub };

// case 2: export a namespace
export declare namespace NAMESPACE {
  export interface Foo {};
}

First, api-extractor cannot build correct api.json for case 1 (invalid name).
Second, while configure api-extractor.json to "namespaceSupport": "permissive", api-extractor successfully builds api.json, but api-documenter won't generate document for namespace.

What this PR does:

  • fix api-extractor for sub module exports
  • fix api-documenter for api reference search (for namespace case, api reference will be more than limited "package" -> "export name" -> "member name" hierarchy, and right now it's a quick fix which only affects api-documenter package )
  • add namespace document support for api-documenter

@msftclas
Copy link

msftclas commented Aug 15, 2018

CLA assistant check
All CLA requirements met. #Resolved

@octogonz
Copy link
Collaborator

octogonz commented Aug 15, 2018

Thanks @adventure-yunfei for submitting this PR! I will take a look soon. #Resolved

…ference for namespace content, and render namespace item
@octogonz
Copy link
Collaborator

octogonz commented Aug 18, 2018

@AlexJerabek your group is the primary user of namespaces with API Extractor.

Before we merge this PR, could you test it against the Office Add-ins project to make sure it doesn't break anything?

My specific concern are the changes in AstNamespace.ts and DocItemSet.ts which affect the YAML pipeline. Thanks! #Resolved

@AlexJerabek
Copy link
Contributor

AlexJerabek commented Aug 20, 2018

@pgonzal Just tested the changes against office-js. Nothing appears to be different in the yaml or json files. #Resolved

@octogonz
Copy link
Collaborator

octogonz commented Aug 21, 2018

Thanks @AlexJerabek for taking the time to test this! I will merge it. #Resolved

@octogonz octogonz changed the title [api-extractor & api-documenter] fix namespace support [api-extractor] Improve namespace support Aug 21, 2018
Copy link
Collaborator

@octogonz octogonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@octogonz octogonz merged commit 2db23f3 into microsoft:master Aug 21, 2018
@octogonz
Copy link
Collaborator

@adventure-yunfei thanks again for contributing this fix!

@adventure-yunfei
Copy link
Contributor Author

@pgonzal I'm just using api-documenter for typescript project right now. Searched around the world and almost tried every ts doc generator, you guys wrote the cleanest codes. While some features are not supported yet, it's not quite hard for me to figure out the logic and implement them. Nice Work!

But at I said this fix is just a quick fix. With namespace, "package" -> "export name" -> "member name" hierarchy is not enough. A re-implementation of api reference may be needed~

@octogonz
Copy link
Collaborator

Is your project open source? If so I'd be interested to see your API and documentation scenario.

We're going to be improving the analysis in our next sprint, by adapting the new .d.ts generator code to handle the .api.ts and .api.json features as well.

@adventure-yunfei
Copy link
Contributor Author

It's an internal project, but I can describe a little bit. The required missing feature is the export statement support.

The directory hierarchy is:

  • root/
    • math/
      • mathUtils/
      • Vector3.ts
    • events/
    • utils.ts

And the exported api file combines all of them.

// api.math.ts
import * as Vector3 from './math/Vector3';
import * as mathUtils from './math/mathUtils';
export { Vector3, mathUtils };

// - api.ts
import * as events from './events';
import * as math from './api.math';
import * as utils from './utils';
export { events, math, utils };

In this case the api reference for class Vector3 would be "" -> "math" -> "Vector3" -> "default" (and it could be deeper with nested namespace/es6-export-statement).

Some other missing features are:

  • type support (const, type). Currently it seems to only support namespace/class/interface/...
  • link support. Sometimes api link doesn't exist for properties, mostly in deep hierarchy, or some special syntax like typeof Foo['bar'];

If you need, I may re-create an example project.

@octogonz
Copy link
Collaborator

Thanks, this is helpful! If you find the time and are able to create a small repro branch on GitHub that illustrates these issues, when I am working on the analysis engine I can try to make sure these cases are handled correctly. If not, I can try to infer it from these notes.

@adventure-yunfei
Copy link
Contributor Author

I've made an example project that demonstrates what I've met before. Hopefully it'll help you.
https://github.com/adventure-yunfei/api-documenter-example-case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants