-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api extractor] export * from 'package' does not export the api surface of the external #1791
Comments
It might be related to #1474. SPFx was tracking that issue to handle wildcard exports of Fabric from a curated Fabric bundle. |
@dzearing I feel like this one is "by design". When export * from 'package-b'; ...the actual exported surface of For example, if Also, suppose export class Example {
private _x: number = 123;
} You might get a TypeScript error when you do this in the consumer project: import { Example as E1 } from 'package-a';
import { Example as E2 } from 'package-b';
let x: E1 = new E1();
let y: E2 = x; // compiler error, types are not compatible (Let me know if I'm misunderstanding something about this request.) |
That's a good point @octogonz. The API surface can shift depending on the point in time the end user npm installed and the dependency's version. But then, what I'm looking at API extractor to do is to warn the dev about downstream API shifts as soon as we bump versions. I want to know that a shift in one package affects another. I'm not necessarily expecting it to be forever perfect, but at least at a point in time a "complete" picture of the API surface. |
I see, so this is really about API reporting, not about rollups or documentation. And really about detecting breaks caused indirectly by dependencies. It makes sense as a feature. But I think we would not want to clutter up package-a.api.md with a bunch of declarations from an external project. Their signatures aren't directly under your control, and a loose SemVer range can make the signatures unpredictable. Thus this seems like qualitatively different information that maybe belongs in its own file. What if we introduced a setting like The concept would be:
Does that approach make sense to you? |
@octogonz wow time flies! So, yes that makes sense completely. We should separate what a package actually defines from what it simply re-exports. I think a flag like that would be great, and if it detects errors, like duplicated exports or removal of named exports, even if just a point in time detection, errors thrown would be very welcome. I've come to my senses on Even when your libraries are in the same mono-repo, even when you follow semver correctly, even when you're careful to avoid breaking your contact, you can still end up adding named exports to multiple sub-libraries completely validly, and introduce export duplication in the suite package. This can result in conflicts downstream. I think maybe a lint rule enforcing no |
I'm in favor of that. 👍👍 Even if people sometimes need I need to add another rule to |
Made a proposal here: typescript-eslint/typescript-eslint#3992 |
Turns out this can be linted using this: "no-restricted-syntax": [
"error",
{
"selector": "ExportAllDeclaration[source.value=/^[^.]{1}.+$/]",
"message": "No exporting star from external packages, {insert explanation}"
}
] |
We implemented no-export-all rule here: https://github.com/microsoft/rnx-kit/tree/main/packages/eslint-plugin |
I'm going to close this as I don't think there's additional actionable work for api-extractor on this issue. |
Is this a feature or a bug?
(Maybe feature request, maybe bug?)
I believe this is a known issue but can't find the bug tracking it.
PackageA:
index.ts exports * from 'PackageB'
Expected in api json:
The api surface from PackageB (and recursively, if PackageB exports * from PackageC.
Resulted in the api json:
The text was updated successfully, but these errors were encountered: