Skip to content

Commit 1079d4f

Browse files
committed
fix: fail build on typescript errors. closes #57
1 parent d18d865 commit 1079d4f

File tree

1 file changed

+50
-33
lines changed

1 file changed

+50
-33
lines changed

src/targets/typescript.ts

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,24 @@ export default async function build({
8585
(platform() === 'win32' ? '.cmd' : '');
8686

8787
if (!(await fs.pathExists(tsc))) {
88-
tsc = await which('tsc');
88+
try {
89+
tsc = await which('tsc');
8990

90-
report.warn(
91-
`Using a global version of ${chalk.blue(
92-
'tsc'
93-
)}. Consider adding ${chalk.blue('typescript')} to your ${chalk.blue(
94-
'devDependencies'
95-
)} or specifying the ${chalk.blue(
96-
'tsc'
97-
)} option for the typescript target.`
98-
);
91+
report.warn(
92+
`Using a global version of ${chalk.blue(
93+
'tsc'
94+
)}. Consider adding ${chalk.blue('typescript')} to your ${chalk.blue(
95+
'devDependencies'
96+
)} or specifying the ${chalk.blue(
97+
'tsc'
98+
)} option for the typescript target.`
99+
);
100+
} catch (e) {
101+
// Ignore
102+
}
99103
}
100104

101-
if (await fs.pathExists(tsc)) {
102-
spawn.sync(
103-
tsc,
104-
[
105-
'--pretty',
106-
'--declaration',
107-
'--emitDeclarationOnly',
108-
'--project',
109-
project,
110-
'--outDir',
111-
output,
112-
],
113-
{ stdio: 'inherit' }
114-
);
115-
116-
await del([
117-
path.join(output, project.replace(/\.json$/, '.tsbuildinfo')),
118-
]);
119-
120-
report.success(
121-
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
122-
);
123-
} else {
105+
if (!(await fs.pathExists(tsc))) {
124106
throw new Error(
125107
`The ${chalk.blue(
126108
'tsc'
@@ -133,6 +115,41 @@ export default async function build({
133115
)} option for typescript.`
134116
);
135117
}
118+
119+
const tsbuildinfo = path.join(
120+
output,
121+
project.replace(/\.json$/, '.tsbuildinfo')
122+
);
123+
124+
try {
125+
await del([tsbuildinfo]);
126+
} catch (e) {
127+
// Ignore
128+
}
129+
130+
const result = spawn.sync(
131+
tsc,
132+
[
133+
'--pretty',
134+
'--declaration',
135+
'--emitDeclarationOnly',
136+
'--project',
137+
project,
138+
'--outDir',
139+
output,
140+
],
141+
{ stdio: 'inherit' }
142+
);
143+
144+
if (result.status === 0) {
145+
await del([tsbuildinfo]);
146+
147+
report.success(
148+
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
149+
);
150+
} else {
151+
throw new Error('Failed to build definition files.');
152+
}
136153
} catch (e) {
137154
if (e.stdout) {
138155
report.error(

0 commit comments

Comments
 (0)