check-node-engine 1.1.0 → 1.2.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/bin/cmd.js CHANGED
@@ -24,9 +24,9 @@
24
24
 
25
25
  if (0 < ARGS.length && ARGS.includes("--get-lts")) {
26
26
 
27
- const getOlderCurrentOfficialLTSVersion = require("../lib/cjs/getOlderCurrentOfficialLTSVersion.js");
27
+ const getCachedOlderCurrentOfficialLTSVersion = require("../lib/cjs/utils/getCachedOlderCurrentOfficialLTSVersion.js").default;
28
28
 
29
- (getOlderCurrentOfficialLTSVersion.default ?? getOlderCurrentOfficialLTSVersion)().then((lts) => {
29
+ getCachedOlderCurrentOfficialLTSVersion().then((lts) => {
30
30
 
31
31
  (0, console).log(lts);
32
32
 
@@ -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 getOlderCurrentOfficialLTSVersion_1 = __importDefault(require("./utils/getOlderCurrentOfficialLTSVersion"));
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, getOlderCurrentOfficialLTSVersion_1.default)().then((olderCurrentOfficialLTS) => {
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 + "\")");
@@ -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.0",
4
+ "version": "1.2.0",
5
5
  "description": "Compare the required node engine to the last older LTS node version.",
6
6
 
7
7
  "type": "commonjs",
@@ -48,19 +48,19 @@
48
48
  "lib/cjs"
49
49
  ],
50
50
  "engines": {
51
- "node": ">=22.22.3"
51
+ "node": ">=22.23.2"
52
52
  },
53
53
 
54
54
  "dependencies": {
55
- "semver": "7.8.1"
55
+ "semver": "7.8.5"
56
56
  },
57
57
  "devDependencies": {
58
- "@types/node": "25.9.1",
59
- "@types/semver": "7.7.1",
58
+ "@types/node": "26.2.0",
59
+ "@types/semver": "7.8.0",
60
60
  "check-version-modules": "2.5.0",
61
61
  "eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
62
62
  "husky": "9.1.7",
63
- "mocha": "11.7.6",
63
+ "mocha": "11.8.0",
64
64
  "nyc": "18.0.0",
65
65
  "rimraf": "6.1.3",
66
66
  "typescript": "5.9.3",