How to use @microsoft/api-extractor - 10 common examples

To help you get started, we’ve selected a few @microsoft/api-extractor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / rushstack / build-tests / api-extractor-scenarios / src / runScenarios.ts View on Github external
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;
        }
      },
github microsoft / rushstack / build-tests / api-extractor-scenarios / src / runScenarios.ts View on Github external
}

  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;
        }
      },
      compilerState
    });
github microsoft / rushstack / build-tests / api-extractor-scenarios / src / runScenarios.ts View on Github external
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;
        }
      },
      compilerState
github microsoft / rushstack / build-tests / api-extractor-scenarios / src / runScenarios.ts View on Github external
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;
        }
      },
      compilerState
github vuejs / vue-next / scripts / build.js View on Github external
)

  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')
          })
        )
        await fs.writeFile(dtsPath, existing + '\n' + toAdd.join('\n'))
      }
github algolia / algoliasearch-client-javascript / scripts / build.js View on Github external
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')}`);
    }
    console.log(chalk.bold(chalk.green(`API Extractor completed successfully.`)));
github algolia / algoliasearch-client-javascript / scripts / build.js View on Github external
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')}`);
    }
github vuejs / vue-next / scripts / build.js View on Github external
.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')
          })
github SkygearIO / skygear-SDK-JS / scripts / dts.js View on Github external
const lines = fs
    .readFileSync(dtsPath, { encoding: "utf8" })
    .split("\n")
    // Remove lines that reference @skygear/core
    // because we are going to inline its index.d.ts
    .filter(line => !/@skygear\/core/.test(line));
  const content =
    fs.readFileSync(coreDtsPath, { encoding: "utf8" }) + lines.join("\n");
  fs.writeFileSync(dtsPath, content);
}
fs.unlinkSync(coreDtsPath);

// Generate api.json
for (const p of publishedPackages) {
  const entrypoint = path.join(projectRoot, `packages/${p}/index.d.ts`);
  const configObject = ExtractorConfig.loadFile(
    path.join(projectRoot, "api-extractor.json")
  );
  configObject.mainEntryPointFilePath = entrypoint;
  configObject.projectFolder = path.join(projectRoot, `packages/${p}`);
  configObject.docModel.enabled = true;
  configObject.docModel.apiJsonFilePath = path.join(
    projectRoot,
    `temp/${p}.api.json`
  );

  const extractorConfig = ExtractorConfig.prepare({
    configObject,
    packageJsonFullPath: path.join(projectRoot, `packages/${p}/package.json`),
  });

  const extractorResult = Extractor.invoke(extractorConfig, {
github esfx / esfx / scripts / docs / patchApiExtractor.js View on Github external
super.serializeInto(jsonObject);
        jsonObject.aliasTypeTokenRange = this.aliasTypeExcerpt.tokenRange;
    }
};

// @ts-ignore
ApiTypeAlias_1.ApiTypeAlias = ApiTypeAlias;
api_extractor_model_1.ApiTypeAlias = ApiTypeAlias;

/**
 * @param {AstDeclaration} astDeclaration
 * @param {string?} exportedName
 * @param {ApiItemContainerMixin} parentApiItem
 */
// @ts-ignore
ApiModelGenerator.prototype._processApiTypeAlias = function(astDeclaration, exportedName, parentApiItem) {
    console.log("ApiModelGenerator.prototype._processApiTypeAlias");
    const name = !!exportedName ? exportedName : astDeclaration.astSymbol.localName;
    const canonicalReference = ApiTypeAlias.getCanonicalReference(name);

    let apiTypeAlias = /** @type {ApiTypeAlias?} */(parentApiItem.tryGetMember(canonicalReference));
    if (apiTypeAlias === undefined) {
      const typeAliasDeclaration = /** @type {ts.TypeAliasDeclaration} */(astDeclaration.declaration);
      const nodesToCapture = [];
      // @ts-ignore
      const aliasTypeTokenRange = ExcerptBuilder.createEmptyTokenRange();
      nodesToCapture.push({ node: typeAliasDeclaration.type, tokenRange: aliasTypeTokenRange });

      const excerptTokens = ExcerptBuilder.build({
        startingNode: astDeclaration.declaration,
        nodesToCapture
      });