From 15cb6b36f8c29df77133b422d46b64e4d508488f Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Wed, 5 Apr 2023 11:51:26 -0700 Subject: [PATCH] Bump windows-process-tree (#179176) * Bump windows-process-tree * Fix compile error * Add explanation to source * Add that the types package has been deprecated --- .eslintrc.json | 2 +- build/.moduleignore | 10 +-- package.json | 5 +- remote/package.json | 4 +- remote/yarn.lock | 14 ++-- src/typings/windows-process-tree.d.ts | 79 +++++++++++++++++++ src/vs/base/node/ps.ts | 2 +- .../node/nativeModules.integrationTest.ts | 8 +- .../terminal/node/windowsShellHelper.ts | 4 +- .../workbench/contrib/debug/node/terminals.ts | 2 +- yarn.lock | 19 ++--- 11 files changed, 111 insertions(+), 38 deletions(-) create mode 100644 src/typings/windows-process-tree.d.ts diff --git a/.eslintrc.json b/.eslintrc.json index d8304880e29..de4e5379e89 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -222,6 +222,7 @@ "@vscode/iconv-lite-umd", "@vscode/policy-watcher", "@vscode/proxy-agent", + "@vscode/windows-process-tree", "assert", "child_process", "console", @@ -251,7 +252,6 @@ "v8-inspect-profiler", "vscode-regexpp", "vscode-textmate", - "windows-process-tree", "worker_threads", "xterm", "xterm-addon-canvas", diff --git a/build/.moduleignore b/build/.moduleignore index 2aa99ddc295..d2379873ccd 100644 --- a/build/.moduleignore +++ b/build/.moduleignore @@ -26,6 +26,11 @@ fsevents/test/** @vscode/windows-mutex/src/** !@vscode/windows-mutex/**/*.node +@vscode/windows-process-tree/binding.gyp +@vscode/windows-process-tree/build/** +@vscode/windows-process-tree/src/** +!@vscode/windows-process-tree/**/*.node + @vscode/windows-registry/binding.gyp @vscode/windows-registry/src/** @vscode/windows-registry/build/** @@ -66,11 +71,6 @@ windows-foreground-love/build/** windows-foreground-love/src/** !windows-foreground-love/**/*.node -windows-process-tree/binding.gyp -windows-process-tree/build/** -windows-process-tree/src/** -!windows-process-tree/**/*.node - keytar/binding.gyp keytar/build/** keytar/src/** diff --git a/package.json b/package.json index f6bed58c124..d64367aedb7 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,6 @@ "@types/webpack": "^5.28.1", "@types/wicg-file-system-access": "^2020.9.5", "@types/windows-foreground-love": "^0.3.0", - "@types/windows-process-tree": "^0.2.0", "@types/winreg": "^1.2.30", "@types/yauzl": "^2.9.1", "@types/yazl": "^2.4.2", @@ -225,9 +224,9 @@ }, "optionalDependencies": { "@vscode/windows-mutex": "0.4.2", + "@vscode/windows-process-tree": "0.4.2", "@vscode/windows-registry": "1.0.10", - "windows-foreground-love": "0.5.0", - "windows-process-tree": "0.4.0" + "windows-foreground-love": "0.5.0" }, "resolutions": { "elliptic": "^6.5.3", diff --git a/remote/package.json b/remote/package.json index 8776ebaf7e6..e6935786bec 100644 --- a/remote/package.json +++ b/remote/package.json @@ -35,7 +35,7 @@ "yazl": "^2.4.3" }, "optionalDependencies": { - "@vscode/windows-registry": "1.0.10", - "windows-process-tree": "0.4.0" + "@vscode/windows-process-tree": "0.4.2", + "@vscode/windows-registry": "1.0.10" } } diff --git a/remote/yarn.lock b/remote/yarn.lock index 3d867a73062..ce95bd447c3 100644 --- a/remote/yarn.lock +++ b/remote/yarn.lock @@ -92,6 +92,13 @@ dependencies: node-addon-api "^3.0.2" +"@vscode/windows-process-tree@0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@vscode/windows-process-tree/-/windows-process-tree-0.4.2.tgz#54d010fdeb06dfe3a9c6d58fcb3ed9acfc962f33" + integrity sha512-b20865s1HG1VtGt887KrB1blwFS6p4L1Fl1o/WplO9j7sGBle8sLqkNnGXbCaRNgdIgfXtitmzG366FVynJZdQ== + dependencies: + nan "^2.17.0" + "@vscode/windows-registry@1.0.10": version "1.0.10" resolved "https://registry.yarnpkg.com/@vscode/windows-registry/-/windows-registry-1.0.10.tgz#17e4e2f8fdd41990206d1bab2daf99c803206247" @@ -824,13 +831,6 @@ wide-align@^1.1.0: dependencies: string-width "^1.0.2 || 2 || 3 || 4" -windows-process-tree@0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/windows-process-tree/-/windows-process-tree-0.4.0.tgz#31ac49c5da557e628ce7e37a5800972173d3349a" - integrity sha512-9LunDnc1WwuhyLeTAXMFX8wbActGJtDCBaiapQXFYk/nO4W4X9YxOKV5g/lQL3XX69QYxveDbjVVrdnTt1qqCQ== - dependencies: - nan "^2.17.0" - wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" diff --git a/src/typings/windows-process-tree.d.ts b/src/typings/windows-process-tree.d.ts new file mode 100644 index 00000000000..1d9bc015902 --- /dev/null +++ b/src/typings/windows-process-tree.d.ts @@ -0,0 +1,79 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// Copied from the `@vscode/windows-process-tree` package. +// The dependency is an optional dependency that is only used on Windows, +// but we need the typings to compile on all platforms. +// The `@types/windows-process-tree` package has also been deprecated. +declare module '@vscode/windows-process-tree' { + export enum ProcessDataFlag { + None = 0, + Memory = 1, + CommandLine = 2 + } + + export interface IProcessInfo { + pid: number; + ppid: number; + name: string; + + /** + * The working set size of the process, in bytes. + */ + memory?: number; + + /** + * The string returned is at most 512 chars, strings exceeding this length are truncated. + */ + commandLine?: string; + } + + export interface IProcessCpuInfo extends IProcessInfo { + cpu?: number; + } + + export interface IProcessTreeNode { + pid: number; + name: string; + memory?: number; + commandLine?: string; + children: IProcessTreeNode[]; + } + + /** + * Returns a tree of processes with the rootPid process as the root. + * @param rootPid - The pid of the process that will be the root of the tree. + * @param callback - The callback to use with the returned list of processes. + * @param flags - The flags for what process data should be included. + */ + export function getProcessTree(rootPid: number, callback: (tree: IProcessTreeNode | undefined) => void, flags?: ProcessDataFlag): void; + + namespace getProcessTree { + function __promisify__(rootPid: number, flags?: ProcessDataFlag): Promise; + } + + /** + * Returns a list of processes containing the rootPid process and all of its descendants. + * @param rootPid - The pid of the process of interest. + * @param callback - The callback to use with the returned set of processes. + * @param flags - The flags for what process data should be included. + */ + export function getProcessList(rootPid: number, callback: (processList: IProcessInfo[] | undefined) => void, flags?: ProcessDataFlag): void; + + namespace getProcessList { + function __promisify__(rootPid: number, flags?: ProcessDataFlag): Promise; + } + + /** + * Returns the list of processes annotated with cpu usage information. + * @param processList - The list of processes. + * @param callback - The callback to use with the returned list of processes. + */ + export function getProcessCpuUsage(processList: IProcessInfo[], callback: (processListWithCpu: IProcessCpuInfo[]) => void): void; + + namespace getProcessCpuUsage { + function __promisify__(processList: IProcessInfo[]): Promise; + } +} diff --git a/src/vs/base/node/ps.ts b/src/vs/base/node/ps.ts index 93432f17237..09a5a8bdca8 100644 --- a/src/vs/base/node/ps.ts +++ b/src/vs/base/node/ps.ts @@ -127,7 +127,7 @@ export function listProcesses(rootPid: number): Promise { } }; - (import('windows-process-tree')).then(windowsProcessTree => { + (import('@vscode/windows-process-tree')).then(windowsProcessTree => { windowsProcessTree.getProcessList(rootPid, (processList) => { if (!processList) { reject(new Error(`Root process ${rootPid} not found`)); diff --git a/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts b/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts index 03572dd0c35..98b252df4c3 100644 --- a/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts +++ b/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts @@ -123,16 +123,16 @@ flakySuite('Native Modules (all platforms)', () => { assert.ok(typeof result === 'boolean', testErrorMessage('windows-foreground-love')); }); - test('windows-process-tree', async () => { - const processTree = await import('windows-process-tree'); - assert.ok(typeof processTree.getProcessTree === 'function', testErrorMessage('windows-process-tree')); + test('@vscode/windows-process-tree', async () => { + const processTree = await import('@vscode/windows-process-tree'); + assert.ok(typeof processTree.getProcessTree === 'function', testErrorMessage('@vscode/windows-process-tree')); return new Promise((resolve, reject) => { processTree.getProcessTree(process.pid, tree => { if (tree) { resolve(); } else { - reject(new Error(testErrorMessage('windows-process-tree'))); + reject(new Error(testErrorMessage('@vscode/windows-process-tree'))); } }); }); diff --git a/src/vs/platform/terminal/node/windowsShellHelper.ts b/src/vs/platform/terminal/node/windowsShellHelper.ts index 21807752f7c..b93e17247a2 100644 --- a/src/vs/platform/terminal/node/windowsShellHelper.ts +++ b/src/vs/platform/terminal/node/windowsShellHelper.ts @@ -9,7 +9,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { isWindows, platform } from 'vs/base/common/platform'; import { TerminalShellType, WindowsShellType } from 'vs/platform/terminal/common/terminal'; -import type * as WindowsProcessTreeType from 'windows-process-tree'; +import type * as WindowsProcessTreeType from '@vscode/windows-process-tree'; export interface IWindowsShellHelper extends IDisposable { readonly onShellNameChanged: Event; @@ -129,7 +129,7 @@ export class WindowsShellHelper extends Disposable implements IWindowsShellHelpe return this._currentRequest; } if (!windowsProcessTree) { - windowsProcessTree = await import('windows-process-tree'); + windowsProcessTree = await import('@vscode/windows-process-tree'); } this._currentRequest = new Promise(resolve => { windowsProcessTree.getProcessTree(this._rootProcessId, tree => { diff --git a/src/vs/workbench/contrib/debug/node/terminals.ts b/src/vs/workbench/contrib/debug/node/terminals.ts index efd2914286d..dab6a2962d5 100644 --- a/src/vs/workbench/contrib/debug/node/terminals.ts +++ b/src/vs/workbench/contrib/debug/node/terminals.ts @@ -30,7 +30,7 @@ export async function hasChildProcesses(processId: number | undefined): Promise< // if shell has at least one child process, assume that shell is busy if (platform.isWindows) { - const windowsProcessTree = await import('windows-process-tree'); + const windowsProcessTree = await import('@vscode/windows-process-tree'); return new Promise(resolve => { windowsProcessTree.getProcessTree(processId, processTree => { resolve(!!processTree && processTree.children.length > 0); diff --git a/yarn.lock b/yarn.lock index 9903f21bd2f..c4499806a68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1153,11 +1153,6 @@ resolved "https://registry.yarnpkg.com/@types/windows-foreground-love/-/windows-foreground-love-0.3.0.tgz#26bc230b2568aa7ab7c56d35bb5653c0a6965a42" integrity sha512-tFUVA/fiofNqOh6lZlymvQiQYPY+cZXZPR9mn9wN6/KS8uwx0zgH4Ij/jmFyRYr+x+DGZWEIeknS2BMi7FZJAQ== -"@types/windows-process-tree@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@types/windows-process-tree/-/windows-process-tree-0.2.0.tgz#2fa205c838a8ef0a07697cd747c954653978d22c" - integrity sha512-vQAnkWpMX4HUPjubkxKta4Rfh2EDy2ksalnr37gFHNrmk+uxx50PRH+/fM5nTsEBCi4ESFT/7t7Za3jGqyTZ4g== - "@types/winreg@^1.2.30": version "1.2.30" resolved "https://registry.yarnpkg.com/@types/winreg/-/winreg-1.2.30.tgz#91d6710e536d345b9c9b017c574cf6a8da64c518" @@ -1394,6 +1389,13 @@ bindings "^1.2.1" nan "^2.14.0" +"@vscode/windows-process-tree@0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@vscode/windows-process-tree/-/windows-process-tree-0.4.2.tgz#54d010fdeb06dfe3a9c6d58fcb3ed9acfc962f33" + integrity sha512-b20865s1HG1VtGt887KrB1blwFS6p4L1Fl1o/WplO9j7sGBle8sLqkNnGXbCaRNgdIgfXtitmzG366FVynJZdQ== + dependencies: + nan "^2.17.0" + "@vscode/windows-registry@1.0.10": version "1.0.10" resolved "https://registry.yarnpkg.com/@vscode/windows-registry/-/windows-registry-1.0.10.tgz#17e4e2f8fdd41990206d1bab2daf99c803206247" @@ -10602,13 +10604,6 @@ windows-foreground-love@0.5.0: resolved "https://registry.yarnpkg.com/windows-foreground-love/-/windows-foreground-love-0.5.0.tgz#7672b04eb05f934a6543cacdc3cd16ff34e3cb10" integrity sha512-yjBwmKEmQBDk3Z7yg/U9hizGWat8C6Pe4MQWl5bN6mvPU81Bt6HV2k/6mGlK3ETJLW1hCLhYx2wcGh+ykUUCyA== -windows-process-tree@0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/windows-process-tree/-/windows-process-tree-0.4.0.tgz#31ac49c5da557e628ce7e37a5800972173d3349a" - integrity sha512-9LunDnc1WwuhyLeTAXMFX8wbActGJtDCBaiapQXFYk/nO4W4X9YxOKV5g/lQL3XX69QYxveDbjVVrdnTt1qqCQ== - dependencies: - nan "^2.17.0" - word-wrap@^1.2.3, word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"