jstack icon indicating copy to clipboard operation
jstack copied to clipboard

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

Open ProdigyRahul opened this issue 10 months ago • 1 comments

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}`
    }

ProdigyRahul avatar Feb 08 '25 15:02 ProdigyRahul