fix(core): use withVerbose util (#27553)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

The `withVerbose` util is only used in a few places.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

The `withVerbose` util is used throughout and also contains middleware
to default to the value in `process.env.NX_VERBOSE_LOGGING === 'true'`

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Jason Jean 2024-08-21 13:07:33 -04:00 committed by GitHub
parent c427717fc1
commit 9269de7763
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 56 additions and 143 deletions

View File

@ -149,6 +149,12 @@ Type: `string`
Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/react@16.0.0,@nx/js@16.0.0") Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/react@16.0.0,@nx/js@16.0.0")
### verbose
Type: `boolean`
Prints additional information about the commands (e.g., stack traces)
### version ### version
Type: `boolean` Type: `boolean`

View File

@ -149,6 +149,12 @@ Type: `string`
Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/react@16.0.0,@nx/js@16.0.0") Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/react@16.0.0,@nx/js@16.0.0")
### verbose
Type: `boolean`
Prints additional information about the commands (e.g., stack traces)
### version ### version
Type: `boolean` Type: `boolean`

View File

@ -13,7 +13,7 @@ export function mapErrorToBodyLines(error: Error): string[] {
const errorLines = error.message?.split('\n').filter((line) => !!line.trim()); const errorLines = error.message?.split('\n').filter((line) => !!line.trim());
if (errorLines.length < 3) { if (errorLines.length < 3) {
const lines = [`Error: ${error.message}`]; const lines = [`Error: ${error.message}`];
if (process.env.NX_VERBOSE_LOGGING) { if (process.env.NX_VERBOSE_LOGGING === 'true') {
lines.push(`Stack: ${error.stack}`); lines.push(`Stack: ${error.stack}`);
} }
return lines; return lines;
@ -24,7 +24,7 @@ export function mapErrorToBodyLines(error: Error): string[] {
? [`Exit code: ${error.code}`, `Log file: ${error.logFile}`] ? [`Exit code: ${error.code}`, `Log file: ${error.logFile}`]
: []; : [];
if (process.env.NX_VERBOSE_LOGGING) { if (process.env.NX_VERBOSE_LOGGING === 'true') {
lines.push(`Error: ${error.message}`); lines.push(`Error: ${error.message}`);
lines.push(`Stack: ${error.stack}`); lines.push(`Stack: ${error.stack}`);
} }

View File

@ -17,12 +17,7 @@ import type { AddOptions } from './command-object';
import { normalizeVersionForNxJson } from '../init/implementation/dot-nx/add-nx-scripts'; import { normalizeVersionForNxJson } from '../init/implementation/dot-nx/add-nx-scripts';
export function addHandler(options: AddOptions): Promise<number> { export function addHandler(options: AddOptions): Promise<number> {
if (options.verbose) { return handleErrors(options.verbose, async () => {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
return handleErrors(isVerbose, async () => {
output.addNewline(); output.addNewline();
const [pkgName, version] = parsePackageSpecifier(options.packageSpecifier); const [pkgName, version] = parsePackageSpecifier(options.packageSpecifier);

View File

@ -1,5 +1,5 @@
import { CommandModule } from 'yargs'; import { CommandModule } from 'yargs';
import { withOverrides } from '../yargs-utils/shared-options'; import { withOverrides, withVerbose } from '../yargs-utils/shared-options';
export interface AddOptions { export interface AddOptions {
packageSpecifier: string; packageSpecifier: string;
@ -15,7 +15,7 @@ export const yargsAddCommand: CommandModule<
command: 'add <packageSpecifier>', command: 'add <packageSpecifier>',
describe: 'Install a plugin and initialize it.', describe: 'Install a plugin and initialize it.',
builder: (yargs) => builder: (yargs) =>
yargs withVerbose(yargs)
.parserConfiguration({ .parserConfiguration({
'strip-dashed': true, 'strip-dashed': true,
'unknown-options-as-args': true, 'unknown-options-as-args': true,
@ -30,11 +30,6 @@ export const yargsAddCommand: CommandModule<
description: description:
'Update `package.json` scripts with inferred targets. Defaults to `true` when the package is a core Nx plugin', 'Update `package.json` scripts with inferred targets. Defaults to `true` when the package is a core Nx plugin',
}) })
.option('verbose', {
type: 'boolean',
description:
'Prints additional information about the commands (e.g., stack traces)',
})
.example( .example(
'$0 add @nx/react', '$0 add @nx/react',
'Install the latest version of the `@nx/react` package and run its `@nx/react:init` generator' 'Install the latest version of the `@nx/react` package and run its `@nx/react:init` generator'

View File

@ -54,10 +54,6 @@ export async function affected(
nxJson nxJson
); );
if (nxArgs.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
await connectToNxCloudIfExplicitlyAsked(nxArgs); await connectToNxCloudIfExplicitlyAsked(nxArgs);
const projectGraph = await createProjectGraphAsync({ exitOnError: true }); const projectGraph = await createProjectGraphAsync({ exitOnError: true });

View File

@ -38,9 +38,6 @@ export async function nxExecCommand(
{ printWarnings: args.graph !== 'stdout' }, { printWarnings: args.graph !== 'stdout' },
nxJson nxJson
); );
if (nxArgs.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const scriptArgV: string[] = readScriptArgV(overrides); const scriptArgV: string[] = readScriptArgV(overrides);
const projectGraph = await createProjectGraphAsync({ exitOnError: true }); const projectGraph = await createProjectGraphAsync({ exitOnError: true });

View File

@ -1,6 +1,7 @@
import { CommandModule, Argv } from 'yargs'; import { CommandModule, Argv } from 'yargs';
import { getCwd } from '../../utils/path'; import { getCwd } from '../../utils/path';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import { withVerbose } from '../yargs-utils/shared-options';
export const yargsGenerateCommand: CommandModule = { export const yargsGenerateCommand: CommandModule = {
command: 'generate <generator> [_..]', command: 'generate <generator> [_..]',
@ -19,7 +20,7 @@ export const yargsGenerateCommand: CommandModule = {
function withGenerateOptions(yargs: Argv) { function withGenerateOptions(yargs: Argv) {
const generatorWillShowHelp = const generatorWillShowHelp =
process.argv[3] && !process.argv[3].startsWith('-'); process.argv[3] && !process.argv[3].startsWith('-');
const res = yargs const res = withVerbose(yargs)
.positional('generator', { .positional('generator', {
describe: 'Name of the generator (e.g., @nx/js:library, library)', describe: 'Name of the generator (e.g., @nx/js:library, library)',
type: 'string', type: 'string',
@ -36,11 +37,6 @@ function withGenerateOptions(yargs: Argv) {
type: 'boolean', type: 'boolean',
default: true, default: true,
}) })
.option('verbose', {
describe:
'Prints additional information about the commands (e.g., stack traces)',
type: 'boolean',
})
.option('quiet', { .option('quiet', {
describe: 'Hides logs from tree operations (e.g. `CREATE package.json`)', describe: 'Hides logs from tree operations (e.g. `CREATE package.json`)',
type: 'boolean', type: 'boolean',

View File

@ -302,12 +302,7 @@ export function printGenHelp(
} }
export async function generate(cwd: string, args: { [k: string]: any }) { export async function generate(cwd: string, args: { [k: string]: any }) {
if (args['verbose']) { return handleErrors(args.verbose, async () => {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const verbose = process.env.NX_VERBOSE_LOGGING === 'true';
return handleErrors(verbose, async () => {
const nxJsonConfiguration = readNxJson(); const nxJsonConfiguration = readNxJson();
const projectGraph = await createProjectGraphAsync(); const projectGraph = await createProjectGraphAsync();
const projectsConfigurations = const projectsConfigurations =
@ -369,7 +364,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
nxJsonConfiguration nxJsonConfiguration
), ),
relative(workspaceRoot, cwd), relative(workspaceRoot, cwd),
verbose args.verbose
); );
if ( if (
@ -382,7 +377,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
) { ) {
const host = new FsTree( const host = new FsTree(
workspaceRoot, workspaceRoot,
verbose, args.verbose,
`generating (${opts.collectionName}:${normalizedGeneratorName})` `generating (${opts.collectionName}:${normalizedGeneratorName})`
); );
const implementation = implementationFactory(); const implementation = implementationFactory();
@ -418,7 +413,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
generatorOptions: combinedOpts, generatorOptions: combinedOpts,
}, },
projectsConfigurations.projects, projectsConfigurations.projects,
verbose args.verbose
); );
} }
}); });

View File

@ -37,12 +37,9 @@ export const yargsImportCommand: CommandModule = {
'import' 'import'
), ),
handler: async (args) => { handler: async (args) => {
const exitCode = await handleErrors( const exitCode = await handleErrors(args.verbose as boolean, async () => {
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true', return (await import('./import')).importHandler(args as any);
async () => { });
return (await import('./import')).importHandler(args as any);
}
);
process.exit(exitCode); process.exit(exitCode);
}, },
}; };

View File

@ -10,6 +10,7 @@ import {
} from '../../utils/package-manager'; } from '../../utils/package-manager';
import { writeJsonFile } from '../../utils/fileutils'; import { writeJsonFile } from '../../utils/fileutils';
import { workspaceRoot } from '../../utils/workspace-root'; import { workspaceRoot } from '../../utils/workspace-root';
import { withVerbose } from '../yargs-utils/shared-options';
export const yargsMigrateCommand: CommandModule = { export const yargsMigrateCommand: CommandModule = {
command: 'migrate [packageAndVersion]', command: 'migrate [packageAndVersion]',
@ -39,7 +40,7 @@ export const yargsInternalMigrateCommand: CommandModule = {
function withMigrationOptions(yargs: Argv) { function withMigrationOptions(yargs: Argv) {
const defaultCommitPrefix = 'chore: [nx migration] '; const defaultCommitPrefix = 'chore: [nx migration] ';
return yargs return withVerbose(yargs)
.positional('packageAndVersion', { .positional('packageAndVersion', {
describe: `The target package and version (e.g, @nx/workspace@16.0.0)`, describe: `The target package and version (e.g, @nx/workspace@16.0.0)`,
type: 'string', type: 'string',
@ -178,7 +179,7 @@ function nxCliPath() {
console.error( console.error(
`Failed to install the ${version} version of the migration script. Using the current version.` `Failed to install the ${version} version of the migration script. Using the current version.`
); );
if (process.env.NX_VERBOSE_LOGGING) { if (process.env.NX_VERBOSE_LOGGING === 'true') {
console.error(e); console.error(e);
} }
return null; return null;

View File

@ -1636,10 +1636,6 @@ export async function migrate(
args: { [k: string]: any }, args: { [k: string]: any },
rawArgs: string[] rawArgs: string[]
) { ) {
if (args['verbose']) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
await daemonClient.stop(); await daemonClient.stop();
return handleErrors(process.env.NX_VERBOSE_LOGGING === 'true', async () => { return handleErrors(process.env.NX_VERBOSE_LOGGING === 'true', async () => {

View File

@ -121,10 +121,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
// Apply default configuration to any optional user configuration // Apply default configuration to any optional user configuration
const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( const { error: configError, nxReleaseConfig } = await createNxReleaseConfig(
projectGraph, projectGraph,

View File

@ -10,6 +10,7 @@ import {
withOutputStyleOption, withOutputStyleOption,
withOverrides, withOverrides,
withRunManyOptions, withRunManyOptions,
withVerbose,
} from '../yargs-utils/shared-options'; } from '../yargs-utils/shared-options';
import { VersionData } from './utils/shared'; import { VersionData } from './utils/shared';
@ -102,7 +103,7 @@ export const yargsReleaseCommand: CommandModule<
describe: describe:
'Orchestrate versioning and publishing of applications and libraries', 'Orchestrate versioning and publishing of applications and libraries',
builder: (yargs) => builder: (yargs) =>
yargs withVerbose(yargs)
.command(releaseCommand) .command(releaseCommand)
.command(versionCommand) .command(versionCommand)
.command(changelogCommand) .command(changelogCommand)
@ -133,11 +134,6 @@ export const yargsReleaseCommand: CommandModule<
type: 'boolean', type: 'boolean',
default: false, default: false,
}) })
.option('verbose', {
type: 'boolean',
describe:
'Prints additional information about the commands (e.g., stack traces)',
})
// NOTE: The camel case format is required for the coerce() function to be called correctly. It still supports --print-config casing. // NOTE: The camel case format is required for the coerce() function to be called correctly. It still supports --print-config casing.
.option('printConfig', { .option('printConfig', {
type: 'string', type: 'string',

View File

@ -37,10 +37,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
// Apply default configuration to any optional user configuration // Apply default configuration to any optional user configuration
const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( const { error: configError, nxReleaseConfig } = await createNxReleaseConfig(
projectGraph, projectGraph,

View File

@ -36,10 +36,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
// Apply default configuration to any optional user configuration // Apply default configuration to any optional user configuration
const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( const { error: configError, nxReleaseConfig } = await createNxReleaseConfig(
projectGraph, projectGraph,

View File

@ -56,10 +56,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (_args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
// Apply default configuration to any optional user configuration // Apply default configuration to any optional user configuration
const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( const { error: configError, nxReleaseConfig } = await createNxReleaseConfig(
projectGraph, projectGraph,
@ -187,10 +183,6 @@ async function runPublishOnProjects(
process.env.NX_DRY_RUN = 'true'; process.env.NX_DRY_RUN = 'true';
} }
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
if (args.firstRelease) { if (args.firstRelease) {
overrides.firstRelease = args.firstRelease; overrides.firstRelease = args.firstRelease;
} }

View File

@ -54,10 +54,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const hasVersionGitConfig = const hasVersionGitConfig =
Object.keys(userProvidedReleaseConfig.version?.git ?? {}).length > 0; Object.keys(userProvidedReleaseConfig.version?.git ?? {}).length > 0;
const hasChangelogGitConfig = const hasChangelogGitConfig =

View File

@ -132,10 +132,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
overrideReleaseConfig ?? {} overrideReleaseConfig ?? {}
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
// Apply default configuration to any optional user configuration // Apply default configuration to any optional user configuration
const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( const { error: configError, nxReleaseConfig } = await createNxReleaseConfig(
projectGraph, projectGraph,

View File

@ -1,5 +1,6 @@
import { ArgumentsCamelCase, CommandModule } from 'yargs'; import { ArgumentsCamelCase, CommandModule } from 'yargs';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import { withVerbose } from '../yargs-utils/shared-options';
export const yargsRepairCommand: CommandModule = { export const yargsRepairCommand: CommandModule = {
command: 'repair', command: 'repair',
@ -13,12 +14,7 @@ export const yargsRepairCommand: CommandModule = {
If your repository has only ever updated to newer versions of Nx with If your repository has only ever updated to newer versions of Nx with
\`nx migrate\`, running \`nx repair\` should do nothing. \`nx migrate\`, running \`nx repair\` should do nothing.
`, `,
builder: (yargs) => builder: (yargs) => linkToNxDevAndExamples(withVerbose(yargs), 'repair'),
linkToNxDevAndExamples(yargs, 'repair').option('verbose', {
type: 'boolean',
describe:
'Prints additional information about the commands (e.g., stack traces)',
}),
handler: async (args: ArgumentsCamelCase<{ verbose: boolean }>) => handler: async (args: ArgumentsCamelCase<{ verbose: boolean }>) =>
process.exit(await (await import('./repair')).repair(args)), process.exit(await (await import('./repair')).repair(args)),
}; };

View File

@ -7,11 +7,7 @@ export async function repair(
args: { verbose: boolean }, args: { verbose: boolean },
extraMigrations = [] as any[] extraMigrations = [] as any[]
) { ) {
if (args['verbose']) { return handleErrors(args.verbose, async () => {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const verbose = process.env.NX_VERBOSE_LOGGING === 'true';
return handleErrors(verbose, async () => {
const nxMigrations = Object.entries(migrationsJson.generators).reduce( const nxMigrations = Object.entries(migrationsJson.generators).reduce(
(agg, [name, migration]) => { (agg, [name, migration]) => {
const skip = migration['x-repair-skip']; const skip = migration['x-repair-skip'];
@ -33,7 +29,7 @@ export async function repair(
const migrationsThatMadeNoChanges = await executeMigrations( const migrationsThatMadeNoChanges = await executeMigrations(
process.cwd(), process.cwd(),
migrations, migrations,
verbose, args.verbose,
false, false,
'' ''
); );

View File

@ -55,9 +55,6 @@ export async function runOne(
nxJson nxJson
); );
if (nxArgs.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
if (nxArgs.help) { if (nxArgs.help) {
await (await import('./run')).printTargetRunHelp(opts, workspaceRoot); await (await import('./run')).printTargetRunHelp(opts, workspaceRoot);
process.exit(0); process.exit(0);

View File

@ -124,13 +124,10 @@ const showProjectsCommand: CommandModule<NxShowArgs, ShowProjectsOptions> = {
'Show affected projects in the workspace, excluding end-to-end projects' 'Show affected projects in the workspace, excluding end-to-end projects'
) as any, ) as any,
handler: async (args) => { handler: async (args) => {
const exitCode = await handleErrors( const exitCode = await handleErrors(args.verbose as boolean, async () => {
args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true', const { showProjectsHandler } = await import('./projects');
async () => { await showProjectsHandler(args);
const { showProjectsHandler } = await import('./projects'); });
await showProjectsHandler(args);
}
);
process.exit(exitCode); process.exit(exitCode);
}, },
}; };
@ -178,13 +175,10 @@ const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
'View project information for my-app in the browser' 'View project information for my-app in the browser'
), ),
handler: async (args) => { handler: async (args) => {
const exitCode = await handleErrors( const exitCode = await handleErrors(args.verbose as boolean, async () => {
args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true', const { showProjectHandler } = await import('./project');
async () => { await showProjectHandler(args);
const { showProjectHandler } = await import('./project'); });
await showProjectHandler(args);
}
);
process.exit(exitCode); process.exit(exitCode);
}, },
}; };

View File

@ -1,4 +1,5 @@
import type { CommandModule } from 'yargs'; import type { CommandModule } from 'yargs';
import { withVerbose } from '../yargs-utils/shared-options';
export interface SyncArgs { export interface SyncArgs {
verbose?: boolean; verbose?: boolean;
@ -10,12 +11,7 @@ export const yargsSyncCommand: CommandModule<
> = { > = {
command: 'sync', command: 'sync',
describe: false, describe: false,
builder: (yargs) => builder: (yargs) => withVerbose(yargs),
yargs.option('verbose', {
type: 'boolean',
description:
'Prints additional information about the commands (e.g., stack traces)',
}),
handler: async (args) => { handler: async (args) => {
process.exit(await import('./sync').then((m) => m.syncHandler(args))); process.exit(await import('./sync').then((m) => m.syncHandler(args)));
}, },
@ -27,12 +23,7 @@ export const yargsSyncCheckCommand: CommandModule<
> = { > = {
command: 'sync:check', command: 'sync:check',
describe: false, describe: false,
builder: (yargs) => builder: (yargs) => withVerbose(yargs),
yargs.option('verbose', {
type: 'boolean',
description:
'Prints additional information about the commands (e.g., stack traces)',
}),
handler: async (args) => { handler: async (args) => {
process.exit( process.exit(
await import('./sync').then((m) => await import('./sync').then((m) =>

View File

@ -16,12 +16,7 @@ interface SyncOptions extends SyncArgs {
} }
export function syncHandler(options: SyncOptions): Promise<number> { export function syncHandler(options: SyncOptions): Promise<number> {
if (options.verbose) { return handleErrors(options.verbose, async () => {
process.env.NX_VERBOSE_LOGGING = 'true';
}
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
return handleErrors(isVerbose, async () => {
const projectGraph = await createProjectGraphAsync(); const projectGraph = await createProjectGraphAsync();
const syncGenerators = await collectAllRegisteredSyncGenerators( const syncGenerators = await collectAllRegisteredSyncGenerators(
projectGraph projectGraph

View File

@ -1,7 +1,7 @@
import { Argv, CommandModule } from 'yargs'; import { Argv, CommandModule } from 'yargs';
import { WatchArguments } from './watch'; import { WatchArguments } from './watch';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import { parseCSV } from '../yargs-utils/shared-options'; import { parseCSV, withVerbose } from '../yargs-utils/shared-options';
export const yargsWatchCommand: CommandModule = { export const yargsWatchCommand: CommandModule = {
command: 'watch', command: 'watch',
@ -13,7 +13,7 @@ export const yargsWatchCommand: CommandModule = {
}; };
function withWatchOptions(yargs: Argv) { function withWatchOptions(yargs: Argv) {
return yargs return withVerbose(yargs)
.parserConfiguration({ .parserConfiguration({
'strip-dashed': true, 'strip-dashed': true,
'populate--': true, 'populate--': true,

View File

@ -155,10 +155,6 @@ export async function watch(args: WatchArguments) {
'g' 'g'
); );
if (args.verbose) {
process.env.NX_VERBOSE_LOGGING = 'true';
}
if (!daemonClient.enabled()) { if (!daemonClient.enabled()) {
output.error({ output.error({
title: title:

View File

@ -132,9 +132,9 @@ export function withVerbose<T>(yargs: Argv<T>) {
type: 'boolean', type: 'boolean',
}) })
.middleware((args) => { .middleware((args) => {
if (args.verbose) { args.verbose ??= process.env.NX_VERBOSE_LOGGING === 'true';
process.env.NX_VERBOSE_LOGGING = 'true'; // If NX_VERBOSE_LOGGING=false and --verbose is passed, we want to set it to true favoring the arg
} process.env.NX_VERBOSE_LOGGING = args.verbose.toString();
}); });
} }

View File

@ -17,7 +17,7 @@ export function assertSupportedPlatform() {
`The Nx CLI could not find or load the native binary for your supported platform (${process.platform}-${process.arch}).`, `The Nx CLI could not find or load the native binary for your supported platform (${process.platform}-${process.arch}).`,
'This likely means that optional dependencies were not installed correctly, or your system is missing some system dependencies.', 'This likely means that optional dependencies were not installed correctly, or your system is missing some system dependencies.',
]; ];
if (process.env.NX_VERBOSE_LOGGING == 'true') { if (process.env.NX_VERBOSE_LOGGING === 'true') {
bodyLines.push('', 'Additional error information:', e.message); bodyLines.push('', 'Additional error information:', e.message);
} }
} else { } else {

View File

@ -133,7 +133,7 @@ async function getInstallationSupportsGitHub(apiUrl: string): Promise<boolean> {
} }
return !!response.data.isGithubIntegrationEnabled; return !!response.data.isGithubIntegrationEnabled;
} catch (e) { } catch (e) {
if (process.env.NX_VERBOSE_LOGGING) { if (process.env.NX_VERBOSE_LOGGING === 'true') {
logger.warn(`Failed to access system features. GitHub integration assumed to be disabled. logger.warn(`Failed to access system features. GitHub integration assumed to be disabled.
${e}`); ${e}`);
} }

View File

@ -52,7 +52,7 @@ export class Cache {
try { try {
this._currentMachineId = await machineId(); this._currentMachineId = await machineId();
} catch (e) { } catch (e) {
if (process.env.NX_VERBOSE_LOGGING == 'true') { if (process.env.NX_VERBOSE_LOGGING === 'true') {
console.log(`Unable to get machineId. Error: ${e.message}`); console.log(`Unable to get machineId. Error: ${e.message}`);
} }
this._currentMachineId = ''; this._currentMachineId = '';

View File

@ -32,7 +32,7 @@ export const logger = {
console.error(...s); console.error(...s);
}, },
verbose: (...s) => { verbose: (...s) => {
if (process.env.NX_VERBOSE_LOGGING) { if (process.env.NX_VERBOSE_LOGGING === 'true') {
console.log(...s); console.log(...s);
} }
}, },