Skip to content

api-extractor initial support for generating *.d.ts files - #448

Merged
Pete Gonzalez (octogonz) merged 35 commits into
masterfrom
pgonzal/dts-generator-try3
Dec 22, 2017
Merged

Pete Gonzalez (octogonz) merged 35 commits into
masterfrom
pgonzal/dts-generator-try3

Conversation

@octogonz

Copy link
Copy Markdown
Collaborator

This PR is the first set of work for a new feature where API Extractor will generate package typings. Suppose the compiler produces ./lib/index.d.ts with the entry point for the package. API Extractor will produce three additional files:

  • ./dist/index-internal.d.ts: all the exported definitions from index.d.ts, but rolled up into one file
  • ./dist/index-preview.d.ts: a rollup containing only the definitions marked as Beta Kuang (@beta) and Alex Stapleton (@public)
  • ./dist/index-public.d.ts: a rollup containing only the definitions marked as Alex Stapleton (@public)

When publishing, the package.json file's "typings" entry will be pointed to one of these three files, depending on the release type.

This PR contains:

  • The new config file settings
  • The basic skeleton of the PackageTypingsGenerator class
  • Some minor refactoring

It's able to to generate a working ./dist/index-internal.d.ts for node-core-library, but is missing features required to handle more complicated libraries. That will be introduced in a separate PR.

],
'strictNullChecks': true
},
'include': [ 'lib/**/*.d.ts' ]

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

'include': [ 'lib/**/*.d.ts' ] [](start = 8, length = 30)

Go figure out how this is going to work with GCB. #Pending

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've got a working prototype of this, but it needs to go in a separate PR branch. It may also require a major version bump for API Extractor.


In reply to: 152421152 [](ancestors = 152421152)

Comment thread apps/api-extractor/src/DebugRun.ts Outdated

console.log('CONFIG:' + JSON.stringify(extractor.config, undefined, ' '));

extractor.analyzeProject();

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

analyzeProject [](start = 10, length = 14)

Rename to processProject #Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fix in a separate PR.


In reply to: 152421384 [](ancestors = 152421384)

* The default value is "index-internal.d.ts". This file will contain all definitions that
* are reachable from the entry point.
*/
internalFilename?: string;

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make it more clear that this gets appended to outputFolder. #Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could consider renaming these to FilePath instead of Filename


In reply to: 152421826 [](ancestors = 152421826)

* are reachable from the entry point, except definitions marked as \@beta, \@alpha,
* or \@internal.
*/
publicFilename?: string;

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My first guess is that these paths are inputs. Make sure it's clear from the names that they're outputs. #Resolved

* It is provided for diagnostic purposes. For example, a build script could write
* this object to a JSON file to report the final configuration options used by API Extractor.
*/
public get config(): IExtractorConfig {

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Call this something other than config, because that implies that it's the same thing that got passed into the constructor. #Resolved

private static _matchParent<T extends ts.Node>(node: ts.Node, parentKinds: ts.SyntaxKind[]): T | undefined {
let current: ts.Node | undefined = node;

let i: number = 0;

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[](start = 7, length = 2)

two spaces #Resolved

let current: ts.Node | undefined = node;

let i: number = 0;
while (true) { // tslint:disable-line:no-constant-condition

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

while [](start = 4, length = 5)

See if you can make this into a normal for loop. #Resolved

}
break;
}
}

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Describe why this is necessary. #Pending

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let's consider _modifySpan() a prototype for now. I need to get it wired up and see how it works for various real world inputs first, then I'll come back and rework this code. Some of the logic will be completely eliminated when we start processing *.d.ts inputs instead of *.ts.


In reply to: 152427693 [](ancestors = 152427693)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

// console.log(PrettyPrinter.dumpTree(declaration));
// console.log('-------------------------------------');
// console.log(declaration.getText());
// console.log('=====================================');

@iclanton Ian Clanton-Thuon (iclanton) Nov 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clean up all of this commented out code. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

concur.


In reply to: 152428250 [](ancestors = 152428250)


const dtsFilename: string = path.resolve(this._absoluteRootFolder,
this._config.packageTypings.outputFolder, this._config.packageTypings.internalFilename);
this._logger.logVerbose(`Writing package typings: ${dtsFilename}`);

@qz2017 QZ (qz2017) Nov 21, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[](start = 6, length = 2)

Extra space. #Resolved

moduleExport: boolean;
}

export default class PackageTypingsGenerator {

@qz2017 QZ (qz2017) Nov 21, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PackageTypingsGenerator [](start = 21, length = 23)

Where is the test for this class? #Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've started moving the integration test projects into the "/build-tests" folder.


In reply to: 152429942 [](ancestors = 152429942)

// Removes the leading underscore, for example: "_example" --> "example*"
// This causes internal definitions to sort alphabetically with regular definitions.
// The star is appended to preserve uniqueness, since "*" is not a legal identifier character.
this._sortKey = this.localName.substr(1) + ' ';

@qz2017 QZ (qz2017) Nov 21, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

' ' [](start = 51, length = 3)

Is this the star you talked about in the comment? #Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point


In reply to: 152430933 [](ancestors = 152430933)

@octogonz

Pete Gonzalez (octogonz) commented Dec 22, 2017 •

Copy link
Copy Markdown
Collaborator Author

:shipit:

Approved with PullApprove Approved with PullApprove Approved with PullApprove

@octogonz
Pete Gonzalez (octogonz) merged commit b558d5a into master Dec 22, 2017
@octogonz
Pete Gonzalez (octogonz) deleted the pgonzal/dts-generator-try3 branch May 2, 2018 04:24
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.

4 participants