Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc, tools: added caching support for CHANGELOG.md in tools/doc/versions.js #32515

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*~
7 changes: 6 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 @@ -45,11 +45,16 @@ 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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be using statSync and check whether the file is outdated – otherwise this isn’t caching, it’s just storing a file and keeping it around forever.

(Also, it’s odd that we use fs.*Sync() functions inside an async function, although it’s not that important for this script. I’d suggest using readFile, stat, writeFile from fs.promises instead, just to reflect best practices.)

changelog = readFileSync(masterChangelog, { encoding: 'utf8' });
} else {
try {
changelog = await getUrl(url);
// Create the .master-CHANGLELOG.md file
writeFileSync(masterChangelog, changelog);
} catch (e) {
// Fail if this is a release build, otherwise fallback to local files.
if (isRelease()) {
Expand Down