From 8b71ca8420004528bd172a83a956467461a8e5bb Mon Sep 17 00:00:00 2001 From: finalchild Date: Thu, 7 Aug 2025 19:19:14 +0900 Subject: [PATCH] [api-extractor] Fix self-package import resolution in TypeScript compiler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When analyzing .d.ts files that import the package itself, TypeScript's module resolution would redirect to source .ts files instead of analyzing the build artifacts. This occurs because TypeScript tries to avoid analyzing build outputs when outDir/declarationDir are set. Fix by deleting outDir and declarationDir options from the compiler configuration, as API Extractor only uses the compiler for analysis and doesn't emit files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- apps/api-extractor/src/api/CompilerState.ts | 9 +++++++++ .../fix-self-import-resolution_2025-08-07-10-22.json | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json diff --git a/apps/api-extractor/src/api/CompilerState.ts b/apps/api-extractor/src/api/CompilerState.ts index 7c9513884c9..a14bcb1af40 100644 --- a/apps/api-extractor/src/api/CompilerState.ts +++ b/apps/api-extractor/src/api/CompilerState.ts @@ -67,6 +67,15 @@ export class CompilerState { ); } + // Delete outDir and declarationDir to prevent TypeScript from redirecting self-package + // imports to source files. When these options are set, TypeScript's module resolution + // tries to map output .d.ts files back to their source .ts files to avoid analyzing + // build outputs during compilation. However, API Extractor specifically wants to analyze + // the .d.ts build artifacts, not the source files. Since API Extractor doesn't emit any + // files, these options are unnecessary and interfere with correct module resolution. + delete commandLine.options.outDir; + delete commandLine.options.declarationDir; + const inputFilePaths: string[] = commandLine.fileNames.concat(extractorConfig.mainEntryPointFilePath); if (options && options.additionalEntryPoints) { inputFilePaths.push(...options.additionalEntryPoints); diff --git a/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json b/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json new file mode 100644 index 00000000000..6f8a769bf5a --- /dev/null +++ b/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Fix self-package import resolution by removing outDir/declarationDir from compiler options", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file