Skip to content

Commit

Permalink
doc, tools: added caching support for CHANGELOG.md in tools/doc/versi…
Browse files Browse the repository at this point in the history
…ons.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 nodejs#32512
  • Loading branch information
hassaanp committed Mar 27, 2020
1 parent 113c04c commit 50772d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _UpgradeReport_Files/
# === Global Rules ===
# Keep last to avoid being excluded
*.pyc
.master-CHANGELOG.md
__pycache__
.DS_Store
*~
13 changes: 12 additions & 1 deletion tools/doc/versions.js
Original file line number Diff line number Diff line change
@@ -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, '..', '..');

Expand Down Expand Up @@ -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 = {
Expand All @@ -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()) {
Expand Down

0 comments on commit 50772d2

Please sign in to comment.