Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/dependencies.js
3520 views
1
"use strict";
2
var __importDefault = (this && this.__importDefault) || function (mod) {
3
return (mod && mod.__esModule) ? mod : { "default": mod };
4
};
5
Object.defineProperty(exports, "__esModule", { value: true });
6
exports.getProductionDependencies = getProductionDependencies;
7
/*---------------------------------------------------------------------------------------------
8
* Copyright (c) Microsoft Corporation. All rights reserved.
9
* Licensed under the MIT License. See License.txt in the project root for license information.
10
*--------------------------------------------------------------------------------------------*/
11
const fs_1 = __importDefault(require("fs"));
12
const path_1 = __importDefault(require("path"));
13
const child_process_1 = __importDefault(require("child_process"));
14
const root = fs_1.default.realpathSync(path_1.default.dirname(path_1.default.dirname(__dirname)));
15
function getNpmProductionDependencies(folder) {
16
let raw;
17
try {
18
raw = child_process_1.default.execSync('npm ls --all --omit=dev --parseable', { cwd: folder, encoding: 'utf8', env: { ...process.env, NODE_ENV: 'production' }, stdio: [null, null, null] });
19
}
20
catch (err) {
21
const regex = /^npm ERR! .*$/gm;
22
let match;
23
while (match = regex.exec(err.message)) {
24
if (/ELSPROBLEMS/.test(match[0])) {
25
continue;
26
}
27
else if (/invalid: xterm/.test(match[0])) {
28
continue;
29
}
30
else if (/A complete log of this run/.test(match[0])) {
31
continue;
32
}
33
else {
34
throw err;
35
}
36
}
37
raw = err.stdout;
38
}
39
return raw.split(/\r?\n/).filter(line => {
40
return !!line.trim() && path_1.default.relative(root, line) !== path_1.default.relative(root, folder);
41
});
42
}
43
function getProductionDependencies(folderPath) {
44
const result = getNpmProductionDependencies(folderPath);
45
// Account for distro npm dependencies
46
const realFolderPath = fs_1.default.realpathSync(folderPath);
47
const relativeFolderPath = path_1.default.relative(root, realFolderPath);
48
const distroFolderPath = `${root}/.build/distro/npm/${relativeFolderPath}`;
49
if (fs_1.default.existsSync(distroFolderPath)) {
50
result.push(...getNpmProductionDependencies(distroFolderPath));
51
}
52
return [...new Set(result)];
53
}
54
if (require.main === module) {
55
console.log(JSON.stringify(getProductionDependencies(root), null, ' '));
56
}
57
//# sourceMappingURL=dependencies.js.map
58