MCPcopy
hub / github.com/parse-community/parse-server / getNodeVersion

Method getNodeVersion

ci/nodeEngineCheck.js:71–101  ·  view source on GitHub ↗

* Extracts and returns the node engine versions of the given package.json * files. * @param {String[]} files The package.json files. * @param {Boolean} clean Is true if packages with undefined node versions * should be removed from the results. * @returns {Object[]} A list of results.

({ files, clean = false })

Source from the content-addressed store, hash-verified

69 * @returns {Object[]} A list of results.
70 */
71 async getNodeVersion({ files, clean = false }) {
72
73 // Declare response
74 let response = [];
75
76 // For each file
77 for (const file of files) {
78 // Get node version
79 const contentString = await fs.readFile(file, 'utf-8');
80 try {
81 const contentJson = JSON.parse(contentString);
82 const version = ((contentJson || {}).engines || {}).node;
83
84 // Add response
85 response.push({
86 file: file,
87 nodeVersion: version
88 });
89 } catch {
90 // eslint-disable-next-line no-console
91 console.log(`Ignoring file because it is not valid JSON: ${file}`);
92 core.warning(`Ignoring file because it is not valid JSON: ${file}`);
93 }
94 }
95
96 // If results should be cleaned by removing undefined node versions
97 if (clean) {
98 response = response.filter(r => r.nodeVersion !== undefined);
99 }
100 return response;
101 }
102
103 /**
104 * Returns the highest semver definition that satisfies all versions

Callers 2

getParentVersionMethod · 0.95
checkFunction · 0.95

Calls 3

readFileMethod · 0.80
filterMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected