From 9258e205cd8c0d231f04c77be9d7760c13027d05 Mon Sep 17 00:00:00 2001 From: Frank Calise Date: Tue, 15 Oct 2024 12:49:43 -0400 Subject: [PATCH 1/2] chore: check node version during preinstall --- package.json | 5 +++-- scripts/check-node-version.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 scripts/check-node-version.js diff --git a/package.json b/package.json index d9aa5675c..b0de39ef1 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,11 @@ "semantic-release": "semantic-release", "clean": "rm -drf ./build ./boilerplate/.gitignore.template ./boilerplate/node_modules ./boilerplate/ios/build/ ./boilerplate/ios/Pods/ ./boilerplate/android/app/build ./boilerplate/ios/.xcode.env.local", "ignite-cli:dev": "node bin/ignite", - "ignite-cli:prod": "wrap () { node bin/ignite \"$@\" --compiled-build | cat; }; wrap" + "ignite-cli:prod": "wrap () { node bin/ignite \"$@\" --compiled-build | cat; }; wrap", + "preinstall": "node ./scripts/check-node-version.js" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": ">=20.10.0" }, "dependencies": { "deepmerge-json": "^1.1.0", diff --git a/scripts/check-node-version.js b/scripts/check-node-version.js new file mode 100644 index 000000000..7bb192664 --- /dev/null +++ b/scripts/check-node-version.js @@ -0,0 +1,30 @@ +const { engines } = require("../package.json") +const currentNodeVersion = process.version +const requiredNodeVersion = engines.node + +const compareVersions = (current, required) => { + const currentParts = current.replace("v", "").split(".") + const requiredParts = required.replace(">=", "").replace("<", "").split(".") + + for (let i = 0; i < requiredParts.length; i++) { + const currentPart = parseInt(currentParts[i] || 0, 10) + const requiredPart = parseInt(requiredParts[i] || 0, 10) + + if (currentPart > requiredPart) { + return true // Current version is higher + } + if (currentPart < requiredPart) { + return false // Current version is lower + } + } + return true // Versions match +} + +if (!compareVersions(currentNodeVersion, requiredNodeVersion)) { + console.error( + `Required Node.js version ${requiredNodeVersion} not satisfied with current version ${currentNodeVersion}.`, + ) + process.exit(1) +} + +console.log("Node.js version is compatible.") From b882f5218272dde33decd06256a88b23ae8cafbd Mon Sep 17 00:00:00 2001 From: Frank Calise Date: Wed, 16 Oct 2024 08:43:31 -0400 Subject: [PATCH 2/2] chore: revert back min node version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0de39ef1..e7713c12c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "preinstall": "node ./scripts/check-node-version.js" }, "engines": { - "node": ">=20.10.0" + "node": ">=20.0.0" }, "dependencies": { "deepmerge-json": "^1.1.0",