Path: blob/main/build/azure-pipelines/common/listNodeModules.ts
3520 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import fs from 'fs';6import path from 'path';78if (process.argv.length !== 3) {9console.error('Usage: node listNodeModules.js OUTPUT_FILE');10process.exit(-1);11}1213const ROOT = path.join(__dirname, '../../../');1415function findNodeModulesFiles(location: string, inNodeModules: boolean, result: string[]) {16const entries = fs.readdirSync(path.join(ROOT, location));17for (const entry of entries) {18const entryPath = `${location}/${entry}`;1920if (/(^\/out)|(^\/src$)|(^\/.git$)|(^\/.build$)/.test(entryPath)) {21continue;22}2324let stat: fs.Stats;25try {26stat = fs.statSync(path.join(ROOT, entryPath));27} catch (err) {28continue;29}3031if (stat.isDirectory()) {32findNodeModulesFiles(entryPath, inNodeModules || (entry === 'node_modules'), result);33} else {34if (inNodeModules) {35result.push(entryPath.substr(1));36}37}38}39}4041const result: string[] = [];42findNodeModulesFiles('', false, result);43fs.writeFileSync(process.argv[2], result.join('\n') + '\n');444546