fix(cli): add early Node.js version check wrapper#767
Conversation
This adds a CJS wrapper to cleanly validate the Node.js version against engines.node before executing the ESM entry point. Resolves NodeSecure#763.
|
|
Hmm any specific reason why you forced on CommonJS instead of implementing the same in ESM? |
|
I reviewed this after seeing #763. The early check itself makes sense, and CI is green. On the CommonJS question: I think this can stay ESM without importing the heavy CLI entrypoint before the version check. For example, #!/usr/bin/env node
import { createRequire } from "node:module";
import semver from "semver";
const require = createRequire(import.meta.url);
const manifest = require("../package.json");
const currentVersion = process.versions.node;
const requiredRange = manifest.engines.node;
if (!semver.satisfies(currentVersion, requiredRange)) {
console.error(`\n @nodesecure/cli requires Node.js ${requiredRange}.` +
`\n Current version: v${currentVersion}\n`);
process.exit(1);
}
await import("./index.js");That keeps the guard before |
Adds an early Node.js version check.
Resolves #763