ui icon indicating copy to clipboard operation
ui copied to clipboard

fix(cli): recognize package.json files in ancestor directories

Open jaredp opened this issue 1 year ago • 1 comments

I have a monorepo with unusual structure

/  <--- repo root
  package.json
  tsconfig.json
  other-stuff/
  server/  <--- nextjs project root
    components.json
    src/pages/
      index.tsx

I'd like to be able to run bunx --bun shadcn@latest add alert-dialog from the //server/ directory.

Without this PR, the package.json in the ancestor directory is not recognized. I get (incorrectly) prompted to create a project, and can't use the shadcn add tool properly.

This change lets the shadcn cli recognize when we're inside a valid node package, not just in the root dir.

I've tested that this works correctly for my project.

As far as I can tell, my directory structure ought to be valid. Other tools accept that we're in a valid package as defined by having some ancestor package.json.

Within this tool, the updateDependencies function is able to work in a subdir, as it uses @antfu/ni to find the package manager, which in turn uses the find-up package that I've switched to here.

jaredp avatar Sep 11 '24 20:09 jaredp

@jaredp is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 11 '24 20:09 vercel[bot]

@shadcn how do I request review?

jaredp avatar Sep 12 '24 15:09 jaredp

@jaredp Yeah this is a valid project structure. So the next app is inside server? Can you give me a more detailed tree of your project setup so that I can test this please?

shadcn avatar Sep 15 '24 08:09 shadcn

@shadcn yep yep, sorry I didn't get a notification about this

.
├── package.json
├── node_modules
├── bun.lockb
├── bunfig.toml
├── server (the nextjs pages-router app)
│   ├── next.config.js
│   ├── components.json
│   ├── postcss.config.cjs
│   ├── tailwind.config.ts
│   ├── drizzle.config.ts
│   ├── next-env.d.ts
│   ├── public
│   ├── src
│   └── vercel.json
├── chrome-extension
│   ├── code for a chrome extension, which imports some things in ../server
│   └── ...
├── tsconfig.json
└── tsconfig.tsbuildinfo

I have package.json/node_modules and tsconfig.json at the root of the monorepo. There are 2 different apps produced:

  • a NextJS app for backend, admin website, and some shared code under server/. This is where the shadcn components live.
  • a Chrome extension under chrome-extension/

jaredp avatar Nov 19 '24 22:11 jaredp

@shadcn ping

jaredp avatar Jan 19 '25 20:01 jaredp

I'm doing monorepo work. I'll take a look at this again.

shadcn avatar Mar 05 '25 11:03 shadcn