Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…e npm by default, use yarn only if there is a yarn.lock
  • Loading branch information
Jolg42 committed Mar 17, 2020
1 parent 8da3475 commit 8938c6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
5 changes: 3 additions & 2 deletions cli/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts"
],
"prisma": {
"version": "377df4fe30aa992f13f1ba152cf83d5770bdbc85"
"version": "4ff8379527ec7797e7bb5b55d374f82f5812a6f9"
},
"devDependencies": {
"@types/jest": "24.0.22",
Expand Down Expand Up @@ -49,6 +49,7 @@
"execa": "^3.4.0",
"flat-map-polyfill": "^0.3.8",
"globby": "^9.2.0",
"has-yarn": "^2.1.0",
"make-dir": "^3.0.0",
"node-fetch": "2.6.0",
"p-map": "^3.0.0",
Expand Down Expand Up @@ -79,4 +80,4 @@
"git add"
]
}
}
}
14 changes: 3 additions & 11 deletions cli/sdk/src/predefinedGeneratorResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import resolvePkg from 'resolve-pkg'
import chalk from 'chalk'
import hasYarn from 'has-yarn'
import execa from 'execa'
import path from 'path'
import fs from 'fs'
Expand Down Expand Up @@ -108,9 +109,9 @@ Please try to install it with ${chalk.bold.greenBright(
}

async function installPackage(baseDir: string, pkg: string): Promise<void> {
const yarnInstalled = await isYarnInstalled()
const yarnUsed = hasYarn(baseDir)

const cmdName = yarnInstalled ? 'yarn add' : 'npm install'
const cmdName = yarnUsed ? 'yarn add' : 'npm install'

await execa.command(`${cmdName} ${pkg}`, {
cwd: baseDir,
Expand All @@ -121,12 +122,3 @@ async function installPackage(baseDir: string, pkg: string): Promise<void> {
},
})
}

async function isYarnInstalled(): Promise<boolean> {
try {
await execa.command(`yarn --version`, { stdio: `ignore` })
return true
} catch (err) {
return false
}
}

0 comments on commit 8938c6f

Please sign in to comment.