Skip to content

Commit

Permalink
fix(core): skip package-manager prompt if non-interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Sep 7, 2021
1 parent 9bda8b2 commit 8d9af82
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/@sanity/core/src/util/checkRequiredDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,26 @@ async function installDependenciesWithPrompt(
const yarnLockExists = await fileExists(path.join(workDir, 'yarn.lock'))
const installPackageArgs: string[] = []

const isInteractive =
// eslint-disable-next-line no-process-env
process.stdout.isTTY && process.env.TERM !== 'dumb' && !('CI' in process.env)

output.print('The Sanity studio needs to install missing dependencies:')
for (const [pkgName, version] of Object.entries(dependencies)) {
const declaration = `${pkgName}@${version}`
output.print(`- ${declaration}`)
installPackageArgs.push(declaration)
}

const pkgManager = await prompt.single({
type: 'list',
message: 'Would you like to use npm or yarn to install these?',
choices: ['npm', 'yarn'],
default: yarnLockExists ? 'yarn' : 'npm',
})
const defaultPkgManager = yarnLockExists ? 'yarn' : 'npm'
const pkgManager = isInteractive
? await prompt.single({
type: 'list',
message: 'Would you like to use npm or yarn to install these?',
choices: ['npm', 'yarn'],
default: defaultPkgManager,
})
: defaultPkgManager

if (pkgManager === 'yarn') {
return yarn(['add', ...installPackageArgs], {
Expand Down

0 comments on commit 8d9af82

Please sign in to comment.