@rushstack/node-core-library
Advanced tools
Comparing version
@@ -174,4 +174,4 @@ /// <reference types="node" /> | ||
} | ||
export declare function parseProcessListOutputAsync(stream: NodeJS.ReadableStream): Promise<Map<number, IProcessInfo>>; | ||
export declare function parseProcessListOutput(output: Iterable<string | null>): Map<number, IProcessInfo>; | ||
export declare function parseProcessListOutputAsync(stream: NodeJS.ReadableStream, platform?: NodeJS.Platform): Promise<Map<number, IProcessInfo>>; | ||
export declare function parseProcessListOutput(output: Iterable<string | null>, platform?: NodeJS.Platform): Map<number, IProcessInfo>; | ||
/** | ||
@@ -178,0 +178,0 @@ * The Executable class provides a safe, portable, recommended solution for tools that need |
@@ -36,4 +36,4 @@ "use strict"; | ||
exports.Executable = exports.parseProcessListOutput = exports.parseProcessListOutputAsync = void 0; | ||
const os = __importStar(require("os")); | ||
const child_process = __importStar(require("child_process")); | ||
const os = __importStar(require("os")); | ||
const path = __importStar(require("path")); | ||
@@ -45,3 +45,4 @@ const EnvironmentMap_1 = require("./EnvironmentMap"); | ||
const InternalError_1 = require("./InternalError"); | ||
async function parseProcessListOutputAsync(stream) { | ||
const OS_PLATFORM = os.platform(); | ||
async function parseProcessListOutputAsync(stream, platform = OS_PLATFORM) { | ||
var _a, e_1, _b, _c; | ||
@@ -59,3 +60,3 @@ const processInfoById = new Map(); | ||
else { | ||
parseProcessInfoEntry(line, processInfoById); | ||
parseProcessInfoEntry(line, processInfoById, platform); | ||
} | ||
@@ -74,4 +75,5 @@ } | ||
exports.parseProcessListOutputAsync = parseProcessListOutputAsync; | ||
function parseProcessListOutput( | ||
// eslint-disable-next-line @rushstack/no-new-null | ||
function parseProcessListOutput(output) { | ||
output, platform = OS_PLATFORM) { | ||
const processInfoById = new Map(); | ||
@@ -84,3 +86,3 @@ let seenHeaders = false; | ||
else { | ||
parseProcessInfoEntry(line, processInfoById); | ||
parseProcessInfoEntry(line, processInfoById, platform); | ||
} | ||
@@ -95,4 +97,4 @@ } | ||
// unix format: | ||
// COMMAND PPID PID | ||
// process name 51234 56784 | ||
// PPID PID COMMAND | ||
// 51234 56784 process name | ||
const NAME_GROUP = 'name'; | ||
@@ -102,5 +104,8 @@ const PROCESS_ID_GROUP = 'pid'; | ||
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp | ||
const PROCESS_LIST_ENTRY_REGEX = new RegExp(`^(?<${NAME_GROUP}>.+?)\\s+(?<${PARENT_PROCESS_ID_GROUP}>\\d+)\\s+(?<${PROCESS_ID_GROUP}>\\d+)\\s*$`); | ||
function parseProcessInfoEntry(line, existingProcessInfoById) { | ||
const match = line.match(PROCESS_LIST_ENTRY_REGEX); | ||
const PROCESS_LIST_ENTRY_REGEX_WIN32 = new RegExp(`^(?<${NAME_GROUP}>.+?)\\s+(?<${PARENT_PROCESS_ID_GROUP}>\\d+)\\s+(?<${PROCESS_ID_GROUP}>\\d+)\\s*$`); | ||
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp | ||
const PROCESS_LIST_ENTRY_REGEX_UNIX = new RegExp(`^\\s*(?<${PARENT_PROCESS_ID_GROUP}>\\d+)\\s+(?<${PROCESS_ID_GROUP}>\\d+)\\s+(?<${NAME_GROUP}>.+?)\\s*$`); | ||
function parseProcessInfoEntry(line, existingProcessInfoById, platform) { | ||
const processListEntryRegex = platform === 'win32' ? PROCESS_LIST_ENTRY_REGEX_WIN32 : PROCESS_LIST_ENTRY_REGEX_UNIX; | ||
const match = line.match(processListEntryRegex); | ||
if (!(match === null || match === void 0 ? void 0 : match.groups)) { | ||
@@ -158,3 +163,2 @@ throw new InternalError_1.InternalError(`Invalid process list entry: ${line}`); | ||
} | ||
const OS_PLATFORM = os.platform(); | ||
function getProcessListProcessOptions() { | ||
@@ -171,6 +175,8 @@ let command; | ||
// -A: Select all processes | ||
// -w: Wide format | ||
// -o: User-defined format | ||
// Order of declared properties impacts the order of the output, so match | ||
// the order of wmic.exe output | ||
args = ['-Ao', 'comm,ppid,pid']; | ||
// Order of declared properties impacts the order of the output. We will | ||
// need to request the "comm" property last in order to ensure that the | ||
// process names are not truncated on certain platforms | ||
args = ['-Awo', 'ppid,pid,comm']; | ||
} | ||
@@ -177,0 +183,0 @@ return { path: command, args }; |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.64.0", | ||
"version": "3.64.1", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1174438
0.14%15199
0.04%