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

refactor(nx-plugin): rename autorun to cli executor #795

Merged
merged 38 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d90229
feat(nx-plugin): refactor autorun executor to general command executor
BioPhoton Aug 14, 2024
446f9d1
refactor(nx-plugin): refactor autorun command to general
BioPhoton Aug 14, 2024
942039b
add upload defaults
BioPhoton Aug 14, 2024
a51ffd7
remove warning
BioPhoton Aug 14, 2024
a94feeb
set default upload options
BioPhoton Aug 14, 2024
0ae3a4e
wip
BioPhoton Aug 14, 2024
e613d5f
Merge branch 'main' into refactor-to-command-executor
BioPhoton Aug 19, 2024
97bbbe7
wip
BioPhoton Aug 19, 2024
dcefc68
Merge branch 'main' into refactor-to-command-executor
BioPhoton Aug 24, 2024
c47d04b
fix tests
BioPhoton Aug 25, 2024
87f3dec
reduce code in registry configuration
BioPhoton Aug 25, 2024
3b9540d
rename executor from command to cli
BioPhoton Aug 26, 2024
4affc18
Merge branch 'main' into refactor-to-command-executor
BioPhoton Aug 28, 2024
89639f9
merge main
BioPhoton Aug 28, 2024
81d73be
fix lint
BioPhoton Aug 28, 2024
2b48975
cleanup
BioPhoton Aug 29, 2024
0cd0824
Merge branch 'main' into refactor-to-command-executor
BioPhoton Oct 1, 2024
bf62f81
fix package.json
BioPhoton Oct 1, 2024
57d3bea
fix 1
BioPhoton Oct 1, 2024
cd00c85
fix 2
BioPhoton Oct 1, 2024
1071e60
fix 3
BioPhoton Oct 1, 2024
465595b
wip
BioPhoton Oct 13, 2024
cdc356b
Merge branch 'main' into refactor-to-command-executor
BioPhoton Oct 14, 2024
088422f
wip 2
BioPhoton Oct 14, 2024
66fadfe
wip 3
BioPhoton Oct 14, 2024
103c1df
fix snapshot
BioPhoton Oct 14, 2024
a930e65
dont exec autorun
BioPhoton Oct 14, 2024
eeaa315
Merge branch 'main' into refactor-to-command-executor
BioPhoton Oct 14, 2024
a3f9bfa
update snapshot
BioPhoton Oct 14, 2024
a494887
fix
BioPhoton Oct 14, 2024
3c594e4
Update packages/nx-plugin/src/executors/cli/schema.json
BioPhoton Oct 15, 2024
c777cb3
Update packages/nx-plugin/src/executors/cli/README.md
BioPhoton Oct 15, 2024
57270dc
Update packages/nx-plugin/src/executors/internal/types.ts
BioPhoton Oct 15, 2024
11c55c8
Update packages/nx-plugin/src/plugin/README.md
BioPhoton Oct 15, 2024
a92d9af
Update packages/nx-plugin/src/plugin/README.md
BioPhoton Oct 15, 2024
190adfa
Update packages/nx-plugin/src/plugin/README.md
BioPhoton Oct 15, 2024
b39f544
Update tools/src/publish/bin/bump-package.ts
BioPhoton Oct 15, 2024
4e0c034
test(cli-e2e): ensure old e2e setup installs packages from local regi…
matejchalk Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ Commands:


Global Options:
--progress Show progress bar in stdout.
--progress Show progress bar in stdout.
[boolean] [default: true]
--verbose When true creates more verbose output. This is helpful w
hen debugging. [boolean] [default: false]
--config Path to config file. By default it loads code-pushup.con
fig.(ts|mjs|js). [string]
--tsconfig Path to a TypeScript config, to be used when loading con
fig file. [string]
--skipCategories List of categories to skip. If not set all categories ar
e run. [array] [default: []]
--onlyCategories List of categories to run. If not set all categories are
run. [array] [default: []]
-P, --skipPlugins List of plugins to skip. If not set all plugins are run.
--verbose When true creates more verbose output. This is helpful when
debugging. [boolean] [default: false]
--config Path to config file. By default it loads code-pushup.config
.(ts|mjs|js). [string]
--tsconfig Path to a TypeScript config, to be used when loading config
file. [string]
-p, --onlyPlugins List of plugins to run. If not set all plugins are run.
[array] [default: []]
-p, --onlyPlugins List of plugins to run. If not set all plugins are run.
-P, --skipPlugins List of plugins to skip. If not set all plugins are run.
[array] [default: []]
matejchalk marked this conversation as resolved.
Show resolved Hide resolved

Persist Options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`nx-plugin > should NOT add config targets dynamically if the project is
{
"code-pushup": {
"configurations": {},
"executor": "@code-pushup/nx-plugin:autorun",
"executor": "@code-pushup/nx-plugin:cli",
"options": {},
},
}
Expand All @@ -26,7 +26,7 @@ exports[`nx-plugin > should add executor target dynamically if the project is co
{
"code-pushup": {
"configurations": {},
"executor": "@code-pushup/nx-plugin:autorun",
"executor": "@code-pushup/nx-plugin:cli",
"options": {},
},
}
Expand Down
97 changes: 85 additions & 12 deletions e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
materializeTree,
} from '@code-pushup/test-nx-utils';
import { teardownTestFolder } from '@code-pushup/test-setup';
import { removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';
import { osAgnosticPath, removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';

function relativePathToCwd(testDir: string): string {
return relative(join(process.cwd(), testDir), process.cwd());
Expand All @@ -27,7 +27,7 @@ async function addTargetToWorkspace(
targets: {
...projectCfg.targets,
['code-pushup']: {
executor: '@code-pushup/nx-plugin:autorun',
executor: '@code-pushup/nx-plugin:cli',
},
},
});
Expand All @@ -37,19 +37,27 @@ async function addTargetToWorkspace(
plugins: [
{
// @TODO replace with inline plugin
fileImports: `import {customPlugin} from "${join(
relativePathToCwd(cwd),
pathRelativeToPackage,
'dist/testing/test-utils',
fileImports: `import {customPlugin} from "${osAgnosticPath(
join(
relativePathToCwd(cwd),
pathRelativeToPackage,
'dist/testing/test-utils',
),
)}";`,
codeStrings: 'customPlugin()',
},
],
upload: {
server: 'https://dummy-server.dev',
organization: 'dummy-organization',
apiKey: 'dummy-api-key',
project: 'dummy-project',
},
});
await materializeTree(tree, cwd);
}

describe('executor autorun', () => {
describe('executor command', () => {
let tree: Tree;
const project = 'my-lib';
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli';
Expand All @@ -62,10 +70,9 @@ describe('executor autorun', () => {
await teardownTestFolder(baseDir);
});

it('should execute autorun executor', async () => {
const cwd = join(baseDir, 'execute-dynamic-executor');
it('should execute no specific command by default', async () => {
const cwd = join(baseDir, 'execute-default-command');
await addTargetToWorkspace(tree, { cwd, project });

const { stdout, code } = await executeProcess({
command: 'npx',
args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'],
Expand All @@ -74,6 +81,72 @@ describe('executor autorun', () => {

expect(code).toBe(0);
const cleanStdout = removeColorCodes(stdout);
expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun');
expect(cleanStdout).toContain('nx run my-lib:code-pushup');
});

it('should execute print-config executor', async () => {
const cwd = join(baseDir, 'execute-print-config-command');
await addTargetToWorkspace(tree, { cwd, project });

const { stdout, code } = await executeProcess({
command: 'npx',
args: ['nx', 'run', `${project}:code-pushup`, 'print-config'],
cwd,
});

expect(code).toBe(0);
const cleanStdout = removeColorCodes(stdout);
expect(cleanStdout).toContain('nx run my-lib:code-pushup print-config');

await expect(() =>
readJsonFile(join(cwd, '.code-pushup', project, 'report.json')),
).rejects.toThrow('');
});

it('should execute collect executor and add report to sub folder named by project', async () => {
const cwd = join(baseDir, 'execute-collect-command');
await addTargetToWorkspace(tree, { cwd, project });

const { stdout, code } = await executeProcess({
command: 'nx',
args: ['run', `${project}:code-pushup`, 'collect'],
cwd,
});

expect(code).toBe(0);
const cleanStdout = removeColorCodes(stdout);
expect(cleanStdout).toContain('nx run my-lib:code-pushup collect');

const report = await readJsonFile(
join(cwd, '.code-pushup', project, 'report.json'),
);
expect(report).toStrictEqual(
expect.objectContaining({
plugins: [
expect.objectContaining({
slug: 'good-feels',
audits: [
expect.objectContaining({
displayValue: '✅ Perfect! 👌',
slug: 'always-perfect',
}),
],
}),
],
}),
);
});

it('should execute upload executor to throw if no report is present', async () => {
const cwd = join(baseDir, 'execute-upload-command');
await addTargetToWorkspace(tree, { cwd, project });

await expect(
executeProcess({
command: 'npx',
args: ['nx', 'run', `${project}:code-pushup`, 'upload'],
cwd,
}),
).rejects.toThrow(/report.json/);
});
});
8 changes: 4 additions & 4 deletions e2e/nx-plugin-e2e/tests/generator-configuration.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('nx-plugin g configuration', () => {
expect.objectContaining({
targets: expect.objectContaining({
'code-pushup': {
executor: '@code-pushup/nx-plugin:autorun',
executor: '@code-pushup/nx-plugin:cli',
},
}),
}),
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('nx-plugin g configuration', () => {
expect.objectContaining({
targets: expect.objectContaining({
'code-pushup': {
executor: '@code-pushup/nx-plugin:autorun',
executor: '@code-pushup/nx-plugin:cli',
},
}),
}),
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('nx-plugin g configuration', () => {
expect.objectContaining({
targets: expect.objectContaining({
'code-pushup': {
executor: '@code-pushup/nx-plugin:autorun',
executor: '@code-pushup/nx-plugin:cli',
},
}),
}),
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('nx-plugin g configuration', () => {
expect.objectContaining({
targets: expect.not.objectContaining({
'code-pushup': {
executor: '@code-pushup/nx-plugin:autorun',
executor: '@code-pushup/nx-plugin:cli',
},
}),
}),
Expand Down
17 changes: 13 additions & 4 deletions e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('nx-plugin', () => {
expect(projectJson.targets).toStrictEqual({
['code-pushup']: {
configurations: {},
executor: `@code-pushup/nx-plugin:autorun`,
executor: `@code-pushup/nx-plugin:cli`,
options: {},
},
});
Expand Down Expand Up @@ -174,16 +174,25 @@ describe('nx-plugin', () => {
codeStrings: 'customPlugin()',
},
],
upload: {
server: 'http://staging.code-pushup.dev',
organization: 'code-pushup',
apiKey: '12345678',
},
});

await materializeTree(tree, cwd);

const { stdout } = await executeProcess({
const { stdout, stderr } = await executeProcess({
command: 'npx',
args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'],
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',
Expand All @@ -208,7 +217,7 @@ describe('nx-plugin', () => {

expect(projectJson.targets).toStrictEqual({
['code-pushup']: expect.objectContaining({
executor: 'XYZ:autorun',
executor: 'XYZ:cli',
}),
});
});
Expand All @@ -231,7 +240,7 @@ describe('nx-plugin', () => {

expect(projectJson.targets).toStrictEqual({
['code-pushup']: expect.objectContaining({
executor: `@code-pushup/nx-plugin:autorun`,
executor: `@code-pushup/nx-plugin:cli`,
options: {
projectPrefix: 'cli',
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-plugin-e2e/vite.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
cacheDir: '../../node_modules/.vite/nx-plugin-e2e',
test: {
reporters: ['basic'],
testTimeout: 60_000,
testTimeout: 160_000,
globals: true,
alias: tsconfigPathAliases(),
pool: 'threads',
Expand Down
4 changes: 2 additions & 2 deletions global-setup.verdaccio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export async function setup() {
export async function teardown() {
// NOTICE - Time saving optimization
// We skip uninstalling packages as the folder is deleted anyway
// comment out to see the folder and web interface
// await nxStopVerdaccioAndTeardownEnv(activeRegistry);

await nxStopVerdaccioAndTeardownEnv(activeRegistry);
}
49 changes: 47 additions & 2 deletions packages/nx-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# @code-pushup/nx-plugin

### Plugin

Register this plugin in your `nx.json` to leverage a set of generators and executors to integrate Code PushUp into a Nx workspace.

#### Registration

```jsonc
// nx.json
{
//...
"plugins": ["@code-pushup/nx-plugin"]
}
```

Resulting targets:

- `nx run <project-name>:code-pushup--configuration` (no config file present)
- `nx run <project-name>:code-pushup` (`code-pushup.config.{ts,mjs,js}` is present)

### Generators

#### Init

Install JS packages and register plugin.
See [init docs](./src/generators/init/README.md) for details
See [init generator docs](./src/generators/init/README.md) for details

Examples:

Expand All @@ -15,9 +34,35 @@ Examples:
#### Configuration

Adds a `code-pushup` target to your `project.json`.
See [configuration docs](./src/generators/configuration/README.md) for details
See [configuration generator docs](./src/generators/configuration/README.md) for details

Examples:

- `nx g @code-pushup/nx-plugin:configuration --project=<project-name>`
- `nx g @code-pushup/nx-plugin:configuration --project=<project-name> --targetName=cp`

### Executor

#### CLI

Install JS packages configure a target in your project json.
See [CLI executor docs](./src/executor/cli/README.md) for details

Examples:

```json
{
"name": "my-project",
"targets": {
"code-pushup": {
"executor": "@code-pushup/nx-plugin:cli",
"options": {
"projectPrefix": "workspace-name"
}
}
}
}
```

- `nx run <project-name>:code-pushup`
- `nx run <project-name>:code-pushup print-config --persist.filename=custom-report`
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/nx-plugin/executors.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"executors": {
"autorun": {
"implementation": "./src/executors/autorun/executor",
"schema": "./src/executors/autorun/schema.json",
"description": "CodePushup CLI autorun command executor. Executes the @code-pushup/cli autorun command See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#autorun-command"
"cli": {
"implementation": "./src/executors/cli/executor",
"schema": "./src/executors/cli/schema.json",
"description": "CodePushup CLI executor. Executes the @code-pushup/cli command's See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#commands"
}
}
}
2 changes: 1 addition & 1 deletion packages/nx-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@nx/devkit": "^17.1.3",
"tslib": "^2.6.2",
"tslib": "2.6.3",
"nx": "^17.1.3",
"@code-pushup/models": "0.51.0",
"zod": "^3.22.4",
Expand Down
1 change: 0 additions & 1 deletion packages/nx-plugin/src/executors/autorun/constants.ts

This file was deleted.

Loading