Skip to content

Commit

Permalink
fix(script): use typescript to load tsconfig files
Browse files Browse the repository at this point in the history
These files aren't actually JSON as they can have trailing commas and comments, so let TS load them for us.
  • Loading branch information
eventualbuddha committed Jun 7, 2022
1 parent 43010bc commit 1bbd565
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions script/src/validate-monorepo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function main({ stdout, stderr }: IO): Promise<number> {
);

const tsconfigPath = join(pkg, 'tsconfig.json');
const tsconfig = await maybeReadTsconfig(tsconfigPath);
const tsconfig = maybeReadTsconfig(tsconfigPath);

if (!tsconfig) {
stderr.write(`${tsconfigPath}: missing TypeScript configuration\n`);
Expand All @@ -76,7 +76,7 @@ export async function main({ stdout, stderr }: IO): Promise<number> {
}

const tsconfigBuildPath = join(pkg, 'tsconfig.build.json');
const tsconfigBuild = await maybeReadTsconfig(tsconfigBuildPath);
const tsconfigBuild = maybeReadTsconfig(tsconfigBuildPath);

function reportValidationIssue(issue: ValidationIssue) {
switch (issue.kind) {
Expand Down
9 changes: 4 additions & 5 deletions script/src/validate-monorepo/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export type ValidationIssue =
| TsconfigInvalidPropertyValueIssue
| TsconfigMissingReferenceIssue;

export async function maybeReadTsconfig(
filepath: string
): Promise<Tsconfig | undefined> {
return await maybeReadJson(filepath);
export function maybeReadTsconfig(filepath: string): Tsconfig | undefined {
const { config, error } = ts.readConfigFile(filepath, ts.sys.readFile);
return error ? undefined : config;
}

export async function maybeReadPackageJson(
Expand Down Expand Up @@ -176,7 +175,7 @@ export async function* checkTsconfigMatchesPackageJson(
);

if (
(await maybeReadTsconfig(expectedWorkspaceDependencyTsconfigBuildPath)) &&
maybeReadTsconfig(expectedWorkspaceDependencyTsconfigBuildPath) &&
!tsconfigReferencesPaths.has(expectedWorkspaceDependencyTsconfigBuildPath)
) {
yield {
Expand Down

0 comments on commit 1bbd565

Please sign in to comment.