Skip to content

Refreshing Node.js supported versions #869

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

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
67 changes: 39 additions & 28 deletions src/core/func-core-tools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,57 @@ describe("funcCoreTools", () => {

describe("fct.isCoreToolsVersionCompatible()", () => {
it("should return true for compatible versions", () => {
expect(fct.isCoreToolsVersionCompatible(4, 10)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 10)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 10)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(2, 10)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 11)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 11)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 11)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(2, 11)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 12)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 12)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 12)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 13)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 14)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 12)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(2, 12)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 13)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 13)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(2, 13)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 14)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 14)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 14)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 15)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 15)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 16)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 16)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(2, 14)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 15)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 15)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(4, 16)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 16)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 16)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 17)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 17)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 17)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 17)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 17)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 18)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 18)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(3, 18)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 18)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 19)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 19)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 19)).toBe(false);
expect(fct.isCoreToolsVersionCompatible(4, 20)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(3, 20)).toBe(true);
expect(fct.isCoreToolsVersionCompatible(2, 20)).toBe(false);
});
});

describe("detectTargetCoreToolsVersion()", () => {
it("should return the latest valid version for each Node version", () => {
expect(fct.detectTargetCoreToolsVersion(8)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(9)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(10)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(11)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(12)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(13)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(14)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(15)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(16)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(10)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(11)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(12)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(13)).toBe(2);
expect(fct.detectTargetCoreToolsVersion(14)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(15)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(16)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(17)).toBe(3);
expect(fct.detectTargetCoreToolsVersion(18)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(19)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(20)).toBe(4);
// Unsupported Node versions should always return the latest version
expect(fct.detectTargetCoreToolsVersion(8)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(9)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(7)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(17)).toBe(4);
expect(fct.detectTargetCoreToolsVersion(21)).toBe(4);
});
});

Expand Down Expand Up @@ -213,7 +224,7 @@ describe("funcCoreTools", () => {
});

it("should return the downloaded binary if the system binary is incompatible", async () => {
fct.setCachedInstalledSystemCoreToolsVersion(3);
fct.setCachedInstalledSystemCoreToolsVersion(2);

vol.fromNestedJSON({
["/home/user/.swa/core-tools/v4"]: { ".release-version": "4.3.2" },
Expand Down Expand Up @@ -256,7 +267,7 @@ describe("funcCoreTools", () => {
{
["/home/user/.swa/core-tools/"]: {},
},
"/home/user"
"/home/user",
);

const binary = await fct.getCoreToolsBinary();
Expand Down
14 changes: 7 additions & 7 deletions src/core/func-core-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ export function isCoreToolsVersionCompatible(coreToolsVersion: number, nodeVersi
// Runtime support reference: https://docs.microsoft.com/azure/azure-functions/functions-versions?pivots=programming-language-javascript#languages
switch (coreToolsVersion) {
case 4:
return nodeVersion >= 14 && nodeVersion <= 20;
return nodeVersion >= 18 && nodeVersion <= 20;
case 3:
return nodeVersion >= 10 && nodeVersion <= 14;
return nodeVersion >= 14 && nodeVersion <= 20;
case 2:
return nodeVersion >= 8 && nodeVersion <= 10;
return nodeVersion >= 10 && nodeVersion <= 14;
default:
return false;
}
}

export function detectTargetCoreToolsVersion(nodeVersion: number): number {
// Pick the highest version that is compatible with the specified Node version
if (nodeVersion >= 14 && nodeVersion <= 20) return 4;
if (nodeVersion >= 10 && nodeVersion < 14) return 3;
if (nodeVersion >= 8 && nodeVersion < 10) return 2;
if (nodeVersion >= 18 && nodeVersion <= 20) return 4;
if (nodeVersion >= 14 && nodeVersion < 20) return 3;
if (nodeVersion >= 10 && nodeVersion < 14) return 2;

// Fallback to the latest version for Unsupported Node version
return 4;
Expand Down Expand Up @@ -155,7 +155,7 @@ async function downloadAndUnzipPackage(release: CoreToolsRelease, dest: string)
{
format: "{bar} {percentage}% | ETA: {eta}s",
},
cliProgress.Presets.shades_classic
cliProgress.Presets.shades_classic,
);
try {
const response = await fetch(release.url);
Expand Down
Loading