Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions packages/cli/src/util/preFlightChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as semver from 'semver';
import * as logger from './logger.js';
import packageJson from '../../package.json' with { type: 'json' };

const CLI_VERSION = packageJson.version;
const REQUIRED_NODE_VERSION = '22.12.0';

function checkNode() {
const nodeVersion = process.version;
const version = semver.coerce(nodeVersion);

if (version === null) {
logger.warn('Unknown version of node detected.');
return;
}
if (semver.lt(version, REQUIRED_NODE_VERSION)) {
logger.error(
`Markbind ${CLI_VERSION} requires node >=${REQUIRED_NODE_VERSION}. `
+ 'Please update node or use an older version of Markbind!',
);
process.exit(1);
Comment on lines +17 to +21
Copy link

Copilot AI Apr 16, 2026

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.
}

/**
* Performs pre-usage checks to ensure the application will run as expected.
* This method may exit the process if checks fail.
*/
export function preFlightChecks() {
checkNode();
}
Loading