Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add validation for import aliases #1255

Merged
merged 6 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("/")) {
justasam marked this conversation as resolved.
Show resolved Hide resolved
return "Import alias can't start with '.' or '/'";
} else {
return true;
}
};