Skip to content

Commit 137407c

Browse files
committed
fix: remove --inspect in node to fix useV3 breaking
Fixes #289
1 parent 87fefe8 commit 137407c

6 files changed

+80
-22
lines changed

src/nodeDebugConfigurationProvider.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { NvmResolver, INvmResolver } from './targets/node/nvmResolver';
1919
import { EnvironmentVars } from './common/environmentVars';
2020
import { resolveProcessId } from './ui/processPicker';
2121
import { BaseConfigurationProvider } from './baseConfigurationProvider';
22+
import { fixInspectFlags } from './ui/configurationUtils';
2223

2324
// eslint-disable-next-line
2425
const config = require('../package.json');
@@ -95,22 +96,7 @@ export class NodeDebugConfigurationProvider extends BaseConfigurationProvider<An
9596
}
9697

9798
// remove manual --inspect flags, which are no longer needed and interfere
98-
if (config.runtimeArgs) {
99-
const resolved: string[] = [];
100-
for (const arg of config.runtimeArgs) {
101-
const flags = /^--inspect(-brk)?(=|$)/.exec(arg);
102-
if (!flags) {
103-
resolved.push(arg);
104-
} else if (flags[1]) {
105-
// --inspect-brk
106-
config.stopOnEntry = config.stopOnEntry ?? true;
107-
} else {
108-
// simple --inspect, ignored
109-
}
110-
}
111-
112-
config.runtimeArgs = resolved;
113-
}
99+
fixInspectFlags(config);
114100
}
115101

116102
// "attach to process via picker" support

src/targets/node/nodeLauncher.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { NodePathProvider } from './nodePathProvider';
1717
import { exists } from '../../common/fsUtils';
1818
import { logger } from '../../common/logging/logger';
1919
import { LogTag } from '../../common/logging';
20+
import { fixInspectFlags } from '../../ui/configurationUtils';
2021

2122
/**
2223
* Tries to get the "program" entrypoint from the config. It a program
@@ -60,19 +61,23 @@ export class NodeLauncher extends NodeLauncherBase<INodeLaunchConfiguration> {
6061
* @inheritdoc
6162
*/
6263
protected resolveParams(params: AnyLaunchConfiguration): INodeLaunchConfiguration | undefined {
64+
let config: INodeLaunchConfiguration | undefined;
6365
if (params.type === Contributions.NodeDebugType && params.request === 'launch') {
64-
return params;
65-
}
66-
67-
if (
66+
config = { ...params };
67+
} else if (
6868
params.type === Contributions.ChromeDebugType &&
6969
params.server &&
7070
'program' in params.server
7171
) {
72-
return params.server;
72+
config = { ...params.server };
73+
}
74+
75+
if (!config) {
76+
return undefined;
7377
}
7478

75-
return undefined;
79+
fixInspectFlags(config);
80+
return config;
7681
}
7782

7883
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
allThreadsStopped : false
3+
description : Paused on debugger statement
4+
reason : pause
5+
threadId : <number>
6+
}
7+
<anonymous> @ ${fixturesDir}/test.js:2:1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
allThreadsStopped : false
3+
description : Paused on breakpoint
4+
reason : breakpoint
5+
threadId : <number>
6+
}
7+
<anonymous> @ ${fixturesDir}/test.js:1:1

src/test/node/node-runtime.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ describe('node runtime', () => {
8888
});
8989
});
9090

91+
describe('inspect flag handling', () => {
92+
itIntegrates('does not break with inspect flag', async ({ r }) => {
93+
createFileTree(testFixturesDir, { 'test.js': ['console.log("hello world");', 'debugger;'] });
94+
const handle = await r.runScript('test.js', {
95+
runtimeArgs: ['--inspect'],
96+
});
97+
handle.load();
98+
await waitForPause(handle);
99+
handle.assertLog({ substring: true });
100+
});
101+
102+
itIntegrates('treats inspect-brk as stopOnEntry', async ({ r }) => {
103+
createFileTree(testFixturesDir, { 'test.js': ['console.log("hello world");'] });
104+
const handle = await r.runScript('test.js', {
105+
cwd: testFixturesDir,
106+
runtimeArgs: ['--inspect-brk'],
107+
});
108+
handle.load();
109+
await waitForPause(handle);
110+
handle.assertLog({ substring: true });
111+
});
112+
});
113+
91114
describe('stopOnEntry', () => {
92115
beforeEach(() =>
93116
createFileTree(testFixturesDir, { 'test.js': '', 'bar.js': 'require("./test")' }),

src/ui/configurationUtils.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import { ResolvingNodeLaunchConfiguration } from '../configuration';
6+
7+
/**
8+
* Removes and handles any --inspect or --inspect-brk flags from the launch
9+
* configuration. These aren't needed and don't work with the new debugger.
10+
*/
11+
export function fixInspectFlags(config: ResolvingNodeLaunchConfiguration) {
12+
if (!config.runtimeArgs) {
13+
return;
14+
}
15+
16+
const resolved: string[] = [];
17+
for (const arg of config.runtimeArgs) {
18+
const flags = /^--inspect(-brk)?(=|$)/.exec(arg);
19+
if (!flags) {
20+
resolved.push(arg);
21+
} else if (flags[1]) {
22+
// --inspect-brk
23+
config.stopOnEntry = config.stopOnEntry || true;
24+
} else {
25+
// simple --inspect, ignored
26+
}
27+
}
28+
29+
config.runtimeArgs = resolved;
30+
}

0 commit comments

Comments
 (0)