From 381f01d9e593aa238a6ff4d132cdbfa88ae0387b Mon Sep 17 00:00:00 2001 From: xiaolai Date: Wed, 24 Jun 2026 20:08:07 +0800 Subject: [PATCH] fix: pin shadcn version instead of @latest Merge PR #284: pin the shadcn CLI helper to a deterministic version fallback while still allowing project package.json overrides. --- .../skills/ui-styling/scripts/shadcn_add.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.claude/skills/ui-styling/scripts/shadcn_add.py b/.claude/skills/ui-styling/scripts/shadcn_add.py index e2a9799..6168df7 100644 --- a/.claude/skills/ui-styling/scripts/shadcn_add.py +++ b/.claude/skills/ui-styling/scripts/shadcn_add.py @@ -64,6 +64,20 @@ class ShadcnInstaller: except (json.JSONDecodeError, KeyError, OSError): return [] + def _get_shadcn_version(self) -> str: + """Read shadcn version from project package.json; fall back to a pinned default.""" + pkg_json = self.project_root / "package.json" + if pkg_json.exists(): + try: + pkg = json.loads(pkg_json.read_text()) + for section in ("dependencies", "devDependencies"): + version = pkg.get(section, {}).get("shadcn") + if version: + return version.lstrip("^~>=<").split()[0] + except (json.JSONDecodeError, KeyError): + pass + return "2.3.0" # pinned fallback; update when newer stable release is needed + def add_components( self, components: List[str], overwrite: bool = False ) -> tuple[bool, str]: @@ -98,7 +112,8 @@ class ShadcnInstaller: ) # Build command - cmd = ["npx", "shadcn@latest", "add"] + components + shadcn_version = self._get_shadcn_version() + cmd = ["npx", f"shadcn@{shadcn_version}", "add"] + components if overwrite: cmd.append("--overwrite") @@ -144,7 +159,8 @@ class ShadcnInstaller: "shadcn not initialized. Run 'npx shadcn@latest init' first", ) - cmd = ["npx", "shadcn@latest", "add", "--all"] + shadcn_version = self._get_shadcn_version() + cmd = ["npx", f"shadcn@{shadcn_version}", "add", "--all"] if overwrite: cmd.append("--overwrite")