mirror of
https://github.com/cypress-io/cypress.git
synced 2025-12-21 14:21:13 -06:00
* add state for global mode * use GlobalEmpty over GlobalPage * Add comment to clarify global type Co-authored-by: Jessica Sachs <jess@jessicasachs.io> * Update server.ts * make global non nullable * move GlobalEmpty to Main.vue * update ClientTestContext to have global Co-authored-by: Jessica Sachs <jess@jessicasachs.io>
69 lines
1.2 KiB
JavaScript
69 lines
1.2 KiB
JavaScript
const chokidar = require('chokidar')
|
|
const childProcess = require('child_process')
|
|
const path = require('path')
|
|
const pDefer = require('p-defer')
|
|
|
|
const watcher = chokidar.watch('packages/graphql/src/**/*.{js,ts}', {
|
|
cwd: path.join(__dirname, '..'),
|
|
ignored: '**/nxs.gen.ts',
|
|
ignoreInitial: true,
|
|
})
|
|
|
|
/**
|
|
* @type {childProcess.ChildProcess}
|
|
*/
|
|
let child
|
|
|
|
let isClosing = false
|
|
let isRestarting = false
|
|
|
|
function runServer () {
|
|
if (child) {
|
|
child.removeAllListeners()
|
|
}
|
|
|
|
child = childProcess.fork(path.join(__dirname, 'start.js'), [...process.argv, '--devWatch'], {
|
|
stdio: 'inherit',
|
|
})
|
|
|
|
child.on('exit', (code) => {
|
|
if (isClosing) {
|
|
process.exit(code)
|
|
}
|
|
})
|
|
|
|
child.on('disconnect', () => {
|
|
child = null
|
|
})
|
|
}
|
|
|
|
async function restartServer () {
|
|
if (isRestarting) {
|
|
return
|
|
}
|
|
|
|
const dfd = pDefer()
|
|
|
|
if (child) {
|
|
child.on('exit', dfd.resolve)
|
|
isRestarting = true
|
|
child.send('close')
|
|
} else {
|
|
dfd.resolve()
|
|
}
|
|
|
|
await dfd.promise
|
|
isRestarting = false
|
|
runServer()
|
|
}
|
|
|
|
watcher.on('add', restartServer)
|
|
watcher.on('change', restartServer)
|
|
|
|
runServer()
|
|
|
|
process.on('beforeExit', () => {
|
|
isClosing = true
|
|
child?.send('close')
|
|
})
|