Skip to content
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] Adds package-defined TSDoc tag support #1950

Merged
merged 24 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a3010f7
adds tsdoc-config and updates tsdoc to have compatible type signatures
nicholasrice Jun 19, 2020
03b0127
construct tsdoc configuration in ExtractorConfig
nicholasrice Jun 19, 2020
ff63440
wire tsdocConfiguration throughout the api-extractor
nicholasrice Jun 19, 2020
5451da7
remove references to AedocDefinitions and replace with configurable t…
nicholasrice Jun 20, 2020
61bdcb6
update test fixtures
nicholasrice Jun 20, 2020
6bd65e4
rush change results
nicholasrice Jun 20, 2020
7ef3840
move tsdoc configuration construction to DeserializerContext
nicholasrice Jun 30, 2020
b1004b0
Bump version
octogonz Jan 16, 2021
26d4b2c
rush update
octogonz Jan 16, 2021
0a5d0a4
rush rebuild
octogonz Jan 16, 2021
32b306e
rush update
nicholasrice Mar 22, 2021
9ecc08f
update tsdoc and tsdoc-config
nicholasrice Mar 22, 2021
52829d8
implement config emission and parsing, add test cases, and rush rebuild
nicholasrice Mar 23, 2021
0ce7230
Merge remote-tracking branch 'remotes/origin/master' into users/niric…
octogonz Apr 16, 2021
7d49b39
rush update
octogonz Apr 16, 2021
9bbf43f
Upgrade to tsdoc-config 0.15.0 which adds the loadFromObject() API
octogonz Apr 16, 2021
ad628a8
rush update
octogonz Apr 16, 2021
00b9aee
Move tsdoc-config to nonbrowser-approved-packages.json
octogonz Apr 16, 2021
ff5f108
rush update
octogonz Apr 17, 2021
bbcbe92
Use TSConfigFile.loadFromObject() to deserialize the TSDoc configuration
octogonz Apr 17, 2021
156aed9
Increment the ApiJsonSchemaVersion and implement backwards compatibility
octogonz Apr 17, 2021
8a5d5c2
Move the AEDoc definitions from ./tsdoc.json --> extends/tsdoc-base.json
octogonz Apr 17, 2021
f55ebc2
Add launch.json config for debugging Jest tests
octogonz Apr 17, 2021
00ed463
Update ExtractorConfig to load tsdoc-base.json, and add an example ts…
octogonz Apr 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api-documenter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"typings": "dist/rollup.d.ts",
"dependencies": {
"@microsoft/api-extractor-model": "workspace:*",
"@microsoft/tsdoc": "0.12.24",
"@microsoft/tsdoc": "0.13.0",
"@rushstack/node-core-library": "workspace:*",
"@rushstack/ts-command-line": "workspace:*",
"colors": "~1.2.1",
Expand Down
3 changes: 2 additions & 1 deletion apps/api-extractor-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"build": "heft test --clean"
},
"dependencies": {
"@microsoft/tsdoc": "0.12.24",
"@microsoft/tsdoc": "0.13.0",
"@microsoft/tsdoc-config": "~0.15.0",
"@rushstack/node-core-library": "workspace:*"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions apps/api-extractor-model/src/aedoc/AedocDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TSDocConfiguration, TSDocTagDefinition, TSDocTagSyntaxKind, StandardTag

/**
* @internal
* @deprecated - tsdoc configuration is now constructed from tsdoc.json files associated with each package.
*/
export class AedocDefinitions {
public static readonly betaDocumentation: TSDocTagDefinition = new TSDocTagDefinition({
Expand Down
3 changes: 1 addition & 2 deletions apps/api-extractor-model/src/items/ApiDocumentedItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import * as tsdoc from '@microsoft/tsdoc';
import { ApiItem, IApiItemOptions, IApiItemJson } from './ApiItem';
import { AedocDefinitions } from '../aedoc/AedocDefinitions';
import { DeserializerContext } from '../model/DeserializerContext';

/**
Expand Down Expand Up @@ -47,7 +46,7 @@ export class ApiDocumentedItem extends ApiItem {
const documentedJson: IApiDocumentedItemJson = jsonObject as IApiDocumentedItemJson;

if (documentedJson.docComment) {
const tsdocParser: tsdoc.TSDocParser = new tsdoc.TSDocParser(AedocDefinitions.tsdocConfiguration);
const tsdocParser: tsdoc.TSDocParser = new tsdoc.TSDocParser(context.tsdocConfiguration);

// NOTE: For now, we ignore TSDoc errors found in a serialized .api.json file.
// Normally these errors would have already been reported by API Extractor during analysis.
Expand Down
58 changes: 54 additions & 4 deletions apps/api-extractor-model/src/model/ApiPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {
JsonFile,
IJsonFileSaveOptions,
PackageJsonLookup,
IPackageJson
IPackageJson,
JsonObject
} from '@rushstack/node-core-library';
import { ApiDocumentedItem, IApiDocumentedItemOptions } from '../items/ApiDocumentedItem';
import { ApiEntryPoint } from './ApiEntryPoint';
import { IApiNameMixinOptions, ApiNameMixin } from '../mixins/ApiNameMixin';
import { DeserializerContext, ApiJsonSchemaVersion } from './DeserializerContext';
import { TSDocConfiguration } from '@microsoft/tsdoc';
import { TSDocConfigFile } from '@microsoft/tsdoc-config';

/**
* Constructor options for {@link ApiPackage}.
Expand All @@ -22,7 +25,9 @@ import { DeserializerContext, ApiJsonSchemaVersion } from './DeserializerContext
export interface IApiPackageOptions
extends IApiItemContainerMixinOptions,
IApiNameMixinOptions,
IApiDocumentedItemOptions {}
IApiDocumentedItemOptions {
tsdocConfiguration: TSDocConfiguration;
}

export interface IApiPackageMetadataJson {
/**
Expand Down Expand Up @@ -58,6 +63,17 @@ export interface IApiPackageMetadataJson {
* `IApiPackageMetadataJson.schemaVersion`.
*/
oldestForwardsCompatibleVersion?: ApiJsonSchemaVersion;

/**
* The TSDoc configuration that was used when analyzing the API for this package.
*
* @remarks
*
* The structure of this objet is defined by the `@microsoft/tsdoc-config` library.
* Normally this configuration is loaded from the project's tsdoc.json file. It is stored
* in the .api.json file so that doc comments can be parsed accurately when loading the file.
*/
tsdocConfig: JsonObject;
}

export interface IApiPackageJson extends IApiItemJson {
Expand Down Expand Up @@ -105,8 +121,12 @@ export interface IApiPackageSaveOptions extends IJsonFileSaveOptions {
* @public
*/
export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumentedItem)) {
private readonly _tsdocConfiguration: TSDocConfiguration;

public constructor(options: IApiPackageOptions) {
super(options);

this._tsdocConfiguration = options.tsdocConfiguration;
}

public static loadFromJsonFile(apiJsonFilename: string): ApiPackage {
Expand Down Expand Up @@ -157,11 +177,25 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
}
}

const tsdocConfiguration: TSDocConfiguration = new TSDocConfiguration();

if (versionToDeserialize >= ApiJsonSchemaVersion.V_1004) {
const tsdocConfigFile: TSDocConfigFile = TSDocConfigFile.loadFromObject(
jsonObject.metadata.tsdocConfig
);
if (tsdocConfigFile.hasErrors) {
throw new Error(`Error loading ${apiJsonFilename}:\n` + tsdocConfigFile.getErrorSummary());
}

tsdocConfigFile.configureParser(tsdocConfiguration);
}

const context: DeserializerContext = new DeserializerContext({
apiJsonFilename,
toolPackage: jsonObject.metadata.toolPackage,
toolVersion: jsonObject.metadata.toolVersion,
versionToDeserialize: versionToDeserialize
versionToDeserialize: versionToDeserialize,
tsdocConfiguration
});

return ApiItem.deserialize(jsonObject, context) as ApiPackage;
Expand All @@ -182,6 +216,18 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
return this.members as ReadonlyArray<ApiEntryPoint>;
}

/**
* The TSDoc configuration that was used when analyzing the API for this package.
*
* @remarks
*
* Normally this configuration is loaded from the project's tsdoc.json file. It is stored
* in the .api.json file so that doc comments can be parsed accurately when loading the file.
*/
public get tsdocConfiguration(): TSDocConfiguration {
return this._tsdocConfiguration;
}

/** @override */
public addMember(member: ApiEntryPoint): void {
if (member.kind !== ApiItemKind.EntryPoint) {
Expand All @@ -201,14 +247,18 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented

const packageJson: IPackageJson = PackageJsonLookup.loadOwnPackageJson(__dirname);

const tsdocConfigFile: TSDocConfigFile = TSDocConfigFile.loadFromParser(this.tsdocConfiguration);
const tsdocConfig: JsonObject = tsdocConfigFile.saveToObject();

const jsonObject: IApiPackageJson = {
metadata: {
toolPackage: options.toolPackage || packageJson.name,
// In test mode, we don't write the real version, since that would cause spurious diffs whenever
// the version is bumped. Instead we write a placeholder string.
toolVersion: options.testMode ? '[test mode]' : options.toolVersion || packageJson.version,
schemaVersion: ApiJsonSchemaVersion.LATEST,
oldestForwardsCompatibleVersion: ApiJsonSchemaVersion.OLDEST_FORWARDS_COMPATIBLE
oldestForwardsCompatibleVersion: ApiJsonSchemaVersion.OLDEST_FORWARDS_COMPATIBLE,
tsdocConfig
}
} as IApiPackageJson;
this.serializeInto(jsonObject);
Expand Down
18 changes: 17 additions & 1 deletion apps/api-extractor-model/src/model/DeserializerContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import { TSDocConfiguration } from '@microsoft/tsdoc';

export enum ApiJsonSchemaVersion {
/**
* The initial release.
Expand All @@ -25,13 +27,21 @@ export enum ApiJsonSchemaVersion {
*/
V_1003 = 1003,

/**
* Add a "tsdocConfig" field that tracks the TSDoc configuration for parsing doc comments.
*
* This is not a breaking change because an older implementation will still work correctly. The
* custom tags will be skipped over by the parser.
*/
V_1004 = 1004,

/**
* The current latest .api.json schema version.
*
* IMPORTANT: When incrementing this number, consider whether `OLDEST_SUPPORTED` or `OLDEST_FORWARDS_COMPATIBLE`
* should be updated.
*/
LATEST = V_1003,
LATEST = V_1004,

/**
* The oldest .api.json schema version that is still supported for backwards compatibility.
Expand Down Expand Up @@ -72,10 +82,16 @@ export class DeserializerContext {
*/
public readonly versionToDeserialize: ApiJsonSchemaVersion;

/**
* The TSDoc configuration for the context.
*/
public readonly tsdocConfiguration: TSDocConfiguration;

public constructor(options: DeserializerContext) {
this.apiJsonFilename = options.apiJsonFilename;
this.toolPackage = options.toolPackage;
this.toolVersion = options.toolVersion;
this.versionToDeserialize = options.versionToDeserialize;
this.tsdocConfiguration = options.tsdocConfiguration;
}
}
4 changes: 3 additions & 1 deletion apps/api-extractor/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
# DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE
#--------------------------------------------

# (Add your project-specific overrides here)
# (Add your project-specific overrides here)

!/extends/*.json
54 changes: 17 additions & 37 deletions apps/api-extractor/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Jest tests",
"program": "${workspaceFolder}/node_modules/@rushstack/heft/lib/start.js",
"cwd": "${workspaceFolder}",
"args": ["--debug", "test", "--clean"],
"console": "integratedTerminal",
"sourceMaps": true
},
{
"type": "node",
"request": "launch",
"name": "Run in specified folder",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "(your project path)",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -23,11 +29,7 @@
"name": "test-01",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-01",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -36,11 +38,7 @@
"name": "test-02",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-02",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -49,11 +47,7 @@
"name": "test-03",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-03",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -62,11 +56,7 @@
"name": "test-04",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-04",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -75,11 +65,7 @@
"name": "test-05",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-05",
"args": [
"--debug",
"run",
"--local"
],
"args": ["--debug", "run", "--local"],
"sourceMaps": true
},
{
Expand All @@ -88,13 +74,7 @@
"name": "scenario",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-scenarios",
"args": [
"--debug",
"run",
"--local",
"--config",
"./temp/configs/api-extractor-typeof.json"
],
"args": ["--debug", "run", "--local", "--config", "./temp/configs/api-extractor-typeof.json"],
"sourceMaps": true
}
]
Expand Down
Loading