Skip to content

Commit 893b1d3

Browse files
author
John Doe
committed
Merge remote-tracking branch 'origin/main' into fix/nx-plugin/add-env-vars-to-executor
# Conflicts: # packages/nx-plugin/src/executors/cli/executor.ts
2 parents f270316 + 068984b commit 893b1d3

File tree

14 files changed

+155
-276
lines changed

14 files changed

+155
-276
lines changed

e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,6 @@ describe('nx-plugin', () => {
103103
});
104104
});
105105

106-
it('should consider plugin option bin in configuration target', async () => {
107-
const cwd = path.join(testFileDir, 'configuration-option-bin');
108-
registerPluginInWorkspace(tree, {
109-
plugin: '@code-pushup/nx-plugin',
110-
options: {
111-
bin: 'XYZ',
112-
},
113-
});
114-
await materializeTree(tree, cwd);
115-
116-
const { code, projectJson } = await nxShowProjectJson(cwd, project);
117-
118-
expect(code).toBe(0);
119-
120-
expect(projectJson.targets).toStrictEqual({
121-
'code-pushup--configuration': expect.objectContaining({
122-
options: {
123-
command: `nx g XYZ:configuration --project="${project}"`,
124-
},
125-
}),
126-
});
127-
});
128-
129106
it('should NOT add config targets dynamically if the project is configured', async () => {
130107
const cwd = path.join(testFileDir, 'configuration-already-configured');
131108
registerPluginInWorkspace(tree, '@code-pushup/nx-plugin');
@@ -199,8 +176,10 @@ describe('nx-plugin', () => {
199176
// Nx command
200177
expect(cleanStdout).toContain('nx run my-lib:code-pushup');
201178
// Run CLI executor
202-
expect(cleanStdout).toContain('Command: npx @code-pushup/cli');
203-
expect(cleanStdout).toContain('--dryRun --verbose');
179+
expect(cleanStdout).toContain('Command:');
180+
expect(cleanStdout).toContain('npx @code-pushup/cli');
181+
expect(cleanStdout).toContain('--verbose');
182+
expect(cleanStdout).toContain('--dryRun ');
204183
});
205184

206185
it('should consider plugin option bin in executor target', async () => {

packages/nx-plugin/src/executors/cli/executor.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { type ExecutorContext, logger } from '@nx/devkit';
22
import { executeProcess } from '../../internal/execute-process.js';
3-
import {
4-
createCliCommandObject,
5-
createCliCommandString,
6-
} from '../internal/cli.js';
73
import { normalizeContext } from '../internal/context.js';
84
import type { AutorunCommandExecutorOptions } from './schema.js';
95
import { parseAutorunExecutorOptions } from './utils.js';
@@ -14,10 +10,14 @@ export type ExecutorOutput = {
1410
error?: Error;
1511
};
1612

13+
/* eslint-disable-next-line max-lines-per-function */
1714
export default async function runAutorunExecutor(
1815
terminalAndExecutorOptions: AutorunCommandExecutorOptions,
1916
context: ExecutorContext,
2017
): Promise<ExecutorOutput> {
18+
const { objectToCliArgs, formatCommandStatus } = await import(
19+
'@code-pushup/utils'
20+
);
2121
const normalizedContext = normalizeContext(context);
2222
const cliArgumentObject = parseAutorunExecutorOptions(
2323
terminalAndExecutorOptions,
@@ -26,14 +26,17 @@ export default async function runAutorunExecutor(
2626
const {
2727
dryRun,
2828
verbose,
29-
command,
29+
command: cliCommand,
3030
bin,
31-
env: targetEnv,
3231
} = terminalAndExecutorOptions;
33-
const commandString = createCliCommandString({
34-
command,
35-
args: cliArgumentObject,
36-
bin,
32+
const command = bin ? `node` : 'npx';
33+
const positionals = [
34+
bin ?? '@code-pushup/cli',
35+
...(cliCommand ? [cliCommand] : []),
36+
];
37+
const args = [...positionals, ...objectToCliArgs(cliArgumentObject)];
38+
const commandString = formatCommandStatus([command, ...args].join(' '), {
39+
cwd: context.cwd,
3740
});
3841
if (verbose) {
3942
logger.info(`Run CLI executor ${command ?? ''}`);
@@ -44,9 +47,9 @@ export default async function runAutorunExecutor(
4447
} else {
4548
try {
4649
await executeProcess({
47-
...createCliCommandObject({ command, args: cliArgumentObject, bin }),
50+
command,
51+
args,
4852
...(context.cwd ? { cwd: context.cwd } : {}),
49-
...(targetEnv ? { env: targetEnv } : {}),
5053
});
5154
} catch (error) {
5255
logger.error(error);

packages/nx-plugin/src/executors/cli/executor.unit.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('runAutorunExecutor', () => {
127127
expect.stringContaining(`Run CLI executor`),
128128
);
129129
expect(loggerInfoSpy).toHaveBeenCalledWith(
130-
expect.stringContaining('Command: npx @code-pushup/cli'),
130+
expect.stringContaining('Command:'),
131131
);
132132
});
133133

@@ -137,9 +137,7 @@ describe('runAutorunExecutor', () => {
137137
expect(loggerInfoSpy).toHaveBeenCalledTimes(0);
138138
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
139139
expect(loggerWarnSpy).toHaveBeenCalledWith(
140-
expect.stringContaining(
141-
'DryRun execution of: npx @code-pushup/cli --dryRun',
142-
),
140+
expect.stringContaining('DryRun execution of'),
143141
);
144142
});
145143
});

packages/nx-plugin/src/executors/internal/cli.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

packages/nx-plugin/src/executors/internal/cli.unit.test.ts

Lines changed: 0 additions & 136 deletions
This file was deleted.

packages/nx-plugin/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const plugin = {
1111
export default plugin;
1212

1313
export type { AutorunCommandExecutorOptions } from './executors/cli/schema.js';
14-
export { objectToCliArgs } from './executors/internal/cli.js';
1514
export { generateCodePushupConfig } from './generators/configuration/code-pushup-config.js';
1615
export { configurationGenerator } from './generators/configuration/generator.js';
1716
export type { ConfigurationGeneratorOptions } from './generators/configuration/schema.js';
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import type { TargetConfiguration } from '@nx/devkit';
22
import type { RunCommandsOptions } from 'nx/src/executors/run-commands/run-commands.impl';
3-
import { objectToCliArgs } from '../../executors/internal/cli.js';
43
import { PACKAGE_NAME } from '../../internal/constants.js';
54

6-
export function createConfigurationTarget(options?: {
5+
export async function createConfigurationTarget(options?: {
76
projectName?: string;
8-
bin?: string;
9-
}): TargetConfiguration<RunCommandsOptions> {
10-
const { projectName, bin = PACKAGE_NAME } = options ?? {};
7+
}): Promise<TargetConfiguration<RunCommandsOptions>> {
8+
const { projectName } = options ?? {};
9+
const { objectToCliArgs } = await import('@code-pushup/utils');
1110
const args = objectToCliArgs({
1211
...(projectName ? { project: projectName } : {}),
1312
});
14-
const argsString = args.length > 0 ? args.join(' ') : '';
15-
const baseCommand = `nx g ${bin}:configuration`;
13+
const argsString = args.length > 0 ? ` ${args.join(' ')}` : '';
1614
return {
17-
command: argsString ? `${baseCommand} ${argsString}` : baseCommand,
15+
command: `nx g ${PACKAGE_NAME}:configuration${argsString}`,
1816
};
1917
}

packages/nx-plugin/src/plugin/target/configuration.target.unit.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { PACKAGE_NAME } from '../../internal/constants.js';
33
import { createConfigurationTarget } from './configuration-target.js';
44

55
describe('createConfigurationTarget', () => {
6-
it('should return code-pushup--configuration target for given project', () => {
7-
expect(
6+
it('should return code-pushup--configuration target for given project', async () => {
7+
await expect(
88
createConfigurationTarget({ projectName: 'my-project' }),
9-
).toStrictEqual({
9+
).resolves.toStrictEqual({
1010
command: `nx g ${PACKAGE_NAME}:configuration --project="my-project"`,
1111
});
1212
});
1313

14-
it('should return code-pushup--configuration target without project name', () => {
15-
expect(createConfigurationTarget()).toStrictEqual({
14+
it('should return code-pushup--configuration target without project name', async () => {
15+
await expect(createConfigurationTarget()).resolves.toStrictEqual({
1616
command: `nx g ${PACKAGE_NAME}:configuration`,
1717
});
1818
});

0 commit comments

Comments
 (0)