check-node-engine 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2026, Sébastien Vidal
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # check-node-engine
2
+ Compare the required node engine to the last older LTS node version.
3
+
4
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
5
+ [![Issues](https://img.shields.io/github/issues/Psychopoulet/check-node-engine.svg)](https://github.com/Psychopoulet/check-node-engine/issues)
6
+ [![Pull requests](https://img.shields.io/github/issues-pr/Psychopoulet/check-node-engine.svg)](https://github.com/Psychopoulet/check-node-engine/pulls)
7
+
8
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
9
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
10
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
11
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
12
+ [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_check-node-engine&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_check-node-engine)
13
+
14
+ [![Known Vulnerabilities](https://snyk.io/test/github/Psychopoulet/check-node-engine/badge.svg)](https://snyk.io/test/github/Psychopoulet/check-node-engine)
15
+
16
+ ## Features
17
+
18
+ * Get the older NodeJS current LTS
19
+ * Compare this version to the current minimal engine node
20
+
21
+ ## Doc
22
+
23
+ ### Methods
24
+
25
+ * ``` (packageJsonPath?: string) => Promise<void> ``` compare node versions
26
+
27
+ ### Command line options
28
+
29
+ * ``` --get-lts ``` => only get the older current official LTS version of NodeJS
30
+ * ``` --package-file <package path> ``` => specify an optional package path
31
+
32
+ ## Examples
33
+
34
+ ### Command line
35
+
36
+ ```bash
37
+ $ cd ./myProject/ && npx check-node-engine
38
+ $ cd ./myProject/ && npx check-node-engine --get-lts
39
+ $ cd ./myProject/ && npx check-node-engine --package-file "./package.json"
40
+ ```
41
+
42
+ ### Native
43
+
44
+ ```javascript
45
+ const checker = require("check-node-engine");
46
+
47
+ checker().then(() => {
48
+ console.log("ok");
49
+ }).catch((err) => {
50
+ console.error(err);
51
+ });
52
+
53
+ checker("./package.json").then(() => {
54
+ console.log("ok");
55
+ }).catch((err) => {
56
+ console.error(err);
57
+ });
58
+ ```
59
+
60
+ ### Typescript
61
+
62
+ ```typescript
63
+ import checker = require("check-node-engine");
64
+
65
+ checker().then(() => {
66
+ console.log("ok");
67
+ }).catch((err) => {
68
+ console.error(err);
69
+ });
70
+
71
+ checker("./package.json").then(() => {
72
+ console.log("ok");
73
+ }).catch((err) => {
74
+ console.error(err);
75
+ });
76
+ ```
77
+
78
+ ## Tests
79
+
80
+ ```bash
81
+ $ npm run tests
82
+ ```
83
+
84
+ ## License
85
+
86
+ [ISC](LICENSE)
package/bin/cmd.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+
3
+ // deps
4
+
5
+ // natives
6
+ const { join } = require("node:path");
7
+ const { EOL } = require("node:os");
8
+
9
+ // externals
10
+
11
+ let colors = null;
12
+ try { // test require optional deps
13
+ colors = require("colors/safe");
14
+ }
15
+ catch (e) {
16
+ // nothing to do here
17
+ }
18
+
19
+ // consts
20
+
21
+ const ARGS = (0, process).argv.slice(2, (0, process).argv.length);
22
+
23
+ // module
24
+
25
+ if (0 < ARGS.length && ARGS.includes("--get-lts")) {
26
+
27
+ const getOlderCurrentOfficialLTSVersion = require("../lib/cjs/getOlderCurrentOfficialLTSVersion.js");
28
+
29
+ (getOlderCurrentOfficialLTSVersion.default ?? getOlderCurrentOfficialLTSVersion)().then((lts) => {
30
+
31
+ (0, console).log(lts);
32
+
33
+ (0, process).exitCode = 0;
34
+ (0, process).exit(0);
35
+
36
+ }).catch((err) => {
37
+
38
+ (0, console).error(err.message ? err.message : err);
39
+
40
+ (0, process).exitCode = 1;
41
+ (0, process).exit(1);
42
+
43
+ });
44
+
45
+ }
46
+ else {
47
+
48
+ const checker = require(join(__dirname, "..", "lib", "cjs", "main.cjs"));
49
+ const PACKAGE = 1 < ARGS.length && ARGS.includes("--package-file") ? ARGS[ARGS.indexOf("--package-file") + 1] : join((0, process).cwd(), "package.json");
50
+
51
+ checker(PACKAGE).then(() => {
52
+
53
+ console.log(colors && colors.green ? colors.green("Package node engine is up to date") : "Package node engine is up to date");
54
+
55
+ (0, process).exitCode = 0;
56
+ (0, process).exit(0);
57
+
58
+ }).catch((err) => {
59
+
60
+ const message = err.message ? err.message : err;
61
+
62
+ (0, console).error(colors && colors.red ? colors.red(message) : message);
63
+
64
+ (0, process).exitCode = 1;
65
+ (0, process).exit(1);
66
+
67
+ });
68
+
69
+ }
@@ -0,0 +1 @@
1
+ export default function checkVersionNode(packageJsonPath?: string): Promise<void>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = checkVersionNode;
8
+ // natives
9
+ const node_path_1 = require("node:path");
10
+ // locals
11
+ const isFile_1 = __importDefault(require("./utils/isFile"));
12
+ const readPackageEngineNode_1 = __importDefault(require("./readPackageEngineNode"));
13
+ const getOlderCurrentOfficialLTSVersion_1 = __importDefault(require("./getOlderCurrentOfficialLTSVersion"));
14
+ const compareVersions_1 = __importDefault(require("./utils/compareVersions"));
15
+ const minimumVersionFromEngine_1 = __importDefault(require("./utils/minimumVersionFromEngine"));
16
+ // module
17
+ function checkVersionNode(packageJsonPath = (0, node_path_1.join)(process.cwd(), "package.json")) {
18
+ return (0, isFile_1.default)(packageJsonPath).then((isPackageAFile) => {
19
+ if (!isPackageAFile) {
20
+ throw new Error("this data is not a file: \"" + packageJsonPath + "\"");
21
+ }
22
+ }).then(() => {
23
+ return (0, readPackageEngineNode_1.default)(packageJsonPath).then((engineNode) => {
24
+ return (0, getOlderCurrentOfficialLTSVersion_1.default)().then((olderCurrentOfficialLTS) => {
25
+ const engineMinimum = (0, minimumVersionFromEngine_1.default)(engineNode);
26
+ if (0 > (0, compareVersions_1.default)(engineMinimum, olderCurrentOfficialLTS)) {
27
+ throw new Error("engines.node \"" + engineNode + "\" (minimum " + engineMinimum + ") is lower than the older current official LTS Node.js (\"" + olderCurrentOfficialLTS + "\")");
28
+ }
29
+ });
30
+ });
31
+ });
32
+ }
@@ -0,0 +1 @@
1
+ export default function getOlderCurrentOfficialLTSVersion(): Promise<string>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = getOlderCurrentOfficialLTSVersion;
8
+ // natives
9
+ const node_https_1 = require("node:https");
10
+ // externals
11
+ const semver_1 = __importDefault(require("semver"));
12
+ // locals
13
+ const compareVersions_1 = __importDefault(require("./utils/compareVersions"));
14
+ // consts
15
+ const NODEJS_DIST_INDEX_URL = "https://nodejs.org/dist/index.json";
16
+ const LTS_LINE_MAX_AGE_MONTHS = 18;
17
+ // module
18
+ function getOlderCurrentOfficialLTSVersion() {
19
+ return new Promise((resolve, reject) => {
20
+ (0, node_https_1.get)(NODEJS_DIST_INDEX_URL, (res) => {
21
+ if (200 !== res.statusCode) {
22
+ reject(new Error("Failed to fetch Node.js releases (" + res.statusCode + " " + res.statusMessage + ")"));
23
+ }
24
+ let data = "";
25
+ res.on("data", (chunk) => {
26
+ data += chunk;
27
+ });
28
+ res.on("end", () => {
29
+ resolve(JSON.parse(data));
30
+ });
31
+ res.on("error", (err) => {
32
+ reject(err);
33
+ });
34
+ });
35
+ }).then((releases) => {
36
+ const cutoff = new Date();
37
+ cutoff.setMonth(cutoff.getMonth() - LTS_LINE_MAX_AGE_MONTHS);
38
+ const latestByMajor = new Map();
39
+ releases.forEach((release) => {
40
+ if ("string" !== typeof release.lts) {
41
+ return;
42
+ }
43
+ const coerced = semver_1.default.coerce(release.version);
44
+ if (null === coerced) {
45
+ return;
46
+ }
47
+ const major = String(coerced.major);
48
+ const current = latestByMajor.get(major);
49
+ if (!current || 0 < (0, compareVersions_1.default)(release.version, current.version)) {
50
+ latestByMajor.set(major, {
51
+ "date": release.date,
52
+ "lts": release.lts,
53
+ "version": release.version
54
+ });
55
+ }
56
+ });
57
+ const activeLTSLines = [...latestByMajor.values()]
58
+ .filter((release) => {
59
+ return cutoff <= new Date(release.date);
60
+ })
61
+ .sort((a, b) => {
62
+ return (0, compareVersions_1.default)(b.version, a.version);
63
+ });
64
+ if (2 > activeLTSLines.length) {
65
+ throw new Error("Not enough active LTS lines to determine the older current official LTS Node.js version");
66
+ }
67
+ const olderLTS = semver_1.default.coerce(activeLTSLines[1].version);
68
+ if (null === olderLTS) {
69
+ throw new Error("Unable to parse older current official LTS Node.js version: \"" + activeLTSLines[1].version + "\"");
70
+ }
71
+ return olderLTS.format();
72
+ });
73
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ // locals
7
+ const checkVersionNode_1 = __importDefault(require("./checkVersionNode"));
8
+ module.exports = checkVersionNode_1.default;
@@ -0,0 +1,2 @@
1
+ import checkVersionNode from "./checkVersionNode";
2
+ export = checkVersionNode;
@@ -0,0 +1 @@
1
+ export default function readPackageEngineNode(packageJsonPath: string): Promise<string>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // deps
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = readPackageEngineNode;
5
+ // natives
6
+ const promises_1 = require("node:fs/promises");
7
+ // module
8
+ function readPackageEngineNode(packageJsonPath) {
9
+ return (0, promises_1.access)(packageJsonPath).catch(() => {
10
+ throw new Error("package.json not found at \"" + packageJsonPath + "\"");
11
+ }).then(() => {
12
+ return (0, promises_1.readFile)(packageJsonPath, "utf8");
13
+ }).then((content) => {
14
+ let packageData = null;
15
+ try {
16
+ packageData = JSON.parse(content);
17
+ }
18
+ catch (e) {
19
+ throw new Error("package.json is not valid JSON : " + (e instanceof Error ? e.message : String(e)));
20
+ }
21
+ if ("object" !== typeof packageData || !("engines" in packageData)) {
22
+ throw new Error("package.json must contain an \"engines\" field");
23
+ }
24
+ const { engines } = packageData;
25
+ if ("object" !== typeof engines || !("node" in engines)) {
26
+ throw new Error("package.json \"engines\" must contain a \"node\" field");
27
+ }
28
+ const { "node": engineNode } = engines;
29
+ if ("string" !== typeof engineNode || "" === engineNode.trim()) {
30
+ throw new Error("package.json \"engines.node\" must be a non-empty string");
31
+ }
32
+ return engineNode;
33
+ });
34
+ }
@@ -0,0 +1 @@
1
+ export default function compareVersions(a: string, b: string): number;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = compareVersions;
8
+ // externals
9
+ const semver_1 = __importDefault(require("semver"));
10
+ // private
11
+ function _coerceVersion(version) {
12
+ const coerced = semver_1.default.coerce(version);
13
+ if (null === coerced) {
14
+ throw new Error("Unable to parse version: \"" + version + "\"");
15
+ }
16
+ return coerced;
17
+ }
18
+ // module
19
+ function compareVersions(a, b) {
20
+ return semver_1.default.compare(_coerceVersion(a), _coerceVersion(b));
21
+ }
@@ -0,0 +1 @@
1
+ export default function isFile(file: string): Promise<boolean>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // deps
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = isFile;
5
+ // natives
6
+ const node_fs_1 = require("node:fs");
7
+ // module
8
+ function isFile(file) {
9
+ return new Promise((resolve) => {
10
+ (0, node_fs_1.lstat)(file, (err, stats) => {
11
+ return resolve(!err && stats.isFile());
12
+ });
13
+ });
14
+ }
@@ -0,0 +1 @@
1
+ export default function minimumVersionFromEngine(range: string): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = minimumVersionFromEngine;
8
+ // externals
9
+ const semver_1 = __importDefault(require("semver"));
10
+ // module
11
+ function minimumVersionFromEngine(range) {
12
+ const trimmed = range.trim();
13
+ const validRange = semver_1.default.validRange(trimmed, {
14
+ "includePrerelease": false,
15
+ "loose": true
16
+ });
17
+ if (null === validRange) {
18
+ throw new Error("Unable to parse engines.node value: \"" + range + "\"");
19
+ }
20
+ const min = semver_1.default.minVersion(validRange);
21
+ if (null === min) {
22
+ throw new Error("Unable to parse engines.node value: \"" + range + "\"");
23
+ }
24
+ return min.format();
25
+ }
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+
3
+ "name": "check-node-engine",
4
+ "version": "1.0.0",
5
+ "description": "Compare the required node engine to the last older LTS node version.",
6
+
7
+ "type": "commonjs",
8
+ "typings": "./lib/cjs/main.d.cts",
9
+ "main": "./lib/cjs/main.cjs",
10
+
11
+ "exports": {
12
+ ".": {
13
+ "require": {
14
+ "types": "./lib/cjs/main.d.cts",
15
+ "default": "./lib/cjs/main.cjs"
16
+ }
17
+ }
18
+ },
19
+
20
+ "scripts": {
21
+
22
+ "lint-bin": "npx eslint --config .eslintrc-bin.js --ext .js,.cjs,.mjs ./bin/**/*",
23
+ "lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
24
+ "lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*",
25
+ "lint": "npm run lint-bin && npm run lint-back && npm run lint-tests",
26
+
27
+ "clean-back": "npx rimraf ./lib/cjs",
28
+ "clean": "npm run clean-back",
29
+
30
+ "build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
31
+ "build": "npm run build-back",
32
+
33
+ "check-node-engine": "node ./bin/cmd.js",
34
+ "check-requires": "npx used-deps-analyzer \"./package.json\" \"./lib/src\" --no-dev --misscalled \"{ \\\"module\\\": \\\"colors\\\", \\\"call\\\": \\\"colors/safe\\\" }\"",
35
+ "check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
36
+ "unit-tests": "npx mocha",
37
+ "unit-tests-local": "npm run build && npx nyc --reporter=html --reporter=text mocha",
38
+
39
+ "tests": "npm run lint && npm run check-node-engine && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests-local"
40
+
41
+ },
42
+
43
+ "bin": {
44
+ "check-node-engine": "./bin/cmd.js"
45
+ },
46
+ "files": [
47
+ "bin",
48
+ "lib/cjs"
49
+ ],
50
+ "engines": {
51
+ "node": ">=22.22.3"
52
+ },
53
+
54
+ "dependencies": {
55
+ "semver": "7.8.1"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "25.9.1",
59
+ "@types/semver": "7.7.1",
60
+ "check-version-modules": "2.4.0",
61
+ "eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
62
+ "husky": "9.1.7",
63
+ "mocha": "11.7.6",
64
+ "nyc": "18.0.0",
65
+ "rimraf": "6.1.3",
66
+ "typescript": "5.9.3",
67
+ "used-deps-analyzer": "0.3.0"
68
+ },
69
+ "optionalDependencies": {
70
+ "colors": "1.4.0"
71
+ },
72
+
73
+ "keywords": [
74
+ "check",
75
+ "lts",
76
+ "node",
77
+ "nodejs",
78
+ "node.js",
79
+ "engine",
80
+ "versions",
81
+ "version",
82
+ "package",
83
+ "cmd",
84
+ "command line"
85
+ ],
86
+ "author": "Sébastien VIDAL",
87
+ "license": "ISC",
88
+
89
+ "homepage": "https://github.com/Psychopoulet/check-node-engine#readme",
90
+ "repository": {
91
+ "type": "git",
92
+ "url": "git://github.com/Psychopoulet/check-node-engine.git"
93
+ },
94
+ "bugs": {
95
+ "url": "https://github.com/Psychopoulet/check-node-engine/issues"
96
+ }
97
+
98
+ }