assistant-ui 0.0.114 → 0.0.116
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.
- package/dist/codemods/v0-12/assistant-api-to-aui.js +1 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.js.map +1 -1
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -1
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js +7 -5
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -1
- package/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +8 -7
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/create.d.ts +9 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +25 -8
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/info.d.ts.map +1 -1
- package/dist/commands/info.js +0 -1
- package/dist/commands/info.js.map +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +0 -1
- package/dist/commands/mcp.js.map +1 -1
- package/dist/lib/create-project.d.ts +7 -1
- package/dist/lib/create-project.d.ts.map +1 -1
- package/dist/lib/create-project.js +27 -18
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/utils/registry.d.ts +4 -2
- package/dist/lib/utils/registry.d.ts.map +1 -1
- package/dist/lib/utils/registry.js +13 -2
- package/dist/lib/utils/registry.js.map +1 -1
- package/package.json +6 -6
- package/src/codemods/v0-12/__tests__/primitive-if-to-aui-if.test.ts +48 -1
- package/src/codemods/v0-12/assistant-api-to-aui.ts +4 -1
- package/src/codemods/v0-12/primitive-if-to-aui-if.ts +18 -7
- package/src/commands/add.ts +10 -6
- package/src/commands/create.ts +47 -8
- package/src/commands/info.ts +0 -1
- package/src/commands/init.ts +1 -1
- package/src/commands/mcp.ts +0 -3
- package/src/lib/create-project.ts +35 -20
- package/src/lib/run-spawn.test.ts +0 -1
- package/src/lib/utils/registry.test.ts +56 -0
- package/src/lib/utils/registry.ts +35 -0
- package/src/run.test.ts +1 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-project.js","names":["path","fs","parseJsonc"],"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { downloadTemplate } from \"giget\";\nimport {\n parse as parseJsonc,\n printParseErrorCode,\n type ParseError,\n} from \"jsonc-parser\";\nimport { logger } from \"./utils/logger\";\nimport { runSpawn, SpawnExitError, SpawnSignalError } from \"./run-spawn\";\nimport { type PackageManagerName } from \"./utils/package-manager\";\nimport { readProjectFiles } from \"./utils/file-scanner\";\n\nexport function dlxCommand(pm: PackageManagerName): [string, string[]] {\n switch (pm) {\n case \"pnpm\":\n return [\"pnpm\", [\"dlx\"]];\n case \"yarn\":\n return [\"yarn\", [\"dlx\"]];\n case \"bun\":\n return [\"bunx\", []];\n case \"npm\":\n return [\"npx\", [\"--yes\"]];\n }\n}\n\nexport interface TransformOptions {\n hasLocalComponents: boolean;\n skipInstall?: boolean;\n packageManager: PackageManagerName;\n}\n\nexport type ProjectSource =\n | {\n kind: \"github\";\n ref: string | undefined;\n }\n | {\n kind: \"local\";\n rootDir: string;\n };\n\nconst LOCAL_PROJECT_ARTIFACT_DIRS: readonly string[] = [\n \"node_modules\",\n \".next\",\n \"dist\",\n \"build\",\n];\n\nconst LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES = LOCAL_PROJECT_ARTIFACT_DIRS.map(\n (dir) => `**/${dir}/**`,\n);\n\nexport function resolvePackageManager(opts: {\n useNpm?: boolean;\n usePnpm?: boolean;\n useYarn?: boolean;\n useBun?: boolean;\n}): PackageManagerName | undefined {\n if (opts.useNpm) return \"npm\";\n if (opts.usePnpm) return \"pnpm\";\n if (opts.useYarn) return \"yarn\";\n if (opts.useBun) return \"bun\";\n return undefined;\n}\n\nfunction resolveGitHubAuthToken(): string | undefined {\n const token =\n process.env.GIGET_AUTH ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;\n const trimmed = token?.trim();\n return trimmed || undefined;\n}\n\nfunction toBearerAuthHeader(token: string): string {\n return token.toLowerCase().startsWith(\"bearer \") ? token : `Bearer ${token}`;\n}\n\nexport async function resolveLatestReleaseRef(): Promise<string | undefined> {\n try {\n const authToken = resolveGitHubAuthToken();\n const res = await fetch(\n \"https://api.github.com/repos/assistant-ui/assistant-ui/releases/latest\",\n authToken\n ? { headers: { Authorization: toBearerAuthHeader(authToken) } }\n : undefined,\n );\n if (!res.ok) return undefined;\n const release = (await res.json()) as { tag_name: string };\n return release.tag_name || undefined;\n } catch {\n return undefined;\n }\n}\n\nconst DOWNLOAD_TIMEOUT_MS = 30_000;\n\nexport async function downloadProject(\n repoPath: string,\n destDir: string,\n ref?: string,\n): Promise<void> {\n const source = ref\n ? `gh:assistant-ui/assistant-ui/${repoPath}#${ref}`\n : `gh:assistant-ui/assistant-ui/${repoPath}`;\n\n // Suppress giget's debug output. The `debug` package (used by the upgrade\n // command) sets process.env.DEBUG at module-load time, and giget logs to\n // console.debug whenever that env var is truthy — even for unrelated\n // namespaces. Temporarily unsetting it targets the root cause.\n const origDebug = process.env.DEBUG;\n delete process.env.DEBUG;\n try {\n const authToken = resolveGitHubAuthToken();\n const downloadPromise = downloadTemplate(source, {\n dir: destDir,\n force: true,\n silent: true,\n ...(authToken ? { auth: authToken } : {}),\n });\n\n let timer: ReturnType<typeof setTimeout>;\n const timeoutPromise = new Promise<never>((_, reject) => {\n timer = setTimeout(\n () =>\n reject(\n new Error(\n \"Download timed out. This may be due to GitHub rate limiting or a network issue. Try again in a few minutes.\",\n ),\n ),\n DOWNLOAD_TIMEOUT_MS,\n );\n });\n\n try {\n await Promise.race([downloadPromise, timeoutPromise]);\n } finally {\n clearTimeout(timer!);\n }\n } finally {\n if (origDebug !== undefined) {\n process.env.DEBUG = origDebug;\n }\n }\n}\n\nfunction shouldCopyLocalProjectPath(src: string, projectDir: string): boolean {\n const relative = path.relative(projectDir, src);\n if (!relative) return true;\n\n const segments = relative.split(path.sep);\n return !segments.some((segment) =>\n LOCAL_PROJECT_ARTIFACT_DIRS.includes(segment),\n );\n}\n\nexport async function scaffoldProject(\n repoPath: string,\n destDir: string,\n source: ProjectSource,\n): Promise<void> {\n if (source.kind === \"github\") {\n await downloadProject(repoPath, destDir, source.ref);\n return;\n }\n\n const localProjectDir = path.resolve(source.rootDir, repoPath);\n try {\n fs.cpSync(localProjectDir, destDir, {\n recursive: true,\n force: true,\n filter: (src) => shouldCopyLocalProjectPath(src, localProjectDir),\n });\n } catch (error) {\n const code =\n error instanceof Error\n ? (error as NodeJS.ErrnoException).code\n : undefined;\n if (code === \"ENOENT\") {\n throw new Error(\n `Local project source does not exist: ${localProjectDir}`,\n );\n }\n throw error;\n }\n}\n\nexport interface TransformResult {\n registryInstallFailure?: { retryCommand: string };\n}\n\nexport async function transformProject(\n projectDir: string,\n opts: TransformOptions,\n): Promise<TransformResult> {\n logger.step(\"Transforming package.json...\");\n transformPackageJson(projectDir);\n\n logger.step(\"Transforming project files...\");\n transformTsConfig(projectDir);\n transformCssFiles(projectDir);\n\n let assistantUI: string[] | undefined;\n let shadcnUI: string[] | undefined;\n\n if (!opts.hasLocalComponents) {\n const components = scanRequiredComponents(projectDir);\n assistantUI = components.assistantUI;\n shadcnUI = components.shadcnUI;\n }\n\n const pm = opts.packageManager;\n if (!opts.skipInstall) {\n logger.step(\"Installing dependencies...\");\n await installDependencies(projectDir, pm);\n }\n\n if (\n !opts.skipInstall &&\n !opts.hasLocalComponents &&\n shadcnUI &&\n assistantUI\n ) {\n const auiComponents = assistantUI.map((c) => `@assistant-ui/${c}`);\n const components = [\"@assistant-ui/utils\", ...shadcnUI, ...auiComponents];\n logger.step(`Installing components: ${components.join(\", \")}...`);\n const failure = await installShadcnRegistry(\n projectDir,\n components,\n \"components\",\n pm,\n );\n if (failure) return { registryInstallFailure: failure };\n await reconcileAssistantUIImportLayout(projectDir);\n }\n return {};\n}\n\nfunction transformPackageJson(projectDir: string): void {\n const pkgPath = path.join(projectDir, \"package.json\");\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n\n // Remove @assistant-ui/ui dependency\n if (pkg.dependencies?.[\"@assistant-ui/ui\"]) {\n delete pkg.dependencies[\"@assistant-ui/ui\"];\n }\n\n // Transform workspace dependencies to latest\n for (const depType of [\"dependencies\", \"devDependencies\"] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n\n for (const [name, version] of Object.entries(deps)) {\n if (String(version).includes(\"workspace:\")) {\n deps[name] = \"latest\";\n }\n }\n }\n\n // Remove devDependencies that are workspace-only\n if (pkg.devDependencies?.[\"@assistant-ui/x-buildutils\"]) {\n delete pkg.devDependencies[\"@assistant-ui/x-buildutils\"];\n }\n\n // Update package name to be unique\n const dirName = path.basename(projectDir);\n pkg.name = dirName;\n\n fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n}\n\nfunction parseTsConfig(content: string): any {\n const errors: ParseError[] = [];\n const tsconfig = parseJsonc(content, errors, { allowTrailingComma: true });\n const error = errors[0];\n if (error) {\n throw new SyntaxError(\n `Invalid tsconfig.json: ${printParseErrorCode(error.error)} at offset ${error.offset}`,\n );\n }\n return tsconfig;\n}\n\nfunction transformTsConfig(projectDir: string): void {\n const tsconfigPath = path.join(projectDir, \"tsconfig.json\");\n\n if (!fs.existsSync(tsconfigPath)) {\n return;\n }\n\n const content = fs.readFileSync(tsconfigPath, \"utf-8\");\n const tsconfig = parseTsConfig(content);\n\n // Remove workspace paths\n if (tsconfig.compilerOptions?.paths) {\n const workspaceKeys = new Set([\n \"@/components/assistant-ui/*\",\n \"@/components/icons/*\",\n \"@/components/ui/*\",\n \"@/components/ui/radix/*\",\n \"@/hooks/*\",\n \"@/lib/utils\",\n \"@assistant-ui/ui/*\",\n ]);\n for (const [key, targets] of Object.entries(\n tsconfig.compilerOptions.paths as Record<string, unknown>,\n )) {\n const targetsWorkspace =\n Array.isArray(targets) &&\n targets.some(\n (target) =>\n typeof target === \"string\" &&\n (target.includes(\"packages/ui/\") || target.startsWith(\"../\")),\n );\n if (workspaceKeys.has(key) || targetsWorkspace) {\n delete tsconfig.compilerOptions.paths[key];\n }\n }\n\n if (Object.keys(tsconfig.compilerOptions.paths).length === 0) {\n delete tsconfig.compilerOptions.paths;\n }\n }\n\n // If extends uses @assistant-ui/x-buildutils, replace with inline config\n if (tsconfig.extends?.includes(\"@assistant-ui/x-buildutils\")) {\n const isNext = tsconfig.extends.includes(\"ts/next\");\n delete tsconfig.extends;\n\n const inlinedCompilerOptions = {\n target: \"ESNext\",\n lib: [\"dom\", \"dom.iterable\", \"ES2023\"],\n skipLibCheck: true,\n strict: true,\n noEmit: true,\n esModuleInterop: true,\n module: \"ESNext\",\n moduleResolution: \"bundler\",\n resolveJsonModule: true,\n isolatedModules: true,\n jsx: \"react-jsx\",\n ...(isNext ? { plugins: [{ name: \"next\" }] } : {}),\n };\n\n tsconfig.compilerOptions = {\n ...inlinedCompilerOptions,\n ...tsconfig.compilerOptions,\n paths: {\n \"@/*\": [\"./*\"],\n ...(tsconfig.compilerOptions?.paths || {}),\n },\n };\n }\n\n fs.writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\\n`);\n}\n\nfunction transformCssFiles(projectDir: string): void {\n for (const { fullPath, content } of readProjectFiles(\"**/*.css\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n try {\n const newContent = content.replace(\n /@source\\s+[\"'][^\"']*packages\\/ui\\/src[^\"']*[\"'];\\s*\\n?/g,\n \"\",\n );\n\n if (newContent !== content) {\n fs.writeFileSync(fullPath, newContent);\n }\n } catch {\n continue;\n }\n }\n}\n\ninterface RequiredComponents {\n assistantUI: string[];\n shadcnUI: string[];\n}\n\nfunction stripImportExtension(component: string): string {\n return component.replace(/\\.[cm]?[tj]sx?$/, \"\");\n}\n\nconst ASSISTANT_UI_OWNED_UI = new Set([\n \"accordion\",\n \"badge\",\n \"diff-viewer\",\n \"direction\",\n \"dot-matrix\",\n \"number-roll\",\n \"select\",\n \"tabs\",\n]);\n\nconst BARE_ELEMENT_ITEMS = new Set([\n \"file\",\n \"generative-ui\",\n \"heat-graph\",\n \"image\",\n \"logos\",\n \"markdown-text\",\n \"syntax-highlighter\",\n \"tooltip-icon-button\",\n]);\n\nfunction toAssistantUIItem(specifier: string): string | null {\n let name = stripImportExtension(specifier);\n const inElements = name.startsWith(\"elements/\");\n if (inElements) {\n name = name.slice(\"elements/\".length);\n } else if (name.includes(\"/\")) {\n return null;\n }\n if (name.endsWith(\".aui\")) {\n return name.slice(0, -\".aui\".length);\n }\n return inElements && !BARE_ELEMENT_ITEMS.has(name)\n ? `elements-${name}`\n : name;\n}\n\n/**\n * Example snapshots are downloaded at a release tag while the shadcn registry\n * is live, so a snapshot may import components at the legacy flat path\n * (`@/components/assistant-ui/<name>`) after the registry has moved the file\n * to `components/assistant-ui/elements/<name>.aui.tsx`. Resolve each legacy\n * specifier against the files the registry actually installed and rewrite it\n * only when the legacy path is absent and the elements layout has it.\n */\nexport async function reconcileAssistantUIImportLayout(\n projectDir: string,\n): Promise<void> {\n const componentRoots = [\"components\", \"src/components\"]\n .map((dir) => path.join(projectDir, dir, \"assistant-ui\"))\n .filter((dir) => fs.existsSync(dir));\n if (componentRoots.length === 0) return;\n\n const resolvesAtLegacyPath = (name: string) =>\n componentRoots.some((root) =>\n [\".tsx\", \".ts\", \"/index.tsx\", \"/index.ts\"].some((suffix) =>\n fs.existsSync(path.join(root, `${name}${suffix}`)),\n ),\n );\n\n // Index the installed tree by import name so the rewrite follows whatever\n // layout the registry delivered — some items install as\n // elements/<name>.aui.tsx, others as elements/<name>.tsx, and a future\n // layout move should not require new knowledge here.\n const installedByName = new Map<string, string>();\n for (const root of componentRoots) {\n for (const { file } of readProjectFiles(\"**/*.{ts,tsx}\", { cwd: root })) {\n const normalized = file.split(path.sep).join(\"/\");\n if (!normalized.includes(\"/\")) continue;\n const specifier = normalized.replace(/\\.[cm]?[tj]sx?$/, \"\");\n const name = path.posix.basename(specifier).replace(/\\.aui$/, \"\");\n // A flat legacy import maps to the registry's `<name>` item, which is\n // the `.aui` file; a colliding bare file with the same basename belongs\n // to the distinct `elements-<name>` item, so the `.aui` variant wins.\n const existing = installedByName.get(name);\n if (\n existing === undefined ||\n (!existing.endsWith(\".aui\") && specifier.endsWith(\".aui\"))\n ) {\n installedByName.set(name, specifier);\n }\n }\n }\n if (installedByName.size === 0) return;\n\n const { default: jscodeshift } = await import(\"jscodeshift\");\n const parsers = {\n ts: jscodeshift.withParser(\"ts\"),\n tsx: jscodeshift.withParser(\"tsx\"),\n };\n\n for (const { fullPath, content } of readProjectFiles(\"**/*.{ts,tsx}\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n if (!content.includes(\"@/components/assistant-ui/\")) continue;\n\n const replacements: Array<{ start: number; end: number; value: string }> =\n [];\n const collectReplacement = (source: {\n value?: unknown;\n start?: number | null;\n end?: number | null;\n }) => {\n if (\n typeof source.value !== \"string\" ||\n source.start == null ||\n source.end == null\n ) {\n return;\n }\n\n const prefix = \"@/components/assistant-ui/\";\n if (!source.value.startsWith(prefix)) return;\n const specifier = source.value.slice(prefix.length);\n if (specifier.includes(\"/\")) return;\n\n const name = stripImportExtension(specifier);\n const installed = installedByName.get(name);\n if (resolvesAtLegacyPath(name) || installed === undefined) return;\n\n const raw = content.slice(source.start, source.end);\n const quote = raw[0];\n if ((quote !== '\"' && quote !== \"'\") || raw.at(-1) !== quote) return;\n replacements.push({\n start: source.start,\n end: source.end,\n value: `${quote}@/components/assistant-ui/${installed}${quote}`,\n });\n };\n\n const j = fullPath.endsWith(\".tsx\") ? parsers.tsx : parsers.ts;\n let root;\n try {\n root = j(content);\n } catch {\n continue;\n }\n root\n .find(j.ImportDeclaration)\n .forEach(({ node }) => collectReplacement(node.source));\n root\n .find(j.ExportNamedDeclaration)\n .forEach(({ node }) => node.source && collectReplacement(node.source));\n root\n .find(j.ExportAllDeclaration)\n .forEach(({ node }) => collectReplacement(node.source));\n\n let next = content;\n for (const replacement of replacements.sort((a, b) => b.start - a.start)) {\n next =\n next.slice(0, replacement.start) +\n replacement.value +\n next.slice(replacement.end);\n }\n if (next !== content) fs.writeFileSync(fullPath, next);\n }\n}\n\nfunction scanRequiredComponents(projectDir: string): RequiredComponents {\n const assistantUIComponents = new Set<string>();\n const shadcnUIComponents = new Set<string>();\n\n for (const { content } of readProjectFiles(\"**/*.{ts,tsx}\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n const assistantUIRegex =\n /from\\s+[\"']@\\/components\\/assistant-ui\\/([^\"']+)[\"']/g;\n for (const match of content.matchAll(assistantUIRegex)) {\n const item = toAssistantUIItem(match[1]!);\n if (item) assistantUIComponents.add(item);\n }\n\n const uiRegex = /from\\s+[\"']@\\/components\\/ui\\/([^\"']+)[\"']/g;\n for (const match of content.matchAll(uiRegex)) {\n const name = stripImportExtension(match[1]!);\n if (ASSISTANT_UI_OWNED_UI.has(name)) {\n assistantUIComponents.add(name);\n } else {\n shadcnUIComponents.add(name);\n }\n }\n }\n\n return {\n assistantUI: Array.from(assistantUIComponents),\n shadcnUI: Array.from(shadcnUIComponents),\n };\n}\n\nasync function installDependencies(\n projectDir: string,\n pm: PackageManagerName,\n): Promise<void> {\n const args = pm === \"yarn\" ? [] : [\"install\"];\n try {\n await runSpawn(pm, args, projectDir);\n } catch (error) {\n if (error instanceof SpawnSignalError) {\n throw error;\n }\n if (error instanceof SpawnExitError) {\n throw new Error(`${pm} install exited with code ${error.code}`);\n }\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to install dependencies: ${message}`);\n }\n}\n\nasync function installShadcnRegistry(\n projectDir: string,\n components: string[],\n label: string,\n pm: PackageManagerName,\n): Promise<{ retryCommand: string } | undefined> {\n const [cmd, dlxArgs] = dlxCommand(pm);\n // For npm, dlxArgs may already include `--yes` for npx auto-install.\n // The trailing `--yes` is for shadcn's own confirmation prompt.\n const retryArgs = [...dlxArgs, \"shadcn@latest\", \"add\", ...components];\n const addArgs = [...retryArgs, \"--yes\"];\n\n try {\n await runSpawn(cmd, addArgs, projectDir);\n return undefined;\n } catch (error) {\n if (error instanceof SpawnSignalError) {\n throw error;\n }\n if (error instanceof SpawnExitError) {\n logger.warn(`shadcn exited with code ${error.code}.`);\n return { retryCommand: `${cmd} ${retryArgs.join(\" \")}` };\n }\n\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to install ${label}: ${message}`);\n }\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,WAAW,IAA4C;CACrE,QAAQ,IAAR;EACE,KAAK,QACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;EACzB,KAAK,QACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;EACzB,KAAK,OACH,OAAO,CAAC,QAAQ,CAAC,CAAC;EACpB,KAAK,OACH,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;CAC5B;AACF;AAkBA,MAAM,8BAAiD;CACrD;CACA;CACA;CACA;AACF;AAEA,MAAM,sCAAsC,4BAA4B,KACrE,QAAQ,MAAM,IAAI,IACrB;AAEA,SAAgB,sBAAsB,MAKH;CACjC,IAAI,KAAK,QAAQ,OAAO;CACxB,IAAI,KAAK,SAAS,OAAO;CACzB,IAAI,KAAK,SAAS,OAAO;CACzB,IAAI,KAAK,QAAQ,OAAO;AAE1B;AAEA,SAAS,yBAA6C;CAIpD,QAFE,QAAQ,IAAI,cAAc,QAAQ,IAAI,gBAAgB,QAAQ,IAAI,SAAA,EAC7C,KAAK,KACV,KAAA;AACpB;AAEA,SAAS,mBAAmB,OAAuB;CACjD,OAAO,MAAM,YAAY,CAAC,CAAC,WAAW,SAAS,IAAI,QAAQ,UAAU;AACvE;AAEA,eAAsB,0BAAuD;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F;AAEA,eAAe,sBACb,YACA,YACA,OACA,IAC+C;CAC/C,MAAM,CAAC,KAAK,WAAW,WAAW,EAAE;CAGpC,MAAM,YAAY;EAAC,GAAG;EAAS;EAAiB;EAAO,GAAG;CAAU;CACpE,MAAM,UAAU,CAAC,GAAG,WAAW,OAAO;CAEtC,IAAI;EACF,MAAM,SAAS,KAAK,SAAS,UAAU;EACvC;CACF,SAAS,OAAO;EACd,IAAI,iBAAiB,kBACnB,MAAM;EAER,IAAI,iBAAiB,gBAAgB;GACnC,OAAO,KAAK,2BAA2B,MAAM,KAAK,EAAE;GACpD,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,UAAU,KAAK,GAAG,IAAI;EACzD;EAEA,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,IAAI,MAAM,qBAAqB,MAAM,IAAI,SAAS;CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"create-project.js","names":["path","fs","parseJsonc"],"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { downloadTemplate } from \"giget\";\nimport {\n parse as parseJsonc,\n printParseErrorCode,\n type ParseError,\n} from \"jsonc-parser\";\nimport { logger } from \"./utils/logger\";\nimport { runSpawn, SpawnExitError, SpawnSignalError } from \"./run-spawn\";\nimport { type PackageManagerName } from \"./utils/package-manager\";\nimport { readProjectFiles } from \"./utils/file-scanner\";\nimport {\n detectRegistryPlatform,\n resolveRegistryItemUrl,\n} from \"./utils/registry\";\n\nexport function dlxCommand(pm: PackageManagerName): [string, string[]] {\n switch (pm) {\n case \"pnpm\":\n return [\"pnpm\", [\"dlx\"]];\n case \"yarn\":\n return [\"yarn\", [\"dlx\"]];\n case \"bun\":\n return [\"bunx\", []];\n case \"npm\":\n return [\"npx\", [\"--yes\"]];\n }\n}\n\nexport interface TransformOptions {\n hasLocalComponents: boolean;\n skipInstall?: boolean;\n packageManager: PackageManagerName;\n}\n\nexport type ProjectSource =\n | {\n kind: \"github\";\n ref: string | undefined;\n }\n | {\n kind: \"local\";\n rootDir: string;\n };\n\nconst LOCAL_PROJECT_ARTIFACT_DIRS: readonly string[] = [\n \"node_modules\",\n \".next\",\n \"dist\",\n \"build\",\n];\n\nconst LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES = LOCAL_PROJECT_ARTIFACT_DIRS.map(\n (dir) => `**/${dir}/**`,\n);\n\nexport function resolvePackageManager(opts: {\n useNpm?: boolean;\n usePnpm?: boolean;\n useYarn?: boolean;\n useBun?: boolean;\n}): PackageManagerName | undefined {\n if (opts.useNpm) return \"npm\";\n if (opts.usePnpm) return \"pnpm\";\n if (opts.useYarn) return \"yarn\";\n if (opts.useBun) return \"bun\";\n return undefined;\n}\n\nfunction resolveGitHubAuthToken(): string | undefined {\n const token =\n process.env.GIGET_AUTH ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;\n const trimmed = token?.trim();\n return trimmed || undefined;\n}\n\nfunction toBearerAuthHeader(token: string): string {\n return token.toLowerCase().startsWith(\"bearer \") ? token : `Bearer ${token}`;\n}\n\nexport async function resolveLatestReleaseRef(): Promise<string | undefined> {\n try {\n const authToken = resolveGitHubAuthToken();\n const res = await fetch(\n \"https://api.github.com/repos/assistant-ui/assistant-ui/releases/latest\",\n authToken\n ? { headers: { Authorization: toBearerAuthHeader(authToken) } }\n : undefined,\n );\n if (!res.ok) return undefined;\n const release = (await res.json()) as { tag_name: string };\n return release.tag_name || undefined;\n } catch {\n return undefined;\n }\n}\n\nconst DOWNLOAD_TIMEOUT_MS = 30_000;\n\nexport async function downloadProject(\n repoPath: string,\n destDir: string,\n ref?: string,\n): Promise<void> {\n const source = ref\n ? `gh:assistant-ui/assistant-ui/${repoPath}#${ref}`\n : `gh:assistant-ui/assistant-ui/${repoPath}`;\n\n // Suppress giget's debug output. The `debug` package (used by the upgrade\n // command) sets process.env.DEBUG at module-load time, and giget logs to\n // console.debug whenever that env var is truthy — even for unrelated\n // namespaces. Temporarily unsetting it targets the root cause.\n const origDebug = process.env.DEBUG;\n delete process.env.DEBUG;\n try {\n const authToken = resolveGitHubAuthToken();\n const downloadPromise = downloadTemplate(source, {\n dir: destDir,\n force: true,\n silent: true,\n ...(authToken ? { auth: authToken } : {}),\n });\n\n let timer: ReturnType<typeof setTimeout>;\n const timeoutPromise = new Promise<never>((_, reject) => {\n timer = setTimeout(\n () =>\n reject(\n new Error(\n \"Download timed out. This may be due to GitHub rate limiting or a network issue. Try again in a few minutes.\",\n ),\n ),\n DOWNLOAD_TIMEOUT_MS,\n );\n });\n\n try {\n await Promise.race([downloadPromise, timeoutPromise]);\n } finally {\n clearTimeout(timer!);\n }\n } finally {\n if (origDebug !== undefined) {\n process.env.DEBUG = origDebug;\n }\n }\n}\n\nfunction shouldCopyLocalProjectPath(src: string, projectDir: string): boolean {\n const relative = path.relative(projectDir, src);\n if (!relative) return true;\n\n const segments = relative.split(path.sep);\n return !segments.some((segment) =>\n LOCAL_PROJECT_ARTIFACT_DIRS.includes(segment),\n );\n}\n\nexport async function scaffoldProject(\n repoPath: string,\n destDir: string,\n source: ProjectSource,\n): Promise<void> {\n if (source.kind === \"github\") {\n await downloadProject(repoPath, destDir, source.ref);\n return;\n }\n\n const localProjectDir = path.resolve(source.rootDir, repoPath);\n try {\n fs.cpSync(localProjectDir, destDir, {\n recursive: true,\n force: true,\n filter: (src) => shouldCopyLocalProjectPath(src, localProjectDir),\n });\n } catch (error) {\n const code =\n error instanceof Error\n ? (error as NodeJS.ErrnoException).code\n : undefined;\n if (code === \"ENOENT\") {\n throw new Error(\n `Local project source does not exist: ${localProjectDir}`,\n );\n }\n throw error;\n }\n}\n\nexport interface TransformResult {\n registryInstallFailure?: { retryCommand: string };\n registryInstallCommand?: string;\n}\n\nexport async function transformProject(\n projectDir: string,\n opts: TransformOptions,\n): Promise<TransformResult> {\n logger.step(\"Transforming package.json...\");\n transformPackageJson(projectDir);\n\n logger.step(\"Transforming project files...\");\n transformTsConfig(projectDir);\n transformCssFiles(projectDir);\n\n const components = opts.hasLocalComponents\n ? undefined\n : resolveRegistryComponents(projectDir, scanRequiredComponents(projectDir));\n\n const pm = opts.packageManager;\n if (opts.skipInstall) {\n if (!components) return {};\n const [cmd, dlxArgs] = dlxCommand(pm);\n return {\n registryInstallCommand: `${cmd} ${[...dlxArgs, \"shadcn@latest\", \"add\", ...components].join(\" \")}`,\n };\n }\n\n logger.step(\"Installing dependencies...\");\n await installDependencies(projectDir, pm);\n\n if (components) {\n logger.step(`Installing components: ${components.join(\", \")}...`);\n const failure = await installShadcnRegistry(\n projectDir,\n components,\n \"components\",\n pm,\n );\n if (failure) return { registryInstallFailure: failure };\n await reconcileAssistantUIImportLayout(projectDir);\n }\n return {};\n}\n\nfunction resolveRegistryComponents(\n projectDir: string,\n { assistantUI, shadcnUI }: RequiredComponents,\n): string[] {\n if (detectRegistryPlatform(projectDir) === \"native\") {\n return [\"utils\", ...shadcnUI, ...assistantUI].map((component) =>\n resolveRegistryItemUrl(component, undefined, \"native\"),\n );\n }\n return [\n \"@assistant-ui/utils\",\n ...shadcnUI,\n ...assistantUI.map((component) => `@assistant-ui/${component}`),\n ];\n}\n\nfunction transformPackageJson(projectDir: string): void {\n const pkgPath = path.join(projectDir, \"package.json\");\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n\n // Remove @assistant-ui/ui dependency\n if (pkg.dependencies?.[\"@assistant-ui/ui\"]) {\n delete pkg.dependencies[\"@assistant-ui/ui\"];\n }\n\n // Transform workspace dependencies to latest\n for (const depType of [\"dependencies\", \"devDependencies\"] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n\n for (const [name, version] of Object.entries(deps)) {\n if (String(version).includes(\"workspace:\")) {\n deps[name] = \"latest\";\n }\n }\n }\n\n // Remove devDependencies that are workspace-only\n if (pkg.devDependencies?.[\"@assistant-ui/x-buildutils\"]) {\n delete pkg.devDependencies[\"@assistant-ui/x-buildutils\"];\n }\n\n // Update package name to be unique\n const dirName = path.basename(projectDir);\n pkg.name = dirName;\n\n fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n}\n\nfunction parseTsConfig(content: string): any {\n const errors: ParseError[] = [];\n const tsconfig = parseJsonc(content, errors, { allowTrailingComma: true });\n const error = errors[0];\n if (error) {\n throw new SyntaxError(\n `Invalid tsconfig.json: ${printParseErrorCode(error.error)} at offset ${error.offset}`,\n );\n }\n return tsconfig;\n}\n\nfunction transformTsConfig(projectDir: string): void {\n const tsconfigPath = path.join(projectDir, \"tsconfig.json\");\n\n if (!fs.existsSync(tsconfigPath)) {\n return;\n }\n\n const content = fs.readFileSync(tsconfigPath, \"utf-8\");\n const tsconfig = parseTsConfig(content);\n\n // Remove workspace paths\n if (tsconfig.compilerOptions?.paths) {\n const workspaceKeys = new Set([\n \"@/components/assistant-ui/*\",\n \"@/components/icons/*\",\n \"@/components/ui/*\",\n \"@/components/ui/radix/*\",\n \"@/hooks/*\",\n \"@/lib/utils\",\n \"@assistant-ui/ui/*\",\n ]);\n for (const [key, targets] of Object.entries(\n tsconfig.compilerOptions.paths as Record<string, unknown>,\n )) {\n const targetsWorkspace =\n Array.isArray(targets) &&\n targets.some(\n (target) =>\n typeof target === \"string\" &&\n (target.includes(\"packages/ui/\") || target.startsWith(\"../\")),\n );\n if (workspaceKeys.has(key) || targetsWorkspace) {\n delete tsconfig.compilerOptions.paths[key];\n }\n }\n\n if (Object.keys(tsconfig.compilerOptions.paths).length === 0) {\n delete tsconfig.compilerOptions.paths;\n }\n }\n\n // If extends uses @assistant-ui/x-buildutils, replace with inline config\n if (tsconfig.extends?.includes(\"@assistant-ui/x-buildutils\")) {\n const isNext = tsconfig.extends.includes(\"ts/next\");\n delete tsconfig.extends;\n\n const inlinedCompilerOptions = {\n target: \"ESNext\",\n lib: [\"dom\", \"dom.iterable\", \"ES2023\"],\n skipLibCheck: true,\n strict: true,\n noEmit: true,\n esModuleInterop: true,\n module: \"ESNext\",\n moduleResolution: \"bundler\",\n resolveJsonModule: true,\n isolatedModules: true,\n jsx: \"react-jsx\",\n ...(isNext ? { plugins: [{ name: \"next\" }] } : {}),\n };\n\n tsconfig.compilerOptions = {\n ...inlinedCompilerOptions,\n ...tsconfig.compilerOptions,\n paths: {\n \"@/*\": [\"./*\"],\n ...(tsconfig.compilerOptions?.paths || {}),\n },\n };\n }\n\n fs.writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\\n`);\n}\n\nfunction transformCssFiles(projectDir: string): void {\n for (const { fullPath, content } of readProjectFiles(\"**/*.css\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n try {\n const newContent = content.replace(\n /@source\\s+[\"'][^\"']*packages\\/ui\\/src[^\"']*[\"'];\\s*\\n?/g,\n \"\",\n );\n\n if (newContent !== content) {\n fs.writeFileSync(fullPath, newContent);\n }\n } catch {\n continue;\n }\n }\n}\n\ninterface RequiredComponents {\n assistantUI: string[];\n shadcnUI: string[];\n}\n\nfunction stripImportExtension(component: string): string {\n return component.replace(/\\.[cm]?[tj]sx?$/, \"\");\n}\n\nconst ASSISTANT_UI_OWNED_UI = new Set([\n \"accordion\",\n \"badge\",\n \"diff-viewer\",\n \"direction\",\n \"dot-matrix\",\n \"number-roll\",\n \"select\",\n \"tabs\",\n]);\n\nconst BARE_ELEMENT_ITEMS = new Set([\n \"file\",\n \"generative-ui\",\n \"heat-graph\",\n \"image\",\n \"logos\",\n \"markdown-text\",\n \"syntax-highlighter\",\n \"tooltip-icon-button\",\n]);\n\nfunction toAssistantUIItem(specifier: string): string | null {\n let name = stripImportExtension(specifier);\n const inElements = name.startsWith(\"elements/\");\n if (inElements) {\n name = name.slice(\"elements/\".length);\n } else if (name.includes(\"/\")) {\n return null;\n }\n if (name.endsWith(\".aui\")) {\n return name.slice(0, -\".aui\".length);\n }\n return inElements && !BARE_ELEMENT_ITEMS.has(name)\n ? `elements-${name}`\n : name;\n}\n\n/**\n * Example snapshots are downloaded at a release tag while the shadcn registry\n * is live, so a snapshot may import components at the legacy flat path\n * (`@/components/assistant-ui/<name>`) after the registry has moved the file\n * to `components/assistant-ui/elements/<name>.aui.tsx`. Resolve each legacy\n * specifier against the files the registry actually installed and rewrite it\n * only when the legacy path is absent and the elements layout has it.\n */\nexport async function reconcileAssistantUIImportLayout(\n projectDir: string,\n): Promise<void> {\n const componentRoots = [\"components\", \"src/components\"]\n .map((dir) => path.join(projectDir, dir, \"assistant-ui\"))\n .filter((dir) => fs.existsSync(dir));\n if (componentRoots.length === 0) return;\n\n const resolvesAtLegacyPath = (name: string) =>\n componentRoots.some((root) =>\n [\".tsx\", \".ts\", \"/index.tsx\", \"/index.ts\"].some((suffix) =>\n fs.existsSync(path.join(root, `${name}${suffix}`)),\n ),\n );\n\n // Index the installed tree by import name so the rewrite follows whatever\n // layout the registry delivered — some items install as\n // elements/<name>.aui.tsx, others as elements/<name>.tsx, and a future\n // layout move should not require new knowledge here.\n const installedByName = new Map<string, string>();\n for (const root of componentRoots) {\n for (const { file } of readProjectFiles(\"**/*.{ts,tsx}\", { cwd: root })) {\n const normalized = file.split(path.sep).join(\"/\");\n if (!normalized.includes(\"/\")) continue;\n const specifier = normalized.replace(/\\.[cm]?[tj]sx?$/, \"\");\n const name = path.posix.basename(specifier).replace(/\\.aui$/, \"\");\n // A flat legacy import maps to the registry's `<name>` item, which is\n // the `.aui` file; a colliding bare file with the same basename belongs\n // to the distinct `elements-<name>` item, so the `.aui` variant wins.\n const existing = installedByName.get(name);\n if (\n existing === undefined ||\n (!existing.endsWith(\".aui\") && specifier.endsWith(\".aui\"))\n ) {\n installedByName.set(name, specifier);\n }\n }\n }\n if (installedByName.size === 0) return;\n\n const { default: jscodeshift } = await import(\"jscodeshift\");\n const parsers = {\n ts: jscodeshift.withParser(\"ts\"),\n tsx: jscodeshift.withParser(\"tsx\"),\n };\n\n for (const { fullPath, content } of readProjectFiles(\"**/*.{ts,tsx}\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n if (!content.includes(\"@/components/assistant-ui/\")) continue;\n\n const replacements: Array<{ start: number; end: number; value: string }> =\n [];\n const collectReplacement = (source: {\n value?: unknown;\n start?: number | null;\n end?: number | null;\n }) => {\n if (\n typeof source.value !== \"string\" ||\n source.start == null ||\n source.end == null\n ) {\n return;\n }\n\n const prefix = \"@/components/assistant-ui/\";\n if (!source.value.startsWith(prefix)) return;\n const specifier = source.value.slice(prefix.length);\n if (specifier.includes(\"/\")) return;\n\n const name = stripImportExtension(specifier);\n const installed = installedByName.get(name);\n if (resolvesAtLegacyPath(name) || installed === undefined) return;\n\n const raw = content.slice(source.start, source.end);\n const quote = raw[0];\n if ((quote !== '\"' && quote !== \"'\") || raw.at(-1) !== quote) return;\n replacements.push({\n start: source.start,\n end: source.end,\n value: `${quote}@/components/assistant-ui/${installed}${quote}`,\n });\n };\n\n const j = fullPath.endsWith(\".tsx\") ? parsers.tsx : parsers.ts;\n let root;\n try {\n root = j(content);\n } catch {\n continue;\n }\n root\n .find(j.ImportDeclaration)\n .forEach(({ node }) => collectReplacement(node.source));\n root\n .find(j.ExportNamedDeclaration)\n .forEach(({ node }) => node.source && collectReplacement(node.source));\n root\n .find(j.ExportAllDeclaration)\n .forEach(({ node }) => collectReplacement(node.source));\n\n let next = content;\n for (const replacement of replacements.sort((a, b) => b.start - a.start)) {\n next =\n next.slice(0, replacement.start) +\n replacement.value +\n next.slice(replacement.end);\n }\n if (next !== content) fs.writeFileSync(fullPath, next);\n }\n}\n\nexport function scanRequiredComponents(projectDir: string): RequiredComponents {\n const assistantUIComponents = new Set<string>();\n const shadcnUIComponents = new Set<string>();\n\n for (const { content } of readProjectFiles(\"**/*.{ts,tsx}\", {\n cwd: projectDir,\n ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,\n })) {\n const assistantUIRegex =\n /from\\s+[\"']@\\/components\\/assistant-ui\\/([^\"']+)[\"']/g;\n for (const match of content.matchAll(assistantUIRegex)) {\n const item = toAssistantUIItem(match[1]!);\n if (item) assistantUIComponents.add(item);\n }\n\n const uiRegex = /from\\s+[\"']@\\/components\\/ui\\/([^\"']+)[\"']/g;\n for (const match of content.matchAll(uiRegex)) {\n const name = stripImportExtension(match[1]!);\n if (ASSISTANT_UI_OWNED_UI.has(name)) {\n assistantUIComponents.add(name);\n } else {\n shadcnUIComponents.add(name);\n }\n }\n }\n\n return {\n assistantUI: Array.from(assistantUIComponents),\n shadcnUI: Array.from(shadcnUIComponents),\n };\n}\n\nasync function installDependencies(\n projectDir: string,\n pm: PackageManagerName,\n): Promise<void> {\n const args = pm === \"yarn\" ? [] : [\"install\"];\n try {\n await runSpawn(pm, args, projectDir);\n } catch (error) {\n if (error instanceof SpawnSignalError) {\n throw error;\n }\n if (error instanceof SpawnExitError) {\n throw new Error(`${pm} install exited with code ${error.code}`);\n }\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to install dependencies: ${message}`);\n }\n}\n\nasync function installShadcnRegistry(\n projectDir: string,\n components: string[],\n label: string,\n pm: PackageManagerName,\n): Promise<{ retryCommand: string } | undefined> {\n const [cmd, dlxArgs] = dlxCommand(pm);\n // For npm, dlxArgs may already include `--yes` for npx auto-install.\n // The trailing `--yes` is for shadcn's own confirmation prompt.\n const retryArgs = [...dlxArgs, \"shadcn@latest\", \"add\", ...components];\n const addArgs = [...retryArgs, \"--yes\"];\n\n try {\n await runSpawn(cmd, addArgs, projectDir);\n return undefined;\n } catch (error) {\n if (error instanceof SpawnSignalError) {\n throw error;\n }\n if (error instanceof SpawnExitError) {\n logger.warn(`shadcn exited with code ${error.code}.`);\n return { retryCommand: `${cmd} ${retryArgs.join(\" \")}` };\n }\n\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to install ${label}: ${message}`);\n }\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,WAAW,IAA4C;CACrE,QAAQ,IAAR;EACE,KAAK,QACH,OAAO,CAAC,QAAQ,CAAC,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AAM;EAER,IAAI,iBAAiB,gBAAgB;GACnC,OAAO,KAAK,2BAA2B,MAAM,KAAK,EAAE;GACpD,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,UAAU,KAAK,GAAG,IAAI;EACzD;EAEA,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,IAAI,MAAM,qBAAqB,MAAM,IAAI,SAAS;CAC1D;AACF"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//#region src/lib/utils/registry.d.ts
|
|
2
|
+
declare const SHARED_REGISTRY_ITEMS: Set<string>;
|
|
3
|
+
declare function detectRegistryPlatform(cwd: string): "web" | "native";
|
|
2
4
|
declare function getComponentsJsonStyle(cwd: string): string | undefined;
|
|
3
5
|
declare function resolveQuickStartRegistryUrl(style?: string): string;
|
|
4
|
-
declare function resolveRegistryItemUrl(component: string, style?: string): string;
|
|
6
|
+
declare function resolveRegistryItemUrl(component: string, style?: string, platform?: "web" | "native"): string;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { getComponentsJsonStyle, resolveQuickStartRegistryUrl, resolveRegistryItemUrl };
|
|
8
|
+
export { SHARED_REGISTRY_ITEMS, detectRegistryPlatform, getComponentsJsonStyle, resolveQuickStartRegistryUrl, resolveRegistryItemUrl };
|
|
7
9
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/lib/utils/registry.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/lib/utils/registry.ts"],"mappings":";cAIa,uBAAqB;iBAElB,uBAAuB;iBA2BvB,uBAAuB;iBAavB,6BAA6B;iBAW7B,uBACd,mBACA,gBACA"}
|
|
@@ -2,6 +2,16 @@ import * as fs$1 from "node:fs";
|
|
|
2
2
|
import * as path$1 from "node:path";
|
|
3
3
|
//#region src/lib/utils/registry.ts
|
|
4
4
|
const REGISTRY_BASE_URL = "https://r.assistant-ui.com";
|
|
5
|
+
const SHARED_REGISTRY_ITEMS = /* @__PURE__ */ new Set(["utils"]);
|
|
6
|
+
function detectRegistryPlatform(cwd) {
|
|
7
|
+
try {
|
|
8
|
+
const packageJsonPath = path$1.join(cwd, "package.json");
|
|
9
|
+
const packageJson = JSON.parse(fs$1.readFileSync(packageJsonPath, "utf8"));
|
|
10
|
+
return [packageJson.dependencies, packageJson.devDependencies].some((dependencies) => typeof dependencies === "object" && dependencies !== null && Object.hasOwn(dependencies, "react-native")) ? "native" : "web";
|
|
11
|
+
} catch {
|
|
12
|
+
return "web";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
5
15
|
function getComponentsJsonStyle(cwd) {
|
|
6
16
|
try {
|
|
7
17
|
const configPath = path$1.join(cwd, "components.json");
|
|
@@ -15,11 +25,12 @@ function resolveQuickStartRegistryUrl(style) {
|
|
|
15
25
|
if (style === void 0 || style.startsWith("base-")) return `${REGISTRY_BASE_URL}/base/chat/b/ai-sdk-quick-start/json`;
|
|
16
26
|
return `${REGISTRY_BASE_URL}/chat/b/ai-sdk-quick-start/json`;
|
|
17
27
|
}
|
|
18
|
-
function resolveRegistryItemUrl(component, style) {
|
|
28
|
+
function resolveRegistryItemUrl(component, style, platform = "web") {
|
|
29
|
+
if (platform === "native") return SHARED_REGISTRY_ITEMS.has(component) ? `${REGISTRY_BASE_URL}/${encodeURIComponent(component)}.json` : `${REGISTRY_BASE_URL}/native/${encodeURIComponent(component)}.json`;
|
|
19
30
|
if (style === void 0) return `${REGISTRY_BASE_URL}/base/${encodeURIComponent(component)}.json`;
|
|
20
31
|
return `${style.startsWith("base-") ? `${REGISTRY_BASE_URL}/styles/${encodeURIComponent(style)}` : REGISTRY_BASE_URL}/${encodeURIComponent(component)}.json`;
|
|
21
32
|
}
|
|
22
33
|
//#endregion
|
|
23
|
-
export { getComponentsJsonStyle, resolveQuickStartRegistryUrl, resolveRegistryItemUrl };
|
|
34
|
+
export { SHARED_REGISTRY_ITEMS, detectRegistryPlatform, getComponentsJsonStyle, resolveQuickStartRegistryUrl, resolveRegistryItemUrl };
|
|
24
35
|
|
|
25
36
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":["path","fs"],"sources":["../../../src/lib/utils/registry.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\nconst REGISTRY_BASE_URL = \"https://r.assistant-ui.com\";\n\nexport function getComponentsJsonStyle(cwd: string): string | undefined {\n try {\n const configPath = path.join(cwd, \"components.json\");\n const config = JSON.parse(fs.readFileSync(configPath, \"utf8\")) as {\n style?: unknown;\n };\n\n return typeof config.style === \"string\" ? config.style : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function resolveQuickStartRegistryUrl(style?: string): string {\n // The shadcn CLI appends a literal /json segment to fetched URLs containing\n // /chat/b/ unless they already end with it, so this item must use the direct\n // tree URLs rather than the /styles/ template.\n if (style === undefined || style.startsWith(\"base-\")) {\n return `${REGISTRY_BASE_URL}/base/chat/b/ai-sdk-quick-start/json`;\n }\n\n return `${REGISTRY_BASE_URL}/chat/b/ai-sdk-quick-start/json`;\n}\n\nexport function resolveRegistryItemUrl(\n component: string,\n style?: string,\n): string {\n if (style === undefined) {\n return `${REGISTRY_BASE_URL}/base/${encodeURIComponent(component)}.json`;\n }\n\n const registryUrl = style.startsWith(\"base-\")\n ? `${REGISTRY_BASE_URL}/styles/${encodeURIComponent(style)}`\n : REGISTRY_BASE_URL;\n\n return `${registryUrl}/${encodeURIComponent(component)}.json`;\n}\n"],"mappings":";;;AAGA,MAAM,oBAAoB;
|
|
1
|
+
{"version":3,"file":"registry.js","names":["path","fs"],"sources":["../../../src/lib/utils/registry.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\nconst REGISTRY_BASE_URL = \"https://r.assistant-ui.com\";\nexport const SHARED_REGISTRY_ITEMS = new Set([\"utils\"]);\n\nexport function detectRegistryPlatform(cwd: string): \"web\" | \"native\" {\n try {\n const packageJsonPath = path.join(cwd, \"package.json\");\n const packageJson = JSON.parse(\n fs.readFileSync(packageJsonPath, \"utf8\"),\n ) as {\n dependencies?: unknown;\n devDependencies?: unknown;\n };\n const dependencyGroups = [\n packageJson.dependencies,\n packageJson.devDependencies,\n ];\n\n return dependencyGroups.some(\n (dependencies) =>\n typeof dependencies === \"object\" &&\n dependencies !== null &&\n Object.hasOwn(dependencies, \"react-native\"),\n )\n ? \"native\"\n : \"web\";\n } catch {\n return \"web\";\n }\n}\n\nexport function getComponentsJsonStyle(cwd: string): string | undefined {\n try {\n const configPath = path.join(cwd, \"components.json\");\n const config = JSON.parse(fs.readFileSync(configPath, \"utf8\")) as {\n style?: unknown;\n };\n\n return typeof config.style === \"string\" ? config.style : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function resolveQuickStartRegistryUrl(style?: string): string {\n // The shadcn CLI appends a literal /json segment to fetched URLs containing\n // /chat/b/ unless they already end with it, so this item must use the direct\n // tree URLs rather than the /styles/ template.\n if (style === undefined || style.startsWith(\"base-\")) {\n return `${REGISTRY_BASE_URL}/base/chat/b/ai-sdk-quick-start/json`;\n }\n\n return `${REGISTRY_BASE_URL}/chat/b/ai-sdk-quick-start/json`;\n}\n\nexport function resolveRegistryItemUrl(\n component: string,\n style?: string,\n platform: \"web\" | \"native\" = \"web\",\n): string {\n if (platform === \"native\") {\n return SHARED_REGISTRY_ITEMS.has(component)\n ? `${REGISTRY_BASE_URL}/${encodeURIComponent(component)}.json`\n : `${REGISTRY_BASE_URL}/native/${encodeURIComponent(component)}.json`;\n }\n\n if (style === undefined) {\n return `${REGISTRY_BASE_URL}/base/${encodeURIComponent(component)}.json`;\n }\n\n const registryUrl = style.startsWith(\"base-\")\n ? `${REGISTRY_BASE_URL}/styles/${encodeURIComponent(style)}`\n : REGISTRY_BASE_URL;\n\n return `${registryUrl}/${encodeURIComponent(component)}.json`;\n}\n"],"mappings":";;;AAGA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ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.116",
|
|
4
4
|
"description": "CLI for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@assistant-ui/agent-launcher": "^0.1.
|
|
29
|
+
"@assistant-ui/agent-launcher": "^0.1.15",
|
|
30
30
|
"@clack/prompts": "^1.7.0",
|
|
31
31
|
"chalk": "^6.0.0",
|
|
32
32
|
"cli-progress": "^3.12.0",
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"semver": "^7.8.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
44
|
+
"@assistant-ui/x-buildutils": "0.0.27",
|
|
45
45
|
"@types/cli-progress": "^3.11.6",
|
|
46
46
|
"@types/cross-spawn": "^6.0.6",
|
|
47
47
|
"@types/debug": "^4.1.13",
|
|
48
48
|
"@types/jscodeshift": "^17.3.0",
|
|
49
|
-
"@types/node": "^26.4.
|
|
49
|
+
"@types/node": "^26.4.1",
|
|
50
50
|
"@types/semver": "^7.8.0",
|
|
51
|
-
"@vitest/coverage-v8": "^
|
|
52
|
-
"vitest": "^
|
|
51
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
52
|
+
"vitest": "^5.0.0"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public",
|
|
@@ -346,7 +346,7 @@ import { MessagePrimitive, AuiIf } from "@assistant-ui/react";
|
|
|
346
346
|
|
|
347
347
|
function MyComponent() {
|
|
348
348
|
return (
|
|
349
|
-
<AuiIf condition={(s) => !s.message.speech != null}>
|
|
349
|
+
<AuiIf condition={(s) => !(s.message.speech != null)}>
|
|
350
350
|
<SpeakIcon />
|
|
351
351
|
</AuiIf>
|
|
352
352
|
);
|
|
@@ -937,3 +937,50 @@ function MyComponent() {
|
|
|
937
937
|
);
|
|
938
938
|
});
|
|
939
939
|
});
|
|
940
|
+
|
|
941
|
+
describe("condition precedence", () => {
|
|
942
|
+
const compileCondition = (jsx: string) => {
|
|
943
|
+
const output = applyTransform(`
|
|
944
|
+
import { MessagePrimitive, ComposerPrimitive } from "@assistant-ui/react";
|
|
945
|
+
|
|
946
|
+
const view = ${jsx};
|
|
947
|
+
`);
|
|
948
|
+
const arrow = j(output!).find(j.ArrowFunctionExpression).nodes()[0]!;
|
|
949
|
+
return new Function("s", `return ${j(arrow.body).toSource()};`) as (
|
|
950
|
+
s: unknown,
|
|
951
|
+
) => boolean;
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
it.each([
|
|
955
|
+
{
|
|
956
|
+
jsx: "<MessagePrimitive.If speaking={false} />",
|
|
957
|
+
hidden: { message: { speech: { status: "running" } } },
|
|
958
|
+
visible: { message: { speech: null } },
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
jsx: "<ComposerPrimitive.If dictation={false} />",
|
|
962
|
+
hidden: { composer: { dictation: { status: "running" } } },
|
|
963
|
+
visible: { composer: { dictation: null } },
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
jsx: "<MessagePrimitive.If hasContent={false} />",
|
|
967
|
+
hidden: { message: { parts: [{}] } },
|
|
968
|
+
visible: { message: { parts: [] } },
|
|
969
|
+
},
|
|
970
|
+
{
|
|
971
|
+
jsx: "<MessagePrimitive.If lastOrHover copied />",
|
|
972
|
+
hidden: { message: { isHovering: true, isLast: false, isCopied: false } },
|
|
973
|
+
visible: { message: { isHovering: true, isLast: false, isCopied: true } },
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
jsx: "<MessagePrimitive.If hasAttachments={false} copied />",
|
|
977
|
+
hidden: { message: { role: "assistant", isCopied: false } },
|
|
978
|
+
visible: { message: { role: "assistant", isCopied: true } },
|
|
979
|
+
},
|
|
980
|
+
])("keeps every filter in $jsx", ({ jsx, hidden, visible }) => {
|
|
981
|
+
const condition = compileCondition(jsx);
|
|
982
|
+
|
|
983
|
+
expect(condition(hidden)).toBe(false);
|
|
984
|
+
expect(condition(visible)).toBe(true);
|
|
985
|
+
});
|
|
986
|
+
});
|
|
@@ -113,6 +113,7 @@ const migrateAssistantApiToAui = createTransformer(
|
|
|
113
113
|
}
|
|
114
114
|
if (j.VariableDeclaration.check(statement)) {
|
|
115
115
|
for (const declarator of statement.declarations) {
|
|
116
|
+
if (!j.VariableDeclarator.check(declarator)) continue;
|
|
116
117
|
if (
|
|
117
118
|
j.Identifier.check(declarator.id) &&
|
|
118
119
|
declarator.id.name === "api"
|
|
@@ -252,9 +253,11 @@ const migrateAssistantApiToAui = createTransformer(
|
|
|
252
253
|
grandparent.source != null
|
|
253
254
|
)
|
|
254
255
|
return;
|
|
256
|
+
// Babel emits exportKind on ExportSpecifier for inline
|
|
257
|
+
// `export { type api }`; ast-types' typings omit it.
|
|
255
258
|
if (
|
|
256
259
|
grandparent?.exportKind === "type" ||
|
|
257
|
-
parent.exportKind === "type"
|
|
260
|
+
(parent as { exportKind?: string }).exportKind === "type"
|
|
258
261
|
)
|
|
259
262
|
return;
|
|
260
263
|
if (parent.exported === path.value && parent.local !== path.value)
|
|
@@ -161,12 +161,23 @@ const getAttrValue = (j: any, attr: any): unknown => {
|
|
|
161
161
|
return UNSUPPORTED_VALUE;
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
// Composed as a syntax tree so the printer parenthesizes by precedence;
|
|
165
|
+
// concatenated text lets `!` and `&&` reassociate a fragment's own operators.
|
|
166
|
+
const buildConditionString = (
|
|
167
|
+
j: any,
|
|
168
|
+
fragments: ConditionFragment[],
|
|
169
|
+
): string => {
|
|
170
|
+
const parseExpression = (source: string) =>
|
|
171
|
+
j(`${source};`).find(j.ExpressionStatement).nodes()[0]!.expression;
|
|
172
|
+
|
|
173
|
+
const condition = fragments
|
|
174
|
+
.map((f) => {
|
|
175
|
+
const expression = parseExpression(f.expression);
|
|
176
|
+
return f.negated ? j.unaryExpression("!", expression) : expression;
|
|
177
|
+
})
|
|
178
|
+
.reduce((left: any, right: any) => j.logicalExpression("&&", left, right));
|
|
179
|
+
|
|
180
|
+
return j(condition).toSource();
|
|
170
181
|
};
|
|
171
182
|
|
|
172
183
|
const migratePrimitiveIfToAuiIf = createTransformer(
|
|
@@ -290,7 +301,7 @@ const migratePrimitiveIfToAuiIf = createTransformer(
|
|
|
290
301
|
// If we couldn't map all props, skip this element
|
|
291
302
|
if (hasUnknownProp || fragments.length === 0) return;
|
|
292
303
|
|
|
293
|
-
convertElementToAuiIf(path, buildConditionString(fragments));
|
|
304
|
+
convertElementToAuiIf(path, buildConditionString(j, fragments));
|
|
294
305
|
});
|
|
295
306
|
|
|
296
307
|
// Add AuiIf import if needed
|
package/src/commands/add.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from "commander";
|
|
|
2
2
|
import { logger } from "../lib/utils/logger";
|
|
3
3
|
import { hasConfig } from "../lib/utils/config";
|
|
4
4
|
import {
|
|
5
|
+
detectRegistryPlatform,
|
|
5
6
|
getComponentsJsonStyle,
|
|
6
7
|
resolveRegistryItemUrl,
|
|
7
8
|
} from "../lib/utils/registry";
|
|
@@ -22,15 +23,15 @@ export function createAddComponentsPlan(params: {
|
|
|
22
23
|
packageManager: PackageManagerName;
|
|
23
24
|
yes?: boolean;
|
|
24
25
|
overwrite?: boolean;
|
|
25
|
-
cwd?: string;
|
|
26
26
|
path?: string;
|
|
27
27
|
style?: string;
|
|
28
|
+
platform?: "web" | "native";
|
|
28
29
|
}): AddComponentsPlan {
|
|
29
30
|
const componentsToAdd = params.components.map((c) => {
|
|
30
31
|
if (!/^[a-zA-Z0-9-/]+$/.test(c)) {
|
|
31
32
|
throw new Error(`Invalid component name: ${c}`);
|
|
32
33
|
}
|
|
33
|
-
return resolveRegistryItemUrl(c, params.style);
|
|
34
|
+
return resolveRegistryItemUrl(c, params.style, params.platform);
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
const [command, dlxArgs] = dlxCommand(params.packageManager);
|
|
@@ -40,7 +41,6 @@ export function createAddComponentsPlan(params: {
|
|
|
40
41
|
// This flag is for shadcn's own confirmation prompt.
|
|
41
42
|
if (params.yes) args.push("--yes");
|
|
42
43
|
if (params.overwrite) args.push("--overwrite");
|
|
43
|
-
if (params.cwd) args.push("--cwd", params.cwd);
|
|
44
44
|
if (params.path) args.push("--path", params.path);
|
|
45
45
|
|
|
46
46
|
return { command, args };
|
|
@@ -63,29 +63,33 @@ export const add = new Command()
|
|
|
63
63
|
.option("--use-yarn", "explicitly use yarn")
|
|
64
64
|
.option("--use-bun", "explicitly use bun")
|
|
65
65
|
.action(async (components: string[], opts) => {
|
|
66
|
+
const platform = detectRegistryPlatform(opts.cwd);
|
|
67
|
+
|
|
66
68
|
// Check if project is initialized
|
|
67
69
|
if (!hasConfig(opts.cwd)) {
|
|
68
70
|
logger.warn(
|
|
69
|
-
|
|
71
|
+
`It looks like you haven't initialized your project yet. Defaulting to ${platform === "native" ? "the native component tree" : "Base UI flavored components"}. Run 'assistant-ui init' first for a configured setup.`,
|
|
70
72
|
);
|
|
71
73
|
logger.break();
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
logger.info(`Using the ${platform} registry tree.`);
|
|
74
77
|
logger.step(`Adding ${components.length} component(s)...`);
|
|
75
78
|
|
|
76
79
|
const packageManager = await resolvePackageManagerForCwd(
|
|
77
80
|
opts.cwd,
|
|
78
81
|
resolvePackageManager(opts),
|
|
79
82
|
);
|
|
80
|
-
const style =
|
|
83
|
+
const style =
|
|
84
|
+
platform === "web" ? getComponentsJsonStyle(opts.cwd) : undefined;
|
|
81
85
|
const { command, args } = createAddComponentsPlan({
|
|
82
86
|
components,
|
|
83
87
|
packageManager,
|
|
84
88
|
yes: opts.yes,
|
|
85
89
|
overwrite: opts.overwrite,
|
|
86
|
-
cwd: opts.cwd,
|
|
87
90
|
path: opts.path,
|
|
88
91
|
...(style === undefined ? {} : { style }),
|
|
92
|
+
platform,
|
|
89
93
|
});
|
|
90
94
|
|
|
91
95
|
try {
|
package/src/commands/create.ts
CHANGED
|
@@ -195,7 +195,7 @@ export const PROJECT_METADATA: ProjectMetadata[] = [
|
|
|
195
195
|
description: "Expo / React Native",
|
|
196
196
|
category: "example",
|
|
197
197
|
path: "examples/with-expo",
|
|
198
|
-
hasLocalComponents:
|
|
198
|
+
hasLocalComponents: false,
|
|
199
199
|
},
|
|
200
200
|
{
|
|
201
201
|
name: "with-interactables",
|
|
@@ -282,8 +282,6 @@ export const PROJECT_METADATA: ProjectMetadata[] = [
|
|
|
282
282
|
// Examples that exist in the monorepo but are intentionally excluded from the CLI:
|
|
283
283
|
//
|
|
284
284
|
// - waterfall: Still in development, not ready for production.
|
|
285
|
-
// - with-cloud-standalone: For cloud without assistant-ui — not for the
|
|
286
|
-
// assistant-ui CLI.
|
|
287
285
|
// - with-store: In development, not ready for public use of the tap store.
|
|
288
286
|
// - with-tap-runtime: In development, not ready for public use of the tap
|
|
289
287
|
// store.
|
|
@@ -388,6 +386,42 @@ export function resolveCreateProjectDirectory(params: {
|
|
|
388
386
|
return undefined;
|
|
389
387
|
}
|
|
390
388
|
|
|
389
|
+
export function resolveProjectDirectoryGuidance(params: {
|
|
390
|
+
absoluteProjectDir: string;
|
|
391
|
+
cwd?: string;
|
|
392
|
+
platform?: NodeJS.Platform;
|
|
393
|
+
}): { display: string; cdCommand: string } {
|
|
394
|
+
const {
|
|
395
|
+
absoluteProjectDir,
|
|
396
|
+
cwd = process.cwd(),
|
|
397
|
+
platform = process.platform,
|
|
398
|
+
} = params;
|
|
399
|
+
const isWindows = platform === "win32";
|
|
400
|
+
const pathApi = isWindows ? path.win32 : path.posix;
|
|
401
|
+
|
|
402
|
+
const relative = pathApi.relative(cwd, absoluteProjectDir);
|
|
403
|
+
const escapesCwd =
|
|
404
|
+
relative === ".." || relative.startsWith(`..${pathApi.sep}`);
|
|
405
|
+
const display =
|
|
406
|
+
relative && !escapesCwd && !pathApi.isAbsolute(relative)
|
|
407
|
+
? relative
|
|
408
|
+
: absoluteProjectDir;
|
|
409
|
+
|
|
410
|
+
const target = display.startsWith("-")
|
|
411
|
+
? `.${pathApi.sep}${display}`
|
|
412
|
+
: display;
|
|
413
|
+
// Neither Windows shell has a literal quoting form the other accepts: cmd
|
|
414
|
+
// reads single quotes as part of the name, and double quotes still expand
|
|
415
|
+
// %VAR% there and $var in PowerShell.
|
|
416
|
+
const quoted = (isWindows ? /^[\w@.:/\\+-]+$/ : /^[\w@./+-]+$/).test(target)
|
|
417
|
+
? target
|
|
418
|
+
: isWindows
|
|
419
|
+
? `"${target}"`
|
|
420
|
+
: `'${target.replaceAll("'", "'\\''")}'`;
|
|
421
|
+
|
|
422
|
+
return { display, cdCommand: `cd ${quoted}` };
|
|
423
|
+
}
|
|
424
|
+
|
|
391
425
|
const PLAYGROUND_PRESET_BASE_URL =
|
|
392
426
|
"https://www.assistant-ui.com/playground/init";
|
|
393
427
|
|
|
@@ -542,11 +576,13 @@ export const create = new Command()
|
|
|
542
576
|
|
|
543
577
|
// Check directory
|
|
544
578
|
const absoluteProjectDir = path.resolve(resolvedProjectDirectory);
|
|
579
|
+
const { display: displayProjectDir, cdCommand } =
|
|
580
|
+
resolveProjectDirectoryGuidance({ absoluteProjectDir });
|
|
545
581
|
try {
|
|
546
582
|
const files = fs.readdirSync(absoluteProjectDir);
|
|
547
583
|
if (files.length > 0) {
|
|
548
584
|
logger.error(
|
|
549
|
-
`Directory ${
|
|
585
|
+
`Directory ${displayProjectDir} already exists and is not empty`,
|
|
550
586
|
);
|
|
551
587
|
process.exit(1);
|
|
552
588
|
}
|
|
@@ -557,12 +593,12 @@ export const create = new Command()
|
|
|
557
593
|
// Directory doesn't exist — good, proceed
|
|
558
594
|
} else if (code === "ENOTDIR") {
|
|
559
595
|
logger.error(
|
|
560
|
-
`${
|
|
596
|
+
`${displayProjectDir} already exists and is not a directory`,
|
|
561
597
|
);
|
|
562
598
|
process.exit(1);
|
|
563
599
|
} else {
|
|
564
600
|
const message = err instanceof Error ? err.message : String(err);
|
|
565
|
-
logger.error(`Cannot access ${
|
|
601
|
+
logger.error(`Cannot access ${displayProjectDir}: ${message}`);
|
|
566
602
|
process.exit(1);
|
|
567
603
|
}
|
|
568
604
|
}
|
|
@@ -700,7 +736,7 @@ export const create = new Command()
|
|
|
700
736
|
logger.break();
|
|
701
737
|
logger.error("Project created with missing components.");
|
|
702
738
|
logger.info("Retry the component install with:");
|
|
703
|
-
logger.info(`
|
|
739
|
+
logger.info(` ${cdCommand}`);
|
|
704
740
|
logger.info(` ${transformResult.registryInstallFailure.retryCommand}`);
|
|
705
741
|
process.exit(1);
|
|
706
742
|
}
|
|
@@ -758,9 +794,12 @@ export const create = new Command()
|
|
|
758
794
|
}
|
|
759
795
|
|
|
760
796
|
logger.info("Next steps:");
|
|
761
|
-
logger.info(`
|
|
797
|
+
logger.info(` ${cdCommand}`);
|
|
762
798
|
if (opts.skipInstall) {
|
|
763
799
|
logger.info(` ${pm} install`);
|
|
800
|
+
if (transformResult.registryInstallCommand) {
|
|
801
|
+
logger.info(` ${transformResult.registryInstallCommand}`);
|
|
802
|
+
}
|
|
764
803
|
}
|
|
765
804
|
logger.info(` # Set up your environment variables in ${envFile}`);
|
|
766
805
|
logger.info(` ${runCmd} ${devScript}`);
|
package/src/commands/info.ts
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -84,7 +84,7 @@ export const init = new Command()
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const createArgs: string[] = [];
|
|
87
|
-
if (projectDirectory) createArgs.push(
|
|
87
|
+
if (projectDirectory) createArgs.push(targetDir);
|
|
88
88
|
if (presetUrl) createArgs.push("--preset", presetUrl);
|
|
89
89
|
if (opts.useNpm) createArgs.push("--use-npm");
|
|
90
90
|
if (opts.usePnpm) createArgs.push("--use-pnpm");
|
package/src/commands/mcp.ts
CHANGED
|
@@ -75,9 +75,6 @@ const MCP_CONFIGS: Record<
|
|
|
75
75
|
if (process.platform === "win32") {
|
|
76
76
|
return path.join(process.env.APPDATA || "", "Zed", "settings.json");
|
|
77
77
|
}
|
|
78
|
-
if (process.platform === "darwin") {
|
|
79
|
-
return path.join(os.homedir(), ".zed", "settings.json");
|
|
80
|
-
}
|
|
81
78
|
return path.join(os.homedir(), ".config", "zed", "settings.json");
|
|
82
79
|
},
|
|
83
80
|
config: {
|