in packages/just-scripts/src/tasks/apiExtractorTask.ts [144:178]
function initApiExtractor(options: ApiExtractorOptions): ApiExtractorContext | undefined {
const apiExtractorModule: typeof ApiExtractorTypes = tryRequire('@microsoft/api-extractor');
if (!apiExtractorModule) {
logger.warn('@microsoft/api-extractor package not detected. This task will have no effect.');
return;
}
if (!apiExtractorModule.Extractor.invoke) {
logger.warn('Please update your @microsoft/api-extractor package. This task will have no effect.');
return;
}
const { ExtractorConfig } = apiExtractorModule;
const { configJsonFilePath = ExtractorConfig.FILENAME, fixNewlines, onResult, ...extractorOptions } = options;
if (!fs.existsSync(configJsonFilePath)) {
const defaultConfig = path.resolve(__dirname, '../../config/apiExtractor/api-extractor.json');
logger.warn(`Config file not found for api-extractor! Please copy ${defaultConfig} to project root folder to try again`);
return;
}
const rawConfig = ExtractorConfig.loadFile(configJsonFilePath);
// Allow modification of the config
options.onConfigLoaded?.(rawConfig);
// This follows the logic from ExtractorConfig.loadFileAndPrepare
// https://github.com/microsoft/rushstack/blob/1eb3d8ccf2a87b90a1038bf464b0b73fb3c7fd78/apps/api-extractor/src/api/ExtractorConfig.ts#L455
const config = ExtractorConfig.prepare({
configObject: rawConfig,
configObjectFullPath: path.resolve(configJsonFilePath),
packageJsonFullPath: path.resolve('package.json'),
});
return { apiExtractorModule, config, extractorOptions, options };
}