Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/listNodeModules.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
9
if (process.argv.length !== 3) {
10
console.error('Usage: node listNodeModules.js OUTPUT_FILE');
11
process.exit(-1);
12
}
13
14
const ROOT = path.join(__dirname, '../../../');
15
16
function findNodeModulesFiles(location: string, inNodeModules: boolean, result: string[]) {
17
const entries = fs.readdirSync(path.join(ROOT, location));
18
for (const entry of entries) {
19
const entryPath = `${location}/${entry}`;
20
21
if (/(^\/out)|(^\/src$)|(^\/.git$)|(^\/.build$)/.test(entryPath)) {
22
continue;
23
}
24
25
let stat: fs.Stats;
26
try {
27
stat = fs.statSync(path.join(ROOT, entryPath));
28
} catch (err) {
29
continue;
30
}
31
32
if (stat.isDirectory()) {
33
findNodeModulesFiles(entryPath, inNodeModules || (entry === 'node_modules'), result);
34
} else {
35
if (inNodeModules) {
36
result.push(entryPath.substr(1));
37
}
38
}
39
}
40
}
41
42
const result: string[] = [];
43
findNodeModulesFiles('', false, result);
44
fs.writeFileSync(process.argv[2], result.join('\n') + '\n');
45
46