Skip to content

Commit 1306af5

Browse files
committed
fix: Ensure typegen CLI command doesn't hang due to open handles
1 parent 92f23da commit 1306af5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

packages/next/src/bin/next.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,10 @@ program
395395
)}`
396396
)
397397
.action((directory: string, options: NextTypegenOptions) =>
398+
// ensure process exits after typegen completes so open handles/connections
399+
// don't cause process to hang
398400
import('../cli/next-typegen.js').then((mod) =>
399-
mod.nextTypegen(options, directory)
401+
mod.nextTypegen(options, directory).then(() => process.exit(0))
400402
)
401403
)
402404
.usage('[directory] [options]')

test/e2e/app-dir/typed-routes/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// intervals/open connections shouldn't block typegen from exiting
2+
setInterval(() => {}, 250)
3+
14
/**
25
* @type {import('next').NextConfig}
36
*/

test/e2e/app-dir/typed-routes/typed-routes.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { nextTestSetup } from 'e2e-utils'
2+
import { runNextCommand } from 'next-test-utils'
23

34
const expectedDts = `
45
type AppRoutes = "/" | "/_shop/[[...category]]" | "/dashboard" | "/dashboard/settings" | "/docs/[...slug]" | "/gallery/photo/[id]" | "/project/[slug]"
@@ -90,4 +91,12 @@ type InvalidRoute = RouteContext<'/api/users/invalid'>`
9091
)
9192
})
9293
}
94+
95+
it('should exit typegen successfully', async () => {
96+
const { code } = await runNextCommand(['typegen'], {
97+
cwd: next.testDir,
98+
})
99+
100+
expect(code).toBe(0)
101+
})
93102
})

0 commit comments

Comments
 (0)