Skip to content

Commit

Permalink
Handle tsconfig.json files as JSON5
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 8, 2022
1 parent 8dc796e commit c402b2c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-dryers-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/cli": patch
---

Handle tsconfig.json files as JSON5
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"graphql-ws": "5.8.2",
"change-case": "4.1.2",
"json-bigint-patch": "0.0.8",
"json5": "2.2.1",
"lodash.get": "4.4.2",
"mkdirp": "1.0.4",
"open": "7.4.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/ts-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ts from 'typescript';
import { pathExists, writeFile, writeJSON } from '@graphql-mesh/utils';
import { generateOperations } from './generate-operations';
import { GraphQLMeshCLIParams } from '..';
import { stripJSONComments } from '../utils';
import JSON5 from 'json5';

const unifiedContextIdentifier = 'MeshContext';

Expand Down Expand Up @@ -444,7 +444,7 @@ const baseDir = pathModule.join(pathModule.dirname(fileURLToPath(import.meta.url
const tsConfigPath = pathModule.join(baseDir, 'tsconfig.json');
if (await pathExists(tsConfigPath)) {
const tsConfigStr = await fs.promises.readFile(tsConfigPath, 'utf-8');
const tsConfig = JSON.parse(stripJSONComments(tsConfigStr));
const tsConfig = JSON5.parse(tsConfigStr);
if (tsConfig?.compilerOptions?.module?.toLowerCase()?.startsWith('es')) {
jobs.push(esmJob('js'));
if (fileType !== 'ts') {
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { register as tsNodeRegister } from 'ts-node';
import { register as tsConfigPathsRegister } from 'tsconfig-paths';
import { config as dotEnvRegister } from 'dotenv';
import { printSchema } from 'graphql';
import { stripJSONComments } from './utils';
import JSON5 from 'json5';

export { generateTsArtifacts, serveMesh, findAndParseConfig };

Expand Down Expand Up @@ -105,8 +105,7 @@ export async function graphqlMesh(
if (tsConfigExists) {
try {
const tsConfigStr = fs.readFileSync(tsConfigPath, 'utf-8');
const tsConfigStrWithoutComments = stripJSONComments(tsConfigStr);
const tsConfig = JSON.parse(tsConfigStrWithoutComments);
const tsConfig = JSON5.parse(tsConfigStr);
if (tsConfig.compilerOptions?.paths) {
tsConfigPathsRegister({
baseUrl: baseDir,
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/src/utils.ts

This file was deleted.

10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15534,18 +15534,18 @@ json3@^3.3.2:
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.3.tgz#7fc10e375fc5ae42c4705a5cc0aa6f62be305b81"
integrity sha512-c7/8mbUsKigAbLkD5B010BK4D9LZm7A1pNItkEwiUZRpIN66exu/e7YQWysGun+TRKaJp8MhemM+VkfWv42aCA==

json5@2.2.1, json5@^2.1.1, json5@^2.1.2, json5@^2.2.0, json5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==

json5@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe"
integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==
dependencies:
minimist "^1.2.0"

json5@^2.1.1, json5@^2.1.2, json5@^2.2.0, json5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==

jsonc-parser@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
Expand Down

1 comment on commit c402b2c

@vercel
Copy link

@vercel vercel bot commented on c402b2c Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.