Skip to content
Open
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
16 changes: 16 additions & 0 deletions extensions/ql-vscode/scripts/util/vscode-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import { fetchJson, fetchText } from "./fetch";

type VsCodePackageJson = {
nativeBuild?: {
runtime?: string;
target?: string;
};
devDependencies?: {
electron?: string;
};
Expand Down Expand Up @@ -34,6 +38,18 @@

async function getVsCodeElectronVersion(version: string): Promise<string> {
const packageJson = await getVsCodePackageJson(version);
if (packageJson.nativeBuild?.runtime === "electron") {
const target = packageJson.nativeBuild.target;
const electronVersion = target && valid(target);
Comment thread
cklin marked this conversation as resolved.
Dismissed
if (!electronVersion) {
throw new Error(
"Could not find a valid Electron version in VS Code package.json nativeBuild.target",
);
}

return electronVersion;
}

const packageElectronVersion = packageJson.devDependencies?.electron;
if (packageElectronVersion) {
const electronVersion = minVersion(packageElectronVersion)?.version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const electronReleases = [
node: "24.18.1",
chrome: "148.0.7778.280",
},
{
version: "43.8.9",
node: "24.22.1",
chrome: "150.0.7871.250",
},
];

function mockFetch(
Expand Down Expand Up @@ -61,6 +66,48 @@ describe("parseElectronVersion", () => {
});

describe("getVersionInformation", () => {
it("reads Electron from nativeBuild.target without fetching .npmrc", async () => {
const fetchMock = mockFetch({
"https://raw.githubusercontent.com/microsoft/vscode/1.147.0/package.json":
{
nativeBuild: {
runtime: "electron",
target: "43.8.9",
},
},
"https://releases.electronjs.org/releases.json": electronReleases,
});

await expect(getVersionInformation("1.147.0")).resolves.toEqual({
vscodeVersion: "1.147.0",
electronVersion: "43.8.9",
nodeVersion: "24.22.1",
chromiumVersion: "150.0.7871.250",
});
expect(fetchMock).not.toHaveBeenCalledWith(
"https://raw.githubusercontent.com/microsoft/vscode/1.147.0/.npmrc",
);
});

it.each([undefined, "not-a-version", "^43.8.9"])(
"rejects an invalid nativeBuild.target: %s",
async (target) => {
mockFetch({
"https://raw.githubusercontent.com/microsoft/vscode/1.147.0/package.json":
{
nativeBuild: {
runtime: "electron",
target,
},
},
});

await expect(getVersionInformation("1.147.0")).rejects.toThrow(
"Could not find a valid Electron version in VS Code package.json nativeBuild.target",
);
},
);

it("reads Electron from package.json for older VS Code releases", async () => {
const fetchMock = mockFetch({
"https://raw.githubusercontent.com/microsoft/vscode/1.90.0/package.json":
Expand All @@ -83,22 +130,26 @@ describe("getVersionInformation", () => {
);
});

it("falls back to .npmrc for newer VS Code releases", async () => {
mockFetch({
"https://raw.githubusercontent.com/microsoft/vscode/1.137.0/package.json":
{
devDependencies: {},
},
"https://raw.githubusercontent.com/microsoft/vscode/1.137.0/.npmrc":
'target="42.10.0"\nruntime="electron"\n',
"https://releases.electronjs.org/releases.json": electronReleases,
});
it.each([
{ devDependencies: {} },
{ nativeBuild: { runtime: "node", target: "24.18.1" } },
])(
"falls back to .npmrc when package.json contains %j",
async (packageJson) => {
mockFetch({
"https://raw.githubusercontent.com/microsoft/vscode/1.137.0/package.json":
packageJson,
"https://raw.githubusercontent.com/microsoft/vscode/1.137.0/.npmrc":
'target="42.10.0"\nruntime="electron"\n',
"https://releases.electronjs.org/releases.json": electronReleases,
});

await expect(getVersionInformation("1.137.0")).resolves.toEqual({
vscodeVersion: "1.137.0",
electronVersion: "42.10.0",
nodeVersion: "24.18.1",
chromiumVersion: "148.0.7778.280",
});
});
await expect(getVersionInformation("1.137.0")).resolves.toEqual({
vscodeVersion: "1.137.0",
electronVersion: "42.10.0",
nodeVersion: "24.18.1",
chromiumVersion: "148.0.7778.280",
});
},
);
});