Merge pull request #3182 from github/koesie10/vscode-versions

Add scripts for updating the Node and Chromium versions
This commit is contained in:
Koen Vlaswinkel
2024-01-03 11:36:35 +01:00
committed by GitHub
8 changed files with 208 additions and 34 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,4 @@
{
"chromiumVersion": "114",
"electronVersion": "25.8.0"
}

View File

@@ -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() {
@@ -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: "..",

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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;
}

View File

@@ -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,
};
}