mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-05 14:09:46 -06:00
* chore: upgrade electron to 32.2.0 -- run ci * fix node versions * fix build * fix evil-dns * various fixes * fix srcdoc * various fixes * update package.json * update yarn.lock * various fixes * fix integrity check * fix binary verification * various fixes * update yarn.lock * fix typo * fix lock file * fix tests * fix tests * various fixes * various fixes * various fixes * fix stuff * fix things * try to fix errors * fix * updates * add yarn berry * upgrade electron * attempt with gcc * blank * update arm64 executor * try to fix the arm64 issue * fix arm64 * bump cache * attempt to fix arm64 again * attempt to fix arm64 again * fix darwin problems * merge release/14.0.0 * update yarn.lock * blank -- run ci * blank * blank * blank * try something * try something * clean up * blank * try to fix sessions issue * fixes * get more info * get more info * try something * fix * try something * try something * try something * tweak * one more thing * let us see if this works * blank * chore: updating v8 snapshot cache * chore: updating v8 snapshot cache * chore: updating v8 snapshot cache * Apply suggestions from code review * Apply suggestions from code review * Update cli/CHANGELOG.md Co-authored-by: Jennifer Shehane <jennifer@cypress.io> * Update cli/CHANGELOG.md Co-authored-by: Jennifer Shehane <jennifer@cypress.io> * Update CHANGELOG.md * Update cache-version.txt * fix nx (maybe) * Update package.json * try something * Update packages/app/src/runner/aut-iframe.ts * bump version * try to bust cache * try to invalidate cache * Update cli/CHANGELOG.md * suppress benign warnings * Apply suggestions from code review * PR comments * PR comment * Apply suggestions from code review * chore: updating v8 snapshot cache * chore: updating v8 snapshot cache * chore: updating v8 snapshot cache * Update cli/CHANGELOG.md Co-authored-by: Matt Schile <mschile@cypress.io> * update debug scenario 4 regex * Update scripts/binary/trigger-publish-binary-pipeline.js --------- Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io> Co-authored-by: Matt Schile <mschile@cypress.io>
107 lines
2.3 KiB
TypeScript
107 lines
2.3 KiB
TypeScript
import type { ChildProcess } from 'child_process'
|
|
import pDefer from 'p-defer'
|
|
import treeKill from 'tree-kill'
|
|
import gulp from 'gulp'
|
|
|
|
const childProcesses = new Set<ChildProcess>()
|
|
const exitedPids = new Set<number>()
|
|
|
|
let hasExited = false
|
|
|
|
export function addChildProcess (child: ChildProcess) {
|
|
if (hasExited) {
|
|
treeKill(child.pid)
|
|
|
|
return
|
|
}
|
|
|
|
childProcesses.add(child)
|
|
child.on('exit', () => {
|
|
if (!hasExited) {
|
|
exitAndRemoveProcess(child)
|
|
}
|
|
})
|
|
}
|
|
|
|
export async function exitAndRemoveProcess (child: ChildProcess) {
|
|
if (exitedPids.has(child.pid)) {
|
|
return
|
|
}
|
|
|
|
if (!childProcesses.has(child)) {
|
|
throw new Error(`Cannot remove child process ${child.pid}, it was never registered`)
|
|
}
|
|
|
|
childProcesses.delete(child)
|
|
|
|
const dfd = pDefer()
|
|
|
|
exitedPids.add(child.pid)
|
|
treeKill(child.pid, (err) => {
|
|
if (err) {
|
|
console.error(err)
|
|
}
|
|
|
|
dfd.resolve()
|
|
})
|
|
|
|
return dfd.promise
|
|
}
|
|
|
|
export async function exitAllProcesses () {
|
|
await Promise.all(Array.from(childProcesses).map(exitAndRemoveProcess))
|
|
}
|
|
|
|
process.stdin.resume() //so the program will not close instantly
|
|
|
|
const _task = gulp.task
|
|
|
|
// So that we auto-exit on single tasks
|
|
// @ts-expect-error
|
|
gulp.task = function () {
|
|
if (arguments.length === 1 && typeof arguments[0] === 'function') {
|
|
process.stdin.pause()
|
|
}
|
|
|
|
// @ts-ignore
|
|
return _task.apply(this, arguments)
|
|
}
|
|
|
|
export async function exitAfterAll () {
|
|
process.stdin.pause()
|
|
}
|
|
|
|
async function exitHandler (exitCode: number) {
|
|
hasExited = true
|
|
console.log(`Exiting with code ${exitCode}`)
|
|
await exitAllProcesses()
|
|
process.exit(exitCode)
|
|
}
|
|
|
|
async function signalHandler (signal: NodeJS.Signals, code: number) {
|
|
hasExited = true
|
|
console.log(`Exiting due to ${signal}`)
|
|
await exitAllProcesses()
|
|
process.exit(128 + code)
|
|
}
|
|
|
|
async function uncaughtExceptionHandler (error: Error) {
|
|
hasExited = true
|
|
console.log(`Uncaught exception ${error.message}`)
|
|
await exitAllProcesses()
|
|
process.exit(6)
|
|
}
|
|
|
|
// do something when app is closing
|
|
process.on('exit', exitHandler)
|
|
|
|
// catches ctrl+c event
|
|
process.on('SIGINT', signalHandler)
|
|
|
|
// catches "kill pid" (for example: nodemon restart)
|
|
process.on('SIGUSR1', signalHandler)
|
|
process.on('SIGUSR2', signalHandler)
|
|
|
|
// catches uncaught exceptions
|
|
process.on('uncaughtException', uncaughtExceptionHandler)
|