Skip to content

Commit 1b3837d

Browse files
committed
chore: use tsx when execution nx to have local plugins working
1 parent 3dbf378 commit 1b3837d

File tree

9 files changed

+82
-12
lines changed

9 files changed

+82
-12
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
# for uploading to portal
1+
# Example environment variables
2+
# These are for reference only - use .env.local for local development
3+
4+
# For uploading to Code PushUp portal
25
CP_API_KEY=
6+
7+
# Note: For local development with tsx/TypeScript execution,
8+
# copy .env.local.example to .env.local and configure NODE_OPTIONS there

.env.local.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Local development environment variables
2+
# Copy this to .env.local (gitignored) and customize for your setup
3+
4+
# Enable tsx for TypeScript execution in Nx
5+
# This allows running local generator/executor directly as .ts files without pre-compilation
6+
# This allowes the local plugins to import files with .js extensions (same as the packages in the repository)
7+
NODE_OPTIONS=--import tsx
8+
# This is used to resolve the paths in the local generator/executor so local packages can be imported as path aliases
9+
TSX_TSCONFIG_PATH=tsconfig.base.json
10+
11+
# Local API keys (optional - only if testing upload features)
12+
# CP_API_KEY=your_api_key_here

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install dependencies
3030
run: npm ci
3131
- name: Check formatting of affected files
32-
run: npx nx format:check
32+
run: npm run ci:nx -- format:check
3333

3434
lint:
3535
runs-on: ubuntu-latest
@@ -49,7 +49,7 @@ jobs:
4949
- name: Install dependencies
5050
run: npm ci
5151
- name: Lint affected projects
52-
run: npx nx affected -t lint --parallel=3
52+
run: npm run ci:nx -- affected -t lint --parallel=3
5353

5454
unit-test:
5555
strategy:
@@ -73,7 +73,7 @@ jobs:
7373
- name: Install dependencies
7474
run: npm ci
7575
- name: Unit test affected projects
76-
run: npx nx affected -t unit-test --parallel=3
76+
run: npm run ci:nx -- affected -t unit-test --parallel=3
7777

7878
integration-test:
7979
strategy:
@@ -97,7 +97,7 @@ jobs:
9797
- name: Install dependencies
9898
run: npm ci
9999
- name: Integration test affected projects
100-
run: npx nx affected -t int-test --parallel=3
100+
run: npm run ci:nx -- affected -t int-test --parallel=3
101101

102102
e2e:
103103
strategy:
@@ -121,7 +121,7 @@ jobs:
121121
- name: Install dependencies
122122
run: npm ci
123123
- name: E2E test affected projects
124-
run: npx nx affected -t e2e-test --parallel=1
124+
run: npm run ci:nx -- affected -t e2e-test --parallel=1
125125

126126
build:
127127
runs-on: ubuntu-latest
@@ -141,6 +141,6 @@ jobs:
141141
- name: Install dependencies
142142
run: npm ci
143143
- name: Build all projects # affected is not used to be able to test-releae packages
144-
run: npx nx run-many --target=build --parallel=3
144+
run: npm run ci:nx -- run-many --target=build --parallel=3
145145
- name: Test-release packages
146146
run: npx pkg-pr-new publish "packages/**/dist"

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: List packages using Nx CLI
2626
id: list-packages
2727
run: |
28-
matrix=$(node tools/scripts/create-codecov-matrix.js)
28+
matrix=$(npm run ci:node -- tools/scripts/create-codecov-matrix.js)
2929
echo "matrix=$matrix" >> $GITHUB_OUTPUT
3030
outputs:
3131
matrix: ${{ steps.list-packages.outputs.matrix }}
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install dependencies
4949
run: npm ci
5050
- name: Execute tests with coverage
51-
run: npx nx run ${{ matrix.project }}:${{ matrix.target }}
51+
run: npm run ci:nx -- run ${{ matrix.project }}:${{ matrix.target }}
5252
- name: Upload coverage reports to Codecov
5353
uses: codecov/codecov-action@v4
5454
with:

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ jobs:
4242
- name: Install dependencies
4343
run: npm ci
4444
- name: Publish packages to npm
45-
run: npx nx release publish
45+
run: npm run ci:nx -- release publish

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ jobs:
4646
- name: Install dependencies
4747
run: npm ci
4848
- name: Version, release and generate changelog
49-
run: npx nx release --skip-publish
5049
env:
5150
GH_TOKEN: ${{ steps.app-token.outputs.token }}
51+
run: npm run ci:nx -- release --skip-publish

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

33
.env
4+
.env.local
45
.npmrc
56

67
# compiled output

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"scripts": {
1616
"prepare": "husky install",
1717
"commit": "git-cz",
18-
"knip": "knip"
18+
"knip": "knip",
19+
"ci:nx": "node tools/scripts/ci-tsx.js nx",
20+
"ci:node": "node tools/scripts/ci-tsx.js node"
1921
},
2022
"private": true,
2123
"dependencies": {
@@ -86,6 +88,7 @@
8688
"chromium": "^3.0.3",
8789
"commitizen": "^4.3.1",
8890
"commitlint-plugin-tense": "^1.0.3",
91+
"cross-env": "^10.1.0",
8992
"dotenv": "^16.4.5",
9093
"eslint-import-resolver-typescript": "^3.6.1",
9194
"eslint-plugin-functional": "^7.1.0",

tools/scripts/ci-tsx.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @ts-check
2+
import { spawn } from 'node:child_process';
3+
import { resolve } from 'node:path';
4+
5+
// Determine the workspace root (GITHUB_WORKSPACE or current working directory)
6+
const workspaceRoot = process.env.GITHUB_WORKSPACE || process.cwd();
7+
const tsconfigPath = resolve(workspaceRoot, 'tsconfig.base.json');
8+
9+
// Set up environment variables
10+
const env = {
11+
...process.env,
12+
NODE_OPTIONS: '--import tsx',
13+
TSX_TSCONFIG_PATH: tsconfigPath,
14+
};
15+
16+
// Get the command and its arguments from the command line
17+
const [command, ...args] = process.argv.slice(2);
18+
19+
if (!command) {
20+
console.error('Usage: node ci-tsx.js <command> [args...]');
21+
console.error('Example: node ci-tsx.js nx affected -t test');
22+
process.exit(1);
23+
}
24+
25+
// Log the command being executed
26+
console.log(`> ${command} ${args.join(' ')}`);
27+
28+
// Spawn the command with the configured environment
29+
const child = spawn(command, args, {
30+
env,
31+
stdio: 'inherit',
32+
shell: true,
33+
});
34+
35+
// Forward exit code
36+
child.on('exit', (code, signal) => {
37+
if (signal) {
38+
process.kill(process.pid, signal);
39+
} else {
40+
process.exit(code ?? 0);
41+
}
42+
});
43+
44+
// Handle errors
45+
child.on('error', error => {
46+
console.error('Failed to start child process:', error);
47+
process.exit(1);
48+
});

0 commit comments

Comments
 (0)