Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
*~
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) => {
Copy link
Member

Choose a reason for hiding this comment

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

this function only is used once, why not code inline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. My bad.
Thanks for the suggestion.

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)) {
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);
createMaster(masterChangelog, changelog);
} catch (e) {
// Fail if this is a release build, otherwise fallback to local files.
if (isRelease()) {
Expand Down