diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 7a69a281d..1fc21fae3 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -103,29 +103,6 @@ describe('nx-plugin', () => { }); }); - it('should consider plugin option bin in configuration target', async () => { - const cwd = path.join(testFileDir, 'configuration-option-bin'); - registerPluginInWorkspace(tree, { - plugin: '@code-pushup/nx-plugin', - options: { - bin: 'XYZ', - }, - }); - await materializeTree(tree, cwd); - - const { code, projectJson } = await nxShowProjectJson(cwd, project); - - expect(code).toBe(0); - - expect(projectJson.targets).toStrictEqual({ - 'code-pushup--configuration': expect.objectContaining({ - options: { - command: `nx g XYZ:configuration --skipTarget --targetName="code-pushup" --project="${project}"`, - }, - }), - }); - }); - it('should NOT add config targets dynamically if the project is configured', async () => { const cwd = path.join(testFileDir, 'configuration-already-configured'); registerPluginInWorkspace(tree, '@code-pushup/nx-plugin'); @@ -189,28 +166,26 @@ describe('nx-plugin', () => { await materializeTree(tree, cwd); - const { stdout, stderr } = await executeProcess({ + const { stdout } = await executeProcess({ command: 'npx', - args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'], + args: ['nx', 'run', `${project}:code-pushup`, '--dryRun', '--verbose'], cwd, }); - const cleanStderr = removeColorCodes(stderr); - // @TODO create test environment for working plugin. This here misses package-lock.json to execute correctly - expect(cleanStderr).toContain('DryRun execution of: npx @code-pushup/cli'); - const cleanStdout = removeColorCodes(stdout); - expect(cleanStdout).toContain( - 'NX Successfully ran target code-pushup for project my-lib', - ); + expect(cleanStdout).toContain('nx run my-lib:code-pushup'); + expect(cleanStdout).toContain('npx @code-pushup/cli'); + expect(cleanStdout).toContain('--dryRun --verbose'); + expect(cleanStdout).toContain(`--upload.project="${project}"`); }); it('should consider plugin option bin in executor target', async () => { - const cwd = path.join(testFileDir, 'configuration-option-bin'); + const cwd = path.join(testFileDir, 'executor-option-bin'); + const binPath = `packages/cli/dist`; registerPluginInWorkspace(tree, { plugin: '@code-pushup/nx-plugin', options: { - bin: 'XYZ', + bin: binPath, }, }); const { root } = readProjectConfiguration(tree, project); @@ -223,13 +198,15 @@ describe('nx-plugin', () => { expect(projectJson.targets).toStrictEqual({ 'code-pushup': expect.objectContaining({ - executor: 'XYZ:cli', + options: { + bin: binPath, + }, }), }); }); it('should consider plugin option projectPrefix in executor target', async () => { - const cwd = path.join(testFileDir, 'configuration-option-bin'); + const cwd = path.join(testFileDir, 'executor-option-projectPrefix'); registerPluginInWorkspace(tree, { plugin: '@code-pushup/nx-plugin', options: { diff --git a/packages/nx-plugin/src/executors/cli/README.md b/packages/nx-plugin/src/executors/cli/README.md index fdb01c9f7..720432911 100644 --- a/packages/nx-plugin/src/executors/cli/README.md +++ b/packages/nx-plugin/src/executors/cli/README.md @@ -7,10 +7,10 @@ For details on the CLI command read the [CLI commands documentation](https://git ## Usage -Configure a target in your project json. +Configure a target in your `project.json`. ```jsonc -// /project.json +// {projectRoot}/project.json { "name": "my-project", "targets": { @@ -74,4 +74,4 @@ Show what will be executed without actually executing it: | **dryRun** | `boolean` | To debug the executor, dry run the command without real execution. | | **bin** | `string` | Path to Code PushUp CLI | -For all other options see the [CLI autorun documentation](../../../../cli/README.md#autorun-command). +For all other options, see the [CLI autorun documentation](../../../../cli/README.md#autorun-command). diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 7eece1129..37c0b1d94 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -27,10 +27,11 @@ export default async function runAutorunExecutor( mergedOptions, normalizedContext, ); - const { dryRun, verbose, command } = mergedOptions; + const { dryRun, verbose, command, bin } = mergedOptions; const commandString = createCliCommandString({ command, args: cliArgumentObject, + bin, }); if (verbose) { logger.info(`Run CLI executor ${command ?? ''}`); @@ -41,7 +42,7 @@ export default async function runAutorunExecutor( } else { try { await executeProcess({ - ...createCliCommandObject({ command, args: cliArgumentObject }), + ...createCliCommandObject({ command, args: cliArgumentObject, bin }), ...(context.cwd ? { cwd: context.cwd } : {}), }); } catch (error) { diff --git a/packages/nx-plugin/src/plugin/target/executor-target.ts b/packages/nx-plugin/src/plugin/target/executor-target.ts index e8b52eb8f..a44c7281e 100644 --- a/packages/nx-plugin/src/plugin/target/executor-target.ts +++ b/packages/nx-plugin/src/plugin/target/executor-target.ts @@ -6,15 +6,13 @@ export function createExecutorTarget(options?: { bin?: string; projectPrefix?: string; }): TargetConfiguration { - const { bin = PACKAGE_NAME, projectPrefix } = options ?? {}; + const { bin, projectPrefix } = options ?? {}; + return { - executor: `${bin}:cli`, - ...(projectPrefix - ? { - options: { - projectPrefix, - }, - } - : {}), + executor: `${PACKAGE_NAME}:cli`, + options: { + ...(bin ? { bin } : {}), + ...(projectPrefix ? { projectPrefix } : {}), + }, }; } diff --git a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts index 610b44bd7..571b63aa2 100644 --- a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts +++ b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts @@ -1,16 +1,22 @@ -import { expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { createExecutorTarget } from './executor-target.js'; describe('createExecutorTarget', () => { it('should return executor target without project name', () => { expect(createExecutorTarget()).toStrictEqual({ executor: '@code-pushup/nx-plugin:cli', + options: {}, }); }); it('should use bin if provides', () => { - expect(createExecutorTarget({ bin: 'xyz' })).toStrictEqual({ - executor: 'xyz:cli', + expect( + createExecutorTarget({ bin: 'packages/cli/src/index.ts' }), + ).toStrictEqual({ + executor: '@code-pushup/nx-plugin:cli', + options: { + bin: 'packages/cli/src/index.ts', + }, }); }); diff --git a/packages/nx-plugin/src/plugin/target/targets.unit.test.ts b/packages/nx-plugin/src/plugin/target/targets.unit.test.ts index 9b730f726..919c235a3 100644 --- a/packages/nx-plugin/src/plugin/target/targets.unit.test.ts +++ b/packages/nx-plugin/src/plugin/target/targets.unit.test.ts @@ -109,6 +109,7 @@ describe('createTargets', () => { expect.objectContaining({ [targetName]: { executor: `${PACKAGE_NAME}:cli`, + options: {}, }, }), ); @@ -133,6 +134,7 @@ describe('createTargets', () => { ).resolves.toStrictEqual({ [DEFAULT_TARGET_NAME]: { executor: '@code-pushup/nx-plugin:cli', + options: {}, }, }); }); @@ -158,6 +160,7 @@ describe('createTargets', () => { ).resolves.toStrictEqual({ cp: { executor: '@code-pushup/nx-plugin:cli', + options: {}, }, }); });