diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e8c8e23a5..060d789d4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,6 +83,21 @@ Therefore, PRs are merged via one of two strategies: - rebase - branch cannot contain merge commits ([rebase instead of merge](https://www.atlassian.com/git/tutorials/merging-vs-rebasing)), - squash - single commit whose message is the PR title (should be in conventional commit format). +## Releases + +We use nx release command to create releases for GitHub as well as publish to npm. + +**Preconditions:** + +- `npm login` - Only users with write access to [code-pushup](https://www.npmjs.com/org/code-pushup) can publish +- (optional) `GITHUB_TOKEN=ghp_...` in `.env` - [Personal access token](https://github.com/settings/personal-access-tokens/new) to create a GitHub release. + +**Steps:** + +- `git checkout main`, `git pull` +- (recommended optional) `npx nx release --dryRun` +- `npx nx release` and confirm publish prompt + ## Project tags [Nx tags](https://nx.dev/core-features/enforce-module-boundaries) are used to enforce module boundaries in the project graph when linting. diff --git a/code-pushup.config.ts b/code-pushup.config.ts index 4ea96774f..0f0f669fa 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -20,6 +20,9 @@ const config: CoreConfig = { server: 'https://api.staging.code-pushup.dev/graphql', apiKey: process.env['CP_API_KEY'], }, + persist: { + outputDir: '.code-pushup', + }, }), plugins: [], }; 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..126bee6e2 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 @@ -229,7 +229,7 @@ describe('nx-plugin', () => { }); it('should consider plugin option projectPrefix in executor target', async () => { - const cwd = path.join(testFileDir, 'configuration-option-bin'); + const cwd = path.join(testFileDir, 'configuration-option-projectPrefix'); registerPluginInWorkspace(tree, { plugin: '@code-pushup/nx-plugin', options: { diff --git a/nx.json b/nx.json index b612c5eed..29692510d 100644 --- a/nx.json +++ b/nx.json @@ -344,6 +344,9 @@ "releaseTagPattern": "v{version}" }, "plugins": [ + { + "plugin": "@code-pushup/nx-plugin" + }, { "plugin": "@push-based/nx-verdaccio", "options": { diff --git a/package-lock.json b/package-lock.json index 6b81834f4..a2b46aed0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.0.0", "license": "MIT", "dependencies": { - "@code-pushup/portal-client": "^0.16.0", "@isaacs/cliui": "^8.0.2", "@nx/devkit": "21.4.1", "@poppinss/cliui": "6.4.1", @@ -39,7 +38,10 @@ "@actions/core": "^1.11.1", "@actions/github": "^6.0.1", "@beaussan/nx-knip": "^0.0.5-15", + "@code-pushup/cli": "^0.79.1", "@code-pushup/eslint-config": "^0.14.2", + "@code-pushup/nx-plugin": "^0.79.1", + "@code-pushup/portal-client": "^0.16.0", "@commitlint/cli": "^19.5.0", "@commitlint/config-conventional": "^19.5.0", "@commitlint/config-nx-scopes": "^19.5.0", @@ -2317,6 +2319,47 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/@code-pushup/cli": { + "version": "0.79.1", + "resolved": "https://registry.npmjs.org/@code-pushup/cli/-/cli-0.79.1.tgz", + "integrity": "sha512-rV5IjoAlcV86sFby2t/9mi7Vkwn/CiqA+wPvnQeoWLjPJBDVOuDl9HA1dwUcaynYZjQPB9IpBpThP7tMfBE/vw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@code-pushup/core": "0.79.1", + "@code-pushup/models": "0.79.1", + "@code-pushup/utils": "0.79.1", + "ansis": "^3.3.0", + "simple-git": "^3.20.0", + "yargs": "^17.7.2" + }, + "bin": { + "code-pushup": "src/index.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@code-pushup/core": { + "version": "0.79.1", + "resolved": "https://registry.npmjs.org/@code-pushup/core/-/core-0.79.1.tgz", + "integrity": "sha512-RNA8uQ0pFiaH5OFzo3fz4U+rdBdF3EuLkCkoQ3nWY8Q+n9BzLRyiH827+uOUR9dBC22gbvZ1hDK22JeQbUUcrw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@code-pushup/models": "0.79.1", + "@code-pushup/utils": "0.79.1", + "ansis": "^3.3.0" + }, + "peerDependencies": { + "@code-pushup/portal-client": "^0.16.0" + }, + "peerDependenciesMeta": { + "@code-pushup/portal-client": { + "optional": true + } + } + }, "node_modules/@code-pushup/eslint-config": { "version": "0.14.2", "resolved": "https://registry.npmjs.org/@code-pushup/eslint-config/-/eslint-config-0.14.2.tgz", @@ -2401,10 +2444,37 @@ } } }, + "node_modules/@code-pushup/models": { + "version": "0.79.1", + "resolved": "https://registry.npmjs.org/@code-pushup/models/-/models-0.79.1.tgz", + "integrity": "sha512-V/8EFG2FNVhsESUnKDsso+BBOjrHO2E5phbA3qOWmM0YG7AnEpIduOlysZMhvU5Y5oakcWueLCxvyFbBGl8PHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "vscode-material-icons": "^0.1.0", + "zod": "^4.0.5" + } + }, + "node_modules/@code-pushup/nx-plugin": { + "version": "0.79.1", + "resolved": "https://registry.npmjs.org/@code-pushup/nx-plugin/-/nx-plugin-0.79.1.tgz", + "integrity": "sha512-5nsdtWcPE3i0a5vB36c5smxYjUaY/ZEghCi1xxEe8dlOFrZQZTzEPOQ+kwc/jSBoI1hA5p+tRuO+IDYcTZoHaQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@code-pushup/models": "0.79.1", + "@code-pushup/utils": "0.79.1", + "@nx/devkit": ">=17.0.0", + "ansis": "^3.3.0", + "nx": ">=17.0.0", + "zod": "^4.0.5" + } + }, "node_modules/@code-pushup/portal-client": { "version": "0.16.0", "resolved": "https://registry.npmjs.org/@code-pushup/portal-client/-/portal-client-0.16.0.tgz", "integrity": "sha512-JlMRcTKkJygVfLS+IWQxDRDnvF64p4q+QDLIXzQPep6X99C1OH3MnA9jbfGAOew/3xqOILCrifn0y54fyRs8Qg==", + "dev": true, "license": "MIT", "dependencies": { "graphql": "^16.6.0", @@ -2413,6 +2483,29 @@ "vscode-material-icons": "^0.1.0" } }, + "node_modules/@code-pushup/utils": { + "version": "0.79.1", + "resolved": "https://registry.npmjs.org/@code-pushup/utils/-/utils-0.79.1.tgz", + "integrity": "sha512-n4Ay1T390dAJqEjgP0R/xW8XduZaKEIDI7DLt4YfqeikKc56oPzT6kBApV1rzS0vCS7IUHtO95bNiYW3cteGUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@code-pushup/models": "0.79.1", + "@isaacs/cliui": "^8.0.2", + "@poppinss/cliui": "^6.4.0", + "ansis": "^3.3.0", + "build-md": "^0.4.2", + "bundle-require": "^5.1.0", + "esbuild": "^0.25.2", + "multi-progress-bars": "^5.0.3", + "semver": "^7.6.0", + "simple-git": "^3.20.0", + "zod": "^4.0.5" + }, + "engines": { + "node": ">=17.0.0" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -3357,6 +3450,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", + "dev": true, "peerDependencies": { "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } @@ -14087,6 +14181,7 @@ "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "dev": true, "dependencies": { "node-fetch": "^2.6.12" } @@ -15069,7 +15164,7 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "iconv-lite": "^0.6.2" @@ -15079,7 +15174,7 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -18139,6 +18234,7 @@ "version": "16.9.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", + "dev": true, "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -18147,6 +18243,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-6.1.0.tgz", "integrity": "sha512-p+XPfS4q7aIpKVcgmnZKhMNqhltk20hfXtkaIkTfjjmiKMJ5xrt5c743cL03y/K7y1rg3WrIC49xGiEQ4mxdNw==", + "dev": true, "dependencies": { "@graphql-typed-document-node/core": "^3.2.0", "cross-fetch": "^3.1.5" @@ -18159,6 +18256,7 @@ "version": "2.12.6", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==", + "dev": true, "dependencies": { "tslib": "^2.1.0" }, @@ -23444,6 +23542,7 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dev": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -23462,17 +23561,20 @@ "node_modules/node-fetch/node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "dev": true }, "node_modules/node-fetch/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "dev": true }, "node_modules/node-fetch/node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dev": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -27126,7 +27228,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "devOptional": true + "dev": true }, "node_modules/saxes": { "version": "6.0.0", diff --git a/package.json b/package.json index 385e84c8c..2907214d0 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "node": ">=22.14" }, "dependencies": { - "@code-pushup/portal-client": "^0.16.0", "@isaacs/cliui": "^8.0.2", "@nx/devkit": "21.4.1", "@poppinss/cliui": "6.4.1", @@ -49,10 +48,13 @@ "zod": "^4.0.5" }, "devDependencies": { + "@code-pushup/portal-client": "^0.16.0", "@actions/core": "^1.11.1", "@actions/github": "^6.0.1", "@beaussan/nx-knip": "^0.0.5-15", + "@code-pushup/cli": "^0.79.1", "@code-pushup/eslint-config": "^0.14.2", + "@code-pushup/nx-plugin": "^0.79.1", "@commitlint/cli": "^19.5.0", "@commitlint/config-conventional": "^19.5.0", "@commitlint/config-nx-scopes": "^19.5.0", diff --git a/packages/nx-plugin/src/executors/cli/utils.ts b/packages/nx-plugin/src/executors/cli/utils.ts index 5530e00c0..5641b07dd 100644 --- a/packages/nx-plugin/src/executors/cli/utils.ts +++ b/packages/nx-plugin/src/executors/cli/utils.ts @@ -34,7 +34,7 @@ export function parseAutorunExecutorOptions( options: Partial, normalizedContext: NormalizedExecutorContext, ): AutorunCommandExecutorOptions { - const { projectPrefix, persist, upload, command } = options; + const { projectPrefix, persist, upload, command, output } = options; const needsUploadParams = command === 'upload' || command === 'autorun' || command === undefined; const uploadCfg = uploadConfig( @@ -46,6 +46,7 @@ export function parseAutorunExecutorOptions( ...parsePrintConfigExecutorOptions(options), ...parseAutorunExecutorOnlyOptions(options), ...globalConfig(options, normalizedContext), + ...(output ? { output } : {}), persist: persistConfig({ projectPrefix, ...persist }, normalizedContext), // @TODO This is a hack to avoid validation errors of upload config for commands that dont need it. // Fix: use utils and execute the core logic directly diff --git a/packages/nx-plugin/src/executors/cli/utils.unit.test.ts b/packages/nx-plugin/src/executors/cli/utils.unit.test.ts index 025c322fb..647640215 100644 --- a/packages/nx-plugin/src/executors/cli/utils.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/utils.unit.test.ts @@ -170,6 +170,33 @@ describe('parseAutorunExecutorOptions', () => { ); }, ); + + it.each(['print-config'])( + 'should include output config for command %s', + command => { + const projectName = 'my-app'; + const executorOptions = parseAutorunExecutorOptions( + { + command, + output: 'code-pushup.config.json', + }, + { + projectName, + workspaceRoot: 'workspaceRoot', + projectConfig: { + name: 'my-app', + root: 'root', + }, + }, + ); + + expect(executorOptions).toEqual( + expect.objectContaining({ + output: 'code-pushup.config.json', + }), + ); + }, + ); }); describe('mergeExecutorOptions', () => { diff --git a/packages/nx-plugin/src/executors/internal/cli.ts b/packages/nx-plugin/src/executors/internal/cli.ts index bab74a8f1..330c67fa5 100644 --- a/packages/nx-plugin/src/executors/internal/cli.ts +++ b/packages/nx-plugin/src/executors/internal/cli.ts @@ -26,7 +26,7 @@ export function createCliCommandObject(options?: { logger.error(error.message); }, onStdout: data => { - logger.log(data); + process.stdout.write(data); }, }, }; diff --git a/packages/nx-plugin/src/index.ts b/packages/nx-plugin/src/index.ts index 356be758c..5582aced5 100644 --- a/packages/nx-plugin/src/index.ts +++ b/packages/nx-plugin/src/index.ts @@ -1,15 +1,7 @@ +import type { CreateNodesV2, NxPlugin } from '@nx/devkit'; import { createNodes, createNodesV2 } from './plugin/index.js'; -// default export for nx.json#plugins -const plugin = { - name: '@code-pushup/nx-plugin', - createNodesV2, - // Keep for backwards compatibility with Nx < 21 - createNodes, -}; - -export default plugin; - +export { createNodes, createNodesV2 } from './plugin/index.js'; export type { AutorunCommandExecutorOptions } from './executors/cli/schema.js'; export { objectToCliArgs } from './executors/internal/cli.js'; export { generateCodePushupConfig } from './generators/configuration/code-pushup-config.js'; @@ -22,4 +14,9 @@ export { type ProcessConfig, } from './internal/execute-process.js'; export * from './internal/versions.js'; -export { createNodes, createNodesV2 } from './plugin/index.js'; + +export default { + name: 'code-pushup', + createNodesV2: createNodesV2 as CreateNodesV2, + createNodes, +} satisfies NxPlugin; diff --git a/packages/nx-plugin/src/plugin/index.ts b/packages/nx-plugin/src/plugin/index.ts index 6af7c1076..4f21f2a12 100644 --- a/packages/nx-plugin/src/plugin/index.ts +++ b/packages/nx-plugin/src/plugin/index.ts @@ -1,2 +1,12 @@ +import type { NxPlugin } from '@nx/devkit'; +import { createNodesV2 } from './plugin.js'; + export { createNodes, createNodesV2 } from './plugin.js'; export type { CreateNodesOptions } from './types.js'; + +const plugin = { + createNodesV2, + name: 'code-pushup-nx-plugin', +} satisfies NxPlugin; + +export default plugin; diff --git a/packages/nx-plugin/src/plugin/plugin.ts b/packages/nx-plugin/src/plugin/plugin.ts index 1b4e3e2f1..489468558 100644 --- a/packages/nx-plugin/src/plugin/plugin.ts +++ b/packages/nx-plugin/src/plugin/plugin.ts @@ -39,14 +39,15 @@ export const createNodes: CreateNodes = [ }, ]; -export const createNodesV2: CreateNodesV2 = [ +export const createNodesV2: CreateNodesV2 = [ `**/${PROJECT_JSON_FILE_NAME}`, async ( projectConfigurationFiles: readonly string[], createNodesOptions: unknown, context: CreateNodesContextV2, ): Promise => { - const parsedCreateNodesOptions = createNodesOptions as CreateNodesOptions; + const parsedCreateNodesOptions = + (createNodesOptions as CreateNodesOptions) ?? {}; return await Promise.all( projectConfigurationFiles.map(async projectConfigurationFile => { diff --git a/project.json b/project.json index c53ed1a80..7e5be7514 100644 --- a/project.json +++ b/project.json @@ -25,19 +25,6 @@ ] }, "code-pushup-jsdocs": {}, - "code-pushup-typescript": {}, - "code-pushup": { - "dependsOn": ["code-pushup-*"], - "executor": "nx:run-commands", - "options": { - "args": [ - "--no-progress", - "--verbose", - "--cache.read", - "--persist.outputDir={projectRoot}/.code-pushup", - "--upload.project={projectName}" - ] - } - } + "code-pushup-typescript": {} } }