Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { build } from './src/cmd/build.js';
import { deploy } from './src/cmd/deploy.js';
import { init } from './src/cmd/init.js';
import { serve } from './src/cmd/serve.js';
import { preFlightChecks } from './src/util/preFlightChecks.js';
import packageJson from './package.json' with { type: 'json' };

const CLI_VERSION = packageJson.version;
Expand All @@ -23,6 +24,9 @@ function printHeader() {
return '';
}

program
.hook('preAction', () => preFlightChecks());

program
.addHelpText('beforeAll', printHeader())
.showHelpAfterError('(run "markbind --help" to list commands)')
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"fs-extra": "^9.0.1",
"live-server": "1.2.1",
"lodash": "^4.17.15",
"semver": "^7.7.4",
"url-parse": "^1.5.10",
"winston": "^3.19.0",
"winston-daily-rotate-file": "^5.0.0"
Expand All @@ -53,6 +54,7 @@
"@babel/core": "^7.29.0",
"@babel/preset-env": "^7.29.0",
"@babel/preset-typescript": "^7.28.5",
"@types/semver": "^7.7.1",
"@types/jest": "^29.4.6",
"@types/lodash": "^4.17.15",
"@types/url-parse": "^1.4.8",
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/util/preFlightChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as semver from 'semver';
import * as logger from './logger.js';
import packageJson from '../../package.json' with { type: 'json' };

const CLI_VERSION = packageJson.version;

function checkNode() {
const nodeVersion = process.version;
const version = nodeVersion.slice(1);

if (semver.lt(version, '22.12.0')) {
logger.error(
`Markbind ${CLI_VERSION} requires Node >=22.12.0. `
Comment thread
Harjun751 marked this conversation as resolved.
Outdated
Comment thread
Harjun751 marked this conversation as resolved.
Outdated
+ 'Please update Node or use an older version of MarkBind!'

Check failure on line 14 in packages/cli/src/util/preFlightChecks.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Missing trailing comma
);
process.exit(1);
Comment on lines +17 to +21

Copilot AI Apr 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling process.exit(1) inside a utility invoked from Commander hooks makes this harder to test and can bypass any centralized error handling/cleanup. Prefer throwing an error (or a Commander-specific error type) and letting the CLI entrypoint decide the exit code.

Suggested change
logger.error(
`Markbind ${CLI_VERSION} requires Node >=22.12.0. `
+ 'Please update Node or use an older version of MarkBind!'
);
process.exit(1);
const message = `Markbind ${CLI_VERSION} requires Node >=22.12.0. `
+ 'Please update Node or use an older version of MarkBind!';
logger.error(message);
throw new Error(message);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking to leave this in. Throwing an error will print the whole stack trace to the user, it's ugly and less helpful from the user's standpoint IMO.

Instead I've added some explicit documentation through jsDoc that says calling the function may exit the process if checks fail.

}
Comment thread
Harjun751 marked this conversation as resolved.
}

export function preFlightChecks() {
checkNode();
}
Loading