Skip to content
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
12 changes: 4 additions & 8 deletions docs/node-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ You can find this info by selecting "About Visual Studio Code" from the top menu

## Updating the Node.js version

The following files will need to be updated:
To update the Node.js version, run:

- `extensions/ql-vscode/.nvmrc` - this will enable nvm to automatically switch to the correct Node
version when you're in the project folder. It will also change the Node version the GitHub Actions
workflows use.
- `extensions/ql-vscode/package.json` - the "engines.node: '[VERSION]'" setting
- `extensions/ql-vscode/package.json` - the "@types/node: '[VERSION]'" dependency

Then run `npm install` to update the `extensions/ql-vscode/package-lock.json` file.
```bash
npx ts-node scripts/update-node-version.ts
```

## Node.js version used in tests

Expand Down
30 changes: 5 additions & 25 deletions docs/vscode-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,12 @@ When updating the minimum version in `package.json`, you should also follow the
### Updating the Chromium target version

For the webview code, we use [esbuild](https://esbuild.github.io/) to bundle the code. This requires a target version of Chromium to be specified.
This version should be the same as the version of Chromium that is bundled with the new minimum VS Code version. There are two
methods to find this version.
This version should be the same as the version of Chromium that is bundled with the new minimum VS Code version. To update
the version, run:

#### Using the About Visual Studio Code dialog

Download the new minimum VS Code version from [the previous release versions](https://code.visualstudio.com/docs/supporting/faq#_previous-release-versions). Then,
select "About Visual Studio Code" from the top menu. This will show the version of Chromium that is bundled with that version of VS Code.

![Chromium version in the About Visual Studio Code dialog](images/about-vscode-chromium.png)

In this case, the `target` would be `chrome114`.

#### Using the VS Code source code

You can find the version of Electron that VS Code uses by looking at its `package.json` file for a specific version
(for example [the `package.json` for `1.82.0`](https://github.com/microsoft/vscode/blob/1.82.0/package.json#L153)).

![Electron version in the `package.json` file](images/electron-version.png)

Then, you can find the version of Chromium that is bundled with that version of Electron by looking at the
Chromium version that is shown for that Electron version on [the Electron releases site](https://releases.electronjs.org/releases/stable)
(for example [the `25.8.0` release](https://releases.electronjs.org/release/v25.8.0)):

![Chromium version in the Electron releases site](images/electron-chromium-version.png)

In this case, the `target` would be `chrome114`.
```bash
npx ts-node scripts/update-chromium-version.ts
```

#### Troubleshooting

Expand Down
4 changes: 4 additions & 0 deletions extensions/ql-vscode/gulpfile.ts/chromium-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"chromiumVersion": "114",
"electronVersion": "25.8.0"
}
4 changes: 3 additions & 1 deletion extensions/ql-vscode/gulpfile.ts/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import esbuild from "gulp-esbuild";
import { createProject } from "gulp-typescript";
import { goodReporter } from "./typescript";

import * as chromiumVersion from "./chromium-version.json";

const tsProject = createProject("src/view/tsconfig.json");

export function compileViewEsbuild() {
Expand All @@ -13,7 +15,7 @@ export function compileViewEsbuild() {
bundle: true,
format: "iife",
platform: "browser",
target: "chrome114", // Electron 25, VS Code 1.85
target: `chrome${chromiumVersion.chromiumVersion}`,
jsx: "automatic",
sourcemap: "linked",
sourceRoot: "..",
Expand Down
42 changes: 42 additions & 0 deletions extensions/ql-vscode/scripts/update-chromium-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { join, resolve } from "path";
import { outputFile, readJSON } from "fs-extra";
import { minVersion } from "semver";
import { getVersionInformation } from "./util/vscode-versions";

const extensionDirectory = resolve(__dirname, "..");

async function updateChromiumVersion() {
const packageJson = await readJSON(
resolve(extensionDirectory, "package.json"),
);

const minimumVsCodeVersion = minVersion(packageJson.engines.vscode)?.version;
if (!minimumVsCodeVersion) {
throw new Error("Could not find minimum VS Code version");
}

const versionInformation = await getVersionInformation(minimumVsCodeVersion);

const chromiumMajorVersion = versionInformation.chromiumVersion.split(".")[0];

console.log(
`VS Code ${minimumVsCodeVersion} uses Chromium ${chromiumMajorVersion}`,
);

await outputFile(
join(extensionDirectory, "gulpfile.ts", "chromium-version.json"),
`${JSON.stringify(
{
chromiumVersion: chromiumMajorVersion,
electronVersion: versionInformation.electronVersion,
},
null,
2,
)}\n`,
);
}

updateChromiumVersion().catch((e: unknown) => {
console.error(e);
process.exit(2);
});
71 changes: 71 additions & 0 deletions extensions/ql-vscode/scripts/update-node-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { join, resolve } from "path";
import { execSync } from "child_process";
import { outputFile, readFile, readJSON } from "fs-extra";
import { getVersionInformation } from "./util/vscode-versions";
import { fetchJson } from "./util/fetch";

const extensionDirectory = resolve(__dirname, "..");

interface Release {
tag_name: string;
}

async function updateNodeVersion() {
const latestVsCodeRelease = await fetchJson<Release>(
"https://api.github.com/repos/microsoft/vscode/releases/latest",
);
const latestVsCodeVersion = latestVsCodeRelease.tag_name;

console.log(`Latest VS Code version is ${latestVsCodeVersion}`);

const versionInformation = await getVersionInformation(latestVsCodeVersion);
console.log(
`VS Code ${versionInformation.vscodeVersion} uses Electron ${versionInformation.electronVersion} and Node ${versionInformation.nodeVersion}`,
);

let currentNodeVersion = (
await readFile(join(extensionDirectory, ".nvmrc"), "utf8")
).trim();
if (currentNodeVersion.startsWith("v")) {
currentNodeVersion = currentNodeVersion.slice(1);
}

if (currentNodeVersion === versionInformation.nodeVersion) {
console.log("Node version is already up to date");
return;
}

console.log("Node version needs to be updated, updating now");

await outputFile(
join(extensionDirectory, ".nvmrc"),
`v${versionInformation.nodeVersion}\n`,
);

console.log("Updated .nvmrc");

const packageJson = await readJSON(
join(extensionDirectory, "package.json"),
"utf8",
);

packageJson.engines.node = `^${versionInformation.nodeVersion}`;
packageJson.devDependencies["@types/node"] =
`${versionInformation.nodeVersion}`;

await outputFile(
join(extensionDirectory, "package.json"),
`${JSON.stringify(packageJson, null, 2)}\n`,
);

console.log("Updated package.json, now running npm install");

execSync("npm install", { cwd: extensionDirectory, stdio: "inherit" });

console.log("Node version updated successfully");
}

updateNodeVersion().catch((e: unknown) => {
console.error(e);
process.exit(2);
});
10 changes: 10 additions & 0 deletions extensions/ql-vscode/scripts/util/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export async function fetchJson<T>(url: string): Promise<T> {
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`Could not fetch ${url}: ${response.status} ${response.statusText}`,
);
}

return (await response.json()) as T;
}
69 changes: 69 additions & 0 deletions extensions/ql-vscode/scripts/util/vscode-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { minVersion } from "semver";
import { fetchJson } from "./fetch";

type VsCodePackageJson = {
devDependencies: {
electron: string;
};
};

async function getVsCodePackageJson(
version: string,
): Promise<VsCodePackageJson> {
return await fetchJson(
`https://raw.githubusercontent.com/microsoft/vscode/${version}/package.json`,
);
}

interface ElectronVersion {
version: string;
date: string;
node: string;
v8: string;
uv: string;
zlib: string;
openssl: string;
modules: string;
chrome: string;
files: string[];
body?: string;
apm?: string;
}

async function getElectronReleases(): Promise<ElectronVersion[]> {
return await fetchJson("https://releases.electronjs.org/releases.json");
}

type VersionInformation = {
vscodeVersion: string;
electronVersion: string;
nodeVersion: string;
chromiumVersion: string;
};

export async function getVersionInformation(
vscodeVersion: string,
): Promise<VersionInformation> {
const vsCodePackageJson = await getVsCodePackageJson(vscodeVersion);
const electronVersion = minVersion(vsCodePackageJson.devDependencies.electron)
?.version;
if (!electronVersion) {
throw new Error("Could not find Electron version");
}

const electronReleases = await getElectronReleases();

const electronRelease = electronReleases.find(
(release) => release.version === electronVersion,
);
if (!electronRelease) {
throw new Error(`Could not find Electron release ${electronVersion}`);
}

return {
vscodeVersion,
electronVersion,
nodeVersion: electronRelease.node,
chromiumVersion: electronRelease.chrome,
};
}