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

fix: treat git bash as un-interactive #1222

Merged
merged 4 commits into from
Feb 19, 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/red-ducks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix: detect and handle git bash environment
35 changes: 31 additions & 4 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ export const runCli = async () => {

// Explained below why this is in a try/catch block
try {
if (
process.env.SHELL?.toLowerCase().includes("git") &&
process.env.SHELL?.includes("bash")
) {
logger.warn(` WARNING: It looks like you are using Git Bash which is non-interactive. Please run create-t3-app with another
terminal such as Windows Terminal or PowerShell if you want to use the interactive CLI.`);

const error = new Error("Non-interactive environment");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any).isTTYError = true;
throw error;
}

// if --CI flag is set, we are running in CI mode and should not prompt the user
// if --default flag is set, we should not prompt the user
if (!cliResults.flags.default && !CIMode) {
Expand All @@ -181,10 +194,24 @@ export const runCli = async () => {
// Otherwise we have to do some fancy namespace extension logic on the Error type which feels overkill for one line
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (err instanceof Error && (err as any).isTTYError) {
logger.warn(
`${CREATE_T3_APP} needs an interactive terminal to provide options`,
);
logger.info(`Bootstrapping a default t3 app in ./${cliResults.appName}`);
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);
}

logger.info(`Bootstrapping a default T3 app in ./${cliResults.appName}`);
} else {
throw err;
}
Expand Down