MCPcopy
hub / github.com/ampproject/amphtml / checkNodeVersion

Function checkNodeVersion

build-system/common/check-package-manager.js:103–165  ·  view source on GitHub ↗

* Check the node version and print a warning if it is not the latest LTS. * * @return {Promise }

()

Source from the content-addressed store, hash-verified

101 * @return {Promise<void>}
102 **/
103function checkNodeVersion() {
104 const nodeVersion = getStdout('node --version').trim();
105 return new Promise((resolve) => {
106 https
107 .get(nodeDistributionsUrl, (res) => {
108 res.setEncoding('utf8');
109 let distributions = '';
110 res.on('data', (data) => {
111 distributions += data;
112 });
113 res.on('end', () => {
114 const distributionsJson = JSON.parse(distributions);
115 const latestLtsVersion = getNodeLatestLtsVersion(distributionsJson);
116 if (latestLtsVersion === '') {
117 console.log(
118 yellow(
119 'WARNING: Something went wrong. ' +
120 'Could not determine the latest LTS version of node.'
121 )
122 );
123 } else if (nodeVersion !== latestLtsVersion) {
124 console.log(
125 yellow('WARNING: Detected node version'),
126 cyan(nodeVersion) +
127 yellow('. Recommended (latest LTS) version is'),
128 cyan(latestLtsVersion) + yellow('.')
129 );
130 console.log(
131 yellow('⤷ To fix this, run'),
132 cyan('"nvm install --lts"'),
133 yellow('or see'),
134 cyan('https://nodejs.org/en/download/package-manager'),
135 yellow('for instructions.')
136 );
137 updatesNeeded.add('node');
138 } else {
139 console.log(
140 green('Detected'),
141 cyan('node'),
142 green('version'),
143 cyan(nodeVersion + ' (latest LTS)') + green('.')
144 );
145 }
146 resolve();
147 });
148 })
149 .on('error', () => {
150 console.log(
151 yellow(
152 'WARNING: Something went wrong. ' +
153 'Could not download node version info from ' +
154 cyan(nodeDistributionsUrl) +
155 yellow('.')
156 )
157 );
158 console.log(
159 yellow('⤷ Detected node version'),
160 cyan(nodeVersion) + yellow('.')

Callers 1

mainFunction · 0.85

Calls 11

getStdoutFunction · 0.85
getNodeLatestLtsVersionFunction · 0.85
yellowFunction · 0.85
cyanFunction · 0.85
greenFunction · 0.85
resolveFunction · 0.50
onMethod · 0.45
getMethod · 0.45
parseMethod · 0.45
logMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected