Skip to content

Commit 33292aa

Browse files
jiangxinclaude
andcommitted
fix: improve Node.js compatibility for versions 18.x, 20.x, and 22.x
This commit addresses compatibility issues with different Node.js versions by: - Adding a compatibility tsconfig.compat.json for older Node.js versions - Updating tsconfig.dev.json with proper module and moduleResolution settings - Modifying the dev:compat script to use the new compatibility config - Cleaning up unnecessary Node.js version checks in the code - Removing unused imports in test files These changes ensure the project works consistently across Node.js 18.x, 20.x, and 22.x versions as verified by testing. Fixes compatibility issues that were causing GitHub Actions failures. 🤖 Generated with [Claude Code](https://claude.ai/code) Change-Id: I6fd74e2947a6cfc5ab481575313ee35c2452e2e7 Co-developed-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 70045e0 commit 33292aa

7 files changed

Lines changed: 27 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "node scripts/build.js",
1111
"start": "ts-node src/bin/commit-msg.ts",
1212
"dev": "NODE_ENV=development NODE_OPTIONS=--no-warnings npx ts-node --esm --transpileOnly --prefer-ts-exts --project tsconfig.dev.json src/bin/commit-msg.dev.ts",
13-
"dev:compat": "NODE_ENV=development NODE_OPTIONS=--no-warnings npx ts-node --transpileOnly --project tsconfig.dev.json src/bin/commit-msg.dev.ts",
13+
"dev:compat": "NODE_ENV=development NODE_OPTIONS=--no-warnings npx ts-node --transpileOnly --project tsconfig.compat.json src/bin/commit-msg.dev.ts",
1414
"test": "vitest run",
1515
"format": "npx prettier --write src/ test/",
1616
"lint": "npx eslint src/ test/",

src/bin/commit-msg.dev.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import { createRequire } from 'module';
77
const require = createRequire(import.meta.url);
88
const packageJson = require('../../package.json');
99

10-
// Check Node.js version and provide appropriate module handling
11-
const nodeVersion = process.version;
12-
const nodeMajorVersion = parseInt(nodeVersion.split('.')[0].replace('v', ''));
13-
1410
async function loadCommands() {
1511
// Dynamically import commands for development
1612
const { install } = await import('../commands/install.ts');

test/integration.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
describe,
3-
it,
4-
expect,
5-
beforeAll,
6-
afterAll,
7-
beforeEach,
8-
afterEach,
9-
} from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
102
import { execSync, spawnSync } from 'child_process';
113
import { existsSync, rmSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
124
import * as path from 'path';

test/pack.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2-
import { execSync, spawnSync } from 'child_process';
2+
import { spawnSync } from 'child_process';
33
import { existsSync, rmSync, mkdirSync } from 'fs';
44
import * as path from 'path';
55
import * as os from 'os';

test/version.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import { execSync } from 'child_process';
3-
import { existsSync, rmSync } from 'fs';
43

54
// Check Node.js version to determine which dev script to use
5+
// Node.js 18 has limited ESM support, so we use the compatibility script for versions < 20
66
const nodeVersion = process.version;
77
const nodeMajorVersion = parseInt(nodeVersion.split('.')[0].replace('v', ''));
88
const devScript = nodeMajorVersion >= 20 ? 'dev' : 'dev:compat';

tsconfig.compat.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"allowImportingTsExtensions": true,
6+
"module": "CommonJS",
7+
"moduleResolution": "node"
8+
},
9+
"ts-node": {
10+
"transpileOnly": true,
11+
"preferTsExts": true,
12+
"compilerOptions": {
13+
"module": "CommonJS",
14+
"moduleResolution": "node"
15+
}
16+
}
17+
}

tsconfig.dev.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"esm": true,
1212
"experimentalResolver": true,
1313
"transpileOnly": true,
14-
"preferTsExts": true
14+
"preferTsExts": true,
15+
"compilerOptions": {
16+
"module": "ESNext",
17+
"moduleResolution": "node"
18+
}
1519
}
1620
}

0 commit comments

Comments
 (0)