Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait next server is available #505

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/nextron-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import webpack from 'webpack'
import * as logger from './logger'
import { getNextronConfig } from './configs/getNextronConfig'
import { config } from './configs/webpack.config.development'
import { waitForPort } from 'get-port-please'
import type { ChildProcess } from 'child_process'

const args = arg({
Expand Down Expand Up @@ -42,7 +43,8 @@ if (args['--inspect']) {
const nextronConfig = getNextronConfig()

const rendererPort = args['--renderer-port'] || 8888
const startupDelay = nextronConfig.startupDelay || args['--startup-delay'] || 0
const startupDelay =
nextronConfig.startupDelay || args['--startup-delay'] || 10_000

let electronOptions = args['--electron-options'] || ''
if (!electronOptions.includes('--remote-debugging-port')) {
Expand Down Expand Up @@ -115,9 +117,16 @@ const execaOptions: execa.Options = {
rendererProcess = startRendererProcess()

// wait until renderer process is ready
await new Promise<void>((resolve) =>
setTimeout(() => resolve(), startupDelay)
)
await waitForPort(rendererPort, {
delay: 500,
retries: startupDelay / 500,
}).catch(() => {
logger.error(
`Failed to start renderer process with port ${rendererPort} in ${startupDelay}ms`
)
killWholeProcess()
process.exit(1)
})

// wait until main process is ready
await new Promise<void>((resolve) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"chalk": "4.1.2",
"execa": "5.1.1",
"fs-extra": "11.2.0",
"get-port-please": "^3.1.2",
"terser-webpack-plugin": "5.3.10",
"tsconfig-paths-webpack-plugin": "4.1.0",
"webpack": "5.92.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading