Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/dependencies.ts
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
import fs from 'fs';
7
import path from 'path';
8
import cp from 'child_process';
9
const root = fs.realpathSync(path.dirname(path.dirname(__dirname)));
10
11
function getNpmProductionDependencies(folder: string): string[] {
12
let raw: string;
13
14
try {
15
raw = cp.execSync('npm ls --all --omit=dev --parseable', { cwd: folder, encoding: 'utf8', env: { ...process.env, NODE_ENV: 'production' }, stdio: [null, null, null] });
16
} catch (err) {
17
const regex = /^npm ERR! .*$/gm;
18
let match: RegExpExecArray | null;
19
20
while (match = regex.exec(err.message)) {
21
if (/ELSPROBLEMS/.test(match[0])) {
22
continue;
23
} else if (/invalid: xterm/.test(match[0])) {
24
continue;
25
} else if (/A complete log of this run/.test(match[0])) {
26
continue;
27
} else {
28
throw err;
29
}
30
}
31
32
raw = err.stdout;
33
}
34
35
return raw.split(/\r?\n/).filter(line => {
36
return !!line.trim() && path.relative(root, line) !== path.relative(root, folder);
37
});
38
}
39
40
export function getProductionDependencies(folderPath: string): string[] {
41
const result = getNpmProductionDependencies(folderPath);
42
// Account for distro npm dependencies
43
const realFolderPath = fs.realpathSync(folderPath);
44
const relativeFolderPath = path.relative(root, realFolderPath);
45
const distroFolderPath = `${root}/.build/distro/npm/${relativeFolderPath}`;
46
47
if (fs.existsSync(distroFolderPath)) {
48
result.push(...getNpmProductionDependencies(distroFolderPath));
49
}
50
51
return [...new Set(result)];
52
}
53
54
if (require.main === module) {
55
console.log(JSON.stringify(getProductionDependencies(root), null, ' '));
56
}
57
58