Skip to content

Commit ccbaa8b

Browse files
committed
fix: resolve CLI packaging issue causing GitHub Actions failures
The tests in test/pack.test.ts were failing because the packaged CLI was not working when installed via npm. Specifically, npx commit-msg --version was returning exit code 1 instead of 0, causing assertions to fail. Root cause: The CLI entry point files were using experimental import syntax for package.json that doesn't work reliably in packaged environments: import packageJson from '../../package.json' with { type: 'json' }; This syntax was causing the CLI to crash on startup in CI environments. Solution: Replace the experimental import with Node.js's createRequire function: import { createRequire } from 'module'; const require = createRequire(import.meta.url); const packageJson = require('../../package.json'); This standard approach works consistently in both development and packaged environments, resolving the GitHub Actions test failures. Change-Id: I95d8f9bb058dcde3f91314b9cbdbbcb9b6630a33 Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
1 parent e6c5b86 commit ccbaa8b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/bin/commit-msg.dev.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// commit-msg CLI entry point for development
44

55
import { Command } from 'commander';
6-
import packageJson from '../../package.json' with { type: 'json' };
6+
import { createRequire } from 'module';
7+
const require = createRequire(import.meta.url);
8+
const packageJson = require('../../package.json');
79

810
// Import commands using relative paths with .ts extension for development
911
import { install } from '../commands/install.ts';

‎src/bin/commit-msg.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// commit-msg CLI entry point
44

55
import { Command } from 'commander';
6-
import packageJson from '../../package.json' with { type: 'json' };
6+
import { createRequire } from 'module';
7+
const require = createRequire(import.meta.url);
8+
const packageJson = require('../../package.json');
79

810
// Import commands using relative paths
911
import { install } from '../commands/install.js';

0 commit comments

Comments
 (0)