Skip to content

Commit cde03ba

Browse files
github-actions[bot]Zelys-DFKHclaude
authored
fix(config): pause progress spinner during interactive editor spawn (#9388)
Backport of #9372 to `release/v11`. Co-authored-by: Zelys <zelys@dfkhelper.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c5e9d73 commit cde03ba

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

lib/commands/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { EOL } = require('node:os')
55
const localeCompare = require('@isaacs/string-locale-compare')('en')
66
const pkgJson = require('@npmcli/package-json')
77
const { defaults, definitions, nerfDarts, proxyEnv } = require('@npmcli/config/lib/definitions')
8-
const { log, output } = require('proc-log')
8+
const { log, output, input } = require('proc-log')
99
const BaseCommand = require('../base-cmd.js')
1010
const { redact } = require('@npmcli/redact')
1111

@@ -266,7 +266,7 @@ ${defData}
266266
`.split('\n').join(EOL)
267267
await mkdir(dirname(file), { recursive: true })
268268
await writeFile(file, tmpData, 'utf8')
269-
await new Promise((res, rej) => {
269+
await input.start(() => new Promise((res, rej) => {
270270
const [bin, ...args] = e.split(/\s+/)
271271
const editor = spawn(bin, [...args, file], { stdio: 'inherit' })
272272
editor.on('exit', (code) => {
@@ -275,7 +275,7 @@ ${defData}
275275
}
276276
return res()
277277
})
278-
})
278+
}))
279279
}
280280

281281
async fix () {

lib/commands/edit.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { resolve } = require('node:path')
22
const { lstat } = require('node:fs/promises')
33
const cp = require('node:child_process')
4+
const { input } = require('proc-log')
45
const completion = require('../utils/installed-shallow.js')
56
const BaseCommand = require('../base-cmd.js')
67

@@ -46,16 +47,17 @@ class Edit extends BaseCommand {
4647
const dir = resolve(this.npm.dir, path)
4748

4849
await lstat(dir)
49-
await new Promise((res, rej) => {
50+
await input.start(() => new Promise((res, rej) => {
5051
const [bin, ...spawnArgs] = this.npm.config.get('editor').split(/\s+/)
5152
const editor = cp.spawn(bin, [...spawnArgs, dir], { stdio: 'inherit' })
52-
editor.on('exit', async (code) => {
53+
editor.on('exit', (code) => {
5354
if (code) {
5455
return rej(new Error(`editor process exited with code: ${code}`))
5556
}
56-
await this.npm.exec('rebuild', [dir]).then(res).catch(rej)
57+
res()
5758
})
58-
})
59+
}))
60+
await this.npm.exec('rebuild', [dir])
5961
}
6062
}
6163

test/lib/commands/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ t.test('config edit', async t => {
582582
},
583583
})
584584

585+
const inputEvents = []
586+
const inputListener = (level) => inputEvents.push(level)
587+
process.on('input', inputListener)
588+
t.teardown(() => process.off('input', inputListener))
589+
585590
await npm.exec('config', ['edit'])
586591

587592
t.ok(editor.called, 'editor was spawned')
@@ -590,6 +595,7 @@ t.test('config edit', async t => {
590595
[join(home, '.npmrc')],
591596
'editor opened the user config file'
592597
)
598+
t.same(inputEvents.slice(0, 2), ['start', 'end'], 'progress paused and resumed around editor')
593599

594600
const contents = await fs.readFile(join(home, '.npmrc'), { encoding: 'utf8' })
595601
t.ok(contents.includes('foo=bar'), 'kept foo')

test/lib/commands/edit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ t.test('npm edit', async t => {
5858
: ['-c', 'testinstall']
5959
spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath })
6060

61+
const inputEvents = []
62+
const inputListener = (level) => inputEvents.push(level)
63+
process.on('input', inputListener)
64+
t.teardown(() => process.off('input', inputListener))
65+
6166
await npm.exec('edit', ['semver'])
6267
t.match(joinedOutput(), 'rebuilt dependencies successfully')
68+
t.same(inputEvents.slice(0, 2), ['start', 'end'], 'progress paused and resumed around editor')
6369
})
6470

6571
t.test('rebuild failure', async t => {

0 commit comments

Comments
 (0)