diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index ab302606df..f88b30d1fd 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -23,6 +23,7 @@ import { dirname, join, } from 'path'; +import prettier from 'prettier'; import fs from 'fs-extra'; import { Extractor, @@ -61,6 +62,27 @@ PackageJsonLookup.prototype.tryGetPackageJsonFilePathFor = function tryGetPackag return old.call(this, path); }; +/** + * Another monkey patch where we apply prettier to the API reports. This has to be patched into + * the middle of the process as API Extractor does a comparison of the contents of the old + * and new files during generation. This inserts the formatting just before that comparison. + */ +const { + ApiReportGenerator, +} = require('@microsoft/api-extractor/lib/generators/ApiReportGenerator'); + +const originalGenerateReviewFileContent = + ApiReportGenerator.generateReviewFileContent; +ApiReportGenerator.generateReviewFileContent = function decoratedGenerateReviewFileContent( + ...args +) { + const content = originalGenerateReviewFileContent.apply(this, args); + return prettier.format(content, { + ...require('@spotify/prettier-config'), + parser: 'markdown', + }); +}; + const PACKAGE_ROOTS = ['packages', 'plugins']; const SKIPPED_PACKAGES = [