From 26c792b011e8f4af420f91d725e4555eb3aa0188 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 15 Nov 2024 02:11:56 -0500 Subject: [PATCH] fix(core): skip nx cloud prompt when interactive is false --- e2e/utils/create-project-utils.ts | 2 +- .../src/internal-utils/prompts.ts | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/e2e/utils/create-project-utils.ts b/e2e/utils/create-project-utils.ts index 25bf031ba8554e..ce3b08d3aa8c97 100644 --- a/e2e/utils/create-project-utils.ts +++ b/e2e/utils/create-project-utils.ts @@ -360,7 +360,7 @@ export function runCreatePlugin( let command = `${ pm.runUninstalledPackage - } create-nx-plugin@${getPublishedVersion()} ${name} --nxCloud=skip`; + } create-nx-plugin@${getPublishedVersion()} ${name} --nxCloud=skip --no-interactive`; if (packageManager && !useDetectedPm) { command += ` --package-manager=${packageManager}`; diff --git a/packages/create-nx-workspace/src/internal-utils/prompts.ts b/packages/create-nx-workspace/src/internal-utils/prompts.ts index 93414a9604de7e..eb30bde792a8b9 100644 --- a/packages/create-nx-workspace/src/internal-utils/prompts.ts +++ b/packages/create-nx-workspace/src/internal-utils/prompts.ts @@ -1,4 +1,7 @@ import * as yargs from 'yargs'; +import * as enquirer from 'enquirer'; +import * as chalk from 'chalk'; + import { MessageKey, messages } from '../utils/nx/ab-testing'; import { output } from '../utils/output'; import { deduceDefaultBase } from '../utils/git/default-base'; @@ -8,17 +11,18 @@ import { packageManagerList, } from '../utils/package-manager'; import { stringifyCollection } from '../utils/string-utils'; -import enquirer = require('enquirer'); import { NxCloud } from '../utils/nx/nx-cloud'; -import chalk = require('chalk'); +import { isCI } from '../utils/ci/is-ci'; export async function determineNxCloud( parsedArgs: yargs.Arguments<{ nxCloud: NxCloud }> ): Promise { - if (parsedArgs.nxCloud === undefined) { - return nxCloudPrompt('setupCI'); - } else { + if (parsedArgs.nxCloud) { return parsedArgs.nxCloud; + } else if (!parsedArgs.interactive || isCI()) { + return 'skip'; + } else { + return nxCloudPrompt('setupCI'); } } @@ -71,6 +75,8 @@ export async function determineDefaultBase( ): Promise { if (parsedArgs.defaultBase) { return Promise.resolve(parsedArgs.defaultBase); + } else if (!parsedArgs.interactive || isCI()) { + return deduceDefaultBase(); } if (parsedArgs.allPrompts) { return enquirer @@ -99,7 +105,8 @@ export async function determineDefaultBase( export async function determinePackageManager( parsedArgs: yargs.Arguments<{ packageManager: string }> ): Promise { - const packageManager: string = parsedArgs.packageManager; + const packageManager: string = + parsedArgs.packageManager ?? process.env.SELECTED_PM; if (packageManager) { if (packageManagerList.includes(packageManager as PackageManager)) { @@ -114,9 +121,9 @@ export async function determinePackageManager( ], }); process.exit(1); - } - - if (parsedArgs.allPrompts) { + } else if (!parsedArgs.interactive || isCI()) { + return detectInvokedPackageManager(); + } else if (parsedArgs.allPrompts) { return enquirer .prompt<{ packageManager: PackageManager }>([ {