8577c4f07b
This ensures we properly detect `pnpm` when installing missing dependencies. This also adds test coverage to ensure we properly detect the correct package manager. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1655568091661719)
40 lines
990 B
TypeScript
40 lines
990 B
TypeScript
import chalk from 'next/dist/compiled/chalk'
|
|
import path from 'path'
|
|
|
|
import { MissingDependency } from './has-necessary-dependencies'
|
|
import { getPkgManager } from './helpers/get-pkg-manager'
|
|
import { install } from './helpers/install'
|
|
import { getOnline } from './helpers/get-online'
|
|
|
|
export type Dependencies = {
|
|
resolved: Map<string, string>
|
|
}
|
|
|
|
export async function installDependencies(
|
|
baseDir: string,
|
|
deps: any,
|
|
dev: boolean = false
|
|
) {
|
|
const packageManager = getPkgManager(baseDir)
|
|
const isOnline = await getOnline()
|
|
|
|
if (deps.length) {
|
|
console.log()
|
|
console.log(
|
|
`Installing ${
|
|
dev ? 'devDependencies' : 'dependencies'
|
|
} (${packageManager}):`
|
|
)
|
|
for (const dep of deps) {
|
|
console.log(`- ${chalk.cyan(dep.pkg)}`)
|
|
}
|
|
console.log()
|
|
|
|
await install(
|
|
path.resolve(baseDir),
|
|
deps.map((dep: MissingDependency) => dep.pkg),
|
|
{ devDependencies: dev, isOnline, packageManager }
|
|
)
|
|
console.log()
|
|
}
|
|
}
|