Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/scripts/xterm-update.js
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
const cp = require('child_process');
7
const path = require('path');
8
9
const moduleNames = [
10
'@xterm/xterm',
11
'@xterm/addon-clipboard',
12
'@xterm/addon-image',
13
'@xterm/addon-ligatures',
14
'@xterm/addon-progress',
15
'@xterm/addon-search',
16
'@xterm/addon-serialize',
17
'@xterm/addon-unicode11',
18
'@xterm/addon-webgl',
19
];
20
21
const backendOnlyModuleNames = [
22
'@xterm/headless'
23
];
24
25
const vscodeDir = process.argv.length >= 3 ? process.argv[2] : process.cwd();
26
if (path.basename(vscodeDir) !== 'vscode') {
27
console.error('The cwd is not named "vscode"');
28
return;
29
}
30
31
function getLatestModuleVersion(moduleName) {
32
return new Promise((resolve, reject) => {
33
cp.exec(`npm view ${moduleName} versions --json`, { cwd: vscodeDir }, (err, stdout, stderr) => {
34
if (err) {
35
reject(err);
36
}
37
let versions = JSON.parse(stdout);
38
// Fix format if there is only a single version published
39
if (typeof versions === 'string') {
40
versions = [versions];
41
}
42
resolve(versions[versions.length - 1]);
43
});
44
});
45
}
46
47
async function update() {
48
console.log('Fetching latest versions');
49
const allModules = moduleNames.concat(backendOnlyModuleNames);
50
const versionPromises = [];
51
for (const m of allModules) {
52
versionPromises.push(getLatestModuleVersion(m));
53
}
54
const latestVersionsArray = await Promise.all(versionPromises);
55
const latestVersions = {};
56
for (const [i, v] of latestVersionsArray.entries()) {
57
latestVersions[allModules[i]] = v;
58
}
59
60
console.log('Detected versions:');
61
for (const m of moduleNames.concat(backendOnlyModuleNames)) {
62
console.log(` ${m}@${latestVersions[m]}`);
63
}
64
65
const pkg = require(path.join(vscodeDir, 'package.json'));
66
67
const modulesWithVersion = [];
68
for (const m of moduleNames) {
69
const moduleWithVersion = `${m}@${latestVersions[m]}`;
70
if (pkg.dependencies[m] === latestVersions[m]) {
71
console.log(`Skipping ${moduleWithVersion}, already up to date`);
72
continue;
73
}
74
modulesWithVersion.push(moduleWithVersion);
75
}
76
77
if (modulesWithVersion.length > 0) {
78
for (const cwd of [vscodeDir, path.join(vscodeDir, 'remote'), path.join(vscodeDir, 'remote/web')]) {
79
console.log(`${path.join(cwd, 'package.json')}: Updating\n ${modulesWithVersion.join('\n ')}`);
80
cp.execSync(`npm install ${modulesWithVersion.join(' ')}`, { cwd });
81
}
82
}
83
84
const backendOnlyModulesWithVersion = [];
85
for (const m of backendOnlyModuleNames) {
86
const moduleWithVersion = `${m}@${latestVersions[m]}`;
87
if (pkg.dependencies[m] === latestVersions[m]) {
88
console.log(`Skipping ${moduleWithVersion}, already up to date`);
89
continue;
90
}
91
backendOnlyModulesWithVersion.push(moduleWithVersion);
92
}
93
if (backendOnlyModulesWithVersion.length > 0) {
94
for (const cwd of [vscodeDir, path.join(vscodeDir, 'remote')]) {
95
console.log(`${path.join(cwd, 'package.json')}: Updating\n ${backendOnlyModulesWithVersion.join('\n ')}`);
96
cp.execSync(`npm install ${backendOnlyModulesWithVersion.join(' ')}`, { cwd });
97
}
98
}
99
}
100
101
update();
102
103