Skip to content

Commit cc55e36

Browse files
authoredNov 25, 2024··
fix: exit code on SIGTERM (#18741)
1 parent bac1089 commit cc55e36

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
 

‎packages/vite/src/node/preview.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ export async function preview(
168168
},
169169
}
170170

171-
const closeServerAndExit = async () => {
171+
const closeServerAndExit = async (_: unknown, exitCode?: number) => {
172172
try {
173173
await server.close()
174174
} finally {
175+
process.exitCode ??= exitCode ? 128 + exitCode : undefined
175176
process.exit()
176177
}
177178
}

‎packages/vite/src/node/server/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,11 @@ export async function _createServer(
729729
},
730730
})
731731

732-
const closeServerAndExit = async () => {
732+
const closeServerAndExit = async (_: unknown, exitCode?: number) => {
733733
try {
734734
await server.close()
735735
} finally {
736+
process.exitCode ??= exitCode ? 128 + exitCode : undefined
736737
process.exit()
737738
}
738739
}

‎packages/vite/src/node/utils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1524,15 +1524,17 @@ export function partialEncodeURIPath(uri: string): string {
15241524
return filePath.replaceAll('%', '%25') + postfix
15251525
}
15261526

1527-
export const setupSIGTERMListener = (callback: () => Promise<void>): void => {
1527+
export const setupSIGTERMListener = (
1528+
callback: (signal?: 'SIGTERM', exitCode?: number) => Promise<void>,
1529+
): void => {
15281530
process.once('SIGTERM', callback)
15291531
if (process.env.CI !== 'true') {
15301532
process.stdin.on('end', callback)
15311533
}
15321534
}
15331535

15341536
export const teardownSIGTERMListener = (
1535-
callback: () => Promise<void>,
1537+
callback: Parameters<typeof setupSIGTERMListener>[0],
15361538
): void => {
15371539
process.off('SIGTERM', callback)
15381540
if (process.env.CI !== 'true') {

0 commit comments

Comments
 (0)
Please sign in to comment.