From 64b2f1a5ad865c831045c954fec85e0fec2289e7 Mon Sep 17 00:00:00 2001 From: shadcn Date: Thu, 12 Sep 2024 17:51:59 +0400 Subject: [PATCH 001/115] feat(shadcn): add experimental docs (#4820) * feat(shadcn): add cli docs * chore: add changeset * fix: tests --- .changeset/small-foxes-destroy.md | 5 +++++ apps/www/registry/schema.ts | 1 + packages/shadcn/src/utils/add-components.ts | 5 +++++ packages/shadcn/src/utils/registry/index.ts | 8 ++++++++ packages/shadcn/src/utils/registry/schema.ts | 2 ++ .../registry-resolve-items-tree.test.ts.snap | 3 +++ 6 files changed, 24 insertions(+) create mode 100644 .changeset/small-foxes-destroy.md diff --git a/.changeset/small-foxes-destroy.md b/.changeset/small-foxes-destroy.md new file mode 100644 index 00000000000..df54c3285cb --- /dev/null +++ b/.changeset/small-foxes-destroy.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +add docs support diff --git a/apps/www/registry/schema.ts b/apps/www/registry/schema.ts index a8161573ed2..ebd45304351 100644 --- a/apps/www/registry/schema.ts +++ b/apps/www/registry/schema.ts @@ -62,6 +62,7 @@ export const registryEntrySchema = z.object({ category: z.string().optional(), subcategory: z.string().optional(), chunks: z.array(blockChunkSchema).optional(), + docs: z.string().optional(), }) export const registrySchema = z.array(registryEntrySchema) diff --git a/packages/shadcn/src/utils/add-components.ts b/packages/shadcn/src/utils/add-components.ts index ea318704661..ee5342ee944 100644 --- a/packages/shadcn/src/utils/add-components.ts +++ b/packages/shadcn/src/utils/add-components.ts @@ -1,5 +1,6 @@ import { type Config } from "@/src/utils/get-config" import { handleError } from "@/src/utils/handle-error" +import { logger } from "@/src/utils/logger" import { registryResolveItemsTree } from "@/src/utils/registry" import { spinner } from "@/src/utils/spinner" import { updateCssVars } from "@/src/utils/updaters/update-css-vars" @@ -48,4 +49,8 @@ export async function addComponents( overwrite: options.overwrite, silent: options.silent, }) + + if (tree.docs) { + logger.info(tree.docs) + } } diff --git a/packages/shadcn/src/utils/registry/index.ts b/packages/shadcn/src/utils/registry/index.ts index b8d54d35b84..b70b1506235 100644 --- a/packages/shadcn/src/utils/registry/index.ts +++ b/packages/shadcn/src/utils/registry/index.ts @@ -321,6 +321,13 @@ export async function registryResolveItemsTree( cssVars = deepmerge(cssVars, item.cssVars ?? {}) }) + let docs = "" + payload.forEach((item) => { + if (item.docs) { + docs += `${item.docs}\n` + } + }) + return registryResolvedItemsTreeSchema.parse({ dependencies: deepmerge.all( payload.map((item) => item.dependencies ?? []) @@ -331,6 +338,7 @@ export async function registryResolveItemsTree( files: deepmerge.all(payload.map((item) => item.files ?? [])), tailwind, cssVars, + docs, }) } catch (error) { handleError(error) diff --git a/packages/shadcn/src/utils/registry/schema.ts b/packages/shadcn/src/utils/registry/schema.ts index 3809654f73f..8f76d324b24 100644 --- a/packages/shadcn/src/utils/registry/schema.ts +++ b/packages/shadcn/src/utils/registry/schema.ts @@ -46,6 +46,7 @@ export const registryItemSchema = z.object({ tailwind: registryItemTailwindSchema.optional(), cssVars: registryItemCssVarsSchema.optional(), meta: z.record(z.string(), z.any()).optional(), + docs: z.string().optional(), }) export type RegistryItem = z.infer @@ -82,4 +83,5 @@ export const registryResolvedItemsTreeSchema = registryItemSchema.pick({ files: true, tailwind: true, cssVars: true, + docs: true, }) diff --git a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap index 2ea9442dbea..86cf01a5c79 100644 --- a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap +++ b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap @@ -20,6 +20,7 @@ exports[`registryResolveItemTree > should resolve index 1`] = ` "tailwind-merge", ], "devDependencies": [], + "docs": "", "files": [ { "content": ""use client" @@ -93,6 +94,7 @@ exports[`registryResolveItemTree > should resolve items tree 1`] = ` "@radix-ui/react-slot", ], "devDependencies": [], + "docs": "", "files": [ { "content": "import * as React from "react" @@ -171,6 +173,7 @@ exports[`registryResolveItemTree > should resolve multiple items tree 1`] = ` "@radix-ui/react-dialog", ], "devDependencies": [], + "docs": "", "files": [ { "content": "import * as React from "react" From 9ef7967b0d39e7084f9e319aec0e97ca4a31a739 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:54:41 +0400 Subject: [PATCH 002/115] chore(release): version packages (#4821) Co-authored-by: github-actions[bot] --- .changeset/small-foxes-destroy.md | 5 ----- packages/shadcn/CHANGELOG.md | 6 ++++++ packages/shadcn/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .changeset/small-foxes-destroy.md diff --git a/.changeset/small-foxes-destroy.md b/.changeset/small-foxes-destroy.md deleted file mode 100644 index df54c3285cb..00000000000 --- a/.changeset/small-foxes-destroy.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn": patch ---- - -add docs support diff --git a/packages/shadcn/CHANGELOG.md b/packages/shadcn/CHANGELOG.md index 29576760e55..3fe661420a3 100644 --- a/packages/shadcn/CHANGELOG.md +++ b/packages/shadcn/CHANGELOG.md @@ -1,5 +1,11 @@ # @shadcn/ui +## 2.0.6 + +### Patch Changes + +- [#4820](https://github.com/shadcn-ui/ui/pull/4820) [`64b2f1a`](https://github.com/shadcn-ui/ui/commit/64b2f1a5ad865c831045c954fec85e0fec2289e7) Thanks [@shadcn](https://github.com/shadcn)! - add docs support + ## 2.0.5 ### Patch Changes diff --git a/packages/shadcn/package.json b/packages/shadcn/package.json index 6820d78b87f..76d40c00214 100644 --- a/packages/shadcn/package.json +++ b/packages/shadcn/package.json @@ -1,6 +1,6 @@ { "name": "shadcn", - "version": "2.0.5", + "version": "2.0.6", "description": "Add components to your apps.", "publishConfig": { "access": "public" From b6221ea5246b5060c6d8562f473e3435284b99f4 Mon Sep 17 00:00:00 2001 From: Quinn Blenkinsop Date: Sun, 15 Sep 2024 01:31:28 -0700 Subject: [PATCH 003/115] fix(www): update broken link to headless ui (#3542) The link appears to have broken at some point, I've updated it Co-authored-by: shadcn --- apps/www/content/docs/components/data-table.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/www/content/docs/components/data-table.mdx b/apps/www/content/docs/components/data-table.mdx index d5c67c5c259..c3e1f01e026 100644 --- a/apps/www/content/docs/components/data-table.mdx +++ b/apps/www/content/docs/components/data-table.mdx @@ -12,7 +12,7 @@ links: Every data table or datagrid I've created has been unique. They all behave differently, have specific sorting and filtering requirements, and work with different data sources. -It doesn't make sense to combine all of these variations into a single component. If we do that, we'll lose the flexibility that [headless UI](https://tanstack.com/table/v8/docs/guide/introduction#what-is-headless-ui) provides. +It doesn't make sense to combine all of these variations into a single component. If we do that, we'll lose the flexibility that [headless UI](https://tanstack.com/table/v8/docs/introduction#what-is-headless-ui) provides. So instead of a data-table component, I thought it would be more helpful to provide a guide on how to build your own. From a9ab7afebf6e38bdb7654f255fa947ee92c863d0 Mon Sep 17 00:00:00 2001 From: Devansh Mahant <86195162+devansh-m12@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:45:29 -0700 Subject: [PATCH 004/115] Fix Incorrect Hook Import Path in Toast Component Example in ShadCN Docs (#4811) #### Summary: This pull request addresses a documentation error found in the ShadCN website's Toast component example. Specifically, the import route for the hook is incorrect in the example. and fixes [#4816](https://github.com/shadcn-ui/ui/issues/4816) #### Issue: Upon reviewing the [ShadCN Toast documentation](https://ui.shadcn.com/docs/components/toast), I found that the import path for the Toast component hook was wrongly mentioned as being located in the `components` folder. According to the `component.json` file, the correct location of the hook is within the `hooks` folder inside the main directory. #### Fix: - Corrected the import path in the Toast component example from `components` to `hooks`, as per the `component.json` file structure. #### Example of Fix: **Before:** ```js import { useToast } from "@/components/use-toast"; ``` **After:** ```js import { useToast } from "@/hooks/use-toast"; ``` #### Testing: - Verified that the corrected path resolves correctly. - Ensured the example works as expected after the change. #### Impact: This fix prevents confusion for users following the example and ensures that the import path accurately reflects the project structure, improving the overall developer experience. --- apps/www/content/docs/components/toast.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/www/content/docs/components/toast.mdx b/apps/www/content/docs/components/toast.mdx index f772be60ca4..87b6c45decc 100644 --- a/apps/www/content/docs/components/toast.mdx +++ b/apps/www/content/docs/components/toast.mdx @@ -104,7 +104,7 @@ export default function RootLayout({ children }) { The `useToast` hook returns a `toast` function that you can use to display a toast. ```tsx -import { useToast } from "@/components/hooks/use-toast" +import { useToast } from "@/hooks/use-toast" ``` ```tsx {2,7-10} From 408760a93b398b7d02a0a522a74a7a195ccda7c4 Mon Sep 17 00:00:00 2001 From: Rana Haris Ali <64707886+rana-haris-ali@users.noreply.github.com> Date: Sun, 15 Sep 2024 10:51:23 +0200 Subject: [PATCH 005/115] fix: correct grammar in "path does not contain a package.json" message (#4815) * fix: correct grammar in "path does not contain a package.json" message * chore: add changeset --------- Co-authored-by: shadcn --- .changeset/lemon-yaks-bathe.md | 5 +++++ packages/shadcn/src/utils/create-project.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/lemon-yaks-bathe.md diff --git a/.changeset/lemon-yaks-bathe.md b/.changeset/lemon-yaks-bathe.md new file mode 100644 index 00000000000..47e0c1af4c6 --- /dev/null +++ b/.changeset/lemon-yaks-bathe.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +fix typo in error message diff --git a/packages/shadcn/src/utils/create-project.ts b/packages/shadcn/src/utils/create-project.ts index 1bbbdb6afa4..ae7b597c48a 100644 --- a/packages/shadcn/src/utils/create-project.ts +++ b/packages/shadcn/src/utils/create-project.ts @@ -23,7 +23,7 @@ export async function createProject( name: "proceed", message: `The path ${highlighter.info( options.cwd - )} is does not contain a package.json file. Would you like to start a new ${highlighter.info( + )} does not contain a package.json file. Would you like to start a new ${highlighter.info( "Next.js" )} project?`, initial: true, From 207b69fe8dd59b10dddc9337d333416976e2a30d Mon Sep 17 00:00:00 2001 From: Shivang Rathore Date: Sun, 15 Sep 2024 14:25:08 +0530 Subject: [PATCH 006/115] fix(cli): Ensure .scss files are considered in getTailwindCssFile (#4797) * fix(cli): Ensure .scss files are considered in getTailwindCssFile - Updated getTailwindCssFile function to include .scss files when checking for Tailwind CSS configuration. - This change ensures that .scss files are properly identified and handled, improving compatibility with projects using SCSS. * chore: add changeset --------- Co-authored-by: shadcn --- .changeset/chilly-geckos-run.md | 5 +++++ packages/cli/src/utils/get-project-info.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/chilly-geckos-run.md diff --git a/.changeset/chilly-geckos-run.md b/.changeset/chilly-geckos-run.md new file mode 100644 index 00000000000..5a34f662d3f --- /dev/null +++ b/.changeset/chilly-geckos-run.md @@ -0,0 +1,5 @@ +--- +"shadcn-ui": patch +--- + +add scss support diff --git a/packages/cli/src/utils/get-project-info.ts b/packages/cli/src/utils/get-project-info.ts index 606145e1532..23fd3d14636 100644 --- a/packages/cli/src/utils/get-project-info.ts +++ b/packages/cli/src/utils/get-project-info.ts @@ -133,7 +133,7 @@ export async function getProjectType(cwd: string): Promise { } export async function getTailwindCssFile(cwd: string) { - const files = await fg.glob("**/*.css", { + const files = await fg.glob(["**/*.css", "**/*.scss"], { cwd, deep: 3, ignore: PROJECT_SHARED_IGNORE, From 52d223393a9834ad9d31b4f0d0f68e48f99b2392 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Sun, 15 Sep 2024 10:20:19 +0100 Subject: [PATCH 007/115] (fix Input) choose file text color in dark mode (#4843) This pull request fixes the issue with the choose file text color in dark mode. The changes ensure that the text color is correctly displayed in dark mode. the reason this bug doesn't happen in the shadcn website is because it sets `color-scheme:dark` on the document; this fix makes sure this always works even if color scheme isn't set. Closes #4842 ![image](https://github.com/user-attachments/assets/37cb3f2a-c1a7-49b3-8ef1-77823dd7bd45) ![image](https://github.com/user-attachments/assets/92913fec-5651-4cfc-8e16-2f12c06c33b8) --- apps/www/public/r/styles/default/input.json | 2 +- apps/www/public/r/styles/new-york/input.json | 2 +- apps/www/registry/default/ui/input.tsx | 2 +- apps/www/registry/new-york/ui/input.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/www/public/r/styles/default/input.json b/apps/www/public/r/styles/default/input.json index 5c1232a9bf4..24dcd50e3c1 100644 --- a/apps/www/public/r/styles/default/input.json +++ b/apps/www/public/r/styles/default/input.json @@ -4,7 +4,7 @@ "files": [ { "path": "ui/input.tsx", - "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface InputProps\n extends React.InputHTMLAttributes {}\n\nconst Input = React.forwardRef(\n ({ className, type, ...props }, ref) => {\n return (\n \n )\n }\n)\nInput.displayName = \"Input\"\n\nexport { Input }\n", + "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface InputProps\n extends React.InputHTMLAttributes {}\n\nconst Input = React.forwardRef(\n ({ className, type, ...props }, ref) => {\n return (\n \n )\n }\n)\nInput.displayName = \"Input\"\n\nexport { Input }\n", "type": "registry:ui", "target": "" } diff --git a/apps/www/public/r/styles/new-york/input.json b/apps/www/public/r/styles/new-york/input.json index 47000165205..20ca4956eb6 100644 --- a/apps/www/public/r/styles/new-york/input.json +++ b/apps/www/public/r/styles/new-york/input.json @@ -4,7 +4,7 @@ "files": [ { "path": "ui/input.tsx", - "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface InputProps\n extends React.InputHTMLAttributes {}\n\nconst Input = React.forwardRef(\n ({ className, type, ...props }, ref) => {\n return (\n \n )\n }\n)\nInput.displayName = \"Input\"\n\nexport { Input }\n", + "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface InputProps\n extends React.InputHTMLAttributes {}\n\nconst Input = React.forwardRef(\n ({ className, type, ...props }, ref) => {\n return (\n \n )\n }\n)\nInput.displayName = \"Input\"\n\nexport { Input }\n", "type": "registry:ui", "target": "" } diff --git a/apps/www/registry/default/ui/input.tsx b/apps/www/registry/default/ui/input.tsx index 677d05fd6c1..a921025cebb 100644 --- a/apps/www/registry/default/ui/input.tsx +++ b/apps/www/registry/default/ui/input.tsx @@ -11,7 +11,7 @@ const Input = React.forwardRef( ( Date: Sun, 15 Sep 2024 13:25:06 +0400 Subject: [PATCH 008/115] ci: update stale config (#4858) --- .github/workflows/issue-stale.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/issue-stale.yml b/.github/workflows/issue-stale.yml index e34856dad69..500d781b08a 100644 --- a/.github/workflows/issue-stale.yml +++ b/.github/workflows/issue-stale.yml @@ -16,11 +16,12 @@ jobs: name: "Close stale issues with no reproduction" with: repo-token: ${{ secrets.STALE_TOKEN }} - close-issue-message: "This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you." + close-issue-message: "This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please reopen or leave a comment. Thank you.\n(This is an automated message.)" days-before-issue-close: 7 - days-before-issue-stale: 15 + days-before-issue-stale: 30 stale-pr-label: "stale?" - days-before-pr-close: -1 - days-before-pr-stale: -1 + days-before-pr-close: 7 + days-before-pr-stale: 15 + only-pr-labels: "postpone: more info or changes requested,please add a reproduction" exempt-issue-labels: "roadmap,next,bug" operations-per-run: 300 # 1 operation per 100 issues, the rest is to label/comment/close From 1af66c2d08df7dd7f6a8d4d1544d965e41a1fb0d Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Sun, 15 Sep 2024 05:27:48 -0400 Subject: [PATCH 009/115] Adding support for ~ in target specification (#4848) * Adding support for ~ in target specification * test(shadcn): add a test for srcDir false * chore: changeset --------- Co-authored-by: shadcn --- .changeset/clever-swans-tan.md | 5 ++ .../shadcn/src/utils/updaters/update-files.ts | 17 ++++- .../test/utils/updaters/update-files.test.ts | 65 +++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 .changeset/clever-swans-tan.md create mode 100644 packages/shadcn/test/utils/updaters/update-files.test.ts diff --git a/.changeset/clever-swans-tan.md b/.changeset/clever-swans-tan.md new file mode 100644 index 00000000000..776948c7352 --- /dev/null +++ b/.changeset/clever-swans-tan.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +add support for ~ dir in target path diff --git a/packages/shadcn/src/utils/updaters/update-files.ts b/packages/shadcn/src/utils/updaters/update-files.ts index 757d15d12dd..3a06110e562 100644 --- a/packages/shadcn/src/utils/updaters/update-files.ts +++ b/packages/shadcn/src/utils/updaters/update-files.ts @@ -17,6 +17,19 @@ import { transformRsc } from "@/src/utils/transformers/transform-rsc" import { transformTwPrefixes } from "@/src/utils/transformers/transform-tw-prefix" import prompts from "prompts" +export function resolveTargetDir( + projectInfo: Awaited>, + config: Config, + target: string +) { + if (target.startsWith("~/")) { + return path.join(config.resolvedPaths.cwd, target.replace("~/", "")) + } + return projectInfo?.isSrcDir + ? path.join(config.resolvedPaths.cwd, "src", target) + : path.join(config.resolvedPaths.cwd, target) +} + export async function updateFiles( files: RegistryItem["files"], config: Config, @@ -58,9 +71,7 @@ export async function updateFiles( let filePath = path.join(targetDir, fileName) if (file.target) { - filePath = projectInfo?.isSrcDir - ? path.join(config.resolvedPaths.cwd, "src", file.target) - : path.join(config.resolvedPaths.cwd, file.target) + filePath = resolveTargetDir(projectInfo, config, file.target) targetDir = path.dirname(filePath) } diff --git a/packages/shadcn/test/utils/updaters/update-files.test.ts b/packages/shadcn/test/utils/updaters/update-files.test.ts new file mode 100644 index 00000000000..4d12fcb841e --- /dev/null +++ b/packages/shadcn/test/utils/updaters/update-files.test.ts @@ -0,0 +1,65 @@ +import { describe, expect, test } from "vitest" + +import { resolveTargetDir } from "../../../src/utils/updaters/update-files" + +describe("resolveTargetDir", () => { + test("should handle a home target without a src directory", () => { + const targetDir = resolveTargetDir( + { + isSrcDir: false, + }, + { + resolvedPaths: { + cwd: "/foo/bar", + }, + }, + "~/.env" + ) + expect(targetDir).toBe("/foo/bar/.env") + }) + + test("should handle a home target even with a src directory", () => { + const targetDir = resolveTargetDir( + { + isSrcDir: true, + }, + { + resolvedPaths: { + cwd: "/foo/bar", + }, + }, + "~/.env" + ) + expect(targetDir).toBe("/foo/bar/.env") + }) + + test("should handle a simple target", () => { + const targetDir = resolveTargetDir( + { + isSrcDir: false, + }, + { + resolvedPaths: { + cwd: "/foo/bar", + }, + }, + "./components/ui/button.tsx" + ) + expect(targetDir).toBe("/foo/bar/components/ui/button.tsx") + }) + + test("should handle a simple target with src directory", () => { + const targetDir = resolveTargetDir( + { + isSrcDir: true, + }, + { + resolvedPaths: { + cwd: "/foo/bar", + }, + }, + "./components/ui/button.tsx" + ) + expect(targetDir).toBe("/foo/bar/src/components/ui/button.tsx") + }) +}) From 061083006f0122bfded841235ee58caefc9fd944 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:40:31 +0400 Subject: [PATCH 010/115] chore(release): version packages (#4857) Co-authored-by: github-actions[bot] --- .changeset/chilly-geckos-run.md | 5 ----- .changeset/clever-swans-tan.md | 5 ----- .changeset/lemon-yaks-bathe.md | 5 ----- packages/cli/CHANGELOG.md | 6 ++++++ packages/cli/package.json | 2 +- packages/shadcn/CHANGELOG.md | 8 ++++++++ packages/shadcn/package.json | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 .changeset/chilly-geckos-run.md delete mode 100644 .changeset/clever-swans-tan.md delete mode 100644 .changeset/lemon-yaks-bathe.md diff --git a/.changeset/chilly-geckos-run.md b/.changeset/chilly-geckos-run.md deleted file mode 100644 index 5a34f662d3f..00000000000 --- a/.changeset/chilly-geckos-run.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn-ui": patch ---- - -add scss support diff --git a/.changeset/clever-swans-tan.md b/.changeset/clever-swans-tan.md deleted file mode 100644 index 776948c7352..00000000000 --- a/.changeset/clever-swans-tan.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn": patch ---- - -add support for ~ dir in target path diff --git a/.changeset/lemon-yaks-bathe.md b/.changeset/lemon-yaks-bathe.md deleted file mode 100644 index 47e0c1af4c6..00000000000 --- a/.changeset/lemon-yaks-bathe.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn": patch ---- - -fix typo in error message diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 0d4b09def11..79d1b05f329 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # @shadcn/ui +## 0.9.1 + +### Patch Changes + +- [#4797](https://github.com/shadcn-ui/ui/pull/4797) [`207b69f`](https://github.com/shadcn-ui/ui/commit/207b69fe8dd59b10dddc9337d333416976e2a30d) Thanks [@Wiper-R](https://github.com/Wiper-R)! - add scss support + ## 0.9.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index d38aec15788..8db4a122406 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "shadcn-ui", - "version": "0.9.0", + "version": "0.9.1", "description": "Add components to your apps.", "publishConfig": { "access": "public" diff --git a/packages/shadcn/CHANGELOG.md b/packages/shadcn/CHANGELOG.md index 3fe661420a3..4ec5ae05baf 100644 --- a/packages/shadcn/CHANGELOG.md +++ b/packages/shadcn/CHANGELOG.md @@ -1,5 +1,13 @@ # @shadcn/ui +## 2.0.7 + +### Patch Changes + +- [#4848](https://github.com/shadcn-ui/ui/pull/4848) [`1af66c2`](https://github.com/shadcn-ui/ui/commit/1af66c2d08df7dd7f6a8d4d1544d965e41a1fb0d) Thanks [@jherr](https://github.com/jherr)! - add support for ~ dir in target path + +- [#4815](https://github.com/shadcn-ui/ui/pull/4815) [`408760a`](https://github.com/shadcn-ui/ui/commit/408760a93b398b7d02a0a522a74a7a195ccda7c4) Thanks [@rana-haris-ali](https://github.com/rana-haris-ali)! - fix typo in error message + ## 2.0.6 ### Patch Changes diff --git a/packages/shadcn/package.json b/packages/shadcn/package.json index 76d40c00214..92fa5da19c4 100644 --- a/packages/shadcn/package.json +++ b/packages/shadcn/package.json @@ -1,6 +1,6 @@ { "name": "shadcn", - "version": "2.0.6", + "version": "2.0.7", "description": "Add components to your apps.", "publishConfig": { "access": "public" From c62167a449a5cf82d8ed93a7af986d5e503893bb Mon Sep 17 00:00:00 2001 From: sapenlei <2503404258gl@gmail.com> Date: Mon, 23 Sep 2024 15:38:59 +0800 Subject: [PATCH 011/115] fix(shadcn): default next styles are not completely cleared (#4922) * fix(shadcn): default next styles are not completely cleared * chore: add changeset * fix(shadcn): tests --------- Co-authored-by: shadcn --- .changeset/hip-ads-destroy.md | 5 +++ .../src/utils/updaters/update-css-vars.ts | 43 ++++++++++++++++++- .../registry-resolve-items-tree.test.ts.snap | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 .changeset/hip-ads-destroy.md diff --git a/.changeset/hip-ads-destroy.md b/.changeset/hip-ads-destroy.md new file mode 100644 index 00000000000..45277802101 --- /dev/null +++ b/.changeset/hip-ads-destroy.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +remove next.js default vars diff --git a/packages/shadcn/src/utils/updaters/update-css-vars.ts b/packages/shadcn/src/utils/updaters/update-css-vars.ts index 0006d1a288e..e4272b67c1b 100644 --- a/packages/shadcn/src/utils/updaters/update-css-vars.ts +++ b/packages/shadcn/src/utils/updaters/update-css-vars.ts @@ -183,6 +183,27 @@ function updateCssVarsPlugin( } } +function removeConflictVars(root: Rule | Root) { + const rootRule = root.nodes.find( + (node): node is Rule => node.type === "rule" && node.selector === ":root" + ) + + if (rootRule) { + const propsToRemove = ["--background", "--foreground"] + + rootRule.nodes + .filter( + (node): node is postcss.Declaration => + node.type === "decl" && propsToRemove.includes(node.prop) + ) + .forEach((node) => node.remove()) + + if (rootRule.nodes.length === 0) { + rootRule.remove() + } + } +} + function cleanupDefaultNextStylesPlugin() { return { postcssPlugin: "cleanup-default-next-styles", @@ -197,7 +218,9 @@ function cleanupDefaultNextStylesPlugin() { (node): node is postcss.Declaration => node.type === "decl" && node.prop === "color" && - node.value === "rgb(var(--foreground-rgb))" + ["rgb(var(--foreground-rgb))", "var(--foreground)"].includes( + node.value + ) ) ?.remove() @@ -208,7 +231,8 @@ function cleanupDefaultNextStylesPlugin() { node.type === "decl" && node.prop === "background" && // This is only going to run on create project, so all good. - node.value.startsWith("linear-gradient") + (node.value.startsWith("linear-gradient") || + node.value === "var(--background)") ) }) ?.remove() @@ -218,6 +242,21 @@ function cleanupDefaultNextStylesPlugin() { bodyRule.remove() } } + + removeConflictVars(root) + + const darkRootRule = root.nodes.find( + (node): node is Rule => + node.type === "atrule" && + node.params === "(prefers-color-scheme: dark)" + ) + + if (darkRootRule) { + removeConflictVars(darkRootRule) + if (darkRootRule.nodes.length === 0) { + darkRootRule.remove() + } + } }, } } diff --git a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap index 86cf01a5c79..9bdcd791efa 100644 --- a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap +++ b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap @@ -251,7 +251,7 @@ const Input = React.forwardRef( Date: Mon, 23 Sep 2024 13:14:27 +0530 Subject: [PATCH 012/115] fix(shadcn): Ensure .scss files are considered in init command (#4866) Co-authored-by: shadcn --- packages/shadcn/src/utils/get-project-info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shadcn/src/utils/get-project-info.ts b/packages/shadcn/src/utils/get-project-info.ts index 9bc01706483..f728e20569c 100644 --- a/packages/shadcn/src/utils/get-project-info.ts +++ b/packages/shadcn/src/utils/get-project-info.ts @@ -108,7 +108,7 @@ export async function getProjectInfo(cwd: string): Promise { } export async function getTailwindCssFile(cwd: string) { - const files = await fg.glob("**/*.css", { + const files = await fg.glob(["**/*.css", "**/*.scss"], { cwd, deep: 5, ignore: PROJECT_SHARED_IGNORE, From ce3adfa075793a46b4fb2ff797ce87ad22bfa2cd Mon Sep 17 00:00:00 2001 From: Braden Corbold Date: Mon, 23 Sep 2024 00:47:37 -0700 Subject: [PATCH 013/115] fix(shadcn): Support single quote formatted registry files (#4870) (#4871) --- .changeset/wise-cheetahs-report.md | 5 ++++ .../utils/transformers/transform-tw-prefix.ts | 16 ++++++------- .../transform-tw-prefix.test.ts.snap | 8 +++++++ .../test/utils/transform-tw-prefix.test.ts | 23 +++++++++++++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .changeset/wise-cheetahs-report.md diff --git a/.changeset/wise-cheetahs-report.md b/.changeset/wise-cheetahs-report.md new file mode 100644 index 00000000000..2dba0b6745d --- /dev/null +++ b/.changeset/wise-cheetahs-report.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +support tw prefixes for registry files with single quote formatting diff --git a/packages/shadcn/src/utils/transformers/transform-tw-prefix.ts b/packages/shadcn/src/utils/transformers/transform-tw-prefix.ts index 1fed9a883fe..22559abf2b1 100644 --- a/packages/shadcn/src/utils/transformers/transform-tw-prefix.ts +++ b/packages/shadcn/src/utils/transformers/transform-tw-prefix.ts @@ -22,7 +22,7 @@ export const transformTwPrefixes: Transformer = async ({ if (defaultClassNames) { defaultClassNames.replaceWithText( `"${applyPrefix( - defaultClassNames.getText()?.replace(/"/g, ""), + defaultClassNames.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -46,7 +46,7 @@ export const transformTwPrefixes: Transformer = async ({ if (classNames) { classNames?.replaceWithText( `"${applyPrefix( - classNames.getText()?.replace(/"/g, ""), + classNames.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -65,7 +65,7 @@ export const transformTwPrefixes: Transformer = async ({ if (value) { value.replaceWithText( `"${applyPrefix( - value.getText()?.replace(/"/g, ""), + value.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -91,7 +91,7 @@ export const transformTwPrefixes: Transformer = async ({ .forEach((node) => { node.replaceWithText( `"${applyPrefix( - node.getText()?.replace(/"/g, ""), + node.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -101,7 +101,7 @@ export const transformTwPrefixes: Transformer = async ({ if (node.isKind(SyntaxKind.StringLiteral)) { node.replaceWithText( `"${applyPrefix( - node.getText()?.replace(/"/g, ""), + node.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -130,7 +130,7 @@ export const transformTwPrefixes: Transformer = async ({ .forEach((node) => { node.replaceWithText( `"${applyPrefix( - node.getText()?.replace(/"/g, ""), + node.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -140,7 +140,7 @@ export const transformTwPrefixes: Transformer = async ({ if (arg.isKind(SyntaxKind.StringLiteral)) { arg.replaceWithText( `"${applyPrefix( - arg.getText()?.replace(/"/g, ""), + arg.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) @@ -155,7 +155,7 @@ export const transformTwPrefixes: Transformer = async ({ if (classNames) { classNames.replaceWithText( `"${applyPrefix( - classNames.getText()?.replace(/"/g, ""), + classNames.getText()?.replace(/"|'/g, ""), config.tailwind.prefix )}"` ) diff --git a/packages/shadcn/test/utils/__snapshots__/transform-tw-prefix.test.ts.snap b/packages/shadcn/test/utils/__snapshots__/transform-tw-prefix.test.ts.snap index b88b1d6e3d6..5019ddb6d73 100644 --- a/packages/shadcn/test/utils/__snapshots__/transform-tw-prefix.test.ts.snap +++ b/packages/shadcn/test/utils/__snapshots__/transform-tw-prefix.test.ts.snap @@ -25,6 +25,14 @@ export function Foo() { `; exports[`transform tailwind prefix 4`] = ` +"import * as React from "react" +export function Foo() { + return
foo
+} + " +`; + +exports[`transform tailwind prefix 5`] = ` "@tailwind base; @tailwind components; @tailwind utilities; diff --git a/packages/shadcn/test/utils/transform-tw-prefix.test.ts b/packages/shadcn/test/utils/transform-tw-prefix.test.ts index 5ba1efdc773..21529f3cbf1 100644 --- a/packages/shadcn/test/utils/transform-tw-prefix.test.ts +++ b/packages/shadcn/test/utils/transform-tw-prefix.test.ts @@ -73,6 +73,29 @@ export function Foo() { }) ).toMatchSnapshot() + expect( + await transform({ + filename: "test.ts", + raw: `import * as React from "react" +export function Foo() { + return
foo
+} + `, + config: { + tailwind: { + baseColor: "stone", + cssVariables: false, + prefix: "tw-", + }, + aliases: { + components: "@/components", + utils: "@/lib/utils", + }, + }, + baseColor: stone, + }) + ).toMatchSnapshot() + expect( applyPrefixesCss( "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 224 71.4% 4.1%;\n \n --muted: 220 14.3% 95.9%;\n --muted-foreground: 220 8.9% 46.1%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 224 71.4% 4.1%;\n \n --card: 0 0% 100%;\n --card-foreground: 224 71.4% 4.1%;\n \n --border: 220 13% 91%;\n --input: 220 13% 91%;\n \n --primary: 220.9 39.3% 11%;\n --primary-foreground: 210 20% 98%;\n \n --secondary: 220 14.3% 95.9%;\n --secondary-foreground: 220.9 39.3% 11%;\n \n --accent: 220 14.3% 95.9%;\n --accent-foreground: 220.9 39.3% 11%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 210 20% 98%;\n \n --ring: 217.9 10.6% 64.9%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 224 71.4% 4.1%;\n --foreground: 210 20% 98%;\n \n --muted: 215 27.9% 16.9%;\n --muted-foreground: 217.9 10.6% 64.9%;\n \n --popover: 224 71.4% 4.1%;\n --popover-foreground: 210 20% 98%;\n \n --card: 224 71.4% 4.1%;\n --card-foreground: 210 20% 98%;\n \n --border: 215 27.9% 16.9%;\n --input: 215 27.9% 16.9%;\n \n --primary: 210 20% 98%;\n --primary-foreground: 220.9 39.3% 11%;\n \n --secondary: 215 27.9% 16.9%;\n --secondary-foreground: 210 20% 98%;\n \n --accent: 215 27.9% 16.9%;\n --accent-foreground: 210 20% 98%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 215 27.9% 16.9%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}", From bd54184e6016261148cd4e806fe17c9043678a88 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:21:55 +0400 Subject: [PATCH 014/115] chore(release): version packages (#4938) Co-authored-by: github-actions[bot] --- .changeset/hip-ads-destroy.md | 5 ----- .changeset/wise-cheetahs-report.md | 5 ----- packages/shadcn/CHANGELOG.md | 8 ++++++++ packages/shadcn/package.json | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 .changeset/hip-ads-destroy.md delete mode 100644 .changeset/wise-cheetahs-report.md diff --git a/.changeset/hip-ads-destroy.md b/.changeset/hip-ads-destroy.md deleted file mode 100644 index 45277802101..00000000000 --- a/.changeset/hip-ads-destroy.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn": patch ---- - -remove next.js default vars diff --git a/.changeset/wise-cheetahs-report.md b/.changeset/wise-cheetahs-report.md deleted file mode 100644 index 2dba0b6745d..00000000000 --- a/.changeset/wise-cheetahs-report.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"shadcn": patch ---- - -support tw prefixes for registry files with single quote formatting diff --git a/packages/shadcn/CHANGELOG.md b/packages/shadcn/CHANGELOG.md index 4ec5ae05baf..4db853260d4 100644 --- a/packages/shadcn/CHANGELOG.md +++ b/packages/shadcn/CHANGELOG.md @@ -1,5 +1,13 @@ # @shadcn/ui +## 2.0.8 + +### Patch Changes + +- [#4922](https://github.com/shadcn-ui/ui/pull/4922) [`c62167a`](https://github.com/shadcn-ui/ui/commit/c62167a449a5cf82d8ed93a7af986d5e503893bb) Thanks [@sapenlei](https://github.com/sapenlei)! - remove next.js default vars + +- [#4871](https://github.com/shadcn-ui/ui/pull/4871) [`ce3adfa`](https://github.com/shadcn-ui/ui/commit/ce3adfa075793a46b4fb2ff797ce87ad22bfa2cd) Thanks [@bcorbold](https://github.com/bcorbold)! - support tw prefixes for registry files with single quote formatting + ## 2.0.7 ### Patch Changes diff --git a/packages/shadcn/package.json b/packages/shadcn/package.json index 92fa5da19c4..e850ad81130 100644 --- a/packages/shadcn/package.json +++ b/packages/shadcn/package.json @@ -1,6 +1,6 @@ { "name": "shadcn", - "version": "2.0.7", + "version": "2.0.8", "description": "Add components to your apps.", "publishConfig": { "access": "public" From 28f34ed3c3e944287cd6f521ff0310d39664329c Mon Sep 17 00:00:00 2001 From: shadcn Date: Wed, 25 Sep 2024 22:56:39 +0400 Subject: [PATCH 015/115] feat(shadcn): recursively resolve registry dependencies (#4961) * feat(shadcn): recursively resolve registry dependencies * chore: add changeset * ci: update actions/upload-artifact --- .changeset/hip-moose-add.md | 5 ++ .github/workflows/prerelease.yml | 2 +- packages/shadcn/src/utils/registry/index.ts | 85 +++++++++++++------ .../registry-resolve-items-tree.test.ts.snap | 28 +++--- 4 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 .changeset/hip-moose-add.md diff --git a/.changeset/hip-moose-add.md b/.changeset/hip-moose-add.md new file mode 100644 index 00000000000..de869d44ad0 --- /dev/null +++ b/.changeset/hip-moose-add.md @@ -0,0 +1,5 @@ +--- +"shadcn": minor +--- + +recursively resolve registry dependencies diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index f354abc95a2..1f1932756aa 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -54,7 +54,7 @@ jobs: path: packages/shadcn - name: Upload packaged artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: npm-package-shadcn@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name path: packages/shadcn/dist/index.js diff --git a/packages/shadcn/src/utils/registry/index.ts b/packages/shadcn/src/utils/registry/index.ts index b70b1506235..429ce4c4add 100644 --- a/packages/shadcn/src/utils/registry/index.ts +++ b/packages/shadcn/src/utils/registry/index.ts @@ -265,44 +265,33 @@ export async function registryResolveItemsTree( return null } - let items = ( - await Promise.all( - names.map(async (name) => { - const item = await getRegistryItem(name, config.style) - return item - }) - ) - ).filter((item): item is NonNullable => item !== null) - - if (!items.length) { - return null + // If we're resolving the index, we want it to go first. + if (names.includes("index")) { + names.unshift("index") } - const registryDependencies: string[] = items - .map((item) => item.registryDependencies ?? []) - .flat() + let registryDependencies: string[] = [] + for (const name of names) { + const itemRegistryDependencies = await resolveRegistryDependencies( + name, + config + ) + registryDependencies.push(...itemRegistryDependencies) + } - const uniqueDependencies = Array.from(new Set(registryDependencies)) - const urls = Array.from([...names, ...uniqueDependencies]).map((name) => - getRegistryUrl(isUrl(name) ? name : `styles/${config.style}/${name}.json`) - ) - let result = await fetchRegistry(urls) + const uniqueRegistryDependencies = Array.from(new Set(registryDependencies)) + let result = await fetchRegistry(uniqueRegistryDependencies) const payload = z.array(registryItemSchema).parse(result) if (!payload) { return null } - // If we're resolving the index, we want it to go first. + // If we're resolving the index, we want to fetch + // the theme item if a base color is provided. + // We do this for index only. + // Other components will ship with their theme tokens. if (names.includes("index")) { - const index = await getRegistryItem("index", config.style) - if (index) { - payload.unshift(index) - } - - // Fetch the theme item if a base color is provided. - // We do this for index only. - // Other components will ship with their theme tokens. if (config.tailwind.baseColor) { const theme = await registryGetTheme(config.tailwind.baseColor, config) if (theme) { @@ -346,6 +335,46 @@ export async function registryResolveItemsTree( } } +async function resolveRegistryDependencies( + url: string, + config: Config +): Promise { + const visited = new Set() + const payload: string[] = [] + + async function resolveDependencies(itemUrl: string) { + const url = getRegistryUrl( + isUrl(itemUrl) ? itemUrl : `styles/${config.style}/${itemUrl}.json` + ) + + if (visited.has(url)) { + return + } + + visited.add(url) + + try { + const [result] = await fetchRegistry([url]) + const item = registryItemSchema.parse(result) + payload.push(url) + + if (item.registryDependencies) { + for (const dependency of item.registryDependencies) { + await resolveDependencies(dependency) + } + } + } catch (error) { + console.error( + `Error fetching or parsing registry item at ${itemUrl}:`, + error + ) + } + } + + await resolveDependencies(url) + return Array.from(new Set(payload)) +} + export async function registryGetTheme(name: string, config: Config) { const baseColor = await getRegistryBaseColor(name) if (!baseColor) { diff --git a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap index 9bdcd791efa..02feee5efe3 100644 --- a/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap +++ b/packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap @@ -12,16 +12,24 @@ exports[`registryResolveItemTree > should resolve index 1`] = ` "tailwindcss-animate", "class-variance-authority", "lucide-react", - "tailwindcss-animate", - "class-variance-authority", - "lucide-react", - "@radix-ui/react-label", "clsx", "tailwind-merge", + "@radix-ui/react-label", ], "devDependencies": [], "docs": "", "files": [ + { + "content": "import { clsx, type ClassValue } from "clsx" +import { twMerge } from "tailwind-merge" + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)) +} +", + "path": "lib/utils.ts", + "type": "registry:lib", + }, { "content": ""use client" @@ -54,23 +62,11 @@ export { Label } "target": "", "type": "registry:ui", }, - { - "content": "import { clsx, type ClassValue } from "clsx" -import { twMerge } from "tailwind-merge" - -export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)) -} -", - "path": "lib/utils.ts", - "type": "registry:lib", - }, ], "tailwind": { "config": { "plugins": [ "require("tailwindcss-animate")", - "require("tailwindcss-animate")", ], "theme": { "extend": { From 7dfdb029e72d6128168f60552c43b05a50a49776 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 26 Sep 2024 14:42:49 +0200 Subject: [PATCH 016/115] use "?url" suffix in "tailwind.css" import (Remix) (#4945) Importing `tailwind.css` is incorrect as it will treat that file as a CSS Module, throwing that it has no `default` export. Instead, the tutorial relies on the import returning a _URL_ to the stylesheet. Adding `?url` to the import specifier is the way to go. --- apps/www/content/docs/installation/remix.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/www/content/docs/installation/remix.mdx b/apps/www/content/docs/installation/remix.mdx index 6ac9ac8150a..170d20a8a44 100644 --- a/apps/www/content/docs/installation/remix.mdx +++ b/apps/www/content/docs/installation/remix.mdx @@ -78,7 +78,7 @@ export default { In your `app/root.tsx` file, import the `tailwind.css` file: ```js {1, 4} -import styles from "./tailwind.css" +import styles from "./tailwind.css?url" export const links: LinksFunction = () => [ { rel: "stylesheet", href: styles }, From 96880e7c9afad3fed6749c5862d05dbfd65c4327 Mon Sep 17 00:00:00 2001 From: Nami Sunami Date: Fri, 27 Sep 2024 14:01:04 +0200 Subject: [PATCH 017/115] =?UTF-8?q?fix:=20Fix=20the=20typo=20in=20error=20?= =?UTF-8?q?messages=20(`component.json`=20=E2=86=92=20`components.json`)?= =?UTF-8?q?=20(#4977)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(prompt): fix error message, component.json -> components.json * fix(config): fix the error message, component.json -> components.json * chore: changeset --------- Co-authored-by: shadcn --- .changeset/rare-bugs-repair.md | 5 +++++ packages/shadcn/src/commands/add.ts | 4 ++-- packages/shadcn/src/utils/get-config.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/rare-bugs-repair.md diff --git a/.changeset/rare-bugs-repair.md b/.changeset/rare-bugs-repair.md new file mode 100644 index 00000000000..3a612ac3c3e --- /dev/null +++ b/.changeset/rare-bugs-repair.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +fix typo in components.json diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index 04f96211d0b..e59e4e8e296 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -82,13 +82,13 @@ export const add = new Command() let { errors, config } = await preFlightAdd(options) - // No component.json file. Prompt the user to run init. + // No components.json file. Prompt the user to run init. if (errors[ERRORS.MISSING_CONFIG]) { const { proceed } = await prompts({ type: "confirm", name: "proceed", message: `You need to create a ${highlighter.info( - "component.json" + "components.json" )} file to add components. Proceed?`, initial: true, }) diff --git a/packages/shadcn/src/utils/get-config.ts b/packages/shadcn/src/utils/get-config.ts index 866113290cc..fafb395015f 100644 --- a/packages/shadcn/src/utils/get-config.ts +++ b/packages/shadcn/src/utils/get-config.ts @@ -125,7 +125,7 @@ export async function getRawConfig(cwd: string): Promise { return rawConfigSchema.parse(configResult.config) } catch (error) { - const componentPath = `${cwd}/component.json` + const componentPath = `${cwd}/components.json` throw new Error( `Invalid configuration found in ${highlighter.info(componentPath)}.` ) From 5fc9ade413ea10da422a2439b5cc2027fb2a055e Mon Sep 17 00:00:00 2001 From: shadcn Date: Fri, 27 Sep 2024 17:43:16 +0400 Subject: [PATCH 018/115] chore(cli): add deprecation notice (#4988) * feat(cli): add deprecation message * chore: changesets --- .changeset/small-plums-swim.md | 5 +++++ packages/cli/README.md | 3 +++ packages/cli/src/commands/add.ts | 3 +++ packages/cli/src/commands/init.ts | 3 +++ packages/cli/src/deprecated.ts | 7 +++++++ packages/cli/src/index.ts | 2 ++ 6 files changed, 23 insertions(+) create mode 100644 .changeset/small-plums-swim.md create mode 100644 packages/cli/src/deprecated.ts diff --git a/.changeset/small-plums-swim.md b/.changeset/small-plums-swim.md new file mode 100644 index 00000000000..cd25161ef71 --- /dev/null +++ b/.changeset/small-plums-swim.md @@ -0,0 +1,5 @@ +--- +"shadcn-ui": patch +--- + +add deprecation notice diff --git a/packages/cli/README.md b/packages/cli/README.md index 49b9014fdf9..816337065e7 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -2,6 +2,9 @@ A CLI for adding components to your project. +> [!WARNING] +> The shadcn-ui CLI is going to be deprecated soon. Bug fixes and new features should be added to the `.packages/shadcn` instead. + ## Usage Use the `init` command to initialize dependencies for a new project. diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 3bded1a9b6f..abf509f49ff 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -1,5 +1,6 @@ import { existsSync, promises as fs } from "fs" import path from "path" +import { DEPRECATED_MESSAGE } from "@/src/deprecated" import { getConfig } from "@/src/utils/get-config" import { getPackageManager } from "@/src/utils/get-package-manager" import { handleError } from "@/src/utils/handle-error" @@ -43,6 +44,8 @@ export const add = new Command() .option("-p, --path ", "the path to add the component to.") .action(async (components, opts) => { try { + console.log(DEPRECATED_MESSAGE) + const options = addOptionsSchema.parse({ components, ...opts, diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 78893dc530d..4ba66f47c26 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -1,5 +1,6 @@ import { existsSync, promises as fs } from "fs" import path from "path" +import { DEPRECATED_MESSAGE } from "@/src/deprecated" import { DEFAULT_COMPONENTS, DEFAULT_TAILWIND_CONFIG, @@ -55,6 +56,8 @@ export const init = new Command() ) .action(async (opts) => { try { + console.log(DEPRECATED_MESSAGE) + const options = initOptionsSchema.parse(opts) const cwd = path.resolve(options.cwd) diff --git a/packages/cli/src/deprecated.ts b/packages/cli/src/deprecated.ts new file mode 100644 index 00000000000..e143fb3e07f --- /dev/null +++ b/packages/cli/src/deprecated.ts @@ -0,0 +1,7 @@ +import chalk from "chalk" + +export const DEPRECATED_MESSAGE = chalk.yellow( + `\nNote: The shadcn-ui CLI is going to be deprecated soon. Please use ${chalk.bold( + "npx shadcn" + )} instead.\n` +) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index f92c33c2714..5a3e938d8cf 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -4,6 +4,7 @@ import { diff } from "@/src/commands/diff" import { init } from "@/src/commands/init" import { Command } from "commander" +import { DEPRECATED_MESSAGE } from "./deprecated" import { getPackageInfo } from "./utils/get-package-info" process.on("SIGINT", () => process.exit(0)) @@ -15,6 +16,7 @@ async function main() { const program = new Command() .name("shadcn-ui") .description("add components and dependencies to your project") + .addHelpText("after", DEPRECATED_MESSAGE) .version( packageInfo.version || "1.0.0", "-v, --version", From 4b546bfb13346fdbaf0fca4e8041ddba35d23f47 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Fri, 27 Sep 2024 19:58:46 +0200 Subject: [PATCH 019/115] fix(cli): remix detection (#4972) # What Some remix templates doesn't package a `vite.config.*` file at their root. It's the case for the recommended starter "stack" templates: blues-stack, indie-stack and grunge-stack. As recommended in a TODO comment, it's more suitable to check for a `@remix-run/*` dependency in the package dependencies. # How - decouple vite and remix checks - retrieve the `package.json` - allow passing a `cwd` to the retrieval method - remove the "empty config file list" that can be empty for a remix stack - check that the `package.json` contains a `@remix-run/*` dependency # Test Added a fixture by running `npx create-remix@latest --template remix-run/indie-stack` in the [frameworks](/Fluf22/shadcn-ui/tree/fix/cli-remix-detection/packages/cli/test/fixtures/frameworks) folder and named it `remix-indie-stack`, if ever we want another stack as a fixture later --- Fixes shadcn-ui/ui#4967 --- .changeset/good-toes-greet.md | 5 + .gitignore | 7 +- packages/shadcn/src/utils/get-package-info.ts | 11 +- packages/shadcn/src/utils/get-project-info.ts | 27 ++- .../remix-indie-stack/.dockerignore | 7 + .../frameworks/remix-indie-stack/.env.example | 2 + .../frameworks/remix-indie-stack/.eslintrc.js | 136 +++++++++++ .../.github/ISSUE_TEMPLATE/bug_report.yml | 41 ++++ .../.github/ISSUE_TEMPLATE/config.yml | 21 ++ .../.github/PULL_REQUEST_TEMPLATE.md | 14 ++ .../remix-indie-stack/.github/dependabot.yml | 6 + .../.github/workflows/deploy.yml | 144 +++++++++++ .../.github/workflows/format-repo.yml | 46 ++++ .../.github/workflows/lint-repo.yml | 33 +++ .../.github/workflows/no-response.yml | 34 +++ .../frameworks/remix-indie-stack/.gitignore | 18 ++ .../remix-indie-stack/.gitpod.Dockerfile | 9 + .../frameworks/remix-indie-stack/.gitpod.yml | 48 ++++ .../frameworks/remix-indie-stack/.npmrc | 1 + .../remix-indie-stack/.prettierignore | 7 + .../frameworks/remix-indie-stack/Dockerfile | 61 +++++ .../frameworks/remix-indie-stack/LICENSE.md | 22 ++ .../frameworks/remix-indie-stack/README.md | 183 ++++++++++++++ .../remix-indie-stack/app/db.server.ts | 9 + .../remix-indie-stack/app/entry.client.tsx | 18 ++ .../remix-indie-stack/app/entry.server.tsx | 120 +++++++++ .../app/models/note.server.ts | 52 ++++ .../app/models/user.server.ts | 63 +++++ .../frameworks/remix-indie-stack/app/root.tsx | 42 ++++ .../remix-indie-stack/app/routes/_index.tsx | 141 +++++++++++ .../app/routes/healthcheck.tsx | 25 ++ .../remix-indie-stack/app/routes/join.tsx | 171 +++++++++++++ .../remix-indie-stack/app/routes/login.tsx | 180 ++++++++++++++ .../remix-indie-stack/app/routes/logout.tsx | 9 + .../app/routes/notes.$noteId.tsx | 70 ++++++ .../app/routes/notes._index.tsx | 12 + .../app/routes/notes.new.tsx | 109 +++++++++ .../remix-indie-stack/app/routes/notes.tsx | 70 ++++++ .../remix-indie-stack/app/session.server.ts | 97 ++++++++ .../remix-indie-stack/app/singleton.server.ts | 13 + .../remix-indie-stack/app/tailwind.css | 3 + .../remix-indie-stack/app/utils.test.ts | 13 + .../frameworks/remix-indie-stack/app/utils.ts | 76 ++++++ .../remix-indie-stack/cypress.config.ts | 26 ++ .../remix-indie-stack/cypress/.eslintrc.js | 6 + .../remix-indie-stack/cypress/e2e/smoke.cy.ts | 51 ++++ .../cypress/fixtures/example.json | 5 + .../cypress/support/commands.ts | 98 ++++++++ .../cypress/support/create-user.ts | 48 ++++ .../cypress/support/delete-user.ts | 37 +++ .../remix-indie-stack/cypress/support/e2e.ts | 17 ++ .../remix-indie-stack/cypress/tsconfig.json | 28 +++ .../frameworks/remix-indie-stack/fly.toml | 52 ++++ .../remix-indie-stack/mocks/README.md | 7 + .../remix-indie-stack/mocks/index.js | 15 ++ .../frameworks/remix-indie-stack/package.json | 93 +++++++ .../remix-indie-stack/postcss.config.js | 6 + .../remix-indie-stack/prettier.config.js | 4 + .../20220713162558_init/migration.sql | 31 +++ .../prisma/migrations/migration_lock.toml | 3 + .../remix-indie-stack/prisma/schema.prisma | 38 +++ .../remix-indie-stack/prisma/seed.ts | 53 ++++ .../remix-indie-stack/public/favicon.ico | Bin 0 -> 16958 bytes .../remix-indie-stack/remix.config.js | 6 + .../remix-indie-stack/remix.env.d.ts | 2 + .../remix-indie-stack/remix.init/gitignore | 10 + .../remix-indie-stack/remix.init/index.js | 227 ++++++++++++++++++ .../remix-indie-stack/remix.init/package.json | 11 + .../frameworks/remix-indie-stack/start.sh | 9 + .../remix-indie-stack/tailwind.config.ts | 9 + .../remix-indie-stack/test/setup-test-env.ts | 4 + .../remix-indie-stack/tsconfig.json | 28 +++ .../remix-indie-stack/vitest.config.ts | 15 ++ .../test/utils/get-project-info.test.ts | 12 + 74 files changed, 3113 insertions(+), 14 deletions(-) create mode 100644 .changeset/good-toes-greet.md create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.dockerignore create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.env.example create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.eslintrc.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/config.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/dependabot.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/deploy.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/format-repo.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/lint-repo.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/no-response.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitignore create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.Dockerfile create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.yml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.npmrc create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.prettierignore create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/Dockerfile create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/LICENSE.md create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/README.md create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/db.server.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.client.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.server.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/note.server.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/user.server.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/root.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/healthcheck.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/join.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/login.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/logout.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.$noteId.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes._index.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.new.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.tsx create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/session.server.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/singleton.server.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/tailwind.css create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/utils.test.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/utils.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress.config.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/.eslintrc.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/e2e/smoke.cy.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/fixtures/example.json create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support/commands.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support/create-user.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support/delete-user.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support/e2e.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/tsconfig.json create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/fly.toml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/mocks/README.md create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/mocks/index.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/package.json create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/postcss.config.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prettier.config.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/migrations/20220713162558_init/migration.sql create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/migrations/migration_lock.toml create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/schema.prisma create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/seed.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/public/favicon.ico create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/remix.config.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/remix.env.d.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/remix.init/gitignore create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/remix.init/index.js create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/remix.init/package.json create mode 100755 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/start.sh create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/tailwind.config.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/test/setup-test-env.ts create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/tsconfig.json create mode 100644 packages/shadcn/test/fixtures/frameworks/remix-indie-stack/vitest.config.ts diff --git a/.changeset/good-toes-greet.md b/.changeset/good-toes-greet.md new file mode 100644 index 00000000000..e3dad3d5213 --- /dev/null +++ b/.changeset/good-toes-greet.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +update remix detection diff --git a/.gitignore b/.gitignore index 24c1ac82436..865a3fd3be3 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,9 @@ yarn-error.log* .turbo .contentlayer -tsconfig.tsbuildinfo \ No newline at end of file +tsconfig.tsbuildinfo + +# ide +.idea +.fleet +.vscode diff --git a/packages/shadcn/src/utils/get-package-info.ts b/packages/shadcn/src/utils/get-package-info.ts index c7f4961927e..946aaf403e6 100644 --- a/packages/shadcn/src/utils/get-package-info.ts +++ b/packages/shadcn/src/utils/get-package-info.ts @@ -2,8 +2,13 @@ import path from "path" import fs from "fs-extra" import { type PackageJson } from "type-fest" -export function getPackageInfo() { - const packageJsonPath = path.join("package.json") +export function getPackageInfo( + cwd: string = "", + shouldThrow: boolean = true +): PackageJson | null { + const packageJsonPath = path.join(cwd, "package.json") - return fs.readJSONSync(packageJsonPath) as PackageJson + return fs.readJSONSync(packageJsonPath, { + throws: shouldThrow, + }) as PackageJson } diff --git a/packages/shadcn/src/utils/get-project-info.ts b/packages/shadcn/src/utils/get-project-info.ts index f728e20569c..cd1f47ce8fa 100644 --- a/packages/shadcn/src/utils/get-project-info.ts +++ b/packages/shadcn/src/utils/get-project-info.ts @@ -6,6 +6,7 @@ import { getConfig, resolveConfigPaths, } from "@/src/utils/get-config" +import { getPackageInfo } from "@/src/utils/get-package-info" import fg from "fast-glob" import fs from "fs-extra" import { loadConfig } from "tsconfig-paths" @@ -36,6 +37,7 @@ export async function getProjectInfo(cwd: string): Promise { tailwindConfigFile, tailwindCssFile, aliasPrefix, + packageJson, ] = await Promise.all([ fg.glob("**/{next,vite,astro}.config.*|gatsby-config.*|composer.json", { cwd, @@ -47,6 +49,7 @@ export async function getProjectInfo(cwd: string): Promise { getTailwindConfigFile(cwd), getTailwindCssFile(cwd), getTsConfigAliasPrefix(cwd), + getPackageInfo(cwd, false), ]) const isUsingAppDir = await fs.pathExists( @@ -63,10 +66,6 @@ export async function getProjectInfo(cwd: string): Promise { aliasPrefix, } - if (!configFiles.length) { - return type - } - // Next.js. if (configFiles.find((file) => file.startsWith("next.config."))?.length) { type.framework = isUsingAppDir @@ -94,13 +93,21 @@ export async function getProjectInfo(cwd: string): Promise { return type } - // Vite and Remix. - // They both have a vite.config.* file. + // Remix. + if ( + Object.keys(packageJson?.dependencies ?? {}).find((dep) => + dep.startsWith("@remix-run/") + ) + ) { + type.framework = FRAMEWORKS["remix"] + return type + } + + // Vite. + // Some Remix templates also have a vite.config.* file. + // We'll assume that it got caught by the Remix check above. if (configFiles.find((file) => file.startsWith("vite.config."))?.length) { - // We'll assume that if the project has an app dir, it's a Remix project. - // Otherwise, it's a Vite project. - // TODO: Maybe check for `@remix-run/react` in package.json? - type.framework = isUsingAppDir ? FRAMEWORKS["remix"] : FRAMEWORKS["vite"] + type.framework = FRAMEWORKS["vite"] return type } diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.dockerignore b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.dockerignore new file mode 100644 index 00000000000..91077d0621d --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.dockerignore @@ -0,0 +1,7 @@ +/node_modules +*.log +.DS_Store +.env +/.cache +/public/build +/build diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.env.example b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.env.example new file mode 100644 index 00000000000..0d0e0d65e4b --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.env.example @@ -0,0 +1,2 @@ +DATABASE_URL="file:./data.db?connection_limit=1" +SESSION_SECRET="super-duper-s3cret" diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.eslintrc.js b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.eslintrc.js new file mode 100644 index 00000000000..9381f33520b --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.eslintrc.js @@ -0,0 +1,136 @@ +/** + * This is intended to be a basic starting point for linting in the Indie Stack. + * It relies on recommended configs out of the box for simplicity, but you can + * and should modify this configuration to best suit your team's needs. + */ + +/** @type {import('eslint').Linter.Config} */ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: "latest", + sourceType: "module", + ecmaFeatures: { + jsx: true, + }, + }, + env: { + browser: true, + commonjs: true, + es6: true, + }, + + // Base config + extends: ["eslint:recommended"], + + overrides: [ + // React + { + files: ["**/*.{js,jsx,ts,tsx}"], + plugins: ["react", "jsx-a11y"], + extends: [ + "plugin:react/recommended", + "plugin:react/jsx-runtime", + "plugin:react-hooks/recommended", + "plugin:jsx-a11y/recommended", + "prettier", + ], + settings: { + react: { + version: "detect", + }, + formComponents: ["Form"], + linkComponents: [ + { name: "Link", linkAttribute: "to" }, + { name: "NavLink", linkAttribute: "to" }, + ], + }, + rules: { + "react/jsx-no-leaked-render": [ + "warn", + { validStrategies: ["ternary"] }, + ], + }, + }, + + // Typescript + { + files: ["**/*.{ts,tsx}"], + plugins: ["@typescript-eslint", "import"], + parser: "@typescript-eslint/parser", + settings: { + "import/internal-regex": "^~/", + "import/resolver": { + node: { + extensions: [".ts", ".tsx"], + }, + typescript: { + alwaysTryTypes: true, + }, + }, + }, + extends: [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/stylistic", + "plugin:import/recommended", + "plugin:import/typescript", + "prettier", + ], + rules: { + "import/order": [ + "error", + { + alphabetize: { caseInsensitive: true, order: "asc" }, + groups: ["builtin", "external", "internal", "parent", "sibling"], + "newlines-between": "always", + }, + ], + }, + }, + + // Markdown + { + files: ["**/*.md"], + plugins: ["markdown"], + extends: ["plugin:markdown/recommended-legacy", "prettier"], + }, + + // Jest/Vitest + { + files: ["**/*.test.{js,jsx,ts,tsx}"], + plugins: ["jest", "jest-dom", "testing-library"], + extends: [ + "plugin:jest/recommended", + "plugin:jest-dom/recommended", + "plugin:testing-library/react", + "prettier", + ], + env: { + "jest/globals": true, + }, + settings: { + jest: { + // we're using vitest which has a very similar API to jest + // (so the linting plugins work nicely), but it means we have to explicitly + // set the jest version. + version: 28, + }, + }, + }, + + // Cypress + { + files: ["cypress/**/*.ts"], + plugins: ["cypress"], + extends: ["plugin:cypress/recommended", "prettier"], + }, + + // Node + { + files: [".eslintrc.js", "mocks/**/*.js"], + env: { + node: true, + }, + }, + ], +}; diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/bug_report.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000000..55a66fb642b --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,41 @@ +name: 🐛 Bug Report +description: Something is wrong with the Stack. +body: + - type: markdown + attributes: + value: >- + Thank you for helping to improve Remix! + + Our bandwidth on maintaining these stacks is limited. As a team, we're + currently focusing our efforts on Remix itself. The good news is you can + fork and adjust this stack however you'd like and start using it today + as a custom stack. Learn more from + [the Remix Stacks docs](https://remix.run/stacks). + + If you'd still like to report a bug, please fill out this form. We can't + promise a timely response, but hopefully when we have the bandwidth to + work on these stacks again we can take a look. Thanks! + + - type: input + attributes: + label: Have you experienced this bug with the latest version of the template? + validations: + required: true + - type: textarea + attributes: + label: Steps to Reproduce + description: Steps to reproduce the behavior. + validations: + required: true + - type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: true + - type: textarea + attributes: + label: Actual Behavior + description: A concise description of what you're experiencing. + validations: + required: true diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/config.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000000..da966200473 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,21 @@ +blank_issues_enabled: false +contact_links: + - name: Get Help + url: https://github.com/remix-run/remix/discussions/new?category=q-a + about: + If you can't get something to work the way you expect, open a question in + the Remix discussions. + - name: Feature Request + url: https://github.com/remix-run/remix/discussions/new?category=ideas + about: + We appreciate you taking the time to improve Remix with your ideas, but we + use the Remix Discussions for this instead of the issues tab 🙂. + - name: 💬 Remix Discord Channel + url: https://rmx.as/discord + about: Interact with other people using Remix 💿 + - name: 💬 New Updates (Twitter) + url: https://twitter.com/remix_run + about: Stay up to date with Remix news on twitter + - name: 🍿 Remix YouTube Channel + url: https://rmx.as/youtube + about: Are you a tech lead or wanting to learn more about Remix in depth? Checkout the Remix YouTube Channel diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/PULL_REQUEST_TEMPLATE.md b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000000..024f9d8e239 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,14 @@ + diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/dependabot.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/dependabot.yml new file mode 100644 index 00000000000..253bcb76bad --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/deploy.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/deploy.yml new file mode 100644 index 00000000000..8f7ec3ce3f6 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/deploy.yml @@ -0,0 +1,144 @@ +name: 🚀 Deploy + +on: + push: + branches: + - main + - dev + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + actions: write + contents: read + +jobs: + lint: + name: ⬣ ESLint + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: 🔬 Lint + run: npm run lint + + typecheck: + name: ʦ TypeScript + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: 🔎 Type check + run: npm run typecheck --if-present + + vitest: + name: ⚡ Vitest + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: ⚡ Run vitest + run: npm run test -- --coverage + + cypress: + name: ⚫️ Cypress + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: 🏄 Copy test env vars + run: cp .env.example .env + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: 🛠 Setup Database + run: npx prisma migrate reset --force + + - name: ⚙️ Build + run: npm run build + + - name: 🌳 Cypress run + uses: cypress-io/github-action@v6 + with: + start: npm run start:mocks + wait-on: http://localhost:8811 + env: + PORT: 8811 + + deploy: + name: 🚀 Deploy + runs-on: ubuntu-latest + needs: [lint, typecheck, vitest, cypress] + # only deploy main/dev branch on pushes + if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} + + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: 👀 Read app name + uses: SebRollen/toml-action@v1.2.0 + id: app_name + with: + file: fly.toml + field: app + + - name: 🎈 Setup Fly + uses: superfly/flyctl-actions/setup-flyctl@v1 + + - name: 🚀 Deploy Staging + if: ${{ github.ref == 'refs/heads/dev' }} + run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}-staging + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + + - name: 🚀 Deploy Production + if: ${{ github.ref == 'refs/heads/main' }} + run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }} + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/format-repo.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/format-repo.yml new file mode 100644 index 00000000000..240b0eccf0b --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/format-repo.yml @@ -0,0 +1,46 @@ +name: 👔 Format + +on: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + format: + if: github.repository == 'remix-run/indie-stack' + runs-on: ubuntu-latest + + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: 👔 Format + run: npm run format:repo + + - name: 💪 Commit + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + git add . + if [ -z "$(git status --porcelain)" ]; then + echo "💿 no formatting changed" + exit 0 + fi + git commit -m "chore: format" + git push + echo "💿 pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)" diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/lint-repo.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/lint-repo.yml new file mode 100644 index 00000000000..b2d38564dde --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/lint-repo.yml @@ -0,0 +1,33 @@ +name: ⬣ Lint repository + +on: + push: + branches: + - main + - dev + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: ⬣ Lint repo + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package.json + node-version: 18 + + - name: 📥 Install deps + run: npm install + + - name: 🔬 Lint + run: npm run lint diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/no-response.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/no-response.yml new file mode 100644 index 00000000000..96426f67109 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.github/workflows/no-response.yml @@ -0,0 +1,34 @@ +name: 🥺 No Response + +on: + schedule: + # Schedule for five minutes after the hour, every hour + - cron: "5 * * * *" + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + if: github.repository == 'remix-run/indie-stack' + runs-on: ubuntu-latest + steps: + - name: 🥺 Handle Ghosting + uses: actions/stale@v9 + with: + days-before-close: 10 + close-issue-message: > + This issue has been automatically closed because we haven't received a + response from the original author 🙈. This automation helps keep the issue + tracker clean from issues that are unactionable. Please reach out if you + have more information for us! 🙂 + close-pr-message: > + This PR has been automatically closed because we haven't received a + response from the original author 🙈. This automation helps keep the issue + tracker clean from PRs that are unactionable. Please reach out if you + have more information for us! 🙂 + # don't automatically mark issues/PRs as stale + days-before-stale: -1 + stale-issue-label: needs-response + stale-pr-label: needs-response diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitignore b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitignore new file mode 100644 index 00000000000..d5f63bb4432 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitignore @@ -0,0 +1,18 @@ +# We don't want lockfiles in stacks, as people could use a different package manager +# This part will be removed by `remix.init` +bun.lockb +package-lock.json +pnpm-lock.yaml +pnpm-lock.yml +yarn.lock + +node_modules + +/build +/public/build +.env + +/cypress/screenshots +/cypress/videos +/prisma/data.db +/prisma/data.db-journal diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.Dockerfile b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.Dockerfile new file mode 100644 index 00000000000..e52ca2d64b6 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.Dockerfile @@ -0,0 +1,9 @@ +FROM gitpod/workspace-full + +# Install Fly +RUN curl -L https://fly.io/install.sh | sh +ENV FLYCTL_INSTALL="/home/gitpod/.fly" +ENV PATH="$FLYCTL_INSTALL/bin:$PATH" + +# Install GitHub CLI +RUN brew install gh diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.yml b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.yml new file mode 100644 index 00000000000..f07c56287f4 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.gitpod.yml @@ -0,0 +1,48 @@ +# https://www.gitpod.io/docs/config-gitpod-file + +image: + file: .gitpod.Dockerfile + +ports: + - port: 3000 + onOpen: notify + +tasks: + - name: Restore .env file + command: | + if [ -f .env ]; then + # If this workspace already has a .env, don't override it + # Local changes survive a workspace being opened and closed + # but they will not persist between separate workspaces for the same repo + + echo "Found .env in workspace" + else + # There is no .env + if [ ! -n "${ENV}" ]; then + # There is no $ENV from a previous workspace + # Default to the example .env + echo "Setting example .env" + + cp .env.example .env + else + # After making changes to .env, run this line to persist it to $ENV + # eval $(gp env -e ENV="$(base64 .env | tr -d '\n')") + # + # Environment variables set this way are shared between all your workspaces for this repo + # The lines below will read $ENV and print a .env file + + echo "Restoring .env from Gitpod" + + echo "${ENV}" | base64 -d | tee .env > /dev/null + fi + fi + + - init: npm install + command: npm run setup && npm run dev + +vscode: + extensions: + - ms-azuretools.vscode-docker + - esbenp.prettier-vscode + - dbaeumer.vscode-eslint + - bradlc.vscode-tailwindcss diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.npmrc b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.npmrc new file mode 100644 index 00000000000..521a9f7c077 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.npmrc @@ -0,0 +1 @@ +legacy-peer-deps=true diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.prettierignore b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.prettierignore new file mode 100644 index 00000000000..8cb6bcbdbb0 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/.prettierignore @@ -0,0 +1,7 @@ +node_modules + +/build +/public/build +.env + +/app/styles/tailwind.css diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/Dockerfile b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/Dockerfile new file mode 100644 index 00000000000..093ace785bf --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/Dockerfile @@ -0,0 +1,61 @@ +# base node image +FROM node:18-bullseye-slim as base + +# set for base and all layer that inherit from it +ENV NODE_ENV production + +# Install openssl for Prisma +RUN apt-get update && apt-get install -y openssl sqlite3 + +# Install all node_modules, including dev dependencies +FROM base as deps + +WORKDIR /myapp + +ADD package.json .npmrc ./ +RUN npm install --include=dev + +# Setup production node_modules +FROM base as production-deps + +WORKDIR /myapp + +COPY --from=deps /myapp/node_modules /myapp/node_modules +ADD package.json .npmrc ./ +RUN npm prune --omit=dev + +# Build the app +FROM base as build + +WORKDIR /myapp + +COPY --from=deps /myapp/node_modules /myapp/node_modules + +ADD prisma . +RUN npx prisma generate + +ADD . . +RUN npm run build + +# Finally, build the production image with minimal footprint +FROM base + +ENV DATABASE_URL=file:/data/sqlite.db +ENV PORT="8080" +ENV NODE_ENV="production" + +# add shortcut for connecting to database CLI +RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli + +WORKDIR /myapp + +COPY --from=production-deps /myapp/node_modules /myapp/node_modules +COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma + +COPY --from=build /myapp/build /myapp/build +COPY --from=build /myapp/public /myapp/public +COPY --from=build /myapp/package.json /myapp/package.json +COPY --from=build /myapp/start.sh /myapp/start.sh +COPY --from=build /myapp/prisma /myapp/prisma + +ENTRYPOINT [ "./start.sh" ] diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/LICENSE.md b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/LICENSE.md new file mode 100644 index 00000000000..8ed8d952958 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/LICENSE.md @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) Remix Software Inc. 2021 +Copyright (c) Shopify Inc. 2022-2023 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/README.md b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/README.md new file mode 100644 index 00000000000..fa24ab98b38 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/README.md @@ -0,0 +1,183 @@ +# Remix Indie Stack + +![The Remix Indie Stack](https://repository-images.githubusercontent.com/465928257/a241fa49-bd4d-485a-a2a5-5cb8e4ee0abf) + +Learn more about [Remix Stacks](https://remix.run/stacks). + +```sh +npx create-remix@latest --template remix-run/indie-stack +``` + +## What's in the stack + +- [Fly app deployment](https://fly.io) with [Docker](https://www.docker.com/) +- Production-ready [SQLite Database](https://sqlite.org) +- Healthcheck endpoint for [Fly backups region fallbacks](https://fly.io/docs/reference/configuration/#services-http_checks) +- [GitHub Actions](https://github.com/features/actions) for deploy on merge to production and staging environments +- Email/Password Authentication with [cookie-based sessions](https://remix.run/utils/sessions#md-createcookiesessionstorage) +- Database ORM with [Prisma](https://prisma.io) +- Styling with [Tailwind](https://tailwindcss.com/) +- End-to-end testing with [Cypress](https://cypress.io) +- Local third party request mocking with [MSW](https://mswjs.io) +- Unit testing with [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com) +- Code formatting with [Prettier](https://prettier.io) +- Linting with [ESLint](https://eslint.org) +- Static Types with [TypeScript](https://typescriptlang.org) + +Not a fan of bits of the stack? Fork it, change it, and use `npx create-remix --template your/repo`! Make it your own. + +## Quickstart + +Click this button to create a [Gitpod](https://gitpod.io) workspace with the project set up and Fly pre-installed + +[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/remix-run/indie-stack/tree/main) + +## Development + +- First run this stack's `remix.init` script and commit the changes it makes to your project. + + ```sh + npx remix init + git init # if you haven't already + git add . + git commit -m "Initialize project" + ``` + +- Initial setup: + + ```sh + npm run setup + ``` + +- Start dev server: + + ```sh + npm run dev + ``` + +This starts your app in development mode, rebuilding assets on file changes. + +The database seed script creates a new user with some data you can use to get started: + +- Email: `rachel@remix.run` +- Password: `racheliscool` + +### Relevant code: + +This is a pretty simple note-taking app, but it's a good example of how you can build a full stack app with Prisma and Remix. The main functionality is creating users, logging in and out, and creating and deleting notes. + +- creating users, and logging in and out [./app/models/user.server.ts](app/models/user.server.ts) +- user sessions, and verifying them [./app/session.server.ts](app/session.server.ts) +- creating, and deleting notes [./app/models/note.server.ts](app/models/note.server.ts) + +## Deployment + +This Remix Stack comes with two GitHub Actions that handle automatically deploying your app to production and staging environments. + +Prior to your first deployment, you'll need to do a few things: + +- [Install Fly](https://fly.io/docs/getting-started/installing-flyctl/) + +- Sign up and log in to Fly + + ```sh + fly auth signup + ``` + + > **Note:** If you have more than one Fly account, ensure that you are signed into the same account in the Fly CLI as you are in the browser. In your terminal, run `fly auth whoami` and ensure the email matches the Fly account signed into the browser. + +- Create two apps on Fly, one for staging and one for production: + + ```sh + fly apps create indie-stack-template + fly apps create indie-stack-template-staging + ``` + + > **Note:** Make sure this name matches the `app` set in your `fly.toml` file. Otherwise, you will not be able to deploy. + + - Initialize Git. + + ```sh + git init + ``` + +- Create a new [GitHub Repository](https://repo.new), and then add it as the remote for your project. **Do not push your app yet!** + + ```sh + git remote add origin + ``` + +- Add a `FLY_API_TOKEN` to your GitHub repo. To do this, go to your user settings on Fly and create a new [token](https://web.fly.io/user/personal_access_tokens/new), then add it to [your repo secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) with the name `FLY_API_TOKEN`. + +- Add a `SESSION_SECRET` to your fly app secrets, to do this you can run the following commands: + + ```sh + fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app indie-stack-template + fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app indie-stack-template-staging + ``` + + If you don't have openssl installed, you can also use [1Password](https://1password.com/password-generator) to generate a random secret, just replace `$(openssl rand -hex 32)` with the generated secret. + +- Create a persistent volume for the sqlite database for both your staging and production environments. Run the following: + + ```sh + fly volumes create data --size 1 --app indie-stack-template + fly volumes create data --size 1 --app indie-stack-template-staging + ``` + +Now that everything is set up you can commit and push your changes to your repo. Every commit to your `main` branch will trigger a deployment to your production environment, and every commit to your `dev` branch will trigger a deployment to your staging environment. + +### Connecting to your database + +The sqlite database lives at `/data/sqlite.db` in your deployed application. You can connect to the live database by running `fly ssh console -C database-cli`. + +### Getting Help with Deployment + +If you run into any issues deploying to Fly, make sure you've followed all of the steps above and if you have, then post as many details about your deployment (including your app name) to [the Fly support community](https://community.fly.io). They're normally pretty responsive over there and hopefully can help resolve any of your deployment issues and questions. + +## GitHub Actions + +We use GitHub Actions for continuous integration and deployment. Anything that gets into the `main` branch will be deployed to production after running tests/build/etc. Anything in the `dev` branch will be deployed to staging. + +## Testing + +### Cypress + +We use Cypress for our End-to-End tests in this project. You'll find those in the `cypress` directory. As you make changes, add to an existing file or create a new file in the `cypress/e2e` directory to test your changes. + +We use [`@testing-library/cypress`](https://testing-library.com/cypress) for selecting elements on the page semantically. + +To run these tests in development, run `npm run test:e2e:dev` which will start the dev server for the app as well as the Cypress client. Make sure the database is running in docker as described above. + +We have a utility for testing authenticated features without having to go through the login flow: + +```ts +cy.login(); +// you are now logged in as a new user +``` + +We also have a utility to auto-delete the user at the end of your test. Just make sure to add this in each test file: + +```ts +afterEach(() => { + cy.cleanupUser(); +}); +``` + +That way, we can keep your local db clean and keep your tests isolated from one another. + +### Vitest + +For lower level tests of utilities and individual components, we use `vitest`. We have DOM-specific assertion helpers via [`@testing-library/jest-dom`](https://testing-library.com/jest-dom). + +### Type Checking + +This project uses TypeScript. It's recommended to get TypeScript set up for your editor to get a really great in-editor experience with type checking and auto-complete. To run type checking across the whole project, run `npm run typecheck`. + +### Linting + +This project uses ESLint for linting. That is configured in `.eslintrc.js`. + +### Formatting + +We use [Prettier](https://prettier.io/) for auto-formatting in this project. It's recommended to install an editor plugin (like the [VSCode Prettier plugin](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) to get auto-formatting on save. There's also a `npm run format` script you can run to format all files in the project. diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/db.server.ts b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/db.server.ts new file mode 100644 index 00000000000..ac5701faa51 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/db.server.ts @@ -0,0 +1,9 @@ +import { PrismaClient } from "@prisma/client"; + +import { singleton } from "./singleton.server"; + +// Hard-code a unique key, so we can look up the client when this module gets re-imported +const prisma = singleton("prisma", () => new PrismaClient()); +prisma.$connect(); + +export { prisma }; diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.client.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.client.tsx new file mode 100644 index 00000000000..186cd934498 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.client.tsx @@ -0,0 +1,18 @@ +/** + * By default, Remix will handle hydrating your app on the client for you. + * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ + * For more information, see https://remix.run/docs/en/main/file-conventions/entry.client + */ + +import { RemixBrowser } from "@remix-run/react"; +import { startTransition, StrictMode } from "react"; +import { hydrateRoot } from "react-dom/client"; + +startTransition(() => { + hydrateRoot( + document, + + + , + ); +}); diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.server.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.server.tsx new file mode 100644 index 00000000000..78d4f1e2408 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/entry.server.tsx @@ -0,0 +1,120 @@ +/** + * By default, Remix will handle generating the HTTP Response for you. + * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ + * For more information, see https://remix.run/docs/en/main/file-conventions/entry.server + */ + +import { PassThrough } from "node:stream"; + +import type { EntryContext } from "@remix-run/node"; +import { createReadableStreamFromReadable } from "@remix-run/node"; +import { RemixServer } from "@remix-run/react"; +import { isbot } from "isbot"; +import { renderToPipeableStream } from "react-dom/server"; + +const ABORT_DELAY = 5_000; + +export default function handleRequest( + request: Request, + responseStatusCode: number, + responseHeaders: Headers, + remixContext: EntryContext, +) { + return isbot(request.headers.get("user-agent")) + ? handleBotRequest( + request, + responseStatusCode, + responseHeaders, + remixContext, + ) + : handleBrowserRequest( + request, + responseStatusCode, + responseHeaders, + remixContext, + ); +} + +function handleBotRequest( + request: Request, + responseStatusCode: number, + responseHeaders: Headers, + remixContext: EntryContext, +) { + return new Promise((resolve, reject) => { + const { abort, pipe } = renderToPipeableStream( + , + { + onAllReady() { + const body = new PassThrough(); + + responseHeaders.set("Content-Type", "text/html"); + + resolve( + new Response(createReadableStreamFromReadable(body), { + headers: responseHeaders, + status: responseStatusCode, + }), + ); + + pipe(body); + }, + onShellError(error: unknown) { + reject(error); + }, + onError(error: unknown) { + responseStatusCode = 500; + console.error(error); + }, + }, + ); + + setTimeout(abort, ABORT_DELAY); + }); +} + +function handleBrowserRequest( + request: Request, + responseStatusCode: number, + responseHeaders: Headers, + remixContext: EntryContext, +) { + return new Promise((resolve, reject) => { + const { abort, pipe } = renderToPipeableStream( + , + { + onShellReady() { + const body = new PassThrough(); + + responseHeaders.set("Content-Type", "text/html"); + + resolve( + new Response(createReadableStreamFromReadable(body), { + headers: responseHeaders, + status: responseStatusCode, + }), + ); + + pipe(body); + }, + onShellError(error: unknown) { + reject(error); + }, + onError(error: unknown) { + console.error(error); + responseStatusCode = 500; + }, + }, + ); + + setTimeout(abort, ABORT_DELAY); + }); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/note.server.ts b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/note.server.ts new file mode 100644 index 00000000000..f385491a2ff --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/note.server.ts @@ -0,0 +1,52 @@ +import type { User, Note } from "@prisma/client"; + +import { prisma } from "~/db.server"; + +export function getNote({ + id, + userId, +}: Pick & { + userId: User["id"]; +}) { + return prisma.note.findFirst({ + select: { id: true, body: true, title: true }, + where: { id, userId }, + }); +} + +export function getNoteListItems({ userId }: { userId: User["id"] }) { + return prisma.note.findMany({ + where: { userId }, + select: { id: true, title: true }, + orderBy: { updatedAt: "desc" }, + }); +} + +export function createNote({ + body, + title, + userId, +}: Pick & { + userId: User["id"]; +}) { + return prisma.note.create({ + data: { + title, + body, + user: { + connect: { + id: userId, + }, + }, + }, + }); +} + +export function deleteNote({ + id, + userId, +}: Pick & { userId: User["id"] }) { + return prisma.note.deleteMany({ + where: { id, userId }, + }); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/user.server.ts b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/user.server.ts new file mode 100644 index 00000000000..42be9b7fbe3 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/user.server.ts @@ -0,0 +1,63 @@ +import type { Password, User } from "@prisma/client"; +import bcrypt from "bcryptjs"; + +import { prisma } from "~/db.server"; + +export type { User } from "@prisma/client"; + +export async function getUserById(id: User["id"]) { + return prisma.user.findUnique({ where: { id } }); +} + +export async function getUserByEmail(email: User["email"]) { + return prisma.user.findUnique({ where: { email } }); +} + +export async function createUser(email: User["email"], password: string) { + const hashedPassword = await bcrypt.hash(password, 10); + + return prisma.user.create({ + data: { + email, + password: { + create: { + hash: hashedPassword, + }, + }, + }, + }); +} + +export async function deleteUserByEmail(email: User["email"]) { + return prisma.user.delete({ where: { email } }); +} + +export async function verifyLogin( + email: User["email"], + password: Password["hash"], +) { + const userWithPassword = await prisma.user.findUnique({ + where: { email }, + include: { + password: true, + }, + }); + + if (!userWithPassword || !userWithPassword.password) { + return null; + } + + const isValid = await bcrypt.compare( + password, + userWithPassword.password.hash, + ); + + if (!isValid) { + return null; + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { password: _password, ...userWithoutPassword } = userWithPassword; + + return userWithoutPassword; +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/root.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/root.tsx new file mode 100644 index 00000000000..426fac3533c --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/root.tsx @@ -0,0 +1,42 @@ +import { cssBundleHref } from "@remix-run/css-bundle"; +import type { LinksFunction, LoaderFunctionArgs } from "@remix-run/node"; +import { json } from "@remix-run/node"; +import { + Links, + LiveReload, + Meta, + Outlet, + Scripts, + ScrollRestoration, +} from "@remix-run/react"; + +import { getUser } from "~/session.server"; +import stylesheet from "~/tailwind.css"; + +export const links: LinksFunction = () => [ + { rel: "stylesheet", href: stylesheet }, + ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []), +]; + +export const loader = async ({ request }: LoaderFunctionArgs) => { + return json({ user: await getUser(request) }); +}; + +export default function App() { + return ( + + + + + + + + + + + + + + + ); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx new file mode 100644 index 00000000000..d266ff726eb --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx @@ -0,0 +1,141 @@ +import type { MetaFunction } from "@remix-run/node"; +import { Link } from "@remix-run/react"; + +import { useOptionalUser } from "~/utils"; + +export const meta: MetaFunction = () => [{ title: "Remix Notes" }]; + +export default function Index() { + const user = useOptionalUser(); + return ( +
+
+
+
+
+ Sonic Youth On Stage +
+
+
+

+ + Indie Stack + +

+

+ Check the README.md file for instructions on how to get this + project deployed. +

+
+ {user ? ( + + View Notes for {user.email} + + ) : ( +
+ + Sign up + + + Log In + +
+ )} +
+ + Remix + +
+
+
+ +
+
+ {[ + { + src: "https://user-images.githubusercontent.com/1500684/157764397-ccd8ea10-b8aa-4772-a99b-35de937319e1.svg", + alt: "Fly.io", + href: "https://fly.io", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157764395-137ec949-382c-43bd-a3c0-0cb8cb22e22d.svg", + alt: "SQLite", + href: "https://sqlite.org", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157764484-ad64a21a-d7fb-47e3-8669-ec046da20c1f.svg", + alt: "Prisma", + href: "https://prisma.io", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157764276-a516a239-e377-4a20-b44a-0ac7b65c8c14.svg", + alt: "Tailwind", + href: "https://tailwindcss.com", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157764454-48ac8c71-a2a9-4b5e-b19c-edef8b8953d6.svg", + alt: "Cypress", + href: "https://www.cypress.io", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157772386-75444196-0604-4340-af28-53b236faa182.svg", + alt: "MSW", + href: "https://mswjs.io", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157772447-00fccdce-9d12-46a3-8bb4-fac612cdc949.svg", + alt: "Vitest", + href: "https://vitest.dev", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157772662-92b0dd3a-453f-4d18-b8be-9fa6efde52cf.png", + alt: "Testing Library", + href: "https://testing-library.com", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157772934-ce0a943d-e9d0-40f8-97f3-f464c0811643.svg", + alt: "Prettier", + href: "https://prettier.io", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157772990-3968ff7c-b551-4c55-a25c-046a32709a8e.svg", + alt: "ESLint", + href: "https://eslint.org", + }, + { + src: "https://user-images.githubusercontent.com/1500684/157773063-20a0ed64-b9f8-4e0b-9d1e-0b65a3d4a6db.svg", + alt: "TypeScript", + href: "https://typescriptlang.org", + }, + ].map((img) => ( + + {img.alt} + + ))} +
+
+
+
+ ); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/healthcheck.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/healthcheck.tsx new file mode 100644 index 00000000000..53168b88299 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/healthcheck.tsx @@ -0,0 +1,25 @@ +// learn more: https://fly.io/docs/reference/configuration/#services-http_checks +import type { LoaderFunctionArgs } from "@remix-run/node"; + +import { prisma } from "~/db.server"; + +export const loader = async ({ request }: LoaderFunctionArgs) => { + const host = + request.headers.get("X-Forwarded-Host") ?? request.headers.get("host"); + + try { + const url = new URL("/", `http://${host}`); + // if we can connect to the database and make a simple query + // and make a HEAD request to ourselves, then we're good. + await Promise.all([ + prisma.user.count(), + fetch(url.toString(), { method: "HEAD" }).then((r) => { + if (!r.ok) return Promise.reject(r); + }), + ]); + return new Response("OK"); + } catch (error: unknown) { + console.log("healthcheck ❌", { error }); + return new Response("ERROR", { status: 500 }); + } +}; diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/join.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/join.tsx new file mode 100644 index 00000000000..f1ea5660686 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/join.tsx @@ -0,0 +1,171 @@ +import type { + ActionFunctionArgs, + LoaderFunctionArgs, + MetaFunction, +} from "@remix-run/node"; +import { json, redirect } from "@remix-run/node"; +import { Form, Link, useActionData, useSearchParams } from "@remix-run/react"; +import { useEffect, useRef } from "react"; + +import { createUser, getUserByEmail } from "~/models/user.server"; +import { createUserSession, getUserId } from "~/session.server"; +import { safeRedirect, validateEmail } from "~/utils"; + +export const loader = async ({ request }: LoaderFunctionArgs) => { + const userId = await getUserId(request); + if (userId) return redirect("/"); + return json({}); +}; + +export const action = async ({ request }: ActionFunctionArgs) => { + const formData = await request.formData(); + const email = formData.get("email"); + const password = formData.get("password"); + const redirectTo = safeRedirect(formData.get("redirectTo"), "/"); + + if (!validateEmail(email)) { + return json( + { errors: { email: "Email is invalid", password: null } }, + { status: 400 }, + ); + } + + if (typeof password !== "string" || password.length === 0) { + return json( + { errors: { email: null, password: "Password is required" } }, + { status: 400 }, + ); + } + + if (password.length < 8) { + return json( + { errors: { email: null, password: "Password is too short" } }, + { status: 400 }, + ); + } + + const existingUser = await getUserByEmail(email); + if (existingUser) { + return json( + { + errors: { + email: "A user already exists with this email", + password: null, + }, + }, + { status: 400 }, + ); + } + + const user = await createUser(email, password); + + return createUserSession({ + redirectTo, + remember: false, + request, + userId: user.id, + }); +}; + +export const meta: MetaFunction = () => [{ title: "Sign Up" }]; + +export default function Join() { + const [searchParams] = useSearchParams(); + const redirectTo = searchParams.get("redirectTo") ?? undefined; + const actionData = useActionData(); + const emailRef = useRef(null); + const passwordRef = useRef(null); + + useEffect(() => { + if (actionData?.errors?.email) { + emailRef.current?.focus(); + } else if (actionData?.errors?.password) { + passwordRef.current?.focus(); + } + }, [actionData]); + + return ( +
+
+
+
+ +
+ + {actionData?.errors?.email ? ( +
+ {actionData.errors.email} +
+ ) : null} +
+
+ +
+ +
+ + {actionData?.errors?.password ? ( +
+ {actionData.errors.password} +
+ ) : null} +
+
+ + + +
+
+ Already have an account?{" "} + + Log in + +
+
+
+
+
+ ); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/login.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/login.tsx new file mode 100644 index 00000000000..c61981c81fa --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/login.tsx @@ -0,0 +1,180 @@ +import type { + ActionFunctionArgs, + LoaderFunctionArgs, + MetaFunction, +} from "@remix-run/node"; +import { json, redirect } from "@remix-run/node"; +import { Form, Link, useActionData, useSearchParams } from "@remix-run/react"; +import { useEffect, useRef } from "react"; + +import { verifyLogin } from "~/models/user.server"; +import { createUserSession, getUserId } from "~/session.server"; +import { safeRedirect, validateEmail } from "~/utils"; + +export const loader = async ({ request }: LoaderFunctionArgs) => { + const userId = await getUserId(request); + if (userId) return redirect("/"); + return json({}); +}; + +export const action = async ({ request }: ActionFunctionArgs) => { + const formData = await request.formData(); + const email = formData.get("email"); + const password = formData.get("password"); + const redirectTo = safeRedirect(formData.get("redirectTo"), "/"); + const remember = formData.get("remember"); + + if (!validateEmail(email)) { + return json( + { errors: { email: "Email is invalid", password: null } }, + { status: 400 }, + ); + } + + if (typeof password !== "string" || password.length === 0) { + return json( + { errors: { email: null, password: "Password is required" } }, + { status: 400 }, + ); + } + + if (password.length < 8) { + return json( + { errors: { email: null, password: "Password is too short" } }, + { status: 400 }, + ); + } + + const user = await verifyLogin(email, password); + + if (!user) { + return json( + { errors: { email: "Invalid email or password", password: null } }, + { status: 400 }, + ); + } + + return createUserSession({ + redirectTo, + remember: remember === "on" ? true : false, + request, + userId: user.id, + }); +}; + +export const meta: MetaFunction = () => [{ title: "Login" }]; + +export default function LoginPage() { + const [searchParams] = useSearchParams(); + const redirectTo = searchParams.get("redirectTo") || "/notes"; + const actionData = useActionData(); + const emailRef = useRef(null); + const passwordRef = useRef(null); + + useEffect(() => { + if (actionData?.errors?.email) { + emailRef.current?.focus(); + } else if (actionData?.errors?.password) { + passwordRef.current?.focus(); + } + }, [actionData]); + + return ( +
+
+
+
+ +
+ + {actionData?.errors?.email ? ( +
+ {actionData.errors.email} +
+ ) : null} +
+
+ +
+ +
+ + {actionData?.errors?.password ? ( +
+ {actionData.errors.password} +
+ ) : null} +
+
+ + + +
+
+ + +
+
+ Don't have an account?{" "} + + Sign up + +
+
+
+
+
+ ); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/logout.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/logout.tsx new file mode 100644 index 00000000000..1ee2c8a97d5 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/logout.tsx @@ -0,0 +1,9 @@ +import type { ActionFunctionArgs } from "@remix-run/node"; +import { redirect } from "@remix-run/node"; + +import { logout } from "~/session.server"; + +export const action = async ({ request }: ActionFunctionArgs) => + logout(request); + +export const loader = async () => redirect("/"); diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.$noteId.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.$noteId.tsx new file mode 100644 index 00000000000..3edd6ff2604 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.$noteId.tsx @@ -0,0 +1,70 @@ +import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node"; +import { json, redirect } from "@remix-run/node"; +import { + Form, + isRouteErrorResponse, + useLoaderData, + useRouteError, +} from "@remix-run/react"; +import invariant from "tiny-invariant"; + +import { deleteNote, getNote } from "~/models/note.server"; +import { requireUserId } from "~/session.server"; + +export const loader = async ({ params, request }: LoaderFunctionArgs) => { + const userId = await requireUserId(request); + invariant(params.noteId, "noteId not found"); + + const note = await getNote({ id: params.noteId, userId }); + if (!note) { + throw new Response("Not Found", { status: 404 }); + } + return json({ note }); +}; + +export const action = async ({ params, request }: ActionFunctionArgs) => { + const userId = await requireUserId(request); + invariant(params.noteId, "noteId not found"); + + await deleteNote({ id: params.noteId, userId }); + + return redirect("/notes"); +}; + +export default function NoteDetailsPage() { + const data = useLoaderData(); + + return ( +
+

{data.note.title}

+

{data.note.body}

+
+
+ +
+
+ ); +} + +export function ErrorBoundary() { + const error = useRouteError(); + + if (error instanceof Error) { + return
An unexpected error occurred: {error.message}
; + } + + if (!isRouteErrorResponse(error)) { + return

Unknown Error

; + } + + if (error.status === 404) { + return
Note not found
; + } + + return
An unexpected error occurred: {error.statusText}
; +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes._index.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes._index.tsx new file mode 100644 index 00000000000..aa858a994d7 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes._index.tsx @@ -0,0 +1,12 @@ +import { Link } from "@remix-run/react"; + +export default function NoteIndexPage() { + return ( +

+ No note selected. Select a note on the left, or{" "} + + create a new note. + +

+ ); +} diff --git a/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.new.tsx b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.new.tsx new file mode 100644 index 00000000000..48dd52de7f4 --- /dev/null +++ b/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/notes.new.tsx @@ -0,0 +1,109 @@ +import type { ActionFunctionArgs } from "@remix-run/node"; +import { json, redirect } from "@remix-run/node"; +import { Form, useActionData } from "@remix-run/react"; +import { useEffect, useRef } from "react"; + +import { createNote } from "~/models/note.server"; +import { requireUserId } from "~/session.server"; + +export const action = async ({ request }: ActionFunctionArgs) => { + const userId = await requireUserId(request); + + const formData = await request.formData(); + const title = formData.get("title"); + const body = formData.get("body"); + + if (typeof title !== "string" || title.length === 0) { + return json( + { errors: { body: null, title: "Title is required" } }, + { status: 400 }, + ); + } + + if (typeof body !== "string" || body.length === 0) { + return json( + { errors: { body: "Body is required", title: null } }, + { status: 400 }, + ); + } + + const note = await createNote({ body, title, userId }); + + return redirect(`/notes/${note.id}`); +}; + +export default function NewNotePage() { + const actionData = useActionData(); + const titleRef = useRef(null); + const bodyRef = useRef(null); + + useEffect(() => { + if (actionData?.errors?.title) { + titleRef.current?.focus(); + } else if (actionData?.errors?.body) { + bodyRef.current?.focus(); + } + }, [actionData]); + + return ( +
+
+ + {actionData?.errors?.title ? ( +
+ {actionData.errors.title} +
+ ) : null} +
+ +
+