Skip to content

Commit 90e0260

Browse files
author
Michael Hladky
committed
refactor: revert
1 parent 6ff3f55 commit 90e0260

File tree

16 files changed

+44
-161
lines changed

16 files changed

+44
-161
lines changed

e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@ async function addTargetToWorkspace(
2727
) {
2828
const { cwd, project } = options;
2929
const projectCfg = readProjectConfiguration(tree, project);
30-
const { root } = projectCfg;
31-
const configPath = path.join(root, 'code-pushup.config.ts');
3230
updateProjectConfiguration(tree, project, {
3331
...projectCfg,
3432
targets: {
3533
...projectCfg.targets,
3634
'code-pushup': {
3735
executor: '@code-pushup/nx-plugin:cli',
38-
options: {
39-
config: configPath,
40-
...executorOptions,
41-
},
36+
...(executorOptions && { options: executorOptions }),
4237
},
4338
},
4439
});
40+
const { root } = projectCfg;
4541
generateCodePushupConfig(tree, root, {
4642
plugins: [
4743
{
@@ -148,7 +144,7 @@ describe('executor command', () => {
148144
).resolves.not.toThrow();
149145
});
150146

151-
it('should execute print-config executor with upload config', async () => {
147+
it('should execute print-config executor with api key', async () => {
152148
const cwd = path.join(testFileDir, 'execute-print-config-command');
153149
await addTargetToWorkspace(tree, { cwd, project });
154150

@@ -160,9 +156,6 @@ describe('executor command', () => {
160156
`${project}:code-pushup`,
161157
'print-config',
162158
'--upload.apiKey=a123a',
163-
'--upload.server=https://example.com',
164-
'--upload.organization=test-org',
165-
'--upload.project=test-project',
166159
],
167160
cwd,
168161
});
@@ -233,7 +226,7 @@ describe('executor command', () => {
233226
expect(cleanStdout).toContain('nx run my-lib:code-pushup collect');
234227

235228
const report = await readJsonFile(
236-
path.join(cwd, 'libs', project, '.code-pushup', 'report.json'),
229+
path.join(cwd, '.code-pushup', project, 'report.json'),
237230
);
238231
expect(report).toStrictEqual(
239232
expect.objectContaining({

packages/nx-plugin/src/executors/cli/schema.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
"type": "string",
2222
"description": "Path to Code PushUp CLI"
2323
},
24-
"env": {
25-
"type": "object",
26-
"additionalProperties": {
27-
"type": "string"
28-
},
29-
"description": "Environment variables to pass to the CLI command"
30-
},
3124
"verbose": {
3225
"type": "boolean",
3326
"description": "Print additional logs"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('parseAutorunExecutorOptions', () => {
107107
);
108108

109109
expect(osAgnosticPath(executorOptions.persist?.outputDir ?? '')).toBe(
110-
osAgnosticPath('{projectRoot}/.code-pushup'),
110+
osAgnosticPath('workspaceRoot/.code-pushup/my-app'),
111111
);
112112
});
113113

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ export function globalConfig(
2323

2424
export function persistConfig(
2525
options: Partial<PersistConfig & ProjectExecutorOnlyOptions>,
26-
_context: BaseNormalizedExecutorContext,
26+
context: BaseNormalizedExecutorContext,
2727
): Partial<PersistConfig> {
28+
const { projectConfig, workspaceRoot } = context;
29+
30+
const { name: projectName = '' } = projectConfig ?? {};
2831
const {
2932
format,
30-
outputDir = '{projectRoot}/.code-pushup',
33+
outputDir = path.join(workspaceRoot, '.code-pushup', projectName), // always in <root>/.code-pushup/<project-name>,
3134
filename,
3235
} = options;
3336

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ describe('persistConfig', () => {
143143
},
144144
},
145145
);
146-
expect(String(outputDir)).toBe('{projectRoot}/.code-pushup');
146+
expect(osAgnosticPath(String(outputDir))).toBe(
147+
osAgnosticPath(`/test/root/workspace-root/.code-pushup/${projectName}`),
148+
);
147149
});
148150

149151
it('should parse given outputDir options', () => {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export type Command =
3030
export type GlobalExecutorOptions = {
3131
command?: Command;
3232
bin?: string;
33-
env?: Record<string, string>;
3433
verbose?: boolean;
3534
config?: string;
3635
};

packages/nx-plugin/src/generators/configuration/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DynamicTargetOptions } from '../../internal/types.js';
22

33
export type ConfigurationGeneratorOptions = {
44
project: string;
5+
bin?: string;
56
skipTarget?: boolean;
67
skipConfig?: boolean;
78
skipFormat?: boolean;

packages/nx-plugin/src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import { plugin } from './plugin/index.js';
1+
import { createNodes, createNodesV2 } from './plugin/index.js';
2+
3+
// default export for nx.json#plugins
4+
const plugin = {
5+
name: '@code-pushup/nx-plugin',
6+
createNodesV2,
7+
// Keep for backwards compatibility with Nx < 21
8+
createNodes,
9+
};
10+
11+
export default plugin;
212

3-
export { createNodes, createNodesV2 } from './plugin/index.js';
413
export type { AutorunCommandExecutorOptions } from './executors/cli/schema.js';
514
export { generateCodePushupConfig } from './generators/configuration/code-pushup-config.js';
615
export { configurationGenerator } from './generators/configuration/generator.js';
716
export type { ConfigurationGeneratorOptions } from './generators/configuration/schema.js';
817
export { initGenerator, initSchematic } from './generators/init/generator.js';
918
export { type InitGeneratorSchema } from './generators/init/schema.js';
1019
export * from './internal/versions.js';
11-
12-
export default plugin;
20+
export { createNodes, createNodesV2 } from './plugin/index.js';
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export type DynamicTargetOptions = {
22
targetName?: string;
33
bin?: string;
4-
env?: Record<string, string>;
54
};

packages/nx-plugin/src/internal/versions.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@ import type { PackageJson } from 'nx/src/utils/package-json';
55
const workspaceRoot = path.join(__dirname, '../../');
66
const projectsFolder = path.join(__dirname, '../../../');
77

8-
export const cpNxPluginVersion = readDependencyVersion(workspaceRoot);
9-
export const cpModelVersion = readDependencyVersion(
8+
export const cpNxPluginVersion = loadPackageJson(workspaceRoot).version;
9+
export const cpModelVersion = loadPackageJson(
1010
path.join(projectsFolder, 'cli'),
11-
);
12-
export const cpUtilsVersion = readDependencyVersion(
11+
).version;
12+
export const cpUtilsVersion = loadPackageJson(
1313
path.join(projectsFolder, 'utils'),
14-
);
15-
export const cpCliVersion = readDependencyVersion(
14+
).version;
15+
export const cpCliVersion = loadPackageJson(
1616
path.join(projectsFolder, 'models'),
17-
);
17+
).version;
1818

1919
/**
20-
* Load the package.json file from the given folder path and returns the package version.
21-
* If the version is not given of the package.json file does not exist it returns the fallback value.
20+
* Load the package.json file from the given folder path.
21+
* @param folderPath
2222
*/
23-
function readDependencyVersion(
24-
folderPath: string,
25-
fallbackVersion = 'latest',
26-
): string {
27-
try {
28-
return (
29-
readJsonFile<PackageJson>(path.join(folderPath, 'package.json'))
30-
.version ?? fallbackVersion
31-
);
32-
} catch {
33-
return fallbackVersion;
34-
}
23+
function loadPackageJson(folderPath: string): PackageJson {
24+
return readJsonFile<PackageJson>(path.join(folderPath, 'package.json'));
3525
}

0 commit comments

Comments
 (0)