Skip to content

Commit 2df2f9d

Browse files
lucygramleyCopilotconnor4312
authored
fix: use DI for vscode API in nodeLauncher instead of direct import (#2369)
* fix: use DI for vscode API in nodeLauncher instead of direct import nodeLauncher.ts was directly importing 'vscode', which causes both a build error (esbuild can't resolve it) and a runtime error (module doesn't exist outside VS Code) for standalone server bundles like vsDebugServerBundle. Switch to the established pattern used elsewhere in the codebase (e.g. defaultBrowserProvider.ts, nodeBinaryProvider.ts): - Use 'import type' so no require() is emitted at runtime - Inject the vscode API via @optional() @Inject(VSCodeApi) - Guard usage with an undefined check for non-VS Code contexts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update src/targets/node/nodeLauncher.ts Co-authored-by: Connor Peet <connor@peet.io> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Connor Peet <connor@peet.io>
1 parent 031a60a commit 2df2f9d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/targets/node/nodeLauncher.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5-
import { inject, injectable, multiInject } from 'inversify';
5+
import { inject, injectable, multiInject, optional } from 'inversify';
66
import { extname, resolve } from 'path';
7-
import * as vscode from 'vscode';
7+
import type * as vscodeType from 'vscode';
88
import { IBreakpointsPredictor } from '../../adapter/breakpointPredictor';
99
import { IPortLeaseTracker } from '../../adapter/portLeaseTracker';
1010
import Cdp from '../../cdp/api';
@@ -16,6 +16,7 @@ import { fixDriveLetterAndSlashes } from '../../common/pathUtils';
1616
import { delay } from '../../common/promiseUtil';
1717
import { absolutePathToFileUrl, urlToRegex } from '../../common/urlUtils';
1818
import { AnyLaunchConfiguration, INodeLaunchConfiguration } from '../../configuration';
19+
import { VSCodeApi } from '../../ioc-extras';
1920
import { fixInspectFlags } from '../../ui/configurationUtils';
2021
import { retryGetNodeEndpoint } from '../browser/spawn/endpoints';
2122
import { ISourcePathResolverFactory } from '../sourcePathResolverFactory';
@@ -77,6 +78,7 @@ export class NodeLauncher extends NodeLauncherBase<INodeLaunchConfiguration> {
7778
@inject(IPackageJsonProvider) private readonly packageJson: IPackageJsonProvider,
7879
@inject(ISourcePathResolverFactory) pathResolverFactory: ISourcePathResolverFactory,
7980
@inject(IPortLeaseTracker) portLeaseTracker: IPortLeaseTracker,
81+
@optional() @inject(VSCodeApi) private readonly vscode?: typeof vscodeType,
8082
) {
8183
super(pathProvider, logger, portLeaseTracker, pathResolverFactory);
8284
}
@@ -313,7 +315,7 @@ export class NodeLauncher extends NodeLauncherBase<INodeLaunchConfiguration> {
313315
return targetProgram;
314316
}
315317

316-
const resolve = readConfig(vscode.workspace, Configuration.ResolveDebugEntrypoint);
318+
const resolve = this.vscode ? readConfig(this.vscode.workspace, Configuration.ResolveDebugEntrypoint) : true;
317319
if (!resolve) {
318320
return targetProgram;
319321
}

0 commit comments

Comments
 (0)