Skip to content

Commit 601cbb2

Browse files
justasamc-ehrlich
andauthored
feat: Add validation for import aliases (#1255)
* 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]>
1 parent e32f887 commit 601cbb2

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Diff for: .changeset/great-buckets-relate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-t3-app": minor
3+
---
4+
5+
Add import alias validation

Diff for: cli/src/cli/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getVersion } from "~/utils/getT3Version.js";
88
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
99
import { logger } from "~/utils/logger.js";
1010
import { validateAppName } from "~/utils/validateAppName.js";
11+
import { validateImportAlias } from "~/utils/validateImportAlias.js";
1112

1213
interface CliFlags {
1314
noGit: boolean;
@@ -322,6 +323,7 @@ const promptImportAlias = async (): Promise<string> => {
322323
type: "input",
323324
message: "What import alias would you like configured?",
324325
default: defaultOptions.flags.importAlias,
326+
validate: validateImportAlias,
325327
transformer: (input: string) => {
326328
return input.trim();
327329
},

Diff for: cli/src/utils/validateImportAlias.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const validateImportAlias = (input: string) => {
2+
if (input.startsWith(".") || input.startsWith("/")) {
3+
return "Import alias can't start with '.' or '/'";
4+
} else {
5+
return true;
6+
}
7+
};

0 commit comments

Comments
 (0)