Skip to content

Commit

Permalink
chore(deps): remove node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehan committed Nov 24, 2023
1 parent 9b28bcb commit 4f8ad39
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"eslint": "^8.27.0",
"husky": ">=6",
"lint-staged": ">=10",
"node-fetch": "~2",
"prettier": "^2.8.8",
"tsx": "^3.12.7",
"typescript": "^5.1.3"
Expand Down
50 changes: 31 additions & 19 deletions scripts/check-node-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const fetch = require("node-fetch"); // @TODO this can be removed once we upgrade to Node 18 and use native fetch

const today = new Date();
const oneMonthFromToday = new Date();
Expand All @@ -14,21 +13,25 @@ const versionRegex = /v(\d+)\.(\d+)\.(\d+)/; // 'v16.14.3'

// convert version string to a number for easier sorting
function calcVersion(x) {
const match = x.match(versionRegex);
if (!match) {
throw new Error(`version regex failed to match version string '${x}'`);
}
return (+match[1] * 1000000) + (+match[2] * 1000) + (+match[3]);
const match = x.match(versionRegex);
if (!match) {
throw new Error(`version regex failed to match version string '${x}'`);
}
return +match[1] * 1000000 + +match[2] * 1000 + +match[3];
}

async function getLTSVersions() {
const response = await fetch("https://nodejs.org/download/release/index.json");
const response = await fetch(
"https://nodejs.org/download/release/index.json"
);
const data = await response.json();
const allLTSVersions = data.filter(item => item.lts);
const allLTSVersions = data.filter((item) => item.lts);

// for performance reasons when sorting,
// precalculate an actual version number from the version string
allLTSVersions.forEach(item => item.numVersion = calcVersion(item.version));
allLTSVersions.forEach(
(item) => (item.numVersion = calcVersion(item.version))
);
allLTSVersions.sort((a, b) => a.numVersion - b.numVersion);

// console.debug("All LTS versions - sorted oldest first");
Expand All @@ -51,13 +54,22 @@ async function getLTSVersions() {
/** Return the earliest supported version whose EOL date is at least a month away */
async function getEarliestSupportedVersion() {
// https://github.com/nodejs/Release/blob/main/schedule.json
const response = await fetch("https://raw.githubusercontent.com/nodejs/Release/main/schedule.json");
const response = await fetch(
"https://raw.githubusercontent.com/nodejs/Release/main/schedule.json"
);
const data = await response.json();
const activelySupportedVersions = Object.entries(data).filter(([version, metadata]) => {
return new Date(metadata.lts) <= today && new Date(metadata.end) > oneMonthFromToday;
}).sort((a, b) => new Date(a[1].start) - new Date(b[1].start));

console.debug("Actively supported versions with an EOL date at least 1 month away")
const activelySupportedVersions = Object.entries(data)
.filter(([version, metadata]) => {
return (
new Date(metadata.lts) <= today &&
new Date(metadata.end) > oneMonthFromToday
);
})
.sort((a, b) => new Date(a[1].start) - new Date(b[1].start));

console.debug(
"Actively supported versions with an EOL date at least 1 month away"
);
console.debug(Object.fromEntries(activelySupportedVersions));

return activelySupportedVersions[0][0];
Expand All @@ -74,10 +86,10 @@ async function getDesiredVersion() {
return version;
}

module.exports = async ({github, context, core}) => {
module.exports = async ({ github, context, core }) => {
const version = await getDesiredVersion();
const short = version.match(versionRegex)[1];

core.exportVariable('NEW_NODEJS_VERSION', version.slice(1)); // strip the 'v' from the start of the string
core.exportVariable('NEW_NODEJS_VERSION_SHORT', short);
}
core.exportVariable("NEW_NODEJS_VERSION", version.slice(1)); // strip the 'v' from the start of the string
core.exportVariable("NEW_NODEJS_VERSION_SHORT", short);
};
1 change: 0 additions & 1 deletion scripts/check-terraform-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const fetch = require("node-fetch"); // @TODO this can be removed once we upgrade to Node 18 and use native fetch

async function getLatestVersion() {
const response = await fetch(
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3016,13 +3016,6 @@ node-fetch@^2.6.11, node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@~2:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
Expand Down

0 comments on commit 4f8ad39

Please sign in to comment.