chore(cli): drop Node.js v18 support (#4583)

This commit is contained in:
James George
2024-12-02 08:19:46 -08:00
committed by GitHub
parent e2e769db71
commit a08c6f6b3e
4 changed files with 145 additions and 90 deletions

View File

@@ -2,27 +2,57 @@
// * The entry point of the CLI
// @ts-check
import { cli } from "../dist/index.js";
import chalk from "chalk";
import { spawnSync } from "child_process";
import fs from "fs";
import { cloneDeep } from "lodash-es";
import semver from "semver";
import { fileURLToPath } from "url";
const nodeVersion = parseInt(process.versions.node.split(".")[0]);
const highlightVersion = (version) => chalk.black.bgYellow(`v${version}`);
const packageJsonPath = fileURLToPath(
new URL("../package.json", import.meta.url)
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const requiredNodeVersionRange = packageJson.engines?.node || ">=20";
// Extract the major version from the start of the range
const requiredNodeVersion = semver.major(
semver.minVersion(requiredNodeVersionRange) ?? "20"
);
const currentNodeVersion = process.versions.node;
// Last supported version of the CLI for Node.js v18
const lastSupportedVersion = "0.11.1";
if (!semver.satisfies(currentNodeVersion, requiredNodeVersionRange)) {
console.error(
`${chalk.greenBright("Hoppscotch CLI")} requires Node.js ${highlightVersion(requiredNodeVersion)} or higher and you're on Node.js ${highlightVersion(currentNodeVersion)}.`
);
console.error(
`\nIf you prefer staying on Node.js ${highlightVersion("18")}, you can install the last supported version of the CLI:\n` +
`${chalk.green(`npm install -g @hoppscotch/cli@${lastSupportedVersion}`)}`
);
process.exit(1);
}
// Dynamically importing the module after the Node.js version check prevents errors due to unrecognized APIs in older Node.js versions
const { cli } = await import("../dist/index.js");
// As per isolated-vm documentation, we need to supply `--no-node-snapshot` for node >= 20
// src: https://github.com/laverdet/isolated-vm?tab=readme-ov-file#requirements
if (nodeVersion >= 20 && !process.execArgv.includes("--no-node-snapshot")) {
if (!process.execArgv.includes("--no-node-snapshot")) {
const argCopy = cloneDeep(process.argv);
// Replace first argument with --no-node-snapshot
// We can get argv[0] from process.argv0
argCopy[0] = "--no-node-snapshot";
const result = spawnSync(
process.argv0,
argCopy,
{ stdio: "inherit" }
);
const result = spawnSync(process.argv0, argCopy, { stdio: "inherit" });
// Exit with the same status code as the spawned process
process.exit(result.status ?? 0);

View File

@@ -1,6 +1,6 @@
{
"name": "@hoppscotch/cli",
"version": "0.13.0",
"version": "0.20.0",
"description": "A CLI to run Hoppscotch test scripts in CI environments.",
"homepage": "https://hoppscotch.io",
"type": "module",
@@ -12,7 +12,7 @@
"access": "public"
},
"engines": {
"node": ">=18"
"node": ">=20"
},
"scripts": {
"build": "pnpm exec tsup",
@@ -48,24 +48,25 @@
"isolated-vm": "5.0.1",
"js-md5": "0.8.3",
"lodash-es": "4.17.21",
"papaparse": "5.4.1",
"qs": "6.13.0",
"verzod": "0.2.3",
"xmlbuilder2": "3.1.1",
"zod": "3.23.8",
"papaparse": "5.4.1"
"zod": "3.23.8"
},
"devDependencies": {
"@hoppscotch/data": "workspace:^",
"@hoppscotch/js-sandbox": "workspace:^",
"@relmify/jest-fp-ts": "2.1.1",
"@types/lodash-es": "4.17.12",
"@types/papaparse": "5.3.14",
"@types/qs": "6.9.16",
"fp-ts": "2.16.9",
"prettier": "3.3.3",
"qs": "6.11.2",
"semver": "7.6.3",
"tsup": "8.3.0",
"typescript": "5.6.3",
"vitest": "2.1.2",
"@types/papaparse": "5.3.14"
"vitest": "2.1.2"
}
}

View File

@@ -1,7 +1,7 @@
import { defineConfig } from "tsup";
export default defineConfig({
entry: [ "./src/index.ts" ],
entry: ["./src/index.ts"],
outDir: "./dist/",
format: ["esm"],
platform: "node",
@@ -10,7 +10,7 @@ export default defineConfig({
target: "esnext",
skipNodeModulesBundle: false,
esbuildOptions(options) {
options.bundle = true
options.bundle = true;
},
clean: true,
});