From efc394cd006b4bc0dd39e2a1bae6cb7c568ac5bd Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Sun, 19 Jan 2020 17:51:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E5=A4=8D=20Node=2013=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=A1=B9=E7=9B=AE=E6=97=B6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=20close=20#5285?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容 Nodejs 13+ 调用 require 时 package.json 格式不能非法 --- packages/taro-cli/src/create/init.ts | 12 +++++++++--- .../taro-cli/templates/default/{package.json => pkg} | 0 2 files changed, 9 insertions(+), 3 deletions(-) rename packages/taro-cli/templates/default/{package.json => pkg} (100%) diff --git a/packages/taro-cli/src/create/init.ts b/packages/taro-cli/src/create/init.ts index 4d81edb0d421..80be8999b49f 100644 --- a/packages/taro-cli/src/create/init.ts +++ b/packages/taro-cli/src/create/init.ts @@ -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', @@ -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 @@ -272,7 +280,5 @@ export async function createApp ( } else { callSuccess() } - - }) } diff --git a/packages/taro-cli/templates/default/package.json b/packages/taro-cli/templates/default/pkg similarity index 100% rename from packages/taro-cli/templates/default/package.json rename to packages/taro-cli/templates/default/pkg