Skip to content

Commit e7ace91

Browse files
Refactoring
1 parent ef78a4a commit e7ace91

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

apps/demos/utils/ts-to-js-converter/converter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,23 @@ const pipeSource = async (
7979
};
8080

8181
const execTsc = async (directory: string, args: string[]): Promise<string> => new Promise((resolve, reject) => {
82-
const proc = cps.spawn('tsc', args);
82+
const proc = cps.spawn('tsc', args, { cwd: directory });
8383
let stdout = '';
8484
let stderr = '';
8585
proc.stdout.on('data', (data: Buffer) => { stdout += data.toString(); });
8686
proc.stderr.on('data', (data: Buffer) => { stderr += data.toString(); });
87-
proc.on('close', (code: number) => {
87+
proc.on('error', (err: Error) => {
88+
// eslint-disable-next-line prefer-promise-reject-errors
89+
reject(`tsc failed to spawn: ${err.message}`);
90+
});
91+
proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {
92+
if (signal !== null) {
93+
// eslint-disable-next-line prefer-promise-reject-errors
94+
return reject(`tsc killed by signal ${signal}\n${stderr}\n${stdout}`);
95+
}
8896
if (code !== 0) {
8997
// eslint-disable-next-line prefer-promise-reject-errors
90-
return reject(`Exit code ${code}\n${stderr}\n${stdout}`);
98+
return reject(`tsc exited with code ${code}\n${stderr}\n${stdout}`);
9199
}
92100
return resolve(stdout);
93101
});

0 commit comments

Comments
 (0)