Skip to content

Commit 970a665

Browse files
authored
Merge f8c425a into f335d20
2 parents f335d20 + f8c425a commit 970a665

File tree

7 files changed

+56
-45
lines changed

7 files changed

+56
-45
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,27 @@ describe('nx-plugin', () => {
189189

190190
await materializeTree(tree, cwd);
191191

192-
const { stdout, stderr } = await executeProcess({
192+
const { stdout } = await executeProcess({
193193
command: 'npx',
194-
args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'],
194+
args: ['nx', 'run', `${project}:code-pushup`, '--dryRun', '--verbose'],
195195
cwd,
196196
});
197197

198-
const cleanStderr = removeColorCodes(stderr);
199-
// @TODO create test environment for working plugin. This here misses package-lock.json to execute correctly
200-
expect(cleanStderr).toContain('DryRun execution of: npx @code-pushup/cli');
201-
202198
const cleanStdout = removeColorCodes(stdout);
203-
expect(cleanStdout).toContain(
204-
'NX Successfully ran target code-pushup for project my-lib',
205-
);
199+
// Nx command
200+
expect(cleanStdout).toContain('nx run my-lib:code-pushup');
201+
// Run CLI executor
202+
expect(cleanStdout).toContain('Command: npx @code-pushup/cli');
203+
expect(cleanStdout).toContain('--dryRun --verbose');
206204
});
207205

208206
it('should consider plugin option bin in executor target', async () => {
209-
const cwd = path.join(testFileDir, 'configuration-option-bin');
207+
const cwd = path.join(testFileDir, 'executor-option-bin');
208+
const binPath = `packages/cli/dist`;
210209
registerPluginInWorkspace(tree, {
211210
plugin: '@code-pushup/nx-plugin',
212211
options: {
213-
bin: 'XYZ',
212+
bin: binPath,
214213
},
215214
});
216215
const { root } = readProjectConfiguration(tree, project);
@@ -223,13 +222,15 @@ describe('nx-plugin', () => {
223222

224223
expect(projectJson.targets).toStrictEqual({
225224
'code-pushup': expect.objectContaining({
226-
executor: 'XYZ:cli',
225+
options: {
226+
bin: binPath,
227+
},
227228
}),
228229
});
229230
});
230231

231232
it('should consider plugin option projectPrefix in executor target', async () => {
232-
const cwd = path.join(testFileDir, 'configuration-option-bin');
233+
const cwd = path.join(testFileDir, 'executor-option-projectPrefix');
233234
registerPluginInWorkspace(tree, {
234235
plugin: '@code-pushup/nx-plugin',
235236
options: {

packages/nx-plugin/src/executors/cli/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ For details on the CLI command read the [CLI commands documentation](https://git
77

88
## Usage
99

10-
Configure a target in your project json.
10+
Configure a target in your `project.json`.
1111

1212
```jsonc
13-
// <project-name>/project.json
13+
// {projectRoot}/project.json
1414
{
1515
"name": "my-project",
1616
"targets": {
@@ -74,4 +74,4 @@ Show what will be executed without actually executing it:
7474
| **dryRun** | `boolean` | To debug the executor, dry run the command without real execution. |
7575
| **bin** | `string` | Path to Code PushUp CLI |
7676

77-
For all other options see the [CLI autorun documentation](../../../../cli/README.md#autorun-command).
77+
For all other options, see the [CLI autorun documentation](../../../../cli/README.md#autorun-command).

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export default async function runAutorunExecutor(
2727
mergedOptions,
2828
normalizedContext,
2929
);
30-
const { dryRun, verbose, command } = mergedOptions;
30+
const { dryRun, verbose, command, bin } = mergedOptions;
3131
const commandString = createCliCommandString({
3232
command,
3333
args: cliArgumentObject,
34+
bin,
3435
});
3536
if (verbose) {
3637
logger.info(`Run CLI executor ${command ?? ''}`);
@@ -41,15 +42,15 @@ export default async function runAutorunExecutor(
4142
} else {
4243
try {
4344
await executeProcess({
44-
...createCliCommandObject({ command, args: cliArgumentObject }),
45+
...createCliCommandObject({ command, args: cliArgumentObject, bin }),
4546
...(context.cwd ? { cwd: context.cwd } : {}),
4647
});
4748
} catch (error) {
4849
logger.error(error);
4950
return {
5051
success: false,
5152
command: commandString,
52-
error: error as Error,
53+
error: error instanceof Error ? error : new Error(`${error}`),
5354
};
5455
}
5556
}

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'node:path';
22
import type { PersistConfig, UploadConfig } from '@code-pushup/models';
3+
import type { NormalizedExecutorContext } from './context.js';
34
import { parseEnv } from './env.js';
45
import type {
56
BaseNormalizedExecutorContext,
@@ -44,26 +45,32 @@ export function persistConfig(
4445

4546
export function uploadConfig(
4647
options: Partial<UploadConfig & ProjectExecutorOnlyOptions>,
47-
context: BaseNormalizedExecutorContext,
48+
context: NormalizedExecutorContext,
4849
): Partial<UploadConfig> {
49-
const { projectConfig, workspaceRoot } = context;
50+
const { workspaceRoot, projectName } = context;
5051

51-
const { name: projectName } = projectConfig ?? {};
5252
const { projectPrefix, server, apiKey, organization, project, timeout } =
5353
options;
5454
const applyPrefix = workspaceRoot === '.';
5555
const prefix = projectPrefix ? `${projectPrefix}-` : '';
56+
57+
const derivedProject =
58+
projectName && !project
59+
? applyPrefix
60+
? `${prefix}${projectName}`
61+
: projectName
62+
: project;
63+
5664
return {
57-
...(projectName
58-
? {
59-
project: applyPrefix ? `${prefix}${projectName}` : projectName,
60-
}
61-
: {}),
6265
...parseEnv(process.env),
6366
...Object.fromEntries(
64-
Object.entries({ server, apiKey, organization, project, timeout }).filter(
65-
([_, v]) => v !== undefined,
66-
),
67+
Object.entries({
68+
server,
69+
apiKey,
70+
organization,
71+
...(derivedProject ? { project: derivedProject } : {}),
72+
timeout,
73+
}).filter(([_, v]) => v !== undefined),
6774
),
6875
};
6976
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ describe('uploadConfig', () => {
267267
expect(
268268
uploadConfig(baseUploadConfig, {
269269
workspaceRoot: 'workspace-root',
270+
projectName,
270271
projectConfig: {
271-
name: projectName,
272272
root: 'root',
273273
},
274274
}),

packages/nx-plugin/src/plugin/target/executor-target.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ export function createExecutorTarget(options?: {
66
bin?: string;
77
projectPrefix?: string;
88
}): TargetConfiguration<ProjectPrefixOptions> {
9-
const { bin = PACKAGE_NAME, projectPrefix } = options ?? {};
10-
return {
11-
executor: `${bin}:cli`,
12-
...(projectPrefix
13-
? {
14-
options: {
15-
projectPrefix,
16-
},
17-
}
18-
: {}),
9+
const { bin, projectPrefix } = options ?? {};
10+
11+
const executor = `${PACKAGE_NAME}:cli`;
12+
const executorOptions = (bin || projectPrefix) && {
13+
...(bin && { bin }),
14+
...(projectPrefix && { projectPrefix }),
1915
};
16+
return { executor, ...(executorOptions && { options: executorOptions }) };
2017
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22
import { createExecutorTarget } from './executor-target.js';
33

44
describe('createExecutorTarget', () => {
@@ -8,9 +8,14 @@ describe('createExecutorTarget', () => {
88
});
99
});
1010

11-
it('should use bin if provides', () => {
12-
expect(createExecutorTarget({ bin: 'xyz' })).toStrictEqual({
13-
executor: 'xyz:cli',
11+
it('should use bin if provided', () => {
12+
expect(
13+
createExecutorTarget({ bin: 'packages/cli/src/index.ts' }),
14+
).toStrictEqual({
15+
executor: '@code-pushup/nx-plugin:cli',
16+
options: {
17+
bin: 'packages/cli/src/index.ts',
18+
},
1419
});
1520
});
1621

0 commit comments

Comments
 (0)