Skip to content

Commit 132b0bc

Browse files
committed
fix: handle typescript projects better
1 parent 02cec5e commit 132b0bc

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"glob": "^7.1.6",
3535
"inquirer": "^7.0.1",
3636
"is-git-dirty": "^1.0.0",
37+
"json5": "^2.1.1",
3738
"metro-react-native-babel-preset": "^0.57.0",
3839
"yargs": "^15.0.2"
3940
},
@@ -53,6 +54,7 @@
5354
"@types/fs-extra": "^8.0.1",
5455
"@types/glob": "^7.1.1",
5556
"@types/inquirer": "^6.5.0",
57+
"@types/json5": "^0.0.30",
5658
"@types/yargs": "^13.0.3",
5759
"commitlint": "^8.2.0",
5860
"eslint": "^6.7.2",

src/targets/typescript.ts

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import child_process from 'child_process';
44
import fs from 'fs-extra';
55
import del from 'del';
6+
import JSON5 from 'json5';
67
import { platform } from 'os';
78
import { Input } from '../types';
89

@@ -19,37 +20,47 @@ export default async function build({ root, output, report }: Input) {
1920

2021
try {
2122
if (await fs.pathExists(tsconfig)) {
22-
const config = JSON.parse(await fs.readFile(tsconfig, 'utf-8'));
23-
24-
if (config.compilerOptions) {
25-
const conflicts: string[] = [];
26-
27-
if (config.compilerOptions.noEmit !== undefined) {
28-
conflicts.push('compilerOptions.noEmit');
29-
}
30-
31-
if (config.compilerOptions.emitDeclarationOnly !== undefined) {
32-
conflicts.push('compilerOptions.emitDeclarationOnly');
33-
}
34-
35-
if (config.compilerOptions.outDir) {
36-
conflicts.push('compilerOptions.outDir');
37-
}
38-
39-
if (config.compilerOptions.declarationDir) {
40-
conflicts.push('compilerOptions.declarationDir');
41-
}
42-
43-
if (conflicts.length) {
44-
report.warn(
45-
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${chalk.blue(
46-
'tsconfig.json'
47-
)}:${conflicts.reduce(
48-
(acc, curr) => acc + `\n${chalk.gray('-')} ${chalk.yellow(curr)}`,
49-
''
50-
)}`
51-
);
23+
try {
24+
const config = JSON5.parse(await fs.readFile(tsconfig, 'utf-8'));
25+
26+
if (config.compilerOptions) {
27+
const conflicts: string[] = [];
28+
29+
if (config.compilerOptions.noEmit !== undefined) {
30+
conflicts.push('compilerOptions.noEmit');
31+
}
32+
33+
if (config.compilerOptions.emitDeclarationOnly !== undefined) {
34+
conflicts.push('compilerOptions.emitDeclarationOnly');
35+
}
36+
37+
if (config.compilerOptions.declarationDir) {
38+
conflicts.push('compilerOptions.declarationDir');
39+
}
40+
41+
if (
42+
config.compilerOptions.outDir &&
43+
path.join(root, config.compilerOptions.outDir) !== output
44+
) {
45+
conflicts.push('compilerOptions.outDir');
46+
}
47+
48+
if (conflicts.length) {
49+
report.warn(
50+
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${chalk.blue(
51+
'tsconfig.json'
52+
)}:${conflicts.reduce(
53+
(acc, curr) =>
54+
acc + `\n${chalk.gray('-')} ${chalk.yellow(curr)}`,
55+
''
56+
)}`
57+
);
58+
}
5259
}
60+
} catch (e) {
61+
report.warn(
62+
`Couldn't parse 'tsconfig.json'. There might be validation errors.`
63+
);
5364
}
5465
}
5566

@@ -73,6 +84,8 @@ export default async function build({ root, output, report }: Input) {
7384
output,
7485
]);
7586

87+
await del([path.join(output, 'tsconfig.tsbuildinfo')]);
88+
7689
report.success(
7790
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
7891
);

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,11 @@
15701570
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
15711571
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
15721572

1573+
"@types/json5@^0.0.30":
1574+
version "0.0.30"
1575+
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.30.tgz#44cb52f32a809734ca562e685c6473b5754a7818"
1576+
integrity sha512-sqm9g7mHlPY/43fcSNrCYfOeX9zkTTK+euO5E6+CVijSMm5tTjkVdwdqRkY3ljjIAf8679vps5jKUoJBCLsMDA==
1577+
15731578
"@types/minimatch@*":
15741579
version "3.0.3"
15751580
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -4322,6 +4327,13 @@ json5@^2.1.0:
43224327
dependencies:
43234328
minimist "^1.2.0"
43244329

4330+
json5@^2.1.1:
4331+
version "2.1.1"
4332+
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.1.tgz#81b6cb04e9ba496f1c7005d07b4368a2638f90b6"
4333+
integrity sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ==
4334+
dependencies:
4335+
minimist "^1.2.0"
4336+
43254337
jsonfile@^4.0.0:
43264338
version "4.0.0"
43274339
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"

0 commit comments

Comments
 (0)