Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;
JsonFile.save(apiExtractorJson, apiExtractorJsonPath, { ensureFolderExists: true });
}
let compilerState: CompilerState | undefined = undefined;
let anyErrors: boolean = false;
process.exitCode = 1;
for (const scenarioFolderName of buildConfig.scenarioFolderNames) {
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;
console.log('Scenario: ' + scenarioFolderName);
// Run the API Extractor command-line
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);
if (!compilerState) {
compilerState = CompilerState.create(extractorConfig, {
additionalEntryPoints: entryPoints
});
}
const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true,
messageCallback: (message: ExtractorMessage) => {
if (message.messageId === ConsoleMessageId.ApiReportCreated) {
// This script deletes the outputs for a clean build, so don't issue a warning if the file gets created
message.logLevel = ExtractorLogLevel.None;
}
},
async function buildDefinition(target, config = '') {
const pkgDir = path.resolve(`packages/${target}`);
const pkg = require(`${pkgDir}/package.json`);
console.log();
console.log(chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`)));
// build types
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor');
const extractorConfigPath = path.resolve(
pkgDir,
`api-extractor${config ? `-${config}` : ''}.json`
);
const extractorConfig = ExtractorConfig.loadFileAndPrepare(extractorConfigPath);
const result = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true,
});
if (result.succeeded) {
if (pkg.buildOptions && pkg.buildOptions.dts) {
const dtsPath = path.resolve(pkgDir, pkg.types);
const existing = await fs.readFile(dtsPath, 'utf-8');
const toAdd = await Promise.all(
pkg.buildOptions.dts.map(file => {
return fs.readFile(path.resolve(pkgDir, file), 'utf-8');
})
);
await fs.writeFile(dtsPath, `${existing}\n${toAdd.join('\n')}`);
}
.join(',')
],
{ stdio: 'inherit' }
)
if (buildTypes && pkg.types) {
console.log()
console.log(
chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`))
)
// build types
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor')
const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`)
const extractorConfig = ExtractorConfig.loadFileAndPrepare(
extractorConfigPath
)
const result = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true
})
if (result.succeeded) {
// concat additional d.ts to rolled-up dts (mostly for JSX)
if (pkg.buildOptions && pkg.buildOptions.dts) {
const dtsPath = path.resolve(pkgDir, pkg.types)
const existing = await fs.readFile(dtsPath, 'utf-8')
const toAdd = await Promise.all(
pkg.buildOptions.dts.map(file => {
return fs.readFile(path.resolve(pkgDir, file), 'utf-8')
})
packages.forEach(json => {
const relativePath = getRelativePathFromJson(json);
const path = baseDir(relativePath, 'api-extractor.json');
const config = ExtractorConfig.loadFileAndPrepare(path);
const result = Extractor.invoke(config, {
localBuild: true,
showVerboseMessages: true,
typescriptCompilerFolder: baseDir('node_modules', 'typescript'),
});
if (result.succeeded) {
console.info(
`API Extractor completed successfully with ${result.warningCount} warnings: ${json.name}`,
);
} else {
console.error(
`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings: ${json.name}`,
);
process.exitCode = 1;
}
function outputDeclarations() {
console.log('Starting generation of typings');
const apiExtractorConfig = ExtractorConfig.loadFileAndPrepare('./api-extractor.json');
const extractorResult = Extractor.invoke(apiExtractorConfig, {});
if (!extractorResult.succeeded) {
throw new Error('Typing extraction failed');
}
console.log('Typings generated');
}