Skip to content

Commit

Permalink
feat: Add validation for import aliases (#1255)
Browse files Browse the repository at this point in the history
* feat: do not allow invalid import aliases

* chore: add changeset

* fix: use validate instead of custom logic

* fix: update changeset to better match changes

* refactor: change naming from path alias to import alias

---------

Co-authored-by: Christopher Ehrlich <ehrlich.christopher@gmail.com>
  • Loading branch information
justasam and c-ehrlich authored Mar 3, 2023
1 parent e32f887 commit 601cbb2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-buckets-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

Add import alias validation
2 changes: 2 additions & 0 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getVersion } from "~/utils/getT3Version.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
import { validateAppName } from "~/utils/validateAppName.js";
import { validateImportAlias } from "~/utils/validateImportAlias.js";

interface CliFlags {
noGit: boolean;
Expand Down Expand Up @@ -322,6 +323,7 @@ const promptImportAlias = async (): Promise<string> => {
type: "input",
message: "What import alias would you like configured?",
default: defaultOptions.flags.importAlias,
validate: validateImportAlias,
transformer: (input: string) => {
return input.trim();
},
Expand Down
7 changes: 7 additions & 0 deletions cli/src/utils/validateImportAlias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const validateImportAlias = (input: string) => {
if (input.startsWith(".") || input.startsWith("/")) {
return "Import alias can't start with '.' or '/'";
} else {
return true;
}
};

1 comment on commit 601cbb2

@vercel
Copy link

@vercel vercel bot commented on 601cbb2 Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.