diff --git a/docs/generated/cli/migrate.md b/docs/generated/cli/migrate.md index f4a2d0f50e973..29eaf43d16dfa 100644 --- a/docs/generated/cli/migrate.md +++ b/docs/generated/cli/migrate.md @@ -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") +### verbose + +Type: `boolean` + +Prints additional information about the commands (e.g., stack traces) + ### version Type: `boolean` diff --git a/docs/generated/packages/nx/documents/migrate.md b/docs/generated/packages/nx/documents/migrate.md index f4a2d0f50e973..29eaf43d16dfa 100644 --- a/docs/generated/packages/nx/documents/migrate.md +++ b/docs/generated/packages/nx/documents/migrate.md @@ -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") +### verbose + +Type: `boolean` + +Prints additional information about the commands (e.g., stack traces) + ### version Type: `boolean` diff --git a/packages/create-nx-workspace/src/utils/error-utils.ts b/packages/create-nx-workspace/src/utils/error-utils.ts index b78365ddc4e95..a2ae6dae8cea4 100644 --- a/packages/create-nx-workspace/src/utils/error-utils.ts +++ b/packages/create-nx-workspace/src/utils/error-utils.ts @@ -13,7 +13,7 @@ export function mapErrorToBodyLines(error: Error): string[] { const errorLines = error.message?.split('\n').filter((line) => !!line.trim()); if (errorLines.length < 3) { const lines = [`Error: ${error.message}`]; - if (process.env.NX_VERBOSE_LOGGING) { + if (process.env.NX_VERBOSE_LOGGING === 'true') { lines.push(`Stack: ${error.stack}`); } return lines; @@ -24,7 +24,7 @@ export function mapErrorToBodyLines(error: Error): string[] { ? [`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(`Stack: ${error.stack}`); } diff --git a/packages/nx/src/command-line/add/add.ts b/packages/nx/src/command-line/add/add.ts index 20c771b43d17e..82e829f291fa0 100644 --- a/packages/nx/src/command-line/add/add.ts +++ b/packages/nx/src/command-line/add/add.ts @@ -17,12 +17,7 @@ import type { AddOptions } from './command-object'; import { normalizeVersionForNxJson } from '../init/implementation/dot-nx/add-nx-scripts'; export function addHandler(options: AddOptions): Promise { - if (options.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; - - return handleErrors(isVerbose, async () => { + return handleErrors(options.verbose, async () => { output.addNewline(); const [pkgName, version] = parsePackageSpecifier(options.packageSpecifier); diff --git a/packages/nx/src/command-line/add/command-object.ts b/packages/nx/src/command-line/add/command-object.ts index a06d51dd2ae2f..266d41902f10a 100644 --- a/packages/nx/src/command-line/add/command-object.ts +++ b/packages/nx/src/command-line/add/command-object.ts @@ -1,5 +1,5 @@ import { CommandModule } from 'yargs'; -import { withOverrides } from '../yargs-utils/shared-options'; +import { withOverrides, withVerbose } from '../yargs-utils/shared-options'; export interface AddOptions { packageSpecifier: string; @@ -15,7 +15,7 @@ export const yargsAddCommand: CommandModule< command: 'add ', describe: 'Install a plugin and initialize it.', builder: (yargs) => - yargs + withVerbose(yargs) .parserConfiguration({ 'strip-dashed': true, 'unknown-options-as-args': true, @@ -30,11 +30,6 @@ export const yargsAddCommand: CommandModule< description: '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( '$0 add @nx/react', 'Install the latest version of the `@nx/react` package and run its `@nx/react:init` generator' diff --git a/packages/nx/src/command-line/affected/affected.ts b/packages/nx/src/command-line/affected/affected.ts index e97a6cb922486..fa69f266c04b0 100644 --- a/packages/nx/src/command-line/affected/affected.ts +++ b/packages/nx/src/command-line/affected/affected.ts @@ -54,10 +54,6 @@ export async function affected( nxJson ); - if (nxArgs.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - await connectToNxCloudIfExplicitlyAsked(nxArgs); const projectGraph = await createProjectGraphAsync({ exitOnError: true }); diff --git a/packages/nx/src/command-line/exec/exec.ts b/packages/nx/src/command-line/exec/exec.ts index 1cf57b508c56f..ef53c844b24b7 100644 --- a/packages/nx/src/command-line/exec/exec.ts +++ b/packages/nx/src/command-line/exec/exec.ts @@ -38,9 +38,6 @@ export async function nxExecCommand( { printWarnings: args.graph !== 'stdout' }, nxJson ); - if (nxArgs.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } const scriptArgV: string[] = readScriptArgV(overrides); const projectGraph = await createProjectGraphAsync({ exitOnError: true }); diff --git a/packages/nx/src/command-line/generate/command-object.ts b/packages/nx/src/command-line/generate/command-object.ts index 707b68bace404..de6fefbf38fa0 100644 --- a/packages/nx/src/command-line/generate/command-object.ts +++ b/packages/nx/src/command-line/generate/command-object.ts @@ -1,6 +1,7 @@ import { CommandModule, Argv } from 'yargs'; import { getCwd } from '../../utils/path'; import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; +import { withVerbose } from '../yargs-utils/shared-options'; export const yargsGenerateCommand: CommandModule = { command: 'generate [_..]', @@ -19,7 +20,7 @@ export const yargsGenerateCommand: CommandModule = { function withGenerateOptions(yargs: Argv) { const generatorWillShowHelp = process.argv[3] && !process.argv[3].startsWith('-'); - const res = yargs + const res = withVerbose(yargs) .positional('generator', { describe: 'Name of the generator (e.g., @nx/js:library, library)', type: 'string', @@ -36,11 +37,6 @@ function withGenerateOptions(yargs: Argv) { type: 'boolean', default: true, }) - .option('verbose', { - describe: - 'Prints additional information about the commands (e.g., stack traces)', - type: 'boolean', - }) .option('quiet', { describe: 'Hides logs from tree operations (e.g. `CREATE package.json`)', type: 'boolean', diff --git a/packages/nx/src/command-line/generate/generate.ts b/packages/nx/src/command-line/generate/generate.ts index de19ab9cc2313..65d4c3eeb533f 100644 --- a/packages/nx/src/command-line/generate/generate.ts +++ b/packages/nx/src/command-line/generate/generate.ts @@ -302,12 +302,7 @@ export function printGenHelp( } export async function generate(cwd: string, args: { [k: string]: any }) { - if (args['verbose']) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - const verbose = process.env.NX_VERBOSE_LOGGING === 'true'; - - return handleErrors(verbose, async () => { + return handleErrors(args.verbose, async () => { const nxJsonConfiguration = readNxJson(); const projectGraph = await createProjectGraphAsync(); const projectsConfigurations = @@ -369,7 +364,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) { nxJsonConfiguration ), relative(workspaceRoot, cwd), - verbose + args.verbose ); if ( @@ -382,7 +377,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) { ) { const host = new FsTree( workspaceRoot, - verbose, + args.verbose, `generating (${opts.collectionName}:${normalizedGeneratorName})` ); const implementation = implementationFactory(); @@ -418,7 +413,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) { generatorOptions: combinedOpts, }, projectsConfigurations.projects, - verbose + args.verbose ); } }); diff --git a/packages/nx/src/command-line/import/command-object.ts b/packages/nx/src/command-line/import/command-object.ts index c3b9971b74737..0158249d09102 100644 --- a/packages/nx/src/command-line/import/command-object.ts +++ b/packages/nx/src/command-line/import/command-object.ts @@ -37,12 +37,9 @@ export const yargsImportCommand: CommandModule = { 'import' ), handler: async (args) => { - const exitCode = await handleErrors( - (args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true', - async () => { - return (await import('./import')).importHandler(args as any); - } - ); + const exitCode = await handleErrors(args.verbose as boolean, async () => { + return (await import('./import')).importHandler(args as any); + }); process.exit(exitCode); }, }; diff --git a/packages/nx/src/command-line/migrate/command-object.ts b/packages/nx/src/command-line/migrate/command-object.ts index 0a37b76351a59..94893d461b679 100644 --- a/packages/nx/src/command-line/migrate/command-object.ts +++ b/packages/nx/src/command-line/migrate/command-object.ts @@ -10,6 +10,7 @@ import { } from '../../utils/package-manager'; import { writeJsonFile } from '../../utils/fileutils'; import { workspaceRoot } from '../../utils/workspace-root'; +import { withVerbose } from '../yargs-utils/shared-options'; export const yargsMigrateCommand: CommandModule = { command: 'migrate [packageAndVersion]', @@ -39,7 +40,7 @@ export const yargsInternalMigrateCommand: CommandModule = { function withMigrationOptions(yargs: Argv) { const defaultCommitPrefix = 'chore: [nx migration] '; - return yargs + return withVerbose(yargs) .positional('packageAndVersion', { describe: `The target package and version (e.g, @nx/workspace@16.0.0)`, type: 'string', @@ -178,7 +179,7 @@ function nxCliPath() { console.error( `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); } return null; diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index 9fdc7f6a733cb..517fbf0b9756d 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1636,10 +1636,6 @@ export async function migrate( args: { [k: string]: any }, rawArgs: string[] ) { - if (args['verbose']) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - await daemonClient.stop(); return handleErrors(process.env.NX_VERBOSE_LOGGING === 'true', async () => { diff --git a/packages/nx/src/command-line/release/changelog.ts b/packages/nx/src/command-line/release/changelog.ts index f6ef05e9ed263..d9f072e0a43f6 100644 --- a/packages/nx/src/command-line/release/changelog.ts +++ b/packages/nx/src/command-line/release/changelog.ts @@ -121,10 +121,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - // Apply default configuration to any optional user configuration const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( projectGraph, diff --git a/packages/nx/src/command-line/release/command-object.ts b/packages/nx/src/command-line/release/command-object.ts index d1c197806bc5e..64f27d1734279 100644 --- a/packages/nx/src/command-line/release/command-object.ts +++ b/packages/nx/src/command-line/release/command-object.ts @@ -10,6 +10,7 @@ import { withOutputStyleOption, withOverrides, withRunManyOptions, + withVerbose, } from '../yargs-utils/shared-options'; import { VersionData } from './utils/shared'; @@ -102,7 +103,7 @@ export const yargsReleaseCommand: CommandModule< describe: 'Orchestrate versioning and publishing of applications and libraries', builder: (yargs) => - yargs + withVerbose(yargs) .command(releaseCommand) .command(versionCommand) .command(changelogCommand) @@ -133,11 +134,6 @@ export const yargsReleaseCommand: CommandModule< type: 'boolean', 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. .option('printConfig', { type: 'string', diff --git a/packages/nx/src/command-line/release/plan-check.ts b/packages/nx/src/command-line/release/plan-check.ts index 2537487b18dd1..6ff5750ccbc55 100644 --- a/packages/nx/src/command-line/release/plan-check.ts +++ b/packages/nx/src/command-line/release/plan-check.ts @@ -37,10 +37,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - // Apply default configuration to any optional user configuration const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( projectGraph, diff --git a/packages/nx/src/command-line/release/plan.ts b/packages/nx/src/command-line/release/plan.ts index 21d937601f3b7..923c172307c96 100644 --- a/packages/nx/src/command-line/release/plan.ts +++ b/packages/nx/src/command-line/release/plan.ts @@ -36,10 +36,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - // Apply default configuration to any optional user configuration const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( projectGraph, diff --git a/packages/nx/src/command-line/release/publish.ts b/packages/nx/src/command-line/release/publish.ts index 080fbf44d77d8..e246d16a174f8 100644 --- a/packages/nx/src/command-line/release/publish.ts +++ b/packages/nx/src/command-line/release/publish.ts @@ -56,10 +56,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (_args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - // Apply default configuration to any optional user configuration const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( projectGraph, @@ -187,10 +183,6 @@ async function runPublishOnProjects( process.env.NX_DRY_RUN = 'true'; } - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - if (args.firstRelease) { overrides.firstRelease = args.firstRelease; } diff --git a/packages/nx/src/command-line/release/release.ts b/packages/nx/src/command-line/release/release.ts index 3e9c685b75fa4..467fe91354e36 100644 --- a/packages/nx/src/command-line/release/release.ts +++ b/packages/nx/src/command-line/release/release.ts @@ -54,10 +54,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - const hasVersionGitConfig = Object.keys(userProvidedReleaseConfig.version?.git ?? {}).length > 0; const hasChangelogGitConfig = diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index ca99663eca085..180281d262f3b 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -132,10 +132,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { overrideReleaseConfig ?? {} ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - // Apply default configuration to any optional user configuration const { error: configError, nxReleaseConfig } = await createNxReleaseConfig( projectGraph, diff --git a/packages/nx/src/command-line/repair/command-object.ts b/packages/nx/src/command-line/repair/command-object.ts index 1fec2ead98bd1..563abe7589620 100644 --- a/packages/nx/src/command-line/repair/command-object.ts +++ b/packages/nx/src/command-line/repair/command-object.ts @@ -1,5 +1,6 @@ import { ArgumentsCamelCase, CommandModule } from 'yargs'; import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; +import { withVerbose } from '../yargs-utils/shared-options'; export const yargsRepairCommand: CommandModule = { command: 'repair', @@ -13,12 +14,7 @@ export const yargsRepairCommand: CommandModule = { If your repository has only ever updated to newer versions of Nx with \`nx migrate\`, running \`nx repair\` should do nothing. `, - builder: (yargs) => - linkToNxDevAndExamples(yargs, 'repair').option('verbose', { - type: 'boolean', - describe: - 'Prints additional information about the commands (e.g., stack traces)', - }), + builder: (yargs) => linkToNxDevAndExamples(withVerbose(yargs), 'repair'), handler: async (args: ArgumentsCamelCase<{ verbose: boolean }>) => process.exit(await (await import('./repair')).repair(args)), }; diff --git a/packages/nx/src/command-line/repair/repair.ts b/packages/nx/src/command-line/repair/repair.ts index 204223a427c00..cae4540769491 100644 --- a/packages/nx/src/command-line/repair/repair.ts +++ b/packages/nx/src/command-line/repair/repair.ts @@ -7,11 +7,7 @@ export async function repair( args: { verbose: boolean }, extraMigrations = [] as any[] ) { - if (args['verbose']) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - const verbose = process.env.NX_VERBOSE_LOGGING === 'true'; - return handleErrors(verbose, async () => { + return handleErrors(args.verbose, async () => { const nxMigrations = Object.entries(migrationsJson.generators).reduce( (agg, [name, migration]) => { const skip = migration['x-repair-skip']; @@ -33,7 +29,7 @@ export async function repair( const migrationsThatMadeNoChanges = await executeMigrations( process.cwd(), migrations, - verbose, + args.verbose, false, '' ); diff --git a/packages/nx/src/command-line/run/run-one.ts b/packages/nx/src/command-line/run/run-one.ts index c09d843b899ab..bebe6e079834c 100644 --- a/packages/nx/src/command-line/run/run-one.ts +++ b/packages/nx/src/command-line/run/run-one.ts @@ -55,9 +55,6 @@ export async function runOne( nxJson ); - if (nxArgs.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } if (nxArgs.help) { await (await import('./run')).printTargetRunHelp(opts, workspaceRoot); process.exit(0); diff --git a/packages/nx/src/command-line/show/command-object.ts b/packages/nx/src/command-line/show/command-object.ts index aacc0e9f62ba5..07e32293e11cc 100644 --- a/packages/nx/src/command-line/show/command-object.ts +++ b/packages/nx/src/command-line/show/command-object.ts @@ -124,13 +124,10 @@ const showProjectsCommand: CommandModule = { 'Show affected projects in the workspace, excluding end-to-end projects' ) as any, handler: async (args) => { - const exitCode = await handleErrors( - args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true', - async () => { - const { showProjectsHandler } = await import('./projects'); - await showProjectsHandler(args); - } - ); + const exitCode = await handleErrors(args.verbose as boolean, async () => { + const { showProjectsHandler } = await import('./projects'); + await showProjectsHandler(args); + }); process.exit(exitCode); }, }; @@ -178,13 +175,10 @@ const showProjectCommand: CommandModule = { 'View project information for my-app in the browser' ), handler: async (args) => { - const exitCode = await handleErrors( - args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true', - async () => { - const { showProjectHandler } = await import('./project'); - await showProjectHandler(args); - } - ); + const exitCode = await handleErrors(args.verbose as boolean, async () => { + const { showProjectHandler } = await import('./project'); + await showProjectHandler(args); + }); process.exit(exitCode); }, }; diff --git a/packages/nx/src/command-line/sync/command-object.ts b/packages/nx/src/command-line/sync/command-object.ts index 238ad559b5a98..8688891bb87fc 100644 --- a/packages/nx/src/command-line/sync/command-object.ts +++ b/packages/nx/src/command-line/sync/command-object.ts @@ -1,4 +1,5 @@ import type { CommandModule } from 'yargs'; +import { withVerbose } from '../yargs-utils/shared-options'; export interface SyncArgs { verbose?: boolean; @@ -10,12 +11,7 @@ export const yargsSyncCommand: CommandModule< > = { command: 'sync', describe: false, - builder: (yargs) => - yargs.option('verbose', { - type: 'boolean', - description: - 'Prints additional information about the commands (e.g., stack traces)', - }), + builder: (yargs) => withVerbose(yargs), handler: async (args) => { process.exit(await import('./sync').then((m) => m.syncHandler(args))); }, @@ -27,12 +23,7 @@ export const yargsSyncCheckCommand: CommandModule< > = { command: 'sync:check', describe: false, - builder: (yargs) => - yargs.option('verbose', { - type: 'boolean', - description: - 'Prints additional information about the commands (e.g., stack traces)', - }), + builder: (yargs) => withVerbose(yargs), handler: async (args) => { process.exit( await import('./sync').then((m) => diff --git a/packages/nx/src/command-line/sync/sync.ts b/packages/nx/src/command-line/sync/sync.ts index 2416d8f9e20c4..4f35112af5807 100644 --- a/packages/nx/src/command-line/sync/sync.ts +++ b/packages/nx/src/command-line/sync/sync.ts @@ -16,12 +16,7 @@ interface SyncOptions extends SyncArgs { } export function syncHandler(options: SyncOptions): Promise { - if (options.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; - - return handleErrors(isVerbose, async () => { + return handleErrors(options.verbose, async () => { const projectGraph = await createProjectGraphAsync(); const syncGenerators = await collectAllRegisteredSyncGenerators( projectGraph diff --git a/packages/nx/src/command-line/watch/command-object.ts b/packages/nx/src/command-line/watch/command-object.ts index b6e7f002720b5..77fb291537bea 100644 --- a/packages/nx/src/command-line/watch/command-object.ts +++ b/packages/nx/src/command-line/watch/command-object.ts @@ -1,7 +1,7 @@ import { Argv, CommandModule } from 'yargs'; import { WatchArguments } from './watch'; 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 = { command: 'watch', @@ -13,7 +13,7 @@ export const yargsWatchCommand: CommandModule = { }; function withWatchOptions(yargs: Argv) { - return yargs + return withVerbose(yargs) .parserConfiguration({ 'strip-dashed': true, 'populate--': true, diff --git a/packages/nx/src/command-line/watch/watch.ts b/packages/nx/src/command-line/watch/watch.ts index 5b673b48df9d0..518f0729999ac 100644 --- a/packages/nx/src/command-line/watch/watch.ts +++ b/packages/nx/src/command-line/watch/watch.ts @@ -155,10 +155,6 @@ export async function watch(args: WatchArguments) { 'g' ); - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } - if (!daemonClient.enabled()) { output.error({ title: diff --git a/packages/nx/src/command-line/yargs-utils/shared-options.ts b/packages/nx/src/command-line/yargs-utils/shared-options.ts index 3e673ab1339b1..a47701c89bc81 100644 --- a/packages/nx/src/command-line/yargs-utils/shared-options.ts +++ b/packages/nx/src/command-line/yargs-utils/shared-options.ts @@ -132,9 +132,9 @@ export function withVerbose(yargs: Argv) { type: 'boolean', }) .middleware((args) => { - if (args.verbose) { - process.env.NX_VERBOSE_LOGGING = 'true'; - } + args.verbose ??= 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(); }); } diff --git a/packages/nx/src/native/assert-supported-platform.ts b/packages/nx/src/native/assert-supported-platform.ts index da988c05b664c..40e3150017090 100644 --- a/packages/nx/src/native/assert-supported-platform.ts +++ b/packages/nx/src/native/assert-supported-platform.ts @@ -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}).`, '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); } } else { diff --git a/packages/nx/src/nx-cloud/utilities/url-shorten.ts b/packages/nx/src/nx-cloud/utilities/url-shorten.ts index 2bd2bd147a90c..fac7532ee5432 100644 --- a/packages/nx/src/nx-cloud/utilities/url-shorten.ts +++ b/packages/nx/src/nx-cloud/utilities/url-shorten.ts @@ -133,7 +133,7 @@ async function getInstallationSupportsGitHub(apiUrl: string): Promise { } return !!response.data.isGithubIntegrationEnabled; } 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. ${e}`); } diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index 12ca95a6e873f..dcf9bb519e5dc 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -52,7 +52,7 @@ export class Cache { try { this._currentMachineId = await machineId(); } 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}`); } this._currentMachineId = ''; diff --git a/packages/nx/src/utils/logger.ts b/packages/nx/src/utils/logger.ts index b29f3c79446e1..218245611359e 100644 --- a/packages/nx/src/utils/logger.ts +++ b/packages/nx/src/utils/logger.ts @@ -32,7 +32,7 @@ export const logger = { console.error(...s); }, verbose: (...s) => { - if (process.env.NX_VERBOSE_LOGGING) { + if (process.env.NX_VERBOSE_LOGGING === 'true') { console.log(...s); } },