check-node-engine 1.1.0 → 1.2.1
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/bin/cmd.js +4 -5
- package/lib/cjs/checkVersionNode.js +2 -2
- package/lib/cjs/types/node.d.ts +2 -2
- package/lib/cjs/utils/LTSCache.d.ts +11 -0
- package/lib/cjs/utils/LTSCache.js +112 -0
- package/lib/cjs/utils/getCachedOlderCurrentOfficialLTSVersion.d.ts +1 -0
- package/lib/cjs/utils/getCachedOlderCurrentOfficialLTSVersion.js +25 -0
- package/package.json +11 -11
package/bin/cmd.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
// natives
|
|
6
6
|
const { join } = require("node:path");
|
|
7
|
-
const { EOL } = require("node:os");
|
|
8
7
|
|
|
9
8
|
// externals
|
|
10
9
|
|
|
@@ -12,7 +11,7 @@
|
|
|
12
11
|
try { // test require optional deps
|
|
13
12
|
colors = require("colors/safe");
|
|
14
13
|
}
|
|
15
|
-
catch
|
|
14
|
+
catch {
|
|
16
15
|
// nothing to do here
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -24,9 +23,9 @@
|
|
|
24
23
|
|
|
25
24
|
if (0 < ARGS.length && ARGS.includes("--get-lts")) {
|
|
26
25
|
|
|
27
|
-
const
|
|
26
|
+
const getCachedOlderCurrentOfficialLTSVersion = require("../lib/cjs/utils/getCachedOlderCurrentOfficialLTSVersion.js").default;
|
|
28
27
|
|
|
29
|
-
(
|
|
28
|
+
getCachedOlderCurrentOfficialLTSVersion().then((lts) => {
|
|
30
29
|
|
|
31
30
|
(0, console).log(lts);
|
|
32
31
|
|
|
@@ -50,7 +49,7 @@ else {
|
|
|
50
49
|
|
|
51
50
|
checker(PACKAGE).then(() => {
|
|
52
51
|
|
|
53
|
-
console.log(colors && colors.green ? colors.green("Package node engine is up to date") : "Package node engine is up to date");
|
|
52
|
+
(0, console).log(colors && colors.green ? colors.green("Package node engine is up to date") : "Package node engine is up to date");
|
|
54
53
|
|
|
55
54
|
(0, process).exitCode = 0;
|
|
56
55
|
(0, process).exit(0);
|
|
@@ -12,7 +12,7 @@ const promises_1 = require("node:fs/promises");
|
|
|
12
12
|
const checkFile_1 = __importDefault(require("./utils/checkFile"));
|
|
13
13
|
const isPlainObject_1 = __importDefault(require("./utils/isPlainObject"));
|
|
14
14
|
const getEngineNode_1 = __importDefault(require("./utils/getEngineNode"));
|
|
15
|
-
const
|
|
15
|
+
const getCachedOlderCurrentOfficialLTSVersion_1 = __importDefault(require("./utils/getCachedOlderCurrentOfficialLTSVersion"));
|
|
16
16
|
const minimumVersionFromEngine_1 = __importDefault(require("./utils/minimumVersionFromEngine"));
|
|
17
17
|
const compareVersions_1 = __importDefault(require("./utils/compareVersions"));
|
|
18
18
|
// module
|
|
@@ -33,7 +33,7 @@ function checkVersionNode(source = (0, node_path_1.join)(process.cwd(), "package
|
|
|
33
33
|
}
|
|
34
34
|
}).then((packageData) => {
|
|
35
35
|
const engineNode = (0, getEngineNode_1.default)(packageData);
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, getCachedOlderCurrentOfficialLTSVersion_1.default)().then((olderCurrentOfficialLTS) => {
|
|
37
37
|
const engineMinimum = (0, minimumVersionFromEngine_1.default)(engineNode);
|
|
38
38
|
if (0 > (0, compareVersions_1.default)(engineMinimum, olderCurrentOfficialLTS)) {
|
|
39
39
|
throw new Error("engines.node \"" + engineNode + "\" (minimum " + engineMinimum + ") is lower than the older current official LTS Node.js (\"" + olderCurrentOfficialLTS + "\")");
|
package/lib/cjs/types/node.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default class LTSCache {
|
|
2
|
+
private constructor();
|
|
3
|
+
static cleanupExpired(): Promise<void>;
|
|
4
|
+
static readFresh(): Promise<string | null>;
|
|
5
|
+
static write(version: string): Promise<void>;
|
|
6
|
+
private static _getCacheDir;
|
|
7
|
+
private static _formatFilename;
|
|
8
|
+
private static _parseFilename;
|
|
9
|
+
private static _isExpired;
|
|
10
|
+
private static _listCacheFiles;
|
|
11
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// deps
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// natives
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const node_os_1 = require("node:os");
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
// consts
|
|
9
|
+
const CACHE_DIR_NAME = "check-node-engine";
|
|
10
|
+
const CACHE_TTL_MS = 15 * 60 * 1000;
|
|
11
|
+
const CACHE_FILENAME_PATTERN = /^(\d{4}-\d{2}-\d{2}T)(\d{2})-(\d{2})-(\d{2})-(\d{3})Z$/;
|
|
12
|
+
// module
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
14
|
+
class LTSCache {
|
|
15
|
+
constructor() {
|
|
16
|
+
throw new Error("LTSCache is a static class");
|
|
17
|
+
}
|
|
18
|
+
static cleanupExpired() {
|
|
19
|
+
return LTSCache._listCacheFiles().then((files) => {
|
|
20
|
+
const now = new Date();
|
|
21
|
+
const dir = LTSCache._getCacheDir();
|
|
22
|
+
return Promise.all(files.map((file) => {
|
|
23
|
+
const date = LTSCache._parseFilename(file);
|
|
24
|
+
if (null === date || !LTSCache._isExpired(date, now)) {
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
return (0, promises_1.unlink)((0, node_path_1.join)(dir, file)).then(() => {
|
|
28
|
+
// nothing to do here
|
|
29
|
+
}).catch(() => {
|
|
30
|
+
// nothing to do here
|
|
31
|
+
});
|
|
32
|
+
})).then(() => {
|
|
33
|
+
// nothing to do here
|
|
34
|
+
});
|
|
35
|
+
}).catch(() => {
|
|
36
|
+
// nothing to do here
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static readFresh() {
|
|
40
|
+
return LTSCache._listCacheFiles().then((files) => {
|
|
41
|
+
const now = new Date();
|
|
42
|
+
const fresh = [];
|
|
43
|
+
files.forEach((file) => {
|
|
44
|
+
const date = LTSCache._parseFilename(file);
|
|
45
|
+
if (null === date || LTSCache._isExpired(date, now)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
fresh.push({
|
|
49
|
+
"name": file,
|
|
50
|
+
"date": date
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
fresh.sort((a, b) => {
|
|
54
|
+
return b.date.getTime() - a.date.getTime();
|
|
55
|
+
});
|
|
56
|
+
if (0 === fresh.length) {
|
|
57
|
+
return Promise.resolve(null);
|
|
58
|
+
}
|
|
59
|
+
return (0, promises_1.readFile)((0, node_path_1.join)(LTSCache._getCacheDir(), fresh[0].name), "utf-8").then((content) => {
|
|
60
|
+
const trimmed = content.trim();
|
|
61
|
+
return "" === trimmed ? null : trimmed;
|
|
62
|
+
}).catch(() => {
|
|
63
|
+
return null;
|
|
64
|
+
});
|
|
65
|
+
}).catch(() => {
|
|
66
|
+
return null;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
static write(version) {
|
|
70
|
+
const dir = LTSCache._getCacheDir();
|
|
71
|
+
const file = (0, node_path_1.join)(dir, LTSCache._formatFilename(new Date()));
|
|
72
|
+
return (0, promises_1.mkdir)(dir, {
|
|
73
|
+
"recursive": true
|
|
74
|
+
}).then(() => {
|
|
75
|
+
return (0, promises_1.writeFile)(file, version, "utf-8");
|
|
76
|
+
}).catch(() => {
|
|
77
|
+
// nothing to do here
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
static _getCacheDir() {
|
|
81
|
+
return (0, node_path_1.join)((0, node_os_1.homedir)(), CACHE_DIR_NAME);
|
|
82
|
+
}
|
|
83
|
+
static _formatFilename(date) {
|
|
84
|
+
return date.toISOString().replaceAll(":", "-").replace(".", "-");
|
|
85
|
+
}
|
|
86
|
+
static _parseFilename(name) {
|
|
87
|
+
const match = CACHE_FILENAME_PATTERN.exec(name);
|
|
88
|
+
if (null === match) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const parsed = new Date(match[1] + match[2] + ":" + match[3] + ":" + match[4] + "." + match[5] + "Z");
|
|
92
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return parsed;
|
|
96
|
+
}
|
|
97
|
+
static _isExpired(date, now) {
|
|
98
|
+
return CACHE_TTL_MS < now.getTime() - date.getTime();
|
|
99
|
+
}
|
|
100
|
+
static _listCacheFiles() {
|
|
101
|
+
return (0, promises_1.readdir)(LTSCache._getCacheDir(), {
|
|
102
|
+
"withFileTypes": true
|
|
103
|
+
}).then((entries) => {
|
|
104
|
+
return entries.filter((entry) => {
|
|
105
|
+
return entry.isFile();
|
|
106
|
+
}).map((entry) => {
|
|
107
|
+
return entry.name;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.default = LTSCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getCachedOlderCurrentOfficialLTSVersion(): Promise<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 = getCachedOlderCurrentOfficialLTSVersion;
|
|
8
|
+
// locals
|
|
9
|
+
const LTSCache_1 = __importDefault(require("./LTSCache"));
|
|
10
|
+
const getOlderCurrentOfficialLTSVersion_1 = __importDefault(require("./getOlderCurrentOfficialLTSVersion"));
|
|
11
|
+
// module
|
|
12
|
+
function getCachedOlderCurrentOfficialLTSVersion() {
|
|
13
|
+
return LTSCache_1.default.cleanupExpired().then(() => {
|
|
14
|
+
return LTSCache_1.default.readFresh();
|
|
15
|
+
}).then((cached) => {
|
|
16
|
+
if (null !== cached) {
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
return (0, getOlderCurrentOfficialLTSVersion_1.default)().then((version) => {
|
|
20
|
+
return LTSCache_1.default.write(version).then(() => {
|
|
21
|
+
return version;
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "check-node-engine",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "Compare the required node engine to the last older LTS node version.",
|
|
6
6
|
|
|
7
7
|
"type": "commonjs",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"check-node-engine": "node ./bin/cmd.js",
|
|
34
34
|
"check-requires": "npx used-deps-analyzer \"./package.json\" \"./lib/src\" --no-dev --misscalled \"{ \\\"module\\\": \\\"colors\\\", \\\"call\\\": \\\"colors/safe\\\" }\"",
|
|
35
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": "
|
|
36
|
+
"unit-tests": "npx c8 --reporter=text-summary --all --include \"lib/src/**/*.ts\" --include \"lib/src/**/*.cts\" --extension .ts --extension .cts --check-coverage --statements 95 --branches 95 --functions 95 --lines 95 mocha --require ./test/register.js",
|
|
37
|
+
"unit-tests-local": "npx c8 --reporter=html --reporter=text --all --include \"lib/src/**/*.ts\" --include \"lib/src/**/*.cts\" --extension .ts --extension .cts mocha --require ./test/register.js",
|
|
38
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
|
|
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"
|
|
40
40
|
|
|
41
41
|
},
|
|
42
42
|
|
|
@@ -48,22 +48,22 @@
|
|
|
48
48
|
"lib/cjs"
|
|
49
49
|
],
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=22.
|
|
51
|
+
"node": ">=22.23.4"
|
|
52
52
|
},
|
|
53
53
|
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"semver": "7.8.
|
|
55
|
+
"semver": "7.8.5"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/node": "
|
|
59
|
-
"@types/semver": "7.
|
|
58
|
+
"@types/node": "26.6.5",
|
|
59
|
+
"@types/semver": "7.8.0",
|
|
60
|
+
"c8": "12.0.0",
|
|
60
61
|
"check-version-modules": "2.5.0",
|
|
61
62
|
"eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
|
|
62
63
|
"husky": "9.1.7",
|
|
63
|
-
"mocha": "
|
|
64
|
-
"nyc": "18.0.0",
|
|
64
|
+
"mocha": "12.0.3",
|
|
65
65
|
"rimraf": "6.1.3",
|
|
66
|
-
"typescript": "
|
|
66
|
+
"typescript": "6.0.3",
|
|
67
67
|
"used-deps-analyzer": "0.4.0"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|