Skip to content

Commit cce0e14

Browse files
authored
Merge pull request #3182 from github/koesie10/vscode-versions
Add scripts for updating the Node and Chromium versions
2 parents 8daf337 + cf00f8f commit cce0e14

File tree

8 files changed

+208
-34
lines changed

8 files changed

+208
-34
lines changed

docs/node-version.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ You can find this info by selecting "About Visual Studio Code" from the top menu
1313

1414
## Updating the Node.js version
1515

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

18-
- `extensions/ql-vscode/.nvmrc` - this will enable nvm to automatically switch to the correct Node
19-
version when you're in the project folder. It will also change the Node version the GitHub Actions
20-
workflows use.
21-
- `extensions/ql-vscode/package.json` - the "engines.node: '[VERSION]'" setting
22-
- `extensions/ql-vscode/package.json` - the "@types/node: '[VERSION]'" dependency
23-
24-
Then run `npm install` to update the `extensions/ql-vscode/package-lock.json` file.
18+
```bash
19+
npx ts-node scripts/update-node-version.ts
20+
```
2521

2622
## Node.js version used in tests
2723

docs/vscode-version.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,12 @@ When updating the minimum version in `package.json`, you should also follow the
3232
### Updating the Chromium target version
3333

3434
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.
35-
This version should be the same as the version of Chromium that is bundled with the new minimum VS Code version. There are two
36-
methods to find this version.
35+
This version should be the same as the version of Chromium that is bundled with the new minimum VS Code version. To update
36+
the version, run:
3737

38-
#### Using the About Visual Studio Code dialog
39-
40-
Download the new minimum VS Code version from [the previous release versions](https://code.visualstudio.com/docs/supporting/faq#_previous-release-versions). Then,
41-
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.
42-
43-
![Chromium version in the About Visual Studio Code dialog](images/about-vscode-chromium.png)
44-
45-
In this case, the `target` would be `chrome114`.
46-
47-
#### Using the VS Code source code
48-
49-
You can find the version of Electron that VS Code uses by looking at its `package.json` file for a specific version
50-
(for example [the `package.json` for `1.82.0`](https://github.com/microsoft/vscode/blob/1.82.0/package.json#L153)).
51-
52-
![Electron version in the `package.json` file](images/electron-version.png)
53-
54-
Then, you can find the version of Chromium that is bundled with that version of Electron by looking at the
55-
Chromium version that is shown for that Electron version on [the Electron releases site](https://releases.electronjs.org/releases/stable)
56-
(for example [the `25.8.0` release](https://releases.electronjs.org/release/v25.8.0)):
57-
58-
![Chromium version in the Electron releases site](images/electron-chromium-version.png)
59-
60-
In this case, the `target` would be `chrome114`.
38+
```bash
39+
npx ts-node scripts/update-chromium-version.ts
40+
```
6141

6242
#### Troubleshooting
6343

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"chromiumVersion": "114",
3+
"electronVersion": "25.8.0"
4+
}

extensions/ql-vscode/gulpfile.ts/view.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import esbuild from "gulp-esbuild";
33
import { createProject } from "gulp-typescript";
44
import { goodReporter } from "./typescript";
55

6+
import * as chromiumVersion from "./chromium-version.json";
7+
68
const tsProject = createProject("src/view/tsconfig.json");
79

810
export function compileViewEsbuild() {
@@ -13,7 +15,7 @@ export function compileViewEsbuild() {
1315
bundle: true,
1416
format: "iife",
1517
platform: "browser",
16-
target: "chrome114", // Electron 25, VS Code 1.85
18+
target: `chrome${chromiumVersion.chromiumVersion}`,
1719
jsx: "automatic",
1820
sourcemap: "linked",
1921
sourceRoot: "..",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { join, resolve } from "path";
2+
import { outputFile, readJSON } from "fs-extra";
3+
import { minVersion } from "semver";
4+
import { getVersionInformation } from "./util/vscode-versions";
5+
6+
const extensionDirectory = resolve(__dirname, "..");
7+
8+
async function updateChromiumVersion() {
9+
const packageJson = await readJSON(
10+
resolve(extensionDirectory, "package.json"),
11+
);
12+
13+
const minimumVsCodeVersion = minVersion(packageJson.engines.vscode)?.version;
14+
if (!minimumVsCodeVersion) {
15+
throw new Error("Could not find minimum VS Code version");
16+
}
17+
18+
const versionInformation = await getVersionInformation(minimumVsCodeVersion);
19+
20+
const chromiumMajorVersion = versionInformation.chromiumVersion.split(".")[0];
21+
22+
console.log(
23+
`VS Code ${minimumVsCodeVersion} uses Chromium ${chromiumMajorVersion}`,
24+
);
25+
26+
await outputFile(
27+
join(extensionDirectory, "gulpfile.ts", "chromium-version.json"),
28+
`${JSON.stringify(
29+
{
30+
chromiumVersion: chromiumMajorVersion,
31+
electronVersion: versionInformation.electronVersion,
32+
},
33+
null,
34+
2,
35+
)}\n`,
36+
);
37+
}
38+
39+
updateChromiumVersion().catch((e: unknown) => {
40+
console.error(e);
41+
process.exit(2);
42+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { join, resolve } from "path";
2+
import { execSync } from "child_process";
3+
import { outputFile, readFile, readJSON } from "fs-extra";
4+
import { getVersionInformation } from "./util/vscode-versions";
5+
import { fetchJson } from "./util/fetch";
6+
7+
const extensionDirectory = resolve(__dirname, "..");
8+
9+
interface Release {
10+
tag_name: string;
11+
}
12+
13+
async function updateNodeVersion() {
14+
const latestVsCodeRelease = await fetchJson<Release>(
15+
"https://api.github.com/repos/microsoft/vscode/releases/latest",
16+
);
17+
const latestVsCodeVersion = latestVsCodeRelease.tag_name;
18+
19+
console.log(`Latest VS Code version is ${latestVsCodeVersion}`);
20+
21+
const versionInformation = await getVersionInformation(latestVsCodeVersion);
22+
console.log(
23+
`VS Code ${versionInformation.vscodeVersion} uses Electron ${versionInformation.electronVersion} and Node ${versionInformation.nodeVersion}`,
24+
);
25+
26+
let currentNodeVersion = (
27+
await readFile(join(extensionDirectory, ".nvmrc"), "utf8")
28+
).trim();
29+
if (currentNodeVersion.startsWith("v")) {
30+
currentNodeVersion = currentNodeVersion.slice(1);
31+
}
32+
33+
if (currentNodeVersion === versionInformation.nodeVersion) {
34+
console.log("Node version is already up to date");
35+
return;
36+
}
37+
38+
console.log("Node version needs to be updated, updating now");
39+
40+
await outputFile(
41+
join(extensionDirectory, ".nvmrc"),
42+
`v${versionInformation.nodeVersion}\n`,
43+
);
44+
45+
console.log("Updated .nvmrc");
46+
47+
const packageJson = await readJSON(
48+
join(extensionDirectory, "package.json"),
49+
"utf8",
50+
);
51+
52+
packageJson.engines.node = `^${versionInformation.nodeVersion}`;
53+
packageJson.devDependencies["@types/node"] =
54+
`${versionInformation.nodeVersion}`;
55+
56+
await outputFile(
57+
join(extensionDirectory, "package.json"),
58+
`${JSON.stringify(packageJson, null, 2)}\n`,
59+
);
60+
61+
console.log("Updated package.json, now running npm install");
62+
63+
execSync("npm install", { cwd: extensionDirectory, stdio: "inherit" });
64+
65+
console.log("Node version updated successfully");
66+
}
67+
68+
updateNodeVersion().catch((e: unknown) => {
69+
console.error(e);
70+
process.exit(2);
71+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export async function fetchJson<T>(url: string): Promise<T> {
2+
const response = await fetch(url);
3+
if (!response.ok) {
4+
throw new Error(
5+
`Could not fetch ${url}: ${response.status} ${response.statusText}`,
6+
);
7+
}
8+
9+
return (await response.json()) as T;
10+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { minVersion } from "semver";
2+
import { fetchJson } from "./fetch";
3+
4+
type VsCodePackageJson = {
5+
devDependencies: {
6+
electron: string;
7+
};
8+
};
9+
10+
async function getVsCodePackageJson(
11+
version: string,
12+
): Promise<VsCodePackageJson> {
13+
return await fetchJson(
14+
`https://raw.githubusercontent.com/microsoft/vscode/${version}/package.json`,
15+
);
16+
}
17+
18+
interface ElectronVersion {
19+
version: string;
20+
date: string;
21+
node: string;
22+
v8: string;
23+
uv: string;
24+
zlib: string;
25+
openssl: string;
26+
modules: string;
27+
chrome: string;
28+
files: string[];
29+
body?: string;
30+
apm?: string;
31+
}
32+
33+
async function getElectronReleases(): Promise<ElectronVersion[]> {
34+
return await fetchJson("https://releases.electronjs.org/releases.json");
35+
}
36+
37+
type VersionInformation = {
38+
vscodeVersion: string;
39+
electronVersion: string;
40+
nodeVersion: string;
41+
chromiumVersion: string;
42+
};
43+
44+
export async function getVersionInformation(
45+
vscodeVersion: string,
46+
): Promise<VersionInformation> {
47+
const vsCodePackageJson = await getVsCodePackageJson(vscodeVersion);
48+
const electronVersion = minVersion(vsCodePackageJson.devDependencies.electron)
49+
?.version;
50+
if (!electronVersion) {
51+
throw new Error("Could not find Electron version");
52+
}
53+
54+
const electronReleases = await getElectronReleases();
55+
56+
const electronRelease = electronReleases.find(
57+
(release) => release.version === electronVersion,
58+
);
59+
if (!electronRelease) {
60+
throw new Error(`Could not find Electron release ${electronVersion}`);
61+
}
62+
63+
return {
64+
vscodeVersion,
65+
electronVersion,
66+
nodeVersion: electronRelease.node,
67+
chromiumVersion: electronRelease.chrome,
68+
};
69+
}

0 commit comments

Comments
 (0)