Skip to content

Commit 1002f98

Browse files
authoredMar 25, 2025··
fix: avoid starting and stopping spinner loops (#7131)
This was a small regression introduced in #7026. I didn't quite map the previous lib's API to nanospinner's correctly. The intent here is to manually control each frame render and each clear. Instead, the spinner here was already started before it's passed in to this method, then it was cleared and started again on each chunk - but `start()` here would start a new interval loop and set up new node.js exit listeners but `clear()` wouldn't clear them (`reset()` does that). This was leading to unnecessary resource utilization and printing warnings like this: ``` MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit (Use node --trace-warnings ... to show where the warning was created) (node:61086) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit ``` The fix here is to just manually render a single frame (`.spin()`) at a time (and `stop()` the initial loop).
1 parent db45131 commit 1002f98

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed
 

‎src/utils/shell.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import execa from 'execa'
44
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'stri... Remove this comment to see the full error message
55
import stripAnsiCc from 'strip-ansi-control-characters'
66

7-
import type { Spinner } from '../lib/spinner.js'
7+
import { stopSpinner, type Spinner } from '../lib/spinner.js'
88
import { chalk, log, NETLIFYDEVERR, NETLIFYDEVWARN } from './command-helpers.js'
99
import { processOnExit } from './dev.js'
1010

@@ -57,16 +57,19 @@ export const runCommand = (
5757
cwd,
5858
})
5959

60-
// This ensures that an active spinner stays at the bottom of the commandline
60+
// Ensure that an active spinner stays at the bottom of the commandline
6161
// even though the actual framework command might be outputting stuff
62+
if (spinner?.isSpinning) {
63+
// The spinner is initially "started" in the usual sense (rendering frames on an interval).
64+
// In this case, we want to manually control when to clear and when to render a frame, so we turn this off.
65+
stopSpinner({ error: false, spinner })
66+
}
6267
const pipeDataWithSpinner = (writeStream: NodeJS.WriteStream, chunk: any) => {
6368
if (spinner?.isSpinning) {
6469
spinner.clear()
6570
}
6671
writeStream.write(chunk, () => {
67-
if (spinner?.isSpinning) {
68-
spinner.start()
69-
}
72+
spinner?.spin()
7073
})
7174
}
7275

1 commit comments

Comments
 (1)

github-actions[bot] commented on Mar 25, 2025

@github-actions[bot]

📊 Benchmark results

  • Dependency count: 1,173
  • Package size: 297 MB
  • Number of ts-expect-error directives: 715
Please sign in to comment.