Skip to content

Commit 3c46bf8

Browse files
committed
fix(js): improve error handling during SWC compilation
fixes: #29599
1 parent dc2c9da commit 3c46bf8

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

packages/js/src/utils/swc/compile-swc.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,25 @@ export async function compileSwc(
8686
rmSync(normalizedOptions.outputPath, { recursive: true, force: true });
8787
}
8888

89-
const swcCmdLog = execSync(getSwcCmd(normalizedOptions), {
90-
encoding: 'utf8',
91-
cwd: normalizedOptions.swcCliOptions.swcCwd,
92-
windowsHide: false,
93-
});
94-
logger.log(swcCmdLog.replace(/\n/, ''));
95-
const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
89+
try {
90+
const swcCmdLog = execSync(getSwcCmd(normalizedOptions), {
91+
encoding: 'utf8',
92+
cwd: normalizedOptions.swcCliOptions.swcCwd,
93+
windowsHide: false,
94+
stdio: 'pipe',
95+
});
96+
logger.log(swcCmdLog.replace(/\n/, ''));
97+
} catch (error) {
98+
logger.error('SWC compilation failed');
99+
if (error.stderr) {
100+
logger.error(error.stderr.toString());
101+
}
102+
return { success: false };
103+
}
96104

97105
if (normalizedOptions.skipTypeCheck && !normalizedOptions.isTsSolutionSetup) {
98106
await postCompilationCallback();
99-
return { success: isCompileSuccess };
107+
return { success: true };
100108
}
101109

102110
const { errors, warnings } = await runTypeCheck(
@@ -111,7 +119,7 @@ export async function compileSwc(
111119

112120
await postCompilationCallback();
113121
return {
114-
success: !hasErrors && isCompileSuccess,
122+
success: !hasErrors,
115123
outfile: normalizedOptions.mainOutputPath,
116124
};
117125
}

0 commit comments

Comments
 (0)