The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(cli): report the Node requirement when launched with npx (#27932)
Weikod126c44faeed
diff --git a/packages/twenty-cli/package.json b/packages/twenty-cli/package.jsonindex 82547f79b31..e8f28aa3abd 100644--- a/packages/twenty-cli/package.json+++ b/packages/twenty-cli/package.json@@ -23,9 +23,6 @@"build": "npx rimraf dist && npx vite build","prepublish": "node scripts/prepublish.mjs"},- "engines": {- "node": "^24.5.0"- },"devDependencies": {"@sniptt/guards": "^0.2.0","@types/lodash.startcase": "^4",@@ -34,6 +31,7 @@"cjs-module-lexer": "^2.2.0","commander": "^14.0.3","lodash.startcase": "^4.4.0",+ "npm-pick-manifest": "^11.0.1","semver": "7.6.3","twenty-client-sdk": "workspace:*","twenty-shared": "workspace:*",diff --git a/packages/twenty-cli/project.json b/packages/twenty-cli/project.jsonindex b3d45fc8c4b..ac4d5c0c642 100644--- a/packages/twenty-cli/project.json+++ b/packages/twenty-cli/project.json@@ -25,7 +25,7 @@"dependsOn": ["build"],"cache": false,"options": {- "command": "node --test packages/twenty-cli/scripts/test-check-publish.mjs packages/twenty-cli/scripts/test-template-lock.mjs packages/twenty-cli/scripts/test-package.mjs"+ "command": "node --test packages/twenty-cli/scripts/test-npm-resolution.mjs packages/twenty-cli/scripts/test-check-publish.mjs packages/twenty-cli/scripts/test-template-lock.mjs packages/twenty-cli/scripts/test-package.mjs"}},"test": {diff --git a/packages/twenty-cli/scripts/test-npm-resolution.mjs b/packages/twenty-cli/scripts/test-npm-resolution.mjsnew file mode 100644index 00000000000..dc8f4d186ad--- /dev/null+++ b/packages/twenty-cli/scripts/test-npm-resolution.mjs@@ -0,0 +1,34 @@+import { strict as assert } from 'node:assert';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import pickManifest from 'npm-pick-manifest';++const manifest = JSON.parse(+ await readFile(new URL('../package.json', import.meta.url), 'utf8'),+);++for (const nodeVersion of [+ '18.17.1',+ '22.12.0',+ '24.4.1',+ '24.5.0',+ '25.0.0',+]) {+ await test(`npm selects the CLI instead of the placeholder on Node ${nodeVersion}`, () => {+ const resolved = pickManifest(+ {+ name: manifest.name,+ 'dist-tags': { latest: manifest.version },+ versions: {+ '0.3.0': { name: manifest.name, version: '0.3.0' },+ [manifest.version]: structuredClone(manifest),+ },+ },+ '*',+ { nodeVersion },+ );++ assert.equal(resolved.version, manifest.version);+ assert.equal(resolved.bin[manifest.name], manifest.bin);+ });+}diff --git a/packages/twenty-cli/src/__tests__/start-cli.spec.ts b/packages/twenty-cli/src/__tests__/start-cli.spec.tsindex 7be874e1ff8..5a0b2897c20 100644--- a/packages/twenty-cli/src/__tests__/start-cli.spec.ts+++ b/packages/twenty-cli/src/__tests__/start-cli.spec.ts@@ -1,7 +1,6 @@import { afterEach, describe, expect, it, vi } from 'vitest';-import { engines } from '../../package.json';-+import { CLI_NODE_VERSION_RANGE } from '@/constants/cli-node-version-range.constant';import { startCli } from '@/start-cli';describe('startCli', () => {@@ -10,40 +9,45 @@ describe('startCli', () => {vi.restoreAllMocks();});- it('runs the loaded CLI with the command line arguments', async () => {- const runCli = vi.fn(async () => undefined);-- await startCli({- args: ['version'],- nodeVersion: process.versions.node,- loadCli: async () => ({ runCli }),- });-- expect(runCli).toHaveBeenCalledWith(['version']);- });+ it.each(['24.5.0', '24.12.0', '25.0.0', '26.0.0'])(+ 'runs the loaded CLI on supported Node %s',+ async (nodeVersion) => {+ const runCli = vi.fn(async () => undefined);- it('explains the Node requirement when the CLI cannot load on an unsupported Node', async () => {- const stderr = vi.spyOn(process.stderr, 'write').mockReturnValue(true);-- await startCli({- args: ['version'],- nodeVersion: '18.17.1',- loadCli: async () => {- throw new Error('crypto.getRandomValues() not supported.');- },- });-- expect(stderr).toHaveBeenCalledWith(- `twenty requires Node.js ${engines.node}; this is Node.js 18.17.1. Switch to a supported Node.js version, then try again.\n`,- );- expect(process.exitCode).toBe(1);- });+ await startCli({+ args: ['version'],+ nodeVersion,+ loadCli: async () => ({ runCli }),+ });++ expect(runCli).toHaveBeenCalledTimes(1);+ expect(runCli).toHaveBeenCalledWith(['version']);+ },+ );++ it.each(['18.17.1', '22.12.0', '24.4.1'])(+ 'rejects unsupported Node %s before loading the CLI',+ async (nodeVersion) => {+ const stderr = vi.spyOn(process.stderr, 'write').mockReturnValue(true);+ const runCli = vi.fn(async () => undefined);+ const loadCli = vi.fn(async () => ({ runCli }));++ await startCli({ args: ['version'], nodeVersion, loadCli });++ expect(stderr).toHaveBeenCalledWith(+ `twenty requires Node.js ${CLI_NODE_VERSION_RANGE}; this is Node.js ${nodeVersion}. Switch to a supported Node.js version, then try again.\n`,+ );+ expect(process.exitCode).toBe(1);+ expect(loadCli).not.toHaveBeenCalled();+ expect(runCli).not.toHaveBeenCalled();+ },+ );it('keeps load failures on a supported Node visible', async () => {await expect(startCli({args: ['version'],- nodeVersion: process.versions.node,+ nodeVersion: '24.5.0',loadCli: async () => {throw new Error('broken bundle');},diff --git a/packages/twenty-cli/src/constants/cli-node-version-range.constant.ts b/packages/twenty-cli/src/constants/cli-node-version-range.constant.tsnew file mode 100644index 00000000000..66c34b17892--- /dev/null+++ b/packages/twenty-cli/src/constants/cli-node-version-range.constant.ts@@ -0,0 +1 @@+export const CLI_NODE_VERSION_RANGE = '>=24.5.0';diff --git a/packages/twenty-cli/src/doctor/get-runtime-doctor-checks.ts b/packages/twenty-cli/src/doctor/get-runtime-doctor-checks.tsindex 43a35766204..b6f730e1b09 100644--- a/packages/twenty-cli/src/doctor/get-runtime-doctor-checks.ts+++ b/packages/twenty-cli/src/doctor/get-runtime-doctor-checks.ts@@ -1,6 +1,5 @@-import { engines } from '../../package.json';-import { checkNodeRequirement } from '@/app/project/check-node-requirement';+import { CLI_NODE_VERSION_RANGE } from '@/constants/cli-node-version-range.constant';import { CLI_VERSION } from '@/constants/cli-version.constant';import { type DoctorCheck } from '@/doctor/types/doctor-check.type';@@ -8,18 +7,21 @@ export const getRuntimeDoctorChecks = (): DoctorCheck[] => {const isSupported =checkNodeRequirement({version: process.versions.node,- range: engines.node,+ range: CLI_NODE_VERSION_RANGE,}) === 'satisfied';return [{id: 'node',status: isSupported ? 'pass' : 'fail',- message: `Node ${process.versions.node}, required ${engines.node}.`,+ message: `Node ${process.versions.node}, required ${CLI_NODE_VERSION_RANGE}.`,...(isSupported? {}: { hint: 'Switch to a supported Node version and rerun doctor.' }),- details: { version: process.versions.node, required: engines.node },+ details: {+ version: process.versions.node,+ required: CLI_NODE_VERSION_RANGE,+ },},{id: 'cli',diff --git a/packages/twenty-cli/src/start-cli.ts b/packages/twenty-cli/src/start-cli.tsindex d1e9ef152d5..f856d848ea7 100644--- a/packages/twenty-cli/src/start-cli.ts+++ b/packages/twenty-cli/src/start-cli.ts@@ -1,6 +1,5 @@-import { engines } from '../package.json';-import { checkNodeRequirement } from '@/app/project/check-node-requirement';+import { CLI_NODE_VERSION_RANGE } from '@/constants/cli-node-version-range.constant';type CliModule = { runCli: (args: string[]) => Promise<void> };@@ -14,24 +13,21 @@ export const startCli = async ({loadCli: () => Promise<CliModule>;}) => {const isNodeSupported =- checkNodeRequirement({ version: nodeVersion, range: engines.node }) ===- 'satisfied';- let cli: CliModule;-- try {- cli = await loadCli();- } catch (error) {- if (isNodeSupported) {- throw error;- }+ checkNodeRequirement({+ version: nodeVersion,+ range: CLI_NODE_VERSION_RANGE,+ }) === 'satisfied';+ if (!isNodeSupported) {process.stderr.write(- `twenty requires Node.js ${engines.node}; this is Node.js ${nodeVersion}. Switch to a supported Node.js version, then try again.\n`,+ `twenty requires Node.js ${CLI_NODE_VERSION_RANGE}; this is Node.js ${nodeVersion}. Switch to a supported Node.js version, then try again.\n`,);process.exitCode = 1;return;}+ const cli = await loadCli();+await cli.runCli(args);};diff --git a/yarn.lock b/yarn.lockindex fb65629c6ab..d210a04c7f6 100644--- a/yarn.lock+++ b/yarn.lock@@ -51037,6 +51037,7 @@ __metadata:commander: "npm:^14.0.3"esbuild: "npm:^0.28.1"lodash.startcase: "npm:^4.4.0"+ npm-pick-manifest: "npm:^11.0.1"semver: "npm:7.6.3"tinyglobby: "npm:^0.2.15"twenty-client-sdk: "workspace:*"