From 1dbf24627d0fed4d6936f53fb84bc94b79372652 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 15 Mar 2021 09:53:17 -0400 Subject: [PATCH] fix(create-app): ensure valid package name when creating project close #2360 --- packages/create-app/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/create-app/index.js b/packages/create-app/index.js index 489c7f02ace65b..0cc1af168e6bfd 100755 --- a/packages/create-app/index.js +++ b/packages/create-app/index.js @@ -118,7 +118,15 @@ async function init() { } const pkg = require(path.join(templateDir, `package.json`)) - pkg.name = path.basename(root) + + pkg.name = path + .basename(root) + // #2360 ensure packgae.json name is valid + .trim() + .replace(/\s+/g, '-') + .replace(/^[._]/, '') + .replace(/[~)('!*]+/g, '-') + write('package.json', JSON.stringify(pkg, null, 2)) const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'