Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO. The api-extractor CLI command forces us into their docs generation and will error.
// By invoking the node API we avoid this.
// But we also swallow errors.
// See https://github.com/Microsoft/web-build-tools/issues/920
const ApiExtractor = require("@microsoft/api-extractor");
const NodeCoreLib = require("@microsoft/node-core-library");
const config = NodeCoreLib.JsonFile.loadAndValidate(
"api-extractor.json",
ApiExtractor.Extractor.jsonSchema
);
// This interface provides additional runtime state that is NOT part of the config file
const options = {
localBuild: process.argv.indexOf("--ship") < 0
};
const extractor = new ApiExtractor.Extractor(config, options);
extractor.processProject();
validationRules: {
missingReleaseTags: 'allow'
}
};
// This interface provides additional runtime state
// that is NOT part of the config file
const options = {
// Indicates that API Extractor is running as part of a local build,
// e.g. on developer's machine. For example, if the *.api.ts output file
// has differences, it will be automatically overwritten for a
// local build, whereas this should report an error for a production build.
localBuild: process.argv.indexOf('--ship') < 0
};
const extractor = new Extractor(config, options);
extractor.analyzeProject();
},
project: {
entryPointSourceFile: 'lib/index.d.ts'
},
validationRules: {
missingReleaseTags: 'allow'
}
};
// This interface provides additional runtime state
// that is NOT part of the config file
const extractorOptions = {
localBuild: options.args && options.args.indexOf('--local') >= 0
};
const extractor = new Extractor(config, extractorOptions);
const success = extractor.processProject();
if (!success) {
throw 'The public API file is out of date. Please run "npm run update-api" and commit the updated API file.';
}
};
public invoke(): Promise {
try {
const extractorOptions: IExtractorOptions = {
...this._extractorOptions,
customLogger: {
logVerbose: this._terminal.writeVerboseLine.bind(this._terminal),
logInfo: this._terminal.writeLine.bind(this._terminal),
logWarning: this._terminal.writeWarningLine.bind(this._terminal),
logError: this._terminal.writeErrorLine.bind(this._terminal)
},
typescriptCompilerFolder: ToolPaths.typescriptPackagePath
};
const extractor: Extractor = new Extractor(this._extractorConfig, extractorOptions);
// NOTE: processProject() returns false if errors or warnings occurred, however we
// already handle this above via our customLogger
extractor.processProject();
return Promise.resolve();
} catch (e) {
return Promise.reject(e);
}
}
}
publishFolderForBeta: this.taskConfig.publishFolderForBeta,
publishFolderForPublic: this.taskConfig.publishFolderForPublic
};
}
const extractorOptions: IExtractorOptions = {
localBuild: !this.buildConfig.production,
customLogger: {
logVerbose: (message: string) => this.logVerbose(message),
logInfo: (message: string) => this.log(message),
logWarning: (message: string) => this.logWarning(message),
logError: (message: string) => this.logError(message)
}
};
const extractor: Extractor = new Extractor(extractorConfig, extractorOptions);
// NOTE: processProject() returns false if errors or warnings occurred, however we
// already handle this above via our customLogger
extractor.processProject();
} catch (e) {
completeCallback(e.message);
return;
}
completeCallback();
}
constructor(private compilerOptions: ts.CompilerOptions, apiErrorHandler?: ApiErrorHandler) {
/**
* We need to ignore @types in these tests
* @see https://github.com/Microsoft/web-build-tools/wiki/API-Extractor-~-Enabling-for-your-project
*/
this.compilerOptions.typeRoots = ["./"];
this.extractor = new Extractor({
compilerOptions: this.compilerOptions,
errorHandler: apiErrorHandler
});
}