Skip to content

[api-extractor] Add a "--diagnostics" command-line option - #1359

Merged
Pete Gonzalez (octogonz) merged 7 commits into
masterfrom
octogonz/ae-diagnostics
Jul 9, 2019
Merged

Pete Gonzalez (octogonz) merged 7 commits into
masterfrom
octogonz/ae-diagnostics

Conversation

@octogonz

Copy link
Copy Markdown
Collaborator

This PR adds a new command-line option --diagnostics and corresponding API IExtractorInvokeOptions.showDiagnostics to help when troubleshooting problems with API Extractor.

In the initial implementation, --diagnostics adds the following information:

  • The final ExtractorConfig properties
  • The final compiler configuration
  • The list of root filenames provided to the compiler
  • A list of all source files analyzed by the compiler
  • It also enables --verbose logging

The diagnostic information is printed to the ExtractorMessageCategory.Console stream as delimited blocks with a DIAGNOSTIC: header.

Below is an sample output when invoking API Extractor on the api-extractor-test-01 test project:

api-extractor 7.2.2  - https://api-extractor.com/

Using configuration from D:\GitRepos\wbt\build-tests\api-extractor-test-01\config\api-extractor.json

============================================================
DIAGNOSTIC: Final prepared ExtractorConfig
============================================================
{
  "projectFolder": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01",
  "packageJson": {
    "bin": null,
    "dependencies": {
      "@microsoft/api-extractor": "7.2.2",
      "@types/jest": "23.3.11",
      "@types/node": "8.5.8",
      "fs-extra": "~7.0.1",
      "typescript": "~3.1.6"
    },
    "description": "Building this project is a regression test for api-extractor",
    "devDependencies": {
      "@types/long": "4.0.0",
      "long": "^4.0.0"
    },
    "homepage": null,
    "license": null,
    "main": "lib/index.js",
    "name": "api-extractor-test-01",
    "optionalDependencies": null,
    "peerDependencies": null,
    "private": true,
    "scripts": {
      "build": "node build.js"
    },
    "typings": "dist/api-extractor-test-01.d.ts",
    "tsdoc": {
      "tsdocFlavor": "AEDoc"
    },
    "tsdocMetadata": null,
    "version": "1.0.0"
  },
  "packageFolder": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01",
  "mainEntryPointFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\lib\\index.d.ts",
  "tsconfigFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\tsconfig.json",
  "overrideTsconfig": null,
  "skipLibCheck": false,
  "apiReportEnabled": true,
  "reportFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\etc\\api-extractor-test-01.api.md",
  "reportTempFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\temp\\api-extractor-test-01.api.md",
  "docModelEnabled": true,
  "apiJsonFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\temp\\api-extractor-test-01.api.json",
  "rollupEnabled": true,
  "untrimmedFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\dist\\api-extractor-test-01.d.ts",
  "betaTrimmedFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\dist\\api-extractor-test-01-beta.d.ts",
  "publicTrimmedFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\dist\\api-extractor-test-01-public.d.ts",
  "omitTrimmingComments": false,
  "tsdocMetadataEnabled": true,
  "tsdocMetadataFilePath": "D:\\GitRepos\\wbt\\build-tests\\api-extractor-test-01\\dist\\tsdoc-metadata.json",
  "messages": {
    "compilerMessageReporting": {
      "default": {
        "logLevel": "warning"
      }
    },
    "extractorMessageReporting": {
      "default": {
        "logLevel": "warning"
      },
      "ae-forgotten-export": {
        "logLevel": "warning",
        "addToApiReportFile": true
      },
      "ae-incompatible-release-tags": {
        "logLevel": "warning",
        "addToApiReportFile": true
      },
      "ae-internal-missing-underscore": {
        "logLevel": "warning",
        "addToApiReportFile": true
      },
      "ae-unresolved-inheritdoc-reference": {
        "logLevel": "warning",
        "addToApiReportFile": true
      },
      "ae-unresolved-inheritdoc-base": {
        "logLevel": "warning",
        "addToApiReportFile": true
      }
    },
    "tsdocMessageReporting": {
      "default": {
        "logLevel": "warning"
      }
    }
  },
  "testMode": true
}
============================================================

============================================================
DIAGNOSTIC: Compiler options
============================================================
{
  "target": 2,
  "forceConsistentCasingInFileNames": true,
  "module": 1,
  "declaration": true,
  "sourceMap": true,
  "declarationMap": true,
  "experimentalDecorators": true,
  "strictNullChecks": true,
  "esModuleInterop": true,
  "types": [
    "node",
    "jest"
  ],
  "lib": [
    "lib.es5.d.ts",
    "lib.scripthost.d.ts",
    "lib.es2015.collection.d.ts",
    "lib.es2015.promise.d.ts",
    "lib.es2015.iterable.d.ts",
    "lib.dom.d.ts"
  ],
  "outDir": "D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib",
  "configFilePath": null
}
============================================================

============================================================
DIAGNOSTIC: Root filenames
============================================================
D:/GitRepos/wbt/build-tests/api-extractor-test-01/typings/tsd.d.ts
D:\GitRepos\wbt\build-tests\api-extractor-test-01\lib\index.d.ts
============================================================

============================================================
DIAGNOSTIC: Files analyzed by compiler
============================================================
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es5.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.dom.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.scripthost.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2015.iterable.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2015.promise.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2015.symbol.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/typescript/3.4.5/node_modules/typescript/lib/lib.es2018.intl.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/typings/tsd.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/@types/jest/23.3.11/node_modules/@types/jest/index.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/AbstractClass.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/AbstractClass2.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/AccessModifiers.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ClassWithTypeLiterals.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/DeclarationMerging.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/Enums.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/DefaultExportEdgeCase.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/@types/long/4.0.0/node_modules/@types/long/index.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/EcmaScriptSymbols.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ForgottenExportConsumer1.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ForgottenExportConsumer2.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ForgottenExportConsumer3.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/IInterfaceAsDefaultExport.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ReexportedClass1.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ReexportedClass2.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ReexportedClass3/index.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ReexportedClass3/ReexportedClass3.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/TypeReferencesInAedoc.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/ReferenceLibDirective.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/variableDeclarations.d.ts
D:/GitRepos/wbt/build-tests/api-extractor-test-01/lib/index.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/@types/node/8.5.8/node_modules/@types/node/inspector.d.ts
D:/GitRepos/wbt/common/temp/node_modules/.registry.npmjs.org/@types/node/8.5.8/node_modules/@types/node/index.d.ts
============================================================

Writing: D:\GitRepos\wbt\build-tests\api-extractor-test-01\temp\api-extractor-test-01.api.json
The API report is up to date: temp/api-extractor-test-01.api.md
Writing package typings: D:\GitRepos\wbt\build-tests\api-extractor-test-01\dist\api-extractor-test-01-public.d.ts
Writing package typings: D:\GitRepos\wbt\build-tests\api-extractor-test-01\dist\api-extractor-test-01-beta.d.ts
Writing package typings: D:\GitRepos\wbt\build-tests\api-extractor-test-01\dist\api-extractor-test-01.d.ts

API Extractor completed successfully

…geFolderPath" to be undefined (e.g. if there isn't one)
…stics" command-line option that we will use to print diagnostic output;

Refactor MessageRouter to get initialized in Extractor.ts instead of Collector.ts
return outputObject;
}

return undefined;

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.

Do you want to return something more useful if the parameter is a function. Maybe <function>?

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.

Not really. The idea is that this function crawls through an object and picks out the printable stuff, ignoring any other members.

Ideally I would have just used JSON.serialize(); however, we need to dump the object returned by TypeScript's ts.program.getCompilerOptions(). I was paranoid that future compiler releases might add some methods to that object.

* or `undefined` if the input cannot be represented as JSON
*/
// tslint:disable-next-line:no-any
public static buildJsonDumpObject(input: any): any | undefined {

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.

It'd be useful to have some unit tests for this.

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 considered promoting this to a real utility in node-core-library, in which case I definitely would have added tests.

However, the concept of buildJsonDumpObject() seems lazy and half-baked. A "correct" implementation would use JSON.serialize() for actual data objects, or for other objects we should implement a proper printer/serializer (that knows all the members and how to format them). In my example output, you can see that dumped options aren't very readable (e.g. "target": 2).

I took the lazy approach because I didn't want to spend too much time on this --diagnostics feature initially. I know that we need some way to investigate API Extractor issues without resorting to a debugger. But this PR is merely a guess about what logging is actually useful.

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.

2 participants