Skip to content

Commit

Permalink
fix: handle typescript projects better
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 12, 2020
1 parent 02cec5e commit 132b0bc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"glob": "^7.1.6",
"inquirer": "^7.0.1",
"is-git-dirty": "^1.0.0",
"json5": "^2.1.1",
"metro-react-native-babel-preset": "^0.57.0",
"yargs": "^15.0.2"
},
Expand All @@ -53,6 +54,7 @@
"@types/fs-extra": "^8.0.1",
"@types/glob": "^7.1.1",
"@types/inquirer": "^6.5.0",
"@types/json5": "^0.0.30",
"@types/yargs": "^13.0.3",
"commitlint": "^8.2.0",
"eslint": "^6.7.2",
Expand Down
73 changes: 43 additions & 30 deletions src/targets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import child_process from 'child_process';
import fs from 'fs-extra';
import del from 'del';
import JSON5 from 'json5';
import { platform } from 'os';
import { Input } from '../types';

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

try {
if (await fs.pathExists(tsconfig)) {
const config = JSON.parse(await fs.readFile(tsconfig, 'utf-8'));

if (config.compilerOptions) {
const conflicts: string[] = [];

if (config.compilerOptions.noEmit !== undefined) {
conflicts.push('compilerOptions.noEmit');
}

if (config.compilerOptions.emitDeclarationOnly !== undefined) {
conflicts.push('compilerOptions.emitDeclarationOnly');
}

if (config.compilerOptions.outDir) {
conflicts.push('compilerOptions.outDir');
}

if (config.compilerOptions.declarationDir) {
conflicts.push('compilerOptions.declarationDir');
}

if (conflicts.length) {
report.warn(
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${chalk.blue(
'tsconfig.json'
)}:${conflicts.reduce(
(acc, curr) => acc + `\n${chalk.gray('-')} ${chalk.yellow(curr)}`,
''
)}`
);
try {
const config = JSON5.parse(await fs.readFile(tsconfig, 'utf-8'));

if (config.compilerOptions) {
const conflicts: string[] = [];

if (config.compilerOptions.noEmit !== undefined) {
conflicts.push('compilerOptions.noEmit');
}

if (config.compilerOptions.emitDeclarationOnly !== undefined) {
conflicts.push('compilerOptions.emitDeclarationOnly');
}

if (config.compilerOptions.declarationDir) {
conflicts.push('compilerOptions.declarationDir');
}

if (
config.compilerOptions.outDir &&
path.join(root, config.compilerOptions.outDir) !== output
) {
conflicts.push('compilerOptions.outDir');
}

if (conflicts.length) {
report.warn(
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${chalk.blue(
'tsconfig.json'
)}:${conflicts.reduce(
(acc, curr) =>
acc + `\n${chalk.gray('-')} ${chalk.yellow(curr)}`,
''
)}`
);
}
}
} catch (e) {
report.warn(
`Couldn't parse 'tsconfig.json'. There might be validation errors.`
);
}
}

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

await del([path.join(output, 'tsconfig.tsbuildinfo')]);

report.success(
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
);
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/json5@^0.0.30":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.30.tgz#44cb52f32a809734ca562e685c6473b5754a7818"
integrity sha512-sqm9g7mHlPY/43fcSNrCYfOeX9zkTTK+euO5E6+CVijSMm5tTjkVdwdqRkY3ljjIAf8679vps5jKUoJBCLsMDA==

"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down Expand Up @@ -4322,6 +4327,13 @@ json5@^2.1.0:
dependencies:
minimist "^1.2.0"

json5@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.1.tgz#81b6cb04e9ba496f1c7005d07b4368a2638f90b6"
integrity sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ==
dependencies:
minimist "^1.2.0"

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
Expand Down

0 comments on commit 132b0bc

Please sign in to comment.