Skip to content

Commit a7baca7

Browse files
committed
Switch windows-process-tree from static import to dynamic require
Static imports can cause the entire module to fail if the native plugin's ABI doesn't match the running Node version. Using dynamic `require()` within a `try-catch` statement allows for a fallback to WMIC if the module is unavailable or incompatible. To ensure compile-time type safety, only type imports are retained. Add a comment to webpack externals explaining why the native addon must be excluded from bundling.
1 parent 63e23ce commit a7baca7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/extension/debugger/attachQuickPick/provider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import { l10n } from 'vscode';
7-
import * as wpc from '@vscode/windows-process-tree';
7+
import type { IProcessInfo } from '@vscode/windows-process-tree';
88
import { getOSType, OSType } from '../../common/platform';
99
import { PsProcessParser } from './psProcessParser';
1010
import { IAttachItem, IAttachProcessProvider, ProcessListCommand } from './types';
@@ -63,8 +63,9 @@ export class AttachProcessProvider implements IAttachProcessProvider {
6363

6464
if (osType === OSType.Windows) {
6565
try {
66-
const processList = await new Promise<wpc.IProcessInfo[]>((resolve) => {
67-
wpc.getAllProcesses((processes) => resolve(processes), wpc.ProcessDataFlag.CommandLine);
66+
const wpc = require('@vscode/windows-process-tree');
67+
const processList = await new Promise<IProcessInfo[]>((resolve) => {
68+
wpc.getAllProcesses((processes: IProcessInfo[]) => resolve(processes), wpc.ProcessDataFlag.CommandLine);
6869
});
6970
return processList.map((p) => ({
7071
label: p.name,

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const extensionConfig = {
3838
'@opentelemetry/instrumentation': 'commonjs @opentelemetry/instrumentation', // ignored because we don't ship instrumentation
3939
'@azure/opentelemetry-instrumentation-azure-sdk': 'commonjs @azure/opentelemetry-instrumentation-azure-sdk', // ignored because we don't ship instrumentation
4040
'@azure/functions-core': '@azure/functions-core', // ignored because we don't ship instrumentation
41-
'@vscode/windows-process-tree': 'commonjs @vscode/windows-process-tree',
41+
'@vscode/windows-process-tree': 'commonjs @vscode/windows-process-tree', // native addon (.node binary); webpack cannot bundle it, resolved at runtime via VS Code's built-in copy
4242
},
4343
resolve: {
4444
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader

0 commit comments

Comments
 (0)