Skip to content

Commit

Permalink
fix(create-app): ensure valid package name when creating project
Browse files Browse the repository at this point in the history
close #2360
  • Loading branch information
yyx990803 committed Mar 15, 2021
1 parent f7d85ae commit 1dbf246
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/create-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1dbf246

Please sign in to comment.