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 2 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
---

Disable incorrect import aliases and show error when they are attempted
39 changes: 26 additions & 13 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,7 @@ export const runCli = async () => {
logger.warn(`
${CREATE_T3_APP} needs an interactive terminal to provide options`);

const { shouldContinue } = await inquirer.prompt<{
shouldContinue: boolean;
}>({
name: "shouldContinue",
type: "confirm",
message: `Continue scaffolding a default T3 app?`,
default: true,
});

if (!shouldContinue) {
logger.info("Exiting...");
process.exit(0);
}
await promptShouldContinue();

logger.info(`Bootstrapping a default T3 app in ./${cliResults.appName}`);
} else {
Expand All @@ -220,6 +208,22 @@ export const runCli = async () => {
return cliResults;
};

const promptShouldContinue = async () => {
const { shouldContinue } = await inquirer.prompt<{
shouldContinue: boolean;
}>({
name: "shouldContinue",
type: "confirm",
message: `Continue scaffolding a default T3 app?`,
default: true,
});

if (!shouldContinue) {
logger.info("Exiting...");
process.exit(0);
}
};

const promptAppName = async (): Promise<string> => {
const { appName } = await inquirer.prompt<Pick<CliResults, "appName">>({
name: "appName",
Expand Down Expand Up @@ -327,5 +331,14 @@ const promptImportAlias = async (): Promise<string> => {
},
});

// tsconfig-paths do not support paths starting with "." or "/"
if (importAlias.startsWith(".") || importAlias.startsWith("/")) {
logger.error("Import alias can't start with '.' or '/'.");

await promptShouldContinue();

return promptImportAlias();
}

return importAlias;
};