From 689004709da098349f0e5ce5fd47a42162ccd1fd Mon Sep 17 00:00:00 2001 From: Felix Schlegel Date: Sat, 11 Jan 2025 20:04:38 +0100 Subject: [PATCH] fix: replace hard coded components path with the resolved path Previously, anybody who didn't use the default components.json couldn't execute the update because if the ui path had been changed, this would resolve in an exception. Now the resolved alias path from the components.json is used. --- packages/cli/src/commands/update.ts | 2 +- .../fixtures/config-custom/components.json | 16 +++++++++++ .../test/fixtures/config-custom/package.json | 16 +++++++++++ .../test/fixtures/config-custom/tsconfig.json | 14 ++++++++++ packages/cli/test/utils/get-config.spec.ts | 28 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 packages/cli/test/fixtures/config-custom/components.json create mode 100644 packages/cli/test/fixtures/config-custom/package.json create mode 100644 packages/cli/test/fixtures/config-custom/tsconfig.json diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index 81bc72e2e..d70ead6c3 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -81,7 +81,7 @@ async function runUpdate(cwd: string, config: cliConfig.Config, options: UpdateO const components = options.components; const registryIndex = await registry.getRegistryIndex(); - const componentDir = path.resolve(config.resolvedPaths.components, "ui"); + const componentDir = path.resolve(config.resolvedPaths.ui); if (!existsSync(componentDir)) { throw error(`Component directory ${color.cyan(componentDir)} does not exist.`); } diff --git a/packages/cli/test/fixtures/config-custom/components.json b/packages/cli/test/fixtures/config-custom/components.json new file mode 100644 index 000000000..f3c82e124 --- /dev/null +++ b/packages/cli/test/fixtures/config-custom/components.json @@ -0,0 +1,16 @@ +{ + "style": "new-york", + "tailwind": { + "config": "custom-tailwind.config.js", + "css": "src/custom-app.pcss", + "baseColor": "zinc" + }, + "aliases": { + "components": "$lib/custom-components", + "utils": "$lib/custom-utils", + "ui": "$lib/components/custom-ui", + "hooks": "$lib/custom-hooks" + }, + "typescript": true, + "registry": "https://next.shadcn-svelte.com/registry" +} diff --git a/packages/cli/test/fixtures/config-custom/package.json b/packages/cli/test/fixtures/config-custom/package.json new file mode 100644 index 000000000..7e8e48ce0 --- /dev/null +++ b/packages/cli/test/fixtures/config-custom/package.json @@ -0,0 +1,16 @@ +{ + "name": "test-cli-config-full", + "version": "0.0.0", + "private": true, + "devDependencies": { + "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^3.0.0", + "svelte": "^4.2.7", + "svelte-check": "^3.6.0", + "tslib": "^2.4.1", + "typescript": "^5.0.0", + "vite": "^5.0.3" + }, + "type": "module" +} diff --git a/packages/cli/test/fixtures/config-custom/tsconfig.json b/packages/cli/test/fixtures/config-custom/tsconfig.json new file mode 100644 index 000000000..a8f10c8e3 --- /dev/null +++ b/packages/cli/test/fixtures/config-custom/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } +} diff --git a/packages/cli/test/utils/get-config.spec.ts b/packages/cli/test/utils/get-config.spec.ts index 453f196e3..7e559319e 100644 --- a/packages/cli/test/utils/get-config.spec.ts +++ b/packages/cli/test/utils/get-config.spec.ts @@ -175,4 +175,32 @@ describe("getConfig", () => { registry: `${SITE_BASE_URL}/registry`, }); }); + + it("handles cases where a full custom config is present", async () => { + expect(await getConf("config-custom")).toEqual({ + style: "new-york", + tailwind: { + config: "custom-tailwind.config.js", + css: "src/custom-app.pcss", + baseColor: "zinc", + }, + aliases: { + components: "$lib/custom-components", + utils: "$lib/custom-utils", + ui: "$lib/components/custom-ui", + hooks: "$lib/custom-hooks", + }, + resolvedPaths: { + tailwindConfig: resolvePath("../fixtures/config-custom/custom-tailwind.config.js"), + tailwindCss: resolvePath("../fixtures/config-custom/src/custom-app.pcss"), + cwd: resolvePath("../fixtures/config-custom"), + components: resolvePath("../fixtures/config-custom/src/lib/custom-components"), + utils: resolvePath("../fixtures/config-custom/src/lib/custom-utils"), + ui: resolvePath("../fixtures/config-custom/src/lib/components/custom-ui"), + hooks: resolvePath("../fixtures/config-custom/src/lib/custom-hooks"), + }, + typescript: true, + registry: `${SITE_BASE_URL}/registry`, + }); + }); });