diff --git a/.env.example b/.env.example index 64dd9ba97..464d2983f 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,8 @@ -# for uploading to portal +# Example environment variables +# These are for reference only - use .env.local for local development + +# For uploading to Code PushUp portal CP_API_KEY= + +# Note: For local development with tsx/TypeScript execution, +# copy .env.local.example to .env.local and configure NODE_OPTIONS there diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 000000000..fe63e05ee --- /dev/null +++ b/.env.local.example @@ -0,0 +1,12 @@ +# Local development environment variables +# Copy this to .env.local (gitignored) and customize for your setup + +# Enable tsx for TypeScript execution in Nx +# This allows running local generator/executor directly as .ts files without pre-compilation +# This allowes the local plugins to import files with .js extensions (same as the packages in the repository) +NODE_OPTIONS=--import tsx +# This is used to resolve the paths in the local generator/executor so local packages can be imported as path aliases +TSX_TSCONFIG_PATH=tsconfig.base.json + +# Local API keys (optional - only if testing upload features) +# CP_API_KEY=your_api_key_here diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c71f05f4e..375866437 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: - name: Install dependencies run: npm ci - name: Check formatting of affected files - run: npx nx format:check + run: npm run ci:nx -- format:check lint: runs-on: ubuntu-latest @@ -49,7 +49,7 @@ jobs: - name: Install dependencies run: npm ci - name: Lint affected projects - run: npx nx affected -t lint --parallel=3 + run: npm run ci:nx -- affected -t lint --parallel=3 unit-test: strategy: @@ -73,7 +73,7 @@ jobs: - name: Install dependencies run: npm ci - name: Unit test affected projects - run: npx nx affected -t unit-test --parallel=3 + run: npm run ci:nx -- affected -t unit-test --parallel=3 integration-test: strategy: @@ -97,7 +97,7 @@ jobs: - name: Install dependencies run: npm ci - name: Integration test affected projects - run: npx nx affected -t int-test --parallel=3 + run: npm run ci:nx -- affected -t int-test --parallel=3 e2e: strategy: @@ -121,7 +121,7 @@ jobs: - name: Install dependencies run: npm ci - name: E2E test affected projects - run: npx nx affected -t e2e-test --parallel=1 + run: npm run ci:nx -- affected -t e2e-test --parallel=1 build: runs-on: ubuntu-latest @@ -141,6 +141,6 @@ jobs: - name: Install dependencies run: npm ci - name: Build all projects # affected is not used to be able to test-releae packages - run: npx nx run-many --target=build --parallel=3 + run: npm run ci:nx -- run-many --target=build --parallel=3 - name: Test-release packages run: npx pkg-pr-new publish "packages/**/dist" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 640a76e5d..fc512c4c7 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,7 @@ jobs: - name: List packages using Nx CLI id: list-packages run: | - matrix=$(node tools/scripts/create-codecov-matrix.js) + matrix=$(npm run ci:node -- tools/scripts/create-codecov-matrix.js) echo "matrix=$matrix" >> $GITHUB_OUTPUT outputs: matrix: ${{ steps.list-packages.outputs.matrix }} @@ -48,7 +48,7 @@ jobs: - name: Install dependencies run: npm ci - name: Execute tests with coverage - run: npx nx run ${{ matrix.project }}:${{ matrix.target }} + run: npm run ci:nx -- run ${{ matrix.project }}:${{ matrix.target }} - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e3896afee..ac1b27fbd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -42,4 +42,4 @@ jobs: - name: Install dependencies run: npm ci - name: Publish packages to npm - run: npx nx release publish + run: npm run ci:nx -- release publish diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d60e37bea..6dc413d8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,6 +46,6 @@ jobs: - name: Install dependencies run: npm ci - name: Version, release and generate changelog - run: npx nx release --skip-publish env: GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: npm run ci:nx -- release --skip-publish diff --git a/.gitignore b/.gitignore index 31d7e1678..1e6ef3822 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. .env +.env.local .npmrc # compiled output diff --git a/examples/plugins/src/package-json/README.md b/examples/plugins/src/package-json/README.md index 34546b094..b3141ffed 100644 --- a/examples/plugins/src/package-json/README.md +++ b/examples/plugins/src/package-json/README.md @@ -20,7 +20,6 @@ You can configure the plugin with the following options: 1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file. 2. Copy the [plugin source](../package-json) as is into your project - 1. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.js`). Pass in the path or the directory to crawl (relative to `process.cwd()`). diff --git a/package-lock.json b/package-lock.json index de389cb9b..17728d183 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,6 +76,7 @@ "chromium": "^3.0.3", "commitizen": "^4.3.1", "commitlint-plugin-tense": "^1.0.3", + "cross-env": "^10.1.0", "dotenv": "^16.4.5", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-functional": "^7.1.0", @@ -2792,6 +2793,13 @@ "tslib": "^2.4.0" } }, + "node_modules/@epic-web/invariant": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@epic-web/invariant/-/invariant-1.0.0.tgz", + "integrity": "sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==", + "dev": true, + "license": "MIT" + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.23.1", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", @@ -14349,6 +14357,24 @@ "node": ">=12.0.0" } }, + "node_modules/cross-env": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-10.1.0.tgz", + "integrity": "sha512-GsYosgnACZTADcmEyJctkJIoqAhHjttw7RsFrVoJNXbsWWqaq6Ym+7kZjq6mS45O0jij6vtiReppKQEtqWy6Dw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@epic-web/invariant": "^1.0.0", + "cross-spawn": "^7.0.6" + }, + "bin": { + "cross-env": "dist/bin/cross-env.js", + "cross-env-shell": "dist/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/cross-fetch": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", diff --git a/package.json b/package.json index 52a48a7d4..3c5bb4446 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "scripts": { "prepare": "husky install", "commit": "git-cz", - "knip": "knip" + "knip": "knip", + "ci:nx": "node tools/scripts/ci-tsx.js nx", + "ci:node": "node tools/scripts/ci-tsx.js node" }, "private": true, "dependencies": { @@ -86,6 +88,7 @@ "chromium": "^3.0.3", "commitizen": "^4.3.1", "commitlint-plugin-tense": "^1.0.3", + "cross-env": "^10.1.0", "dotenv": "^16.4.5", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-functional": "^7.1.0", diff --git a/packages/plugin-eslint/README.md b/packages/plugin-eslint/README.md index 8a4ca9027..31b296864 100644 --- a/packages/plugin-eslint/README.md +++ b/packages/plugin-eslint/README.md @@ -72,7 +72,6 @@ Detected ESLint rules are mapped to Code PushUp audits. Audit reports are calcul ``` If you're using an Nx monorepo, additional helper functions are provided to simplify your configuration: - - If you wish to combine all projects in your workspace into one report, use the `eslintConfigFromAllNxProjects` helper: ```js diff --git a/tools/scripts/ci-tsx.js b/tools/scripts/ci-tsx.js new file mode 100644 index 000000000..22fad1a94 --- /dev/null +++ b/tools/scripts/ci-tsx.js @@ -0,0 +1,48 @@ +// @ts-check +import { spawn } from 'node:child_process'; +import { resolve } from 'node:path'; + +// Determine the workspace root (GITHUB_WORKSPACE or current working directory) +const workspaceRoot = process.env.GITHUB_WORKSPACE || process.cwd(); +const tsconfigPath = resolve(workspaceRoot, 'tsconfig.base.json'); + +// Set up environment variables +const env = { + ...process.env, + NODE_OPTIONS: '--import tsx', + TSX_TSCONFIG_PATH: tsconfigPath, +}; + +// Get the command and its arguments from the command line +const [command, ...args] = process.argv.slice(2); + +if (!command) { + console.error('Usage: node ci-tsx.js [args...]'); + console.error('Example: node ci-tsx.js nx affected -t test'); + process.exit(1); +} + +// Log the command being executed +console.log(`> ${command} ${args.join(' ')}`); + +// Spawn the command with the configured environment +const child = spawn(command, args, { + env, + stdio: 'inherit', + shell: true, +}); + +// Forward exit code +child.on('exit', (code, signal) => { + if (signal) { + process.kill(process.pid, signal); + } else { + process.exit(code ?? 0); + } +}); + +// Handle errors +child.on('error', error => { + console.error('Failed to start child process:', error); + process.exit(1); +});