Skip to content

Commit

Permalink
chore: add warning for outdated or buggy Node.js versions
Browse files Browse the repository at this point in the history
Fixes #1017
  • Loading branch information
connor4312 committed Jun 2, 2021
1 parent 5303fa0 commit d6eae01
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he
- fix: worker processes breaking sessions when attaching multiple times ([ref](https://github.com/microsoft/vscode/issues/124045))
- fix: wrong name of autogenerated edge debug config
- chore: adopt new terminal profile contribution point ([ref](https://github.com/microsoft/vscode/issues/120369))
- chore: add warning for outdated or buggy Node.js versions ([#1017](https://github.com/microsoft/vscode-js-debug/issues/1017))

## v1.56 (April 2021)

Expand Down
9 changes: 9 additions & 0 deletions src/targets/node/nodeBinaryProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ describe('NodeBinary', () => {
expect(b2.has(Capability.UseSpacesInRequirePath)).to.be.true;
expect(b2.has(Capability.UseSpacesInRequirePath, false)).to.be.true;
});

it('includes warnings', () => {
const b1 = new NodeBinary('', new Semver(12, 0, 0));
expect(b1.warning).to.be.undefined;
const b2 = new NodeBinary('', new Semver(16, 0, 0));
expect(b2.warning?.message).include('breakpoint');
const b3 = new NodeBinary('', new Semver(16, 10, 0));
expect(b3.warning).to.be.undefined;
});
});
42 changes: 42 additions & 0 deletions src/targets/node/nodeBinaryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ export const getRunScript = (
const assumedVersion = new Semver(12, 0, 0);
const minimumVersion = new Semver(8, 0, 0);

export interface IWarningMessage {
inclusiveMin: Semver;
inclusiveMax: Semver;
message: string;
}

const warningMessages: ReadonlyArray<IWarningMessage> = [
{
inclusiveMin: new Semver(16, 0, 0),
inclusiveMax: new Semver(16, 2, 0),
message: localize(
'warning.16bpIssue',
'Some breakpoints might not work in your version of Node.js. We suggest temporarily downgrading to Node 14. Details: https://aka.ms/AAcsvqm',
),
},
{
inclusiveMin: new Semver(7, 0, 0),
inclusiveMax: new Semver(8, 99, 99),
message: localize(
'warning.8outdated',
"You're running an outdated version of Node.js. We recommend upgrading for the latest bug, performance, and security fixes.",
),
},
];

/**
* DTO returned from the NodeBinaryProvider.
*/
Expand All @@ -74,6 +99,23 @@ export class NodeBinary {
return this.version !== undefined;
}

/**
* Gets a warning message for users of the binary.
*/
public get warning() {
if (!this.version) {
return;
}

for (const message of warningMessages) {
if (message.inclusiveMax.gte(this.version) && message.inclusiveMin.lte(this.version)) {
return message;
}
}

return undefined;
}

private capabilities = new Set<Capability>();

constructor(public readonly path: string, public version: Semver | undefined) {
Expand Down
9 changes: 9 additions & 0 deletions src/targets/node/nodeLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export class NodeLauncher extends NodeLauncherBase<INodeLaunchConfiguration> {
runData.params,
runData.params.runtimeExecutable || undefined,
);

const warning = binary.warning;
if (warning) {
runData.context.dap.output({
category: 'stderr',
output: warning.message,
});
}

const callbackFile = new CallbackFile<IProcessTelemetry>();
let env = await this.resolveEnvironment(runData, binary, {
fileCallback: callbackFile.path,
Expand Down

0 comments on commit d6eae01

Please sign in to comment.