Skip to content

Commit

Permalink
feat: Add validation for import aliases (t3-oss#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 <[email protected]>
  • Loading branch information
justasam and c-ehrlich committed Mar 3, 2023
1 parent e89a2c0 commit bfa20f2
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;
}
};

0 comments on commit bfa20f2

Please sign in to comment.