| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3f24a87 commit 5e8b2a8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,33 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + const { readFileSync } = require('fs'); | ||
| 4 | + const path = require('path'); | ||
| 5 | + const srcRoot = path.join(__dirname, '..', '..'); | ||
| 6 | + | ||
| 3 | 7 | let _versions; | |
| 4 | 8 | ||
| 9 | + const isRelease = () => { | ||
| 10 | + const re = /#define NODE_VERSION_IS_RELEASE 0/; | ||
| 11 | + const file = path.join(srcRoot, 'src', 'node_version.h'); | ||
| 12 | + return !re.test(readFileSync(file, { encoding: 'utf8' })); | ||
| 13 | + }; | ||
| 14 | + | ||
| 5 | 15 | const getUrl = (url) => { | |
| 6 | 16 | return new Promise((resolve, reject) => { | |
| 7 | 17 | const https = require('https'); | |
| 8 | - const request = https.get(url, (response) => { | ||
| 18 | + const request = https.get(url, { timeout: 5000 }, (response) => { | ||
| 9 | 19 | if (response.statusCode !== 200) { | |
| 10 | 20 | reject(new Error( | |
| 11 | 21 | `Failed to get ${url}, status code ${response.statusCode}`)); | |
| 12 | 22 | } | |
| 13 | 23 | response.setEncoding('utf8'); | |
| 14 | 24 | let body = ''; | |
| 25 | + response.on('aborted', () => reject()); | ||
| 15 | 26 | response.on('data', (data) => body += data); | |
| 16 | 27 | response.on('end', () => resolve(body)); | |
| 17 | 28 | }); | |
| 18 | 29 | request.on('error', (err) => reject(err)); | |
| 30 | + request.on('timeout', () => request.abort()); | ||
| 19 | 31 | }); | |
| 20 | 32 | }; | |
| 21 | 33 | ||
@@ -27,10 +39,23 @@ module.exports = { | |||
| 27 | 39 | ||
| 28 | 40 | // The CHANGELOG.md on release branches may not reference newer semver | |
| 29 | 41 | // majors of Node.js so fetch and parse the version from the master branch. | |
| 30 | - const githubContentUrl = 'https://raw.githubusercontent.com/nodejs/node/'; | ||
| 31 | - const changelog = await getUrl(`${githubContentUrl}/master/CHANGELOG.md`); | ||
| 42 | + const url = | ||
| 43 | + 'https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md'; | ||
| 44 | + let changelog; | ||
| 45 | + try { | ||
| 46 | + changelog = await getUrl(url); | ||
| 47 | + } catch (e) { | ||
| 48 | + // Fail if this is a release build, otherwise fallback to local files. | ||
| 49 | + if (isRelease()) { | ||
| 50 | + throw e; | ||
| 51 | + } else { | ||
| 52 | + const file = path.join(srcRoot, 'CHANGELOG.md'); | ||
| 53 | + console.warn(`Unable to retrieve ${url}. Falling back to ${file}.`); | ||
| 54 | + changelog = readFileSync(file, { encoding: 'utf8' }); | ||
| 55 | + } | ||
| 56 | + } | ||
| 32 | 57 | const ltsRE = /Long Term Support/i; | |
| 33 | - const versionRE = /\* \[Node\.js ([0-9.]+)\][^-—]+[-—]\s*(.*)\n/g; | ||
| 58 | + const versionRE = /\* \[Node\.js ([0-9.]+)\][^-—]+[-—]\s*(.*)\r?\n/g; | ||
| 34 | 59 | _versions = []; | |
| 35 | 60 | let match; | |
| 36 | 61 | while ((match = versionRE.exec(changelog)) != null) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments