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(run): exclude dependencies with --scope when nx.json is not present #336

Merged
merged 1 commit into from
Sep 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/cli/schemas/lerna-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
"profileLocation": {
"$ref": "#/$defs/commandOptions/shared/profileLocation"
},
"verbose": {
"$ref": "#/$defs/commandOptions/shared/verbose"
},
"skipNxCache": {
"$ref": "#/$defs/commandOptions/run/skipNxCache"
},
Expand Down Expand Up @@ -979,6 +982,9 @@
},
"ignorePrepublish": {
"$ref": "#/$defs/commandOptions/shared/ignorePrepublish"
},
"verbose": {
"$ref": "#/$defs/commandOptions/shared/verbose"
}
},
"$defs": {
Expand Down Expand Up @@ -1442,6 +1448,10 @@
"ignorePrepublish": {
"type": "boolean",
"description": "During `lerna publish` and `lerna bootstrap`, when true, disable deprecated 'prepublish' lifecycle script."
},
"verbose": {
"type": "boolean",
"description": "When true, escalates loglevel to 'verbose' and shows nx verbose output if useNx is true."
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/cli-commands/cli-run-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export default {
hidden: true,
type: 'boolean',
},
verbose: {
group: 'Command Options:',
describe: 'When "useNx" is true, show verbose output from dependent tasks.',
type: 'boolean',
},
});

return filterOptions(yargs);
Expand Down
99 changes: 99 additions & 0 deletions packages/core/src/__tests__/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,103 @@ describe('core-command', () => {
);
});
});

describe('loglevel with verbose option true', () => {
it('should be set to verbose if loglevel is error', async () => {
const command = testFactory({
loglevel: 'error',
verbose: true,
});
await command;

expect(command.options.loglevel).toEqual('verbose');
});

it('should be set to verbose if loglevel is warn', async () => {
const command = testFactory({
loglevel: 'warn',
verbose: true,
});
await command;

expect(command.options.loglevel).toEqual('verbose');
});

it('should be set to verbose if loglevel is info', async () => {
const command = testFactory({
loglevel: 'info',
verbose: true,
});
await command;

expect(command.options.loglevel).toEqual('verbose');
});

it('should remain set to verbose if loglevel is verbose', async () => {
const command = testFactory({
loglevel: 'verbose',
verbose: true,
});
await command;

expect(command.options.loglevel).toEqual('verbose');
});

it('should not be set to verbose if loglevel is silly', async () => {
const command = testFactory({
loglevel: 'silly',
verbose: true,
});
await command;

expect(command.options.loglevel).toEqual('silly');
});
});

describe('loglevel without verbose option', () => {
it('should remain set to error if loglevel is error', async () => {
const command = testFactory({
loglevel: 'error',
});
await command;

expect(command.options.loglevel).toEqual('error');
});

it('should remain set to warn if loglevel is warn', async () => {
const command = testFactory({
loglevel: 'warn',
});
await command;

expect(command.options.loglevel).toEqual('warn');
});

it('should remain set to info if loglevel is info', async () => {
const command = testFactory({
loglevel: 'info',
});
await command;

expect(command.options.loglevel).toEqual('info');
});

it('should remain set to verbose if loglevel is verbose', async () => {
const command = testFactory({
loglevel: 'verbose',
});
await command;

expect(command.options.loglevel).toEqual('verbose');
});

it('should remain set to silly if loglevel is silly', async () => {
const command = testFactory({
loglevel: 'silly',
});
await command;

expect(command.options.loglevel).toEqual('silly');
});
});
});
4 changes: 4 additions & 0 deletions packages/core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export class Command<T extends AvailableCommandOption> {
// Environmental defaults prepared in previous step
this.envDefaults
);

if (this.options.verbose && this.options.loglevel !== 'silly') {
this.options.loglevel = 'verbose';
}
}

configureProperties() {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/models/command-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ export interface RunCommandOption {
/** npm script to run by the command. */
script: string;

/** Enables integration with [Nx](https://nx.dev). */
useNx?: boolean;

/** when "useNx" is enabled, do we want to skip caching with Nx? */
skipNxCache?: boolean;

/** enables integration with [Nx](https://nx.dev). */
useNx?: boolean;
}
27 changes: 27 additions & 0 deletions packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,44 @@ export interface LernaConfig {
export interface ProjectConfig extends LernaConfig, QueryGraphConfig {
/** Lerna JSON Schema https://json-schema.org/ */
$schema: string;

/** enabled when running in CI (Continuous Integration). */
ci?: boolean;

/** how many threads to use when Lerna parallelizes the tasks (defaults to count of logical CPU cores) */
concurrency: number | string;

/** current working directory */
cwd: string;

/** Composed commands are called from other commands, like publish -> version */
composed?: boolean;

/** Lerna CLI version */
lernaVersion: string;

/** show progress bars. */
progress?: boolean;

/** Only include packages that have been changed since the specified [ref]. */
since?: string;

/** When true, Lerna will sort the packages topologically (dependencies before dependents). */
sort?: boolean;

/** During `lerna exec` and `lerna run`, stream output with lines prefixed by originating package name. */
stream?: boolean;

/** Enables integration with [Nx](https://nx.dev). */
useNx?: boolean;

/** When useNx is true, show verbose output from dependent tasks. */
verbose?: boolean;

/** callback to execute when Promise rejected */
onRejected?: (result: any) => void;

/** callback to execute when Promise resolved */
onResolved?: (result: any) => void;
}

Expand Down
21 changes: 18 additions & 3 deletions packages/run/src/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
ValidationError,
} from '@lerna-lite/core';
import { FilterOptions, getFilteredPackages, Profiler } from '@lerna-lite/optional-cmd-common';
import fs from 'fs-extra';
import pMap from 'p-map';
import path from 'path';
import { performance } from 'perf_hooks';

import { npmRunScript, npmRunScriptStreaming, timer } from './lib';
Expand Down Expand Up @@ -218,7 +220,7 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
}
performance.mark('init-local');
this.configureNxOutput();
const { targetDependencies, options } = await this.prepNxOptions();
const { extraOptions, targetDependencies, options } = await this.prepNxOptions();
if (this.packagesWithScript.length === 1) {
const { runOne } = await import('nx/src/command-line/run-one');
const fullQualifiedTarget =
Expand All @@ -229,7 +231,8 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
'project:target:configuration': fullQualifiedTarget,
...options,
},
targetDependencies
targetDependencies,
extraOptions
);
} else {
const { runMany } = await import('nx/src/command-line/run-many');
Expand Down Expand Up @@ -280,10 +283,22 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
nxBail: this.bail,
nxIgnoreCycles: !this.options.rejectCycles,
skipNxCache: this.options.skipNxCache,
verbose: this.options.verbose,
__overrides__: this.args.map((t) => t.toString()),
};

return { targetDependencies, options };
const excludeTaskDependencies = !fs.existsSync(path.join(this.project.rootPath, 'nx.json'));
if (excludeTaskDependencies) {
this.logger.verbose(this.name, 'nx.json was not found. Task dependencies will not be automatically included.');
} else {
this.logger.verbose(this.name, 'nx.json was found. Task dependencies will be automatically included.');
}

const extraOptions = {
excludeTaskDependencies,
};

return { targetDependencies, options, extraOptions };
}

runScriptInPackagesParallel() {
Expand Down