Skip to content

Commit 07a3ff0

Browse files
committed
fix(dev): various 🐰
1 parent 9392426 commit 07a3ff0

11 files changed

Lines changed: 155 additions & 79 deletions

File tree

capture/captures.config.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PtySession } from './lib/pty.ts'
2-
import { readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
2+
import { lstatSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
33
import { dirname, join } from 'node:path'
44
import process from 'node:process'
55
import { fileURLToPath } from 'node:url'
@@ -140,9 +140,22 @@ export const captures: Capture[] = [
140140

141141
// `installNuxtModule` runs the *project's* `@nuxt/cli` in-process, which
142142
// the fixture installed from the registry; the capture should show the
143-
// build under test, so the project copy is pointed at it.
143+
// build under test, so the project copy is pointed at it for the
144+
// recording and put back afterwards. A symlink found here is residue of
145+
// an interrupted run, with nothing behind it to preserve.
144146
const projectCli = join(cwd, 'node_modules/@nuxt/cli')
145-
rmSync(projectCli, { recursive: true, force: true })
147+
const savedCli = `${projectCli}.original`
148+
if (lstatSync(savedCli, { throwIfNoEntry: false })) {
149+
rmSync(projectCli, { recursive: true, force: true })
150+
renameSync(savedCli, projectCli)
151+
}
152+
const installed = lstatSync(projectCli, { throwIfNoEntry: false })
153+
if (installed?.isSymbolicLink()) {
154+
rmSync(projectCli, { force: true })
155+
}
156+
else if (installed) {
157+
renameSync(projectCli, savedCli)
158+
}
146159
symlinkSync(dirname(dirname(bin)), projectCli, 'dir')
147160

148161
try {
@@ -168,6 +181,10 @@ export const captures: Capture[] = [
168181
writeFileSync(file, text)
169182
}
170183
rmSync(join(cwd, 'node_modules/@nuxt/scripts'), { recursive: true, force: true })
184+
rmSync(projectCli, { force: true })
185+
if (lstatSync(savedCli, { throwIfNoEntry: false })) {
186+
renameSync(savedCli, projectCli)
187+
}
171188
}
172189
},
173190
},

capture/output/nuxt-dev-install-module.svg

Lines changed: 42 additions & 34 deletions
Loading

capture/output/nuxt-dev-install-module.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
styles: 47b4eb73fea90d67
2-
Local http://localhost:3000/
3-
Local http://localhost:3000/ ⠋
4-
Network http://192.168.1.10:3000/
5-
Network http://192.168.1.10:3000/ ⠋
1+
styles: eba055abc05015cd
2+
Local http://localhost:3000/
3+
Local http://localhost:3000/ ⠋
64
waiting for requests
75
━━━━━━━━━━━━━━━━━━━━ 0% · 42 ms
86
━━━━━━━━━━━━━━━━━━━━ 17% · 42 ms

capture/output/nuxt-dev-plain.svg

Lines changed: 17 additions & 13 deletions
Loading

capture/output/nuxt-dev-plain.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
styles: 4eeca6108c97ac69
1+
styles: e92e0d98f3b543db
22
press h + enter to see available shortcuts
33
➜ DevTools: press Shift + Alt + D in the browser (x.y.z)
44
➜ Local: http://localhost:3000/
55
➜ Network: use --host to expose
6+
ℹ Re-optimizing dependencies because vite config has changed
67
ℹ Vite client warmed up in 42 ms
78
ℹ Vite server warmed up in 42 ms
89

capture/output/nuxt-init.svg

Lines changed: 10 additions & 13 deletions
Loading

packages/nuxt-cli/src/dev/tui/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ export function setupDevUI(context: ShortcutContext, options: DevUIOptions = {})
371371

372372
let detach = attachKeys(onKey)
373373

374+
/** Set at teardown, so a borrow that outlives the session cannot restore it. */
375+
let torn = false
376+
374377
/**
375378
* Give borrowed work the terminal for as long as it needs it.
376379
*
@@ -387,8 +390,13 @@ export function setupDevUI(context: ShortcutContext, options: DevUIOptions = {})
387390
}
388391
finally {
389392
resume()
390-
detach = attachKeys(onKey)
391-
render()
393+
// A session torn down mid-borrow (Ctrl-C answered a prompt) has already
394+
// detached and given the terminal back; re-attaching would put stdin
395+
// into raw mode with nothing listening and keep the process alive.
396+
if (!torn) {
397+
detach = attachKeys(onKey)
398+
render()
399+
}
392400
}
393401
}
394402

@@ -475,6 +483,7 @@ export function setupDevUI(context: ShortcutContext, options: DevUIOptions = {})
475483
},
476484
})
477485
session.onTeardown(() => {
486+
torn = true
478487
clearInterval(animation)
479488
clearTimeout(activityTimer)
480489
clearTimeout(noticeTimer)

packages/nuxt-cli/src/dev/tui/session.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export function beginDevUI(options: DevUISupportOptions & { version?: string, cw
258258
transient = undefined
259259
return
260260
}
261-
const stored = events.push({
261+
const event: DevLogEvent = {
262262
time: Date.now(),
263263
level: 2,
264264
type: 'log',
@@ -268,8 +268,12 @@ export function beginDevUI(options: DevUISupportOptions & { version?: string, cw
268268
source: isServingRequest() ? 'runtime' : 'build',
269269
request: currentRequest()?.label,
270270
requestId: currentRequest()?.id,
271-
})
272-
transient = rewriting ? stored : undefined
271+
}
272+
const stored = events.push(event)
273+
// Only an entry of this run's own may be rewritten by its later frames:
274+
// `push` can merge into an existing structured event, whose message is a
275+
// real log that has to survive.
276+
transient = rewriting && stored === event ? stored : undefined
273277
}
274278

275279
/**

packages/nuxt-cli/src/utils/spinner.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ export async function withSpinner<T>(message: string, fn: (spinner: Spinner) =>
3434
if (host) {
3535
const task = host.startTask(message)
3636
try {
37-
return await fn({ update: text => task.update(text), done: setDone })
38-
}
39-
finally {
37+
const result = await fn({ update: text => task.update(text), done: setDone })
4038
task.stop(done, 'success')
39+
return result
40+
}
41+
catch (error) {
42+
// The message the work chose describes it succeeding; whoever threw
43+
// reports the failure itself.
44+
task.stop(undefined, 'failure')
45+
throw error
4146
}
4247
}
4348

packages/nuxt-cli/test/unit/dev-tui.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,21 @@ describe('the terminal host on the panel', () => {
22512251
})
22522252
})
22532253

2254+
it('does not take stdin back when torn down during a borrow', async () => {
2255+
let finish!: () => void
2256+
let borrowed!: Promise<unknown>
2257+
await withPanel(async () => {
2258+
const host = useTerminalHost()!
2259+
borrowed = host.withTerminal(() => new Promise<void>((resolve) => {
2260+
finish = resolve
2261+
}))
2262+
await vi.waitFor(() => expect(process.stdin.listenerCount('keypress')).toBe(0))
2263+
})
2264+
finish()
2265+
await borrowed
2266+
expect(process.stdin.listenerCount('keypress')).toBe(0)
2267+
})
2268+
22542269
it('holds a notification on the status line until it is dismissed', async () => {
22552270
await withPanel(async (ui, settle) => {
22562271
ui.setStatus('ready')
@@ -2263,11 +2278,13 @@ describe('the terminal host on the panel', () => {
22632278
expect(frames).toContain('permission Request')
22642279
expect(frames).toContain('Open http://localhost:3000/auth to approve.')
22652280

2281+
const seen = frames.length
22662282
notice.dismiss()
22672283
await notice.dismissed
2284+
// Dismissal restores the status badge, so the repaint carries it.
22682285
frames = await settle()
2269-
expect(frames.split('permission Request').length - 1)
2270-
.toBe((await settle()).split('permission Request').length - 1)
2286+
expect(frames.slice(seen)).toContain('READY')
2287+
expect(frames.slice(seen)).not.toContain('permission Request')
22712288
})
22722289
})
22732290

0 commit comments

Comments
 (0)