diff --git a/packages/api/core/src/api/start.ts b/packages/api/core/src/api/start.ts index 3021b1e832..487ddfdea0 100644 --- a/packages/api/core/src/api/start.ts +++ b/packages/api/core/src/api/start.ts @@ -1,4 +1,5 @@ import { spawn, SpawnOptions } from 'child_process'; +import { EventEmitter } from 'events'; import { getElectronVersion, listrCompatibleRebuildHook } from '@electron-forge/core-utils'; import { ElectronProcess, ForgeArch, ForgeListrTaskFn, ForgePlatform, ResolvedForgeConfig, StartOptions } from '@electron-forge/shared-types'; @@ -24,6 +25,8 @@ type StartContext = { spawned: ElectronProcess; }; +const restartAppEventEmitter = new EventEmitter(); + export default autoTrace( { name: 'start()', category: '@electron-forge/core' }, async ( @@ -213,20 +216,20 @@ export default autoTrace( }; if (interactive) { - process.on('FORGE_RESTART_APP', async () => { + restartAppEventEmitter.on('restart', async () => { if (lastSpawned) { - console.info(chalk.cyan('\nRestarting App\n')); - lastSpawned.restarted = true; - lastSpawned.kill('SIGTERM'); - lastSpawned.emit('restarted', await forgeSpawnWrapper()); - } - }); + console.info(chalk.cyan('\nRestarting App\n')); + lastSpawned.restarted = true; + lastSpawned.kill('SIGTERM'); + lastSpawned.emit('restarted', await forgeSpawnWrapper()); + } + }); - process.stdin.on('data', async (data) => { - if (data.toString().trim() === 'rs') { - process.emit('FORGE_RESTART_APP'); - } - }); + process.stdin.on('data', async (data) => { + if (data.toString().trim() === 'rs') { + restartApp(); + } + }); process.stdin.resume(); } @@ -238,3 +241,7 @@ export default autoTrace( return spawned; } ); + +export function restartApp() { + restartAppEventEmitter.emit('restart'); +} diff --git a/typings/nodejs/index.d.ts b/typings/nodejs/index.d.ts deleted file mode 100644 index 3b809f6b73..0000000000 --- a/typings/nodejs/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare namespace NodeJS { - interface Process extends EventEmitter { - emit(event: 'FORGE_RESTART_APP'): boolean; - - on(event: 'FORGE_RESTART_APP', listener: () => void): NodeJS.Process; - } -}