microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.82k stars 593 forks source link

[api-extractor] Allow multiple entrypoints #3557

Open mkilpatrick opened 2 years ago

mkilpatrick commented 2 years ago

mainEntryPointFilePath only allows a single entrypoint.

Let's say I have a repo that has multiple exports and types:

"exports": {
    ".": "./dist/index.js",
    "./foo": "./dist/foo/foo.js",
    "./util": "./dist/util/index.js"
  },
  "typesVersions": {
    "*": {
      "*": [
        "dist/types/src/index.d.ts"
      ],
      "foo": [
        "dist/types/src/foo/index.d.ts"
      ],
      "util": [
        "dist/types/src/util/index.d.ts"
      ]
    }
  },

I can't generate correct docs based on this. The only thing you can do is export all types at the root, but that is incorrect for this project structure.

zelliott commented 2 years ago

Relevant:

dzearing commented 1 year ago

dupe of https://github.com/microsoft/rushstack/issues/3274 as well.

vjpr commented 1 year ago

Is additionalEntryPoints suppose to allow this:

https://github.com/microsoft/rushstack/blob/main/build-tests/api-extractor-scenarios/src/runScenarios.ts#L100

derekdon commented 8 months ago

Be great to get an official steer on this.

In the meantime, I've created a single entry point in src that exports all the package.json exports which works for now:

// ./src/index.docs.ts

/**
 * API Docs index. This is used by api-extractor given our package.json exports.
 * Monitoring: https://github.com/microsoft/rushstack/issues/3557
 */
export * from './index';
export * from './exportA';
export * from './exportB';

...and reference that instead as the mainEntryPointFilePath.

{
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
  "extends": "../../../api-extractor.json",
  "mainEntryPointFilePath": "<projectFolder>/dist/dts/index.docs.d.ts"
}

Tried and failed on various workarounds.

Invalid schema. I think additionalEntryPoints is a cmd line option, but not sure it's really exposed / works.

{
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
  "extends": "../../../api-extractor.json",
  "additionalEntryPoints": [
    {
      "modulePath": "exportA",
      "filePath": "<projectFolder>/dist/dts/exportA/index.d.ts"
    },
    {
      "modulePath": "exportB",
      "filePath": "<projectFolder>/dist/dts/exportB/index.d.ts"
    }
  ]
}

Not a valid node_module or something to that effect.

{
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
  "extends": "../../../api-extractor.json",
  "bundledPackages": ["<projectFolder>/dist/dts/exportA/index.d.ts", "<projectFolder>/dist/dts/exportB/index.d.ts"]
}

The root api-extractor.json file contains a standard mainEntryPointFilePath, which is:

"mainEntryPointFilePath": "<projectFolder>/dist/dts/index.d.ts",

runspired commented 4 months ago

Is additionalEntryPoints suppose to allow this:

it feels like maybe but its not exposed to consumers it seems

Chklang commented 3 months ago

I've tried additionalEntryPoints, i've removed the "throw" in json validator lib to ignore schema validation and additional entry points are ignored. So it's not "just" not exposed to consumers.