|
| 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 | +}); |
0 commit comments