Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli): handle dot input and validate npm package names#41

Open
ProdigyRahul wants to merge 1 commit intoupstash:main from
ProdigyRahul:fix/package-name
Open

fix(cli): handle dot input and validate npm package names #41
ProdigyRahul wants to merge 1 commit intoupstash:main from
ProdigyRahul:fix/package-name

Conversation

@ProdigyRahul
Copy link

@ProdigyRahul ProdigyRahul commented Feb 8, 2025
edited
Loading

image

added:

// NPM package name validation regex
const VALID_PACKAGE_NAME = /^(?:(?:@(?:[a-z0-9-(削除) ][a-z0-9-. (削除ここまで)])?/)?[a-z0-9-._~][a-z0-9-(削除) ]|[a-z0-9- (削除ここまで)])$/

// Function to sanitize package name
const sanitizePackageName = (name: string): string => {
return name
.toLowerCase()
.replace(/[^a-z0-9-~]/g, '-')
.replace(/^[._]/, '')
.replace(/^-+|-+$/g, '')
|| 'jstack-app'
}

and also added this validation:
// Handle "." input by using current directory name
if (value === ".") {
const currentDir = path.basename(process.cwd())
value = currentDir
}

 // Validate against npm package name rules
 if (!VALID_PACKAGE_NAME.test(value)) {
 const sanitized = sanitizePackageName(value)
 return `Invalid package name. Try: ${sanitized}`
 }

Copy link
Author

ProdigyRahul commented Feb 8, 2025
edited
Loading

I've submitted a PR to a public open-source repo. Hoping they merge it. >_< @joschan21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /