Skip to content

Commit

Permalink
fix(cli): 修复 Node 13 创建项目时的问题, close NervJS#5285
Browse files Browse the repository at this point in the history
兼容 Nodejs 13+ 调用 require 时 package.json 格式不能非法
  • Loading branch information
Chen-jj authored and jiangzm committed Dec 7, 2020
1 parent c1bb746 commit debc1f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/taro-cli/src/create/init.ts
Expand Up @@ -10,6 +10,7 @@ import * as helper from '../util'

const CONFIG_DIR_NAME = 'config'
const TEMPLATE_CREATOR = 'template_creator.js'
const PACKAGE_JSON_ALIAS = '/pkg'

const styleExtMap = {
sass: 'scss',
Expand Down Expand Up @@ -104,8 +105,15 @@ function createFiles (
destRePath = destRePath.replace('.css', `.${currentStyleExt}`)
}

let dest = path.join(projectPath, destRePath)

// 兼容 Nodejs 13+ 调用 require 时 package.json 格式不能非法
if (fileRePath === PACKAGE_JSON_ALIAS) {
dest = path.join(projectPath, 'package.json')
}

// 创建
creater.template(template, fileRePath, path.join(projectPath, destRePath), config)
creater.template(template, fileRePath, dest, config)
logs.push(`${chalk.green('✔ ')}${chalk.grey(`创建文件: ${path.join(projectName, destRePath)}`)}`)
})
return logs
Expand Down Expand Up @@ -272,7 +280,5 @@ export async function createApp (
} else {
callSuccess()
}


})
}
File renamed without changes.

0 comments on commit debc1f6

Please sign in to comment.