Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/api-extractor/src/api/ExtractorMessageId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export enum ExtractorMessageId {
MissingGetter = 'ae-missing-getter',

/**
* "Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension.
* "The inline import path ___ cannot be resolved in the .d.ts rollup, because the rollup does not
* preserve the original file layout."
*/
UnresolvedImportPath = 'ae-unresolved-import-path',

to analyze compiler outputs with the .d.ts file extension.
* Troubleshooting tips: `https://api-extractor.com/link/dts-error`"
*/
WrongInputFileType = 'ae-wrong-input-file-type'
Expand All @@ -141,5 +146,6 @@ export const allExtractorMessageIds: Set<string> = new Set<string>([
'ae-unresolved-link',
'ae-setter-with-docs',
'ae-missing-getter',
'ae-unresolved-import-path',
'ae-wrong-input-file-type'
]);
15 changes: 15 additions & 0 deletions apps/api-extractor/src/generators/DtsEmitHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Span } from '../analyzer/Span';
import type { IndentedWriter } from './IndentedWriter';
import { SourceFileLocationFormatter } from '../analyzer/SourceFileLocationFormatter';
import { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';
import { ExtractorMessageId } from '../api/ExtractorMessageId';

/**
* Some common code shared between DtsRollupGenerator and ApiReportGenerator.
Expand Down Expand Up @@ -170,6 +171,20 @@ export class DtsEmitHelpers {
span.modification.skipAll();
span.modification.prefix = `${referencedEntity.nameForEmit}${typeArgumentsText}${separatorAfter}`;
}
} else if (ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
// The import was not resolved to a rolled up entity, so its span gets emitted verbatim. A relative
// path is meaningless in the rollup, which does not preserve the original file layout, so the
// emitted .d.ts would not compile. Report that instead of leaving the user to discover it later.
const modulePath: string = node.argument.literal.text;
if (modulePath.startsWith('.')) {
collector.messageRouter.addAnalyzerIssue(
ExtractorMessageId.UnresolvedImportPath,
`The inline import path "${modulePath}" could not be resolved, so it would be emitted unchanged` +
` into the .d.ts rollup, where it does not resolve to anything. Import the symbol at the top` +
` of the file instead of using an inline import() type.`,
astDeclaration
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"comment": "Report a new `ae-unresolved-import-path` message when an inline `import()` type with a relative path cannot be resolved, instead of silently emitting the unusable path into the .d.ts rollup.",
"type": "minor",
"packageName": "@microsoft/api-extractor"
}
],
"packageName": "@microsoft/api-extractor"
}
1 change: 1 addition & 0 deletions common/reviews/api/api-extractor.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export enum ExtractorMessageId {
PreapprovedUnsupportedType = "ae-preapproved-unsupported-type",
SetterWithDocs = "ae-setter-with-docs",
Undocumented = "ae-undocumented",
UnresolvedImportPath = "ae-unresolved-import-path",
UnresolvedInheritDocBase = "ae-unresolved-inheritdoc-base",
UnresolvedInheritDocReference = "ae-unresolved-inheritdoc-reference",
UnresolvedLink = "ae-unresolved-link",
Expand Down
Loading