@srcroot/ui 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +25 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -971,11 +971,9 @@ var ComponentAdder = class {
971
971
  return "unknown";
972
972
  }
973
973
  transformForVite(name, content) {
974
- content = content.replace(/^["']use client["'];?\r?\n?/m, "");
975
- content = content.replace(/import\s*\{[^}]*\}\s*from\s*["']next-themes["'];?\r?\n?/g, "");
976
- content = content.replace(/import\s*\{[^}]*\}\s*from\s*["']@\/lib\/utils["'];?\r?\n?/g, 'import { cn } from "../../lib/utils"\n');
977
- content = content.replace(/import\s*\{[^}]*\}\s*from\s*["']@\/components\/ui\/slot["'];?\r?\n?/g, 'import { Slot } from "./slot"\n');
978
- const allComponents = [
974
+ const lines = content.split("\n");
975
+ const result = [];
976
+ const componentNames = [
979
977
  "accordion",
980
978
  "alert-dialog",
981
979
  "alert",
@@ -1045,10 +1043,29 @@ var ComponentAdder = class {
1045
1043
  "tooltip",
1046
1044
  "whatsapp"
1047
1045
  ];
1048
- for (const comp of allComponents) {
1049
- content = content.replace(new RegExp(`from\\s+["']@/components/ui/${comp}["']`, "g"), `from "./${comp}"`);
1046
+ for (const line of lines) {
1047
+ if (line.includes('"use client"') || line.includes("'use client'")) continue;
1048
+ if (line.includes('from "next-themes"') || line.includes("from 'next-themes'")) continue;
1049
+ if (line.includes('from "@/lib/utils"') || line.includes("from '@/lib/utils")) {
1050
+ result.push(line.replace(/@\/lib\/utils/, "../../lib/utils"));
1051
+ continue;
1052
+ }
1053
+ if (line.includes('from "@/components/ui/slot"') || line.includes("from '@/components/ui/slot")) {
1054
+ result.push(line.replace(/@\/components\/ui\/slot/, "./slot"));
1055
+ continue;
1056
+ }
1057
+ let matched = false;
1058
+ for (const comp of componentNames) {
1059
+ if (line.includes(`@/components/ui/${comp}"`) || line.includes(`'@/components/ui/${comp}'`)) {
1060
+ result.push(line.replace(`@/components/ui/${comp}`, `./${comp}`));
1061
+ matched = true;
1062
+ break;
1063
+ }
1064
+ }
1065
+ if (matched) continue;
1066
+ result.push(line);
1050
1067
  }
1051
- return content.trimStart();
1068
+ return result.join("\n").trim();
1052
1069
  }
1053
1070
  async add(components) {
1054
1071
  if (this.framework === "vite") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srcroot/ui",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A UI library with polymorphic, accessible React components",
5
5
  "readme": "README.md",
6
6
  "author": "Shifaul Islam",