Skip to content

Commit

Permalink
fix(core): skip nx cloud prompt when interactive is false
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Nov 20, 2024
1 parent 09a01eb commit d1ee686
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
33 changes: 20 additions & 13 deletions packages/create-nx-workspace/src/internal-utils/prompts.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<NxCloud> {
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');
}
}

Expand Down Expand Up @@ -70,7 +74,9 @@ export async function determineDefaultBase(
parsedArgs: yargs.Arguments<{ defaultBase?: string }>
): Promise<string> {
if (parsedArgs.defaultBase) {
return Promise.resolve(parsedArgs.defaultBase);
return parsedArgs.defaultBase;
} else if (!parsedArgs.interactive || isCI()) {
return deduceDefaultBase();
}
if (parsedArgs.allPrompts) {
return enquirer
Expand All @@ -93,17 +99,18 @@ export async function determineDefaultBase(
return a.DefaultBase;
});
}
return Promise.resolve(deduceDefaultBase());
return deduceDefaultBase();
}

export async function determinePackageManager(
parsedArgs: yargs.Arguments<{ packageManager: string }>
): Promise<PackageManager> {
const packageManager: string = parsedArgs.packageManager;
const packageManager: string =
parsedArgs.packageManager ?? process.env.SELECTED_PM;

if (packageManager) {
if (packageManagerList.includes(packageManager as PackageManager)) {
return Promise.resolve(packageManager as PackageManager);
return packageManager as PackageManager;
}
output.error({
title: 'Invalid package manager',
Expand All @@ -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 }>([
{
Expand All @@ -135,5 +142,5 @@ export async function determinePackageManager(
.then((a) => a.packageManager);
}

return Promise.resolve(detectInvokedPackageManager());
return detectInvokedPackageManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function addE2eProject(host: Tree, options: NormalizedSchema) {
{
pluginName: options.project,
cliName: options.name,
packageManagerCommands: getPackageManagerCommand('npm'),
packageManagerCommands: getPackageManagerCommand(),
pluginPackageName,
tmpl: '',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ describe('<%= cliName %>', () => {
let projectDirectory: string;

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
if (projectDirectory) {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
}
});


Expand Down Expand Up @@ -43,7 +45,7 @@ function createTestProject(extraArgs = '') {
});

execSync(
`<%= packageManagerCommands.exec %> --yes <%= cliName %>@e2e ${projectName} ${extraArgs}`,
`<%= packageManagerCommands.exec %> <%= cliName %>@e2e ${projectName} ${extraArgs}`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/generators/e2e-project/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function addFiles(host: Tree, options: NormalizedSchema) {
...options,
tmpl: '',
rootTsConfigPath: getRelativePathToRootTsConfig(host, options.projectRoot),
packageManagerCommands: getPackageManagerCommand('npm'),
packageManagerCommands: getPackageManagerCommand(),
pluginPackageName,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ describe('<%= pluginName %>', () => {
});

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
if (projectDirectory) {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
}
});


Expand Down Expand Up @@ -53,7 +55,7 @@ function createTestProject() {
});

execSync(
`<%= packageManagerCommands.exec %> --yes create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
`<%= packageManagerCommands.exec %> create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
Expand Down

0 comments on commit d1ee686

Please sign in to comment.