Skip to content

🔥 fix(broken): infallible registry generation, 0 error possible #348

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nrjdalal
Copy link
Contributor

@nrjdalal nrjdalal commented May 7, 2025

this PR is made to fix -

just via switching as below, there will be no human error, and all errors above are fixed automatically -

{
- "registry:build": "shadcn build"
+ "registry:build": "smart-registry"
}

Note

if we don't wish to make any changes other then package.json, we can UNDO changes made to file registry.json, no code is added to it anyways, only subtracted


in future if we need to add a new component, all we need to do is (and nothing else, seriously nothing else) -

  • more files? nope, smart-registry adds them for you
  • dependencies, registryDeps, devDeps? nope, smart-registry adds them for you
{
  "name": "comp-[number]",
  "type": "registry:component",
  "files": [
    {
      "path": "registry/default/components/comp-[number].tsx",
      "type": "registry:component"
    }
  ],
  "meta": {
    "tags": ["tag1", "tag2", "..."],
    "colSpan": "number (optional)"
  }
}

you can always add additional files and deps (human error prone)

if you wish to be shadcn build compatible, won't make any difference during smart-registry generation as smart-registry is drop-in yet smart replacement to shadcn build but still a shadcn compatible registry is generated at public/r/registry.json 🔥


🔥 bonus - smart-registry also yields style.json and ui.json (i.e. equivalent to shadcn add -a), in our case -

# add all originui's UI components
npx shadcn add https://originui.com/r/ui.json

and voila we have all registry:ui components from originui in our existing project

  • and if you wish to update cssVars only aka registry:style
# add all cssVars to the stylesheet
npx shadcn add https://originui.com/r/style.json

previews and tests -

  1. site:
https://originui-git-infallible-registry-generated-nrjdalals-projects.vercel.app
  1. auto-generated shadcn compatible registry
https://originui-git-infallible-registry-generated-nrjdalals-projects.vercel.app/r/registry.json
  1. tests:
# update styles in a project
npx shadcn add https://originui-git-infallible-registry-generated-nrjdalals-projects.vercel.app/r/style.json
# add all originui's components in a project
npx shadcn add https://originui-git-infallible-registry-generated-nrjdalals-projects.vercel.app/r/ui.json
Image

Copy link

vercel bot commented May 7, 2025

@nrjdalal is attempting to deploy a commit to the Cruip Team on Vercel.

A member of the Team first needs to authorize it.

@nrjdalal
Copy link
Contributor Author

nrjdalal commented May 7, 2025

automated script for migration with 100% prefection -

  • stop worring about adding deps, dev deps or registry deps
  • only add the original component in files array and meta

following command cleans up the the registry.json by removing deps and unwanted files and the generates smart-registry using npx smart-registry which doesn't break the site behaviour at all and fixes all unknown issues too -

# clean up
npx fx '({ 
  ...this,
  items: this.items.map(item => { 
    delete item.registryDependencies 
    delete item.dependencies 
    delete item.devDependencies 
    delete item.tailwind
    if (item.files && Array.isArray(item.files)) {
      if (item.name === "comp-62") {
        item.files[0] = { ...item.files[0], path: "registry/default/components/comp-62.tsx" }
      } else {
        item.files = [item.files[0]]
      }
    }
    return item 
  }) 
})' registry.json > registry.tmp.json && mv registry.tmp.json registry.json
# fix all existing and unknown issues and generates smart-registry
npx smart-registry@latest
# replace build with smart-registry
npx fx '({
  ...this,
  scripts: {
    ...this.scripts,
    "registry:build": "npx smart-registry@latest"
  }
})' package.json > package.tmp.json && mv package.tmp.json package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant