Skip to content

Commit 6d5a521

Browse files
author
Timothy Wang
committed
Refresh node.js supported versions of azure function core tools
1 parent 5bcec83 commit 6d5a521

2 files changed

Lines changed: 48 additions & 35 deletions

File tree

src/core/func-core-tools.spec.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,46 +53,57 @@ describe("funcCoreTools", () => {
5353

5454
describe("fct.isCoreToolsVersionCompatible()", () => {
5555
it("should return true for compatible versions", () => {
56-
expect(fct.isCoreToolsVersionCompatible(4, 10)).toBe(false);
57-
expect(fct.isCoreToolsVersionCompatible(3, 10)).toBe(true);
56+
expect(fct.isCoreToolsVersionCompatible(3, 10)).toBe(false);
5857
expect(fct.isCoreToolsVersionCompatible(2, 10)).toBe(true);
59-
expect(fct.isCoreToolsVersionCompatible(3, 11)).toBe(true);
60-
expect(fct.isCoreToolsVersionCompatible(2, 11)).toBe(false);
58+
expect(fct.isCoreToolsVersionCompatible(3, 11)).toBe(false);
59+
expect(fct.isCoreToolsVersionCompatible(2, 11)).toBe(true);
6160
expect(fct.isCoreToolsVersionCompatible(4, 12)).toBe(false);
62-
expect(fct.isCoreToolsVersionCompatible(3, 12)).toBe(true);
63-
expect(fct.isCoreToolsVersionCompatible(2, 12)).toBe(false);
64-
expect(fct.isCoreToolsVersionCompatible(3, 13)).toBe(true);
65-
expect(fct.isCoreToolsVersionCompatible(4, 14)).toBe(true);
61+
expect(fct.isCoreToolsVersionCompatible(3, 12)).toBe(false);
62+
expect(fct.isCoreToolsVersionCompatible(2, 12)).toBe(true);
63+
expect(fct.isCoreToolsVersionCompatible(4, 13)).toBe(false);
64+
expect(fct.isCoreToolsVersionCompatible(3, 13)).toBe(false);
65+
expect(fct.isCoreToolsVersionCompatible(2, 13)).toBe(true);
66+
expect(fct.isCoreToolsVersionCompatible(4, 14)).toBe(false);
6667
expect(fct.isCoreToolsVersionCompatible(3, 14)).toBe(true);
67-
expect(fct.isCoreToolsVersionCompatible(2, 14)).toBe(false);
68-
expect(fct.isCoreToolsVersionCompatible(4, 15)).toBe(true);
69-
expect(fct.isCoreToolsVersionCompatible(3, 15)).toBe(false);
70-
expect(fct.isCoreToolsVersionCompatible(4, 16)).toBe(true);
71-
expect(fct.isCoreToolsVersionCompatible(3, 16)).toBe(false);
68+
expect(fct.isCoreToolsVersionCompatible(2, 14)).toBe(true);
69+
expect(fct.isCoreToolsVersionCompatible(4, 15)).toBe(false);
70+
expect(fct.isCoreToolsVersionCompatible(3, 15)).toBe(true);
71+
expect(fct.isCoreToolsVersionCompatible(4, 16)).toBe(false);
72+
expect(fct.isCoreToolsVersionCompatible(3, 16)).toBe(true);
7273
expect(fct.isCoreToolsVersionCompatible(2, 16)).toBe(false);
73-
expect(fct.isCoreToolsVersionCompatible(4, 17)).toBe(true);
74-
expect(fct.isCoreToolsVersionCompatible(3, 17)).toBe(false);
74+
expect(fct.isCoreToolsVersionCompatible(4, 17)).toBe(false);
75+
expect(fct.isCoreToolsVersionCompatible(3, 17)).toBe(true);
7576
expect(fct.isCoreToolsVersionCompatible(2, 17)).toBe(false);
7677
expect(fct.isCoreToolsVersionCompatible(4, 18)).toBe(true);
77-
expect(fct.isCoreToolsVersionCompatible(3, 18)).toBe(false);
78+
expect(fct.isCoreToolsVersionCompatible(3, 18)).toBe(true);
7879
expect(fct.isCoreToolsVersionCompatible(2, 18)).toBe(false);
80+
expect(fct.isCoreToolsVersionCompatible(4, 19)).toBe(true);
81+
expect(fct.isCoreToolsVersionCompatible(3, 19)).toBe(true);
82+
expect(fct.isCoreToolsVersionCompatible(2, 19)).toBe(false);
83+
expect(fct.isCoreToolsVersionCompatible(4, 20)).toBe(true);
84+
expect(fct.isCoreToolsVersionCompatible(3, 20)).toBe(true);
85+
expect(fct.isCoreToolsVersionCompatible(2, 20)).toBe(false);
7986
});
8087
});
8188

8289
describe("detectTargetCoreToolsVersion()", () => {
8390
it("should return the latest valid version for each Node version", () => {
84-
expect(fct.detectTargetCoreToolsVersion(8)).toBe(2);
85-
expect(fct.detectTargetCoreToolsVersion(9)).toBe(2);
86-
expect(fct.detectTargetCoreToolsVersion(10)).toBe(3);
87-
expect(fct.detectTargetCoreToolsVersion(11)).toBe(3);
88-
expect(fct.detectTargetCoreToolsVersion(12)).toBe(3);
89-
expect(fct.detectTargetCoreToolsVersion(13)).toBe(3);
90-
expect(fct.detectTargetCoreToolsVersion(14)).toBe(4);
91-
expect(fct.detectTargetCoreToolsVersion(15)).toBe(4);
92-
expect(fct.detectTargetCoreToolsVersion(16)).toBe(4);
91+
expect(fct.detectTargetCoreToolsVersion(10)).toBe(2);
92+
expect(fct.detectTargetCoreToolsVersion(11)).toBe(2);
93+
expect(fct.detectTargetCoreToolsVersion(12)).toBe(2);
94+
expect(fct.detectTargetCoreToolsVersion(13)).toBe(2);
95+
expect(fct.detectTargetCoreToolsVersion(14)).toBe(3);
96+
expect(fct.detectTargetCoreToolsVersion(15)).toBe(3);
97+
expect(fct.detectTargetCoreToolsVersion(16)).toBe(3);
98+
expect(fct.detectTargetCoreToolsVersion(17)).toBe(3);
99+
expect(fct.detectTargetCoreToolsVersion(18)).toBe(4);
100+
expect(fct.detectTargetCoreToolsVersion(19)).toBe(4);
101+
expect(fct.detectTargetCoreToolsVersion(20)).toBe(4);
93102
// Unsupported Node versions should always return the latest version
103+
expect(fct.detectTargetCoreToolsVersion(8)).toBe(4);
104+
expect(fct.detectTargetCoreToolsVersion(9)).toBe(4);
94105
expect(fct.detectTargetCoreToolsVersion(7)).toBe(4);
95-
expect(fct.detectTargetCoreToolsVersion(17)).toBe(4);
106+
expect(fct.detectTargetCoreToolsVersion(21)).toBe(4);
96107
});
97108
});
98109

@@ -213,7 +224,7 @@ describe("funcCoreTools", () => {
213224
});
214225

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

218229
vol.fromNestedJSON({
219230
["/home/user/.swa/core-tools/v4"]: { ".release-version": "4.3.2" },
@@ -256,7 +267,7 @@ describe("funcCoreTools", () => {
256267
{
257268
["/home/user/.swa/core-tools/"]: {},
258269
},
259-
"/home/user"
270+
"/home/user",
260271
);
261272

262273
const binary = await fct.getCoreToolsBinary();

src/core/func-core-tools.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ export function isCoreToolsVersionCompatible(coreToolsVersion: number, nodeVersi
4242
// Runtime support reference: https://docs.microsoft.com/azure/azure-functions/functions-versions?pivots=programming-language-javascript#languages
4343
switch (coreToolsVersion) {
4444
case 4:
45-
return nodeVersion >= 14 && nodeVersion <= 20;
45+
return nodeVersion >= 18 && nodeVersion <= 20;
4646
case 3:
47-
return nodeVersion >= 10 && nodeVersion <= 14;
47+
return nodeVersion >= 14 && nodeVersion <= 20;
4848
case 2:
49-
return nodeVersion >= 8 && nodeVersion <= 10;
49+
return nodeVersion >= 10 && nodeVersion <= 14;
5050
default:
5151
return false;
5252
}
5353
}
5454

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

6161
// Fallback to the latest version for Unsupported Node version
6262
return 4;
@@ -92,9 +92,11 @@ async function getInstalledSystemCoreToolsVersion(): Promise<number | undefined>
9292

9393
function getDownloadedCoreToolsVersion(targetVersion: number): string | undefined {
9494
const folder = getCoreToolsFolder(targetVersion);
95+
console.log("DOWNLOAD", folder);
9596
if (!fs.existsSync(folder)) {
9697
return undefined;
9798
}
99+
console.log("Ok folder exists");
98100

99101
const versionFile = path.join(folder, VERSION_FILE);
100102
if (!fs.existsSync(versionFile)) {
@@ -155,7 +157,7 @@ async function downloadAndUnzipPackage(release: CoreToolsRelease, dest: string)
155157
{
156158
format: "{bar} {percentage}% | ETA: {eta}s",
157159
},
158-
cliProgress.Presets.shades_classic
160+
cliProgress.Presets.shades_classic,
159161
);
160162
try {
161163
const response = await fetch(release.url);

0 commit comments

Comments
 (0)