-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: create-svelte
support for scoped packages
#4851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-svelte': patch | ||
--- | ||
|
||
Now asks for project name instead of inferring it from filepath |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,41 @@ async function main() { | |
console.log(gray(`\ncreate-svelte version ${version}`)); | ||
console.log(disclaimer); | ||
|
||
let cwd = process.argv[2] || '.'; | ||
|
||
if (cwd === '.') { | ||
const opts = await prompts([ | ||
const package_name = await prompts( | ||
[ | ||
{ | ||
type: 'text', | ||
name: 'dir', | ||
message: 'Where should we create your project?\n (leave blank to use current directory)' | ||
name: 'packagename', | ||
message: 'What would you like to name your project?', | ||
validate: (value) => { | ||
const regex = new RegExp(/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/); | ||
const match = regex.test(value); | ||
return !match | ||
? 'Value is not a valid NPM package name. Package names must be lowercase and one word, and may contain hyphens and underscores, or be scoped and of the form @scope/package.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're sort of right. The error message would never be returned with |
||
: true; | ||
} | ||
} | ||
], | ||
{ | ||
onCancel: () => process.exit(1) | ||
} | ||
); | ||
|
||
let cwd = process.argv[2] || `./${package_name.packagename}`; | ||
|
||
if (cwd !== process.argv[2]) { | ||
const opts = await prompts( | ||
[ | ||
{ | ||
type: 'text', | ||
name: 'dir', | ||
message: `Where should we create your project?\n (leave blank to use default: ${cwd})` | ||
} | ||
], | ||
{ | ||
onCancel: () => process.exit(1) | ||
} | ||
]); | ||
); | ||
|
||
if (opts.dir) { | ||
cwd = opts.dir; | ||
|
@@ -113,7 +138,7 @@ async function main() { | |
) | ||
); | ||
|
||
options.name = path.basename(path.resolve(cwd)); | ||
options.name = package_name.packagename; | ||
|
||
await create(cwd, options); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~ is no longer allowed for new packages, see https://github.com/npm/validate-npm-package-name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! That's probably a second bug fix for us -- the current function we're using to convert folder names to package names is still allowing them. I'll likely change this implementation to use the library you linked in your top level comment anyway -- I didn't realize that was an official NPM library when I saw it!