From eab9cd75685384f958834a061168cacef9b50b13 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 22:51:04 +0000 Subject: [PATCH 1/5] Initial plan From c8d00825631cba446812b2f379150281249796b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 22:58:34 +0000 Subject: [PATCH 2/5] Fix utils path display to show actual file location Co-authored-by: huntabyte <64506580+huntabyte@users.noreply.github.com> --- packages/cli/src/utils/add-registry-items.ts | 11 ++++ .../cli/test/utils/add-registry-items.test.ts | 55 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/packages/cli/src/utils/add-registry-items.ts b/packages/cli/src/utils/add-registry-items.ts index b0ba70ae2..70db0ca73 100644 --- a/packages/cli/src/utils/add-registry-items.ts +++ b/packages/cli/src/utils/add-registry-items.ts @@ -120,6 +120,7 @@ export async function addRegistryItems(opts: AddRegistryItemsProps) { : `Adding ${highlight(item.name)}`, // @ts-expect-error this is intentional since we don't want to return a string during `init` async task() { + let firstFilePath: string | undefined; for (const file of item.files) { let filePath = registry.resolveItemFilePath(opts.config, item, file); @@ -135,6 +136,11 @@ export async function addRegistryItems(opts: AddRegistryItemsProps) { filePath = filePath.replace(".ts", ".js"); } await fs.writeFile(filePath, content, "utf8"); + + // Track the first file path for display purposes + if (!firstFilePath) { + firstFilePath = filePath; + } } if (item.cssVars) { @@ -149,6 +155,11 @@ export async function addRegistryItems(opts: AddRegistryItemsProps) { const itemPath = path.relative(cwd, opts.config.resolvedPaths.tailwindCss); return `${highlight(item.name)} installed at ${color.gray(itemPath)}`; } + // Use the actual file path that was written + if (item.name === "utils" && firstFilePath) { + const itemPath = path.relative(cwd, firstFilePath); + return `${highlight(item.name)} installed at ${color.gray(itemPath)}`; + } const aliasDir = registry.getItemAliasDir(opts.config, item.type); const itemPath = path.relative(cwd, path.resolve(aliasDir, item.name)); return `${highlight(item.name)} installed at ${color.gray(itemPath)}`; diff --git a/packages/cli/test/utils/add-registry-items.test.ts b/packages/cli/test/utils/add-registry-items.test.ts index 85eb98c47..579516198 100644 --- a/packages/cli/test/utils/add-registry-items.test.ts +++ b/packages/cli/test/utils/add-registry-items.test.ts @@ -184,4 +184,59 @@ describe("addRegistryItems", () => { ]) ); }); + + it("should display correct path for utils with custom location", async () => { + const utilsItem = { + name: "utils", + type: "registry:lib", + files: [{ target: "utils.ts", type: "registry:lib", content: "export const cn = () => {}" }], + } satisfies ResolvedRegistryItem; + + // Mock config with custom utils path + const customConfig = { + ...mockConfig, + resolvedPaths: { + ...mockConfig.resolvedPaths, + utils: "/test/custom/path/shadcn-utils", + }, + }; + + vi.mocked(existsSync).mockReturnValue(false); + + vi.mocked(registry.resolveRegistryItems).mockResolvedValue([utilsItem]); + vi.mocked(registry.fetchRegistryItems).mockResolvedValue([utilsItem]); + + // Simulate the actual behavior of resolveItemFilePath for utils + vi.mocked(registry.resolveItemFilePath).mockImplementation((config, item, _file) => { + if (item.name === "utils") { + const utils = config.resolvedPaths.utils; + if (utils.match(/.*\.(ts|js)$/)) return utils; + else return `${utils}.ts`; + } + return "/default/path"; + }); + vi.mocked(registry.getItemAliasDir).mockReturnValue("/test/lib"); + + // Capture the task that gets executed + let taskResult: string | undefined; + vi.mocked(p.tasks).mockImplementation(async (tasks) => { + for (const task of tasks) { + if (typeof task.task === "function") { + taskResult = await task.task(); + } + } + }); + + await addRegistryItems({ + selectedItems: ["utils"], + config: customConfig, + overwrite: false, + deps: true, + }); + + // Verify that the displayed path matches the actual file path written + expect(taskResult).toContain("custom/path/shadcn-utils.ts"); + // Verify it doesn't use the default lib path + expect(taskResult).not.toContain("lib/utils"); + }); }); From 325e5a1228a8b4c563377dfe2d40f196e6bf013b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 23:02:16 +0000 Subject: [PATCH 3/5] Apply prettier formatting to test file Co-authored-by: huntabyte <64506580+huntabyte@users.noreply.github.com> --- packages/cli/test/utils/add-registry-items.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/test/utils/add-registry-items.test.ts b/packages/cli/test/utils/add-registry-items.test.ts index 579516198..3f831b30a 100644 --- a/packages/cli/test/utils/add-registry-items.test.ts +++ b/packages/cli/test/utils/add-registry-items.test.ts @@ -189,7 +189,9 @@ describe("addRegistryItems", () => { const utilsItem = { name: "utils", type: "registry:lib", - files: [{ target: "utils.ts", type: "registry:lib", content: "export const cn = () => {}" }], + files: [ + { target: "utils.ts", type: "registry:lib", content: "export const cn = () => {}" }, + ], } satisfies ResolvedRegistryItem; // Mock config with custom utils path @@ -205,7 +207,7 @@ describe("addRegistryItems", () => { vi.mocked(registry.resolveRegistryItems).mockResolvedValue([utilsItem]); vi.mocked(registry.fetchRegistryItems).mockResolvedValue([utilsItem]); - + // Simulate the actual behavior of resolveItemFilePath for utils vi.mocked(registry.resolveItemFilePath).mockImplementation((config, item, _file) => { if (item.name === "utils") { From c548fcb50e6690b7cf45e918188ff7914d20fc02 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Oct 2025 13:55:08 +0000 Subject: [PATCH 4/5] Fix Windows test failure by normalizing paths Co-authored-by: huntabyte <64506580+huntabyte@users.noreply.github.com> --- packages/cli/test/utils/add-registry-items.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/test/utils/add-registry-items.test.ts b/packages/cli/test/utils/add-registry-items.test.ts index 3f831b30a..0e6b288a0 100644 --- a/packages/cli/test/utils/add-registry-items.test.ts +++ b/packages/cli/test/utils/add-registry-items.test.ts @@ -4,6 +4,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import * as registry from "../../src/utils/registry/index.js"; import { addRegistryItems } from "../../src/utils/add-registry-items.js"; import type { ResolvedConfig } from "../../src/utils/get-config"; +import { toPosixPath } from "./test-helpers.js"; vi.mock("node:fs", () => ({ existsSync: vi.fn(), @@ -237,8 +238,9 @@ describe("addRegistryItems", () => { }); // Verify that the displayed path matches the actual file path written - expect(taskResult).toContain("custom/path/shadcn-utils.ts"); + // Normalize paths for cross-platform compatibility + expect(toPosixPath(taskResult ?? "")).toContain("custom/path/shadcn-utils.ts"); // Verify it doesn't use the default lib path - expect(taskResult).not.toContain("lib/utils"); + expect(toPosixPath(taskResult ?? "")).not.toContain("lib/utils"); }); }); From c10e8f8a30534f6f24bc33417406cb6ccd17430f Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Wed, 15 Oct 2025 19:14:24 -0400 Subject: [PATCH 5/5] add changeset --- .changeset/lazy-papayas-film.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-papayas-film.md diff --git a/.changeset/lazy-papayas-film.md b/.changeset/lazy-papayas-film.md new file mode 100644 index 000000000..e55882a34 --- /dev/null +++ b/.changeset/lazy-papayas-film.md @@ -0,0 +1,5 @@ +--- +"shadcn-svelte": patch +--- + +fix: display correct path for utils file during init