Skip to content
Closed
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
29 changes: 18 additions & 11 deletions code/renderers/react/src/componentManifest/reactDocgenTypescript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname } from 'node:path';
import { dirname, resolve } from 'node:path';

import {
type ComponentDoc,
Expand Down Expand Up @@ -192,18 +192,25 @@ 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) {
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(
Expand All @@ -217,7 +224,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,
};
Expand Down
Loading