Skip to content

1.97.1 cherry pick #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Nothing, yet

## 1.97 (January 2025)

### 1.97.1

- fix: don't look for binaries outside the workspace folder ([vscode#240407](https://github.com/microsoft/vscode/issues/240407))

### 1.97.0

- fix: allow pretty printing sources when not paused ([#2138](https://github.com/microsoft/vscode-js-debug/issues/2138))
- fix: breakpoints not registered in transpiled file in remoteRoot ([#2122](https://github.com/microsoft/vscode-js-debug/issues/2122))
- fix: content verification of files in Node.js failing with UTF-8 BOM
Expand Down
44 changes: 42 additions & 2 deletions src/targets/node/nodeBinaryProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { join } from 'path';
import { SinonStub, stub } from 'sinon';
import { EnvironmentVars } from '../../common/environmentVars';
import { Logger } from '../../common/logging/logger';
import { upcastPartial } from '../../common/objUtils';
import { Semver } from '../../common/semver';
import { AnyLaunchConfiguration } from '../../configuration';
import { ErrorCodes } from '../../dap/errors';
import { ProtocolError } from '../../dap/protocolError';
import { Capability, NodeBinary, NodeBinaryProvider } from '../../targets/node/nodeBinaryProvider';
Expand All @@ -20,6 +22,8 @@ describe('NodeBinaryProvider', function() {
this.timeout(30 * 1000); // windows lookups in CI seem to be very slow sometimes

let p: NodeBinaryProvider;
let dir: string;

const env = (name: string) =>
EnvironmentVars.empty.addToPath(join(testWorkspace, 'nodePathProvider', name));
const binaryLocation = (name: string, binary = 'node') =>
Expand All @@ -33,11 +37,17 @@ describe('NodeBinaryProvider', function() {
let packageJson: IPackageJsonProvider;

beforeEach(() => {
dir = getTestDir();
packageJson = {
getPath: () => Promise.resolve(undefined),
getContents: () => Promise.resolve(undefined),
};
p = new NodeBinaryProvider(Logger.null, fsPromises, packageJson);
p = new NodeBinaryProvider(
Logger.null,
fsPromises,
packageJson,
upcastPartial<AnyLaunchConfiguration>({ __workspaceFolder: dir }),
);
});

it('rejects not found', async () => {
Expand Down Expand Up @@ -198,8 +208,38 @@ describe('NodeBinaryProvider', function() {
});
});

it('does not recurse upwards past workspace folder', async () => {
const cwd = join(dir, 'subdir');
p = new NodeBinaryProvider(
Logger.null,
fsPromises,
packageJson,
upcastPartial<AnyLaunchConfiguration>({ __workspaceFolder: cwd }),
);
await fsPromises.mkdir(cwd, { recursive: true });

createFileTree(dir, {
'node_modules/.bin': {
'node.exe': '',
node: '',
},
});

try {
const r = await p.resolveAndValidate(
EnvironmentVars.empty.update('PATHEXT', '.EXE'),
'node',
undefined,
cwd,
);
console.log(r);
} catch (err) {
expect(err).to.be.an.instanceOf(ProtocolError);
expect(err.cause.id).to.equal(ErrorCodes.CannotFindNodeBinary);
}
});

it('automatically finds programs in node_modules/.bin', async () => {
const dir = getTestDir();
createFileTree(dir, {
'node_modules/.bin': {
'mocha.cmd': '',
Expand Down
17 changes: 14 additions & 3 deletions src/targets/node/nodeBinaryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import type * as vscodeType from 'vscode';
import { EnvironmentVars } from '../../common/environmentVars';
import { existsInjected } from '../../common/fsUtils';
import { ILogger, LogTag } from '../../common/logging';
import { findExecutable, findInPath } from '../../common/pathUtils';
import { findExecutable, findInPath, isSubpathOrEqualTo } from '../../common/pathUtils';
import { spawnAsync } from '../../common/processUtils';
import { Semver } from '../../common/semver';
import { getNormalizedBinaryName, nearestDirectoryWhere } from '../../common/urlUtils';
import { AnyLaunchConfiguration } from '../../configuration';
import {
cannotFindNodeBinary,
cwdDoesNotExist,
Expand Down Expand Up @@ -220,6 +221,7 @@ export class NodeBinaryProvider implements INodeBinaryProvider {
@inject(ILogger) private readonly logger: ILogger,
@inject(FS) private readonly fs: FsPromises,
@inject(IPackageJsonProvider) private readonly packageJson: IPackageJsonProvider,
@inject(AnyLaunchConfiguration) private readonly launchConfig: Partial<AnyLaunchConfiguration>,
) {}

/**
Expand Down Expand Up @@ -263,9 +265,17 @@ export class NodeBinaryProvider implements INodeBinaryProvider {
return undefined;
}

const workspaceFolder = this.launchConfig.__workspaceFolder;
if (!workspaceFolder) {
return undefined;
}

return nearestDirectoryWhere(
cwd,
dir => findExecutable(this.fs, join(dir, 'node_modules', '.bin', executable), env),
dir =>
!isSubpathOrEqualTo(workspaceFolder, dir)
? Promise.resolve(undefined)
: findExecutable(this.fs, join(dir, 'node_modules', '.bin', executable), env),
);
}

Expand Down Expand Up @@ -391,9 +401,10 @@ export class InteractiveNodeBinaryProvider extends NodeBinaryProvider {
@inject(ILogger) logger: ILogger,
@inject(FS) fs: FsPromises,
@inject(IPackageJsonProvider) packageJson: IPackageJsonProvider,
@inject(AnyLaunchConfiguration) launchConfig: Partial<AnyLaunchConfiguration>,
@optional() @inject(VSCodeApi) private readonly vscode: typeof vscodeType | undefined,
) {
super(logger, fs, packageJson);
super(logger, fs, packageJson, launchConfig);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/ui/autoAttach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ export function registerAutoAttach(

const launcher = (async () => {
const logger = new ProxyLogger();
let config = readConfig(vscode.workspace, Configuration.TerminalDebugConfig);
if (workspaceFolder) {
const fsPath = workspaceFolder?.uri.fsPath;
config = { ...config, cwd: fsPath, __workspaceFolder: fsPath };
}
// TODO: Figure out how to inject FsUtils
const inst = new AutoAttachLauncher(
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider),
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider, config || {}),
logger,
context,
services.get(FS),
services.get(NodeOnlyPathResolverFactory),
services.get(IPortLeaseTracker),
);

let config = readConfig(vscode.workspace, Configuration.TerminalDebugConfig);
if (workspaceFolder) {
const fsPath = workspaceFolder?.uri.fsPath;
config = { ...config, cwd: fsPath, __workspaceFolder: fsPath };
}

await launchVirtualTerminalParent(delegate, inst, config);

inst.onTargetListChanged(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/debugTerminalUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export function registerDebugTerminalUI(
const logger = new ProxyLogger();
const launcher = createLauncherFn(
logger,
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider),
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider, {}),
);

launcher.onTerminalCreated(terminal => {
Expand Down
Loading