scripts/api-extractor: run prettier on generated API reports

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-07-12 11:19:31 +02:00
parent 1a6362b423
commit e87aa59df3
+22
View File
@@ -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 = [