Skip to content
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

[bug]: transformImport util doesn't support registry items that are formatted with single quotes #4870

Open
2 tasks done
bcorbold opened this issue Sep 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@bcorbold
Copy link

bcorbold commented Sep 17, 2024

Describe the bug

I'm working on building an internal component registry for use at my org, and while testing out the new cli with our registry files, I found a bug with the transformImport util.

Since we format our files with ' instead of ", the regex used in the util mentioned doesn't add prefixes correctly when referencing files formatted like ours.

I'll submit a PR for a fix shortly, which will update the regex to look for both ' and " so it can support both formatting styles

Affected component/components

N/A

How to reproduce

  1. Go to codesandbox link
  2. Run pnpm dlx shadcn@latest add https://lht8mm-3000.csb.app/registry/custom-button.json
  3. Generated custom-button.tsx file will have incorrect class names generated

Sample output:

import * as React from 'react'
import { cn } from '@/lib/utils'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'

const buttonVariants = cva(
  "tw-'rounded-md tw-inline-flex tw-items-center tw-justify-center tw-whitespace-nowrap tw-text-sm tw-font-medium tw-ring-offset-background tw-transition-colors focus-visible:tw-outline-none focus-visible:tw-ring-2 focus-visible:tw-ring-ring focus-visible:tw-ring-offset-2 disabled:tw-pointer-events-none disabled:tw-opacity-50'",
  {
    variants: {
      variant: {
        default: "tw-'bg-primary tw-text-primary-foreground hover:tw-bg-primary/90'",
        destructive: "tw-'bg-destructive tw-text-destructive-foreground hover:tw-bg-destructive/90'",
        outline: "tw-'border tw-border-input tw-bg-background hover:tw-bg-accent hover:tw-text-accent-foreground'",
        secondary: "tw-'bg-secondary tw-text-secondary-foreground hover:tw-bg-secondary/80'",
        ghost: "'hover:tw-bg-accent hover:tw-text-accent-foreground'",
        link: "tw-'text-primary tw-underline-offset-4 hover:tw-underline'",
      },
      size: {
        default: "tw-'h-10 tw-px-4 tw-py-2'",
        sm: "tw-'rounded-md tw-h-9 tw-px-3'",
        lg: "tw-'rounded-md tw-h-11 tw-px-8'",
        icon: "tw-'h-10 tw-w-10'",
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  },
)

export interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof buttonVariants> {
  asChild?: boolean
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant, size, asChild = false, ...props }, ref) => {
    const Comp = asChild ? Slot : 'button'
    return (
      <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
    )
  },
)
Button.displayName = 'Button'

export { Button, buttonVariants }

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/dark-hill-lht8mm

Logs

No response

System Info

-

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@bcorbold bcorbold added the bug Something isn't working label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant