Skip to content

Commit

Permalink
fix: Parse tsconfig for static type generation (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLeedham committed Sep 24, 2021
1 parent 143d4ef commit 27d7158
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/getStaticTypes.js
Expand Up @@ -4,6 +4,7 @@ const keyBy = require('lodash/keyBy');
const mapValues = require('lodash/mapValues');
const fs = require('fs');
const ts = require('typescript');
const path = require('path');

const stringRegex = /^"(.*)"$/;
const parsePropType = (propType) => {
Expand All @@ -23,6 +24,7 @@ module.exports = async (playroomConfig) => {
} = playroomConfig;

const tsConfigPath = await findUp('tsconfig.json', { cwd });
const basePath = path.dirname(tsConfigPath);

if (!tsConfigPath) {
return {};
Expand All @@ -38,12 +40,25 @@ module.exports = async (playroomConfig) => {
throw error;
}

const { options, errors } = ts.parseJsonConfigFileContent(
config,
ts.sys,
basePath,
{},
tsConfigPath
);

if (errors && errors.length) {
console.error('Error parsing tsConfig file.');
throw errors[0];
}

try {
const files = await fastGlob(typeScriptFiles, { cwd, absolute: true });
const types = require('react-docgen-typescript')
.withCompilerOptions(
{
...config.compilerOptions,
...options,
noErrorTruncation: true,
},
{
Expand Down

0 comments on commit 27d7158

Please sign in to comment.