From 50772d2a02b10d61c8edd740682e80cb3daa161c Mon Sep 17 00:00:00 2001 From: Hassaan Pasha Date: Fri, 27 Mar 2020 12:21:00 +0500 Subject: [PATCH] doc, tools: added caching support for CHANGELOG.md in tools/doc/versions.js When running `make doc` the CHANGELOG.md file is pulled everytime for each of the doc file that requires the versions list. This commit introduces a new file called `.master-CHANGELOG.md` which will be created once so that subsequent calls for the version are pulled locally instead of from the repo. Since this file is not part of the codebase proper, it is appended in the .gitignore file. References Issue #32512 --- .gitignore | 1 + tools/doc/versions.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 425a5ddbec0fca..fbeb441c1f3924 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,7 @@ _UpgradeReport_Files/ # === Global Rules === # Keep last to avoid being excluded *.pyc +.master-CHANGELOG.md __pycache__ .DS_Store *~ diff --git a/tools/doc/versions.js b/tools/doc/versions.js index bff6ac3617fbde..1fc37e82479402 100644 --- a/tools/doc/versions.js +++ b/tools/doc/versions.js @@ -1,6 +1,6 @@ 'use strict'; -const { readFileSync } = require('fs'); +const { readFileSync, existsSync, writeFileSync } = require('fs'); const path = require('path'); const srcRoot = path.join(__dirname, '..', '..'); @@ -31,6 +31,13 @@ const getUrl = (url) => { }); }; +const createMaster = (masterPath, file) => { + writeFileSync( + masterPath, + file, { encoding: 'utf8' } + ); +}; + const kNoInternet = !!process.env.NODE_TEST_NO_INTERNET; module.exports = { @@ -45,11 +52,15 @@ module.exports = { 'https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md'; let changelog; const file = path.join(srcRoot, 'CHANGELOG.md'); + const masterChangelog = path.join(srcRoot, '.master-CHANGELOG.md'); if (kNoInternet) { changelog = readFileSync(file, { encoding: 'utf8' }); + } else if (existsSync(masterChangelog)) { + changelog = readFileSync(masterChangelog, { encoding: 'utf8' }); } else { try { changelog = await getUrl(url); + createMaster(masterChangelog, changelog); } catch (e) { // Fail if this is a release build, otherwise fallback to local files. if (isRelease()) {