Skip to content

Commit

Permalink
fix: 修复 pnpm 安装依赖失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Sep 2, 2022
1 parent 221523f commit 388d7a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,7 @@ async function init(projectPath: string, answers: InitAnswers) {
cwd: projectPath,
})

const loading = ora('正在安装依赖……').start()
try {
await asyncExec(`${PACKAGE_MANAGER} i`, {
cwd: projectPath,
})
loading.succeed('依赖安装成功!')
} catch (error) {
console.error(error)
loading.fail('依赖安装失败!')
// process.exit(1)
}
await installNpmPackages(projectPath)

await asyncExec('git add .', {
cwd: projectPath,
Expand Down Expand Up @@ -230,6 +220,22 @@ export async function sleep(time: number) {
return new Promise((resolve) => setTimeout(resolve, time))
}

async function installNpmPackages(projectPath: string) {
const loading = ora('正在安装依赖……').start()
try {
const files = ['.npmrc']
await copyFilesFromTemplates(projectPath, files)
await asyncExec(`${PACKAGE_MANAGER} i`, {
cwd: projectPath,
})
loading.succeed('依赖安装成功!')
} catch (error) {
console.error(error)
loading.fail('依赖安装失败!')
// process.exit(1)
}
}

async function initDependabot(projectPath: string, answers: InitAnswers) {
try {
const { isOpenSource, isRemoveDependabot } = answers
Expand Down
1 change: 1 addition & 0 deletions templates/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strict-peer-dependencies=false

0 comments on commit 388d7a0

Please sign in to comment.