Skip to content

Commit 1dbf246

Browse files
committed
fix(create-app): ensure valid package name when creating project
close #2360
1 parent f7d85ae commit 1dbf246

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/create-app/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ async function init() {
118118
}
119119

120120
const pkg = require(path.join(templateDir, `package.json`))
121-
pkg.name = path.basename(root)
121+
122+
pkg.name = path
123+
.basename(root)
124+
// #2360 ensure packgae.json name is valid
125+
.trim()
126+
.replace(/\s+/g, '-')
127+
.replace(/^[._]/, '')
128+
.replace(/[~)('!*]+/g, '-')
129+
122130
write('package.json', JSON.stringify(pkg, null, 2))
123131

124132
const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'

0 commit comments

Comments
 (0)