From bbe4cbd49531ab61afa032b98844cddbc69a34f9 Mon Sep 17 00:00:00 2001 From: Alam Date: Sun, 29 Mar 2026 18:57:40 +0800 Subject: [PATCH 1/3] React: Respect tsconfigPath option in react-docgen-typescript parser --- .../src/componentManifest/reactDocgenTypescript.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts index 8a9304fb16fe..1c4d2ce977d9 100644 --- a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts +++ b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts @@ -1,4 +1,4 @@ -import { dirname } from 'node:path'; +import { dirname, resolve } from 'node:path'; import { type ComponentDoc, @@ -192,7 +192,12 @@ async function getParser(userOptions?: ParserOptions) { } if (!parser) { - const configPath = findTsconfigPath(process.cwd()); + // If the user provided a tsconfigPath, use it instead of auto-detecting + const { tsconfigPath: customTsconfigPath, ...restUserOptions } = (userOptions ?? {}) as + ParserOptions & { tsconfigPath?: string }; + const configPath = customTsconfigPath + ? resolve(process.cwd(), customTsconfigPath) + : findTsconfigPath(process.cwd()); cachedCompilerOptions = { noErrorTruncation: true, strict: true }; if (configPath) { @@ -217,7 +222,7 @@ async function getParser(userOptions?: ParserOptions) { const parserOptions: ParserOptions = { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, - ...userOptions, + ...restUserOptions, // Always force savePropValueAsString so default values are in a consistent format savePropValueAsString: true, }; From 300233a73778dad85682379ee1aac77d46915a88 Mon Sep 17 00:00:00 2001 From: Alam Date: Mon, 30 Mar 2026 08:54:43 +0000 Subject: [PATCH 2/3] chore: fix formatting --- .../react/src/componentManifest/reactDocgenTypescript.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts index 1c4d2ce977d9..3569122a3331 100644 --- a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts +++ b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts @@ -193,8 +193,8 @@ async function getParser(userOptions?: ParserOptions) { if (!parser) { // If the user provided a tsconfigPath, use it instead of auto-detecting - const { tsconfigPath: customTsconfigPath, ...restUserOptions } = (userOptions ?? {}) as - ParserOptions & { tsconfigPath?: string }; + const { tsconfigPath: customTsconfigPath, ...restUserOptions } = (userOptions ?? + {}) as ParserOptions & { tsconfigPath?: string }; const configPath = customTsconfigPath ? resolve(process.cwd(), customTsconfigPath) : findTsconfigPath(process.cwd()); From bfaa03bed7d4da02fba6ddf22a0c39ba979ecd10 Mon Sep 17 00:00:00 2001 From: Alam Date: Mon, 30 Mar 2026 09:23:18 +0000 Subject: [PATCH 3/3] handle tsconfig read errors gracefully --- .../componentManifest/reactDocgenTypescript.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts index 3569122a3331..bd38a3f70543 100644 --- a/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts +++ b/code/renderers/react/src/componentManifest/reactDocgenTypescript.ts @@ -201,14 +201,16 @@ async function getParser(userOptions?: ParserOptions) { cachedCompilerOptions = { noErrorTruncation: true, strict: true }; if (configPath) { - const { config } = typescript.readConfigFile(configPath, typescript.sys.readFile); - const parsed = typescript.parseJsonConfigFileContent( - config, - typescript.sys, - dirname(configPath) - ); - cachedCompilerOptions = { ...parsed.options, noErrorTruncation: true }; - cachedFileNames = parsed.fileNames; + const { config, error } = typescript.readConfigFile(configPath, typescript.sys.readFile); + if (!error && config) { + const parsed = typescript.parseJsonConfigFileContent( + config, + typescript.sys, + dirname(configPath) + ); + cachedCompilerOptions = { ...parsed.options, noErrorTruncation: true }; + cachedFileNames = parsed.fileNames; + } } const program = typescript.createProgram(