check-node-engine 1.0.0 → 1.1.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/README.md CHANGED
@@ -22,7 +22,7 @@ Compare the required node engine to the last older LTS node version.
22
22
 
23
23
  ### Methods
24
24
 
25
- * ``` (packageJsonPath?: string) => Promise<void> ``` compare node versions
25
+ * ``` (source?: string | tPackageType) => Promise<void> ``` compare node versions
26
26
 
27
27
  ### Command line options
28
28
 
@@ -1 +1,2 @@
1
- export default function checkVersionNode(packageJsonPath?: string): Promise<void>;
1
+ export type tPackageType = Record<string, object | string | number | boolean>;
2
+ export default function checkVersionNode(source?: string | tPackageType): Promise<void>;
@@ -7,26 +7,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.default = checkVersionNode;
8
8
  // natives
9
9
  const node_path_1 = require("node:path");
10
+ const promises_1 = require("node:fs/promises");
10
11
  // 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"));
12
+ const checkFile_1 = __importDefault(require("./utils/checkFile"));
13
+ const isPlainObject_1 = __importDefault(require("./utils/isPlainObject"));
14
+ const getEngineNode_1 = __importDefault(require("./utils/getEngineNode"));
15
+ const getOlderCurrentOfficialLTSVersion_1 = __importDefault(require("./utils/getOlderCurrentOfficialLTSVersion"));
15
16
  const minimumVersionFromEngine_1 = __importDefault(require("./utils/minimumVersionFromEngine"));
17
+ const compareVersions_1 = __importDefault(require("./utils/compareVersions"));
16
18
  // 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
- }
19
+ function checkVersionNode(source = (0, node_path_1.join)(process.cwd(), "package.json")) {
20
+ return Promise.resolve().then(() => {
21
+ if ("string" === typeof source) {
22
+ return (0, checkFile_1.default)(source).then(() => {
23
+ return (0, promises_1.readFile)(source, "utf-8");
24
+ }).then((content) => {
25
+ return JSON.parse(content);
29
26
  });
27
+ }
28
+ else if ((0, isPlainObject_1.default)(source)) {
29
+ return source;
30
+ }
31
+ else {
32
+ throw new TypeError("\"source\" parameter is not a string or a package type");
33
+ }
34
+ }).then((packageData) => {
35
+ const engineNode = (0, getEngineNode_1.default)(packageData);
36
+ return (0, getOlderCurrentOfficialLTSVersion_1.default)().then((olderCurrentOfficialLTS) => {
37
+ const engineMinimum = (0, minimumVersionFromEngine_1.default)(engineNode);
38
+ if (0 > (0, compareVersions_1.default)(engineMinimum, olderCurrentOfficialLTS)) {
39
+ throw new Error("engines.node \"" + engineNode + "\" (minimum " + engineMinimum + ") is lower than the older current official LTS Node.js (\"" + olderCurrentOfficialLTS + "\")");
40
+ }
30
41
  });
31
42
  });
32
43
  }
@@ -0,0 +1,13 @@
1
+ export type Release = {
2
+ "version": string;
3
+ "date": string;
4
+ "lts": boolean;
5
+ "files": string[];
6
+ "npm": string;
7
+ "v8": string;
8
+ "uv": string;
9
+ "zlib": string;
10
+ "openssl": string;
11
+ "modules": string;
12
+ "security": boolean;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export default function checkFile(file: string): Promise<void>;
@@ -0,0 +1,17 @@
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 = checkFile;
8
+ // locals
9
+ const isFile_1 = __importDefault(require("./isFile"));
10
+ // module
11
+ function checkFile(file) {
12
+ return (0, isFile_1.default)(file).then((isItAFile) => {
13
+ if (!isItAFile) {
14
+ throw new Error("\"file\" parameter (" + file + ") is not a valid file");
15
+ }
16
+ });
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { tPackageType } from "../checkVersionNode";
2
+ export default function getEngineNode(packageData: tPackageType): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // types & interfaces
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = getEngineNode;
5
+ // module
6
+ function getEngineNode(packageData) {
7
+ if ("object" !== typeof packageData || !("engines" in packageData)) {
8
+ throw new Error("package.json must contain an \"engines\" field");
9
+ }
10
+ const { engines } = packageData;
11
+ if ("object" !== typeof engines || !("node" in engines)) {
12
+ throw new Error("package.json \"engines\" must contain a \"node\" field");
13
+ }
14
+ const { "node": engineNode } = engines;
15
+ if ("string" !== typeof engineNode || "" === engineNode.trim()) {
16
+ throw new Error("package.json \"engines.node\" must be a non-empty string");
17
+ }
18
+ return engineNode;
19
+ }
@@ -10,7 +10,7 @@ const node_https_1 = require("node:https");
10
10
  // externals
11
11
  const semver_1 = __importDefault(require("semver"));
12
12
  // locals
13
- const compareVersions_1 = __importDefault(require("./utils/compareVersions"));
13
+ const compareVersions_1 = __importDefault(require("./compareVersions"));
14
14
  // consts
15
15
  const NODEJS_DIST_INDEX_URL = "https://nodejs.org/dist/index.json";
16
16
  const LTS_LINE_MAX_AGE_MONTHS = 18;
@@ -47,18 +47,12 @@ function getOlderCurrentOfficialLTSVersion() {
47
47
  const major = String(coerced.major);
48
48
  const current = latestByMajor.get(major);
49
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
- });
50
+ latestByMajor.set(major, { ...release });
55
51
  }
56
52
  });
57
- const activeLTSLines = [...latestByMajor.values()]
58
- .filter((release) => {
53
+ const activeLTSLines = [...latestByMajor.values()].filter((release) => {
59
54
  return cutoff <= new Date(release.date);
60
- })
61
- .sort((a, b) => {
55
+ }).sort((a, b) => {
62
56
  return (0, compareVersions_1.default)(b.version, a.version);
63
57
  });
64
58
  if (2 > activeLTSLines.length) {
@@ -0,0 +1 @@
1
+ export default function isPlainObject(value: unknown): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // module
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = isPlainObject;
5
+ function isPlainObject(value) {
6
+ if ("object" !== typeof value || null === value) {
7
+ return false;
8
+ }
9
+ return Object.getPrototypeOf(value) === Object.getPrototypeOf({});
10
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "check-node-engine",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "Compare the required node engine to the last older LTS node version.",
6
6
 
7
7
  "type": "commonjs",
@@ -22,7 +22,7 @@
22
22
  "lint-bin": "npx eslint --config .eslintrc-bin.js --ext .js,.cjs,.mjs ./bin/**/*",
23
23
  "lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
24
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",
25
+ "lint": "npm run lint-bin && npm run build && npm run lint-back && npm run lint-tests",
26
26
 
27
27
  "clean-back": "npx rimraf ./lib/cjs",
28
28
  "clean": "npm run clean-back",
@@ -57,14 +57,14 @@
57
57
  "devDependencies": {
58
58
  "@types/node": "25.9.1",
59
59
  "@types/semver": "7.7.1",
60
- "check-version-modules": "2.4.0",
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
63
  "mocha": "11.7.6",
64
64
  "nyc": "18.0.0",
65
65
  "rimraf": "6.1.3",
66
66
  "typescript": "5.9.3",
67
- "used-deps-analyzer": "0.3.0"
67
+ "used-deps-analyzer": "0.4.0"
68
68
  },
69
69
  "optionalDependencies": {
70
70
  "colors": "1.4.0"
@@ -1 +0,0 @@
1
- export default function readPackageEngineNode(packageJsonPath: string): Promise<string>;
@@ -1,34 +0,0 @@
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
- }