Skip to content

Commit

Permalink
fix: replace hard coded components path with the resolved path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Slartibartfass2 committed Jan 11, 2025
1 parent 401b857 commit 6890047
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/test/fixtures/config-custom/components.json
Original file line number Diff line number Diff line change
@@ -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"
}
16 changes: 16 additions & 0 deletions packages/cli/test/fixtures/config-custom/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 14 additions & 0 deletions packages/cli/test/fixtures/config-custom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions packages/cli/test/utils/get-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
});
});
});

0 comments on commit 6890047

Please sign in to comment.