Skip to content

Commit

Permalink
feat(check-node): allow silencing @jsii/check-node warnings (#3841)
Browse files Browse the repository at this point in the history
Allows silencing @jsii/check-node warnings when the runtime is not End-of-Life, so that users who know what they are doing can suppress the extraneous output.

This is particularly useful for new Node releases that are un-tested, but can typically be expected to work, or known broken releases that happen to work for a given use-case that is carefully crafted to avoid the known issues; but is also possible for deprecated node releases.

Messages about using end-of-life releases are intentionally not suppressible.

Also updated the message for un-tested and known-broken releases to better frame the fact that these might work fine, and urge users to retry using a known supported release before they file a bug report.

Additionally adds testing for Node 19.x.

Fixes #3817
Fixes #3171
  • Loading branch information
RomainMuller committed Nov 24, 2022
1 parent 8862c07 commit 880dbcc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ jobs:
- '14' # EOL 2023-04-30
- '16' # EOL 2023-09-11
- '18' # EOL 2025-04-30
- '19' # EOL 2023-06-01
os: [ubuntu-latest]
python: ['3.7']
# Add specific combinations to be tested against "node 14" (to restrict cardinality)
Expand Down
4 changes: 4 additions & 0 deletions .mergify/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ queue_rules:
- status-success~=^Test \(.* node 14 .*$
- status-success~=^Test \(.* node 16 .*$
- status-success~=^Test \(.* node 18 .*$
- status-success~=^Test \(.* node 19 .*$
# One test for each supported dotnet version
- status-success~=^Test \(.* dotnet 3\.1\.x .*$
- status-success~=^Test \(.* dotnet 6\.0\.x .*$
Expand Down Expand Up @@ -63,6 +64,7 @@ pull_request_rules:
- status-success~=^Test \(.* node 14 .*$
- status-success~=^Test \(.* node 16 .*$
- status-success~=^Test \(.* node 18 .*$
- status-success~=^Test \(.* node 19 .*$
# One test for each supported dotnet version
- status-success~=^Test \(.* dotnet 3\.1\.x .*$
- status-success~=^Test \(.* dotnet 6\.0\.x .*$
Expand Down Expand Up @@ -115,6 +117,7 @@ pull_request_rules:
- status-success~=^Test \(.* node 14 .*$
- status-success~=^Test \(.* node 16 .*$
- status-success~=^Test \(.* node 18 .*$
- status-success~=^Test \(.* node 19 .*$
# One test for each supported dotnet version
- status-success~=^Test \(.* dotnet 3\.1\.x .*$
- status-success~=^Test \(.* dotnet 6\.0\.x .*$
Expand Down Expand Up @@ -167,6 +170,7 @@ pull_request_rules:
- status-success~=^Test \(.* node 14 .*$
- status-success~=^Test \(.* node 16 .*$
- status-success~=^Test \(.* node 18 .*$
- status-success~=^Test \(.* node 19 .*$
# One test for each supported dotnet version
- status-success~=^Test \(.* dotnet 3\.1\.x .*$
- status-success~=^Test \(.* dotnet 6\.0\.x .*$
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/check-node/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class NodeRelease {
new NodeRelease(18, { endOfLife: new Date('2025-04-30') }),

// Future (planned releases)
new NodeRelease(19, { endOfLife: new Date('2023-06-01'), untested: true }),
new NodeRelease(19, { endOfLife: new Date('2023-06-01') }),
new NodeRelease(20, { endOfLife: new Date('2026-04-30'), untested: true }),
];

Expand Down
59 changes: 43 additions & 16 deletions packages/@jsii/check-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import { NodeRelease } from './constants';
* Checks the current process' node runtime version against the release support
* matrix, and issues a warning to STDERR if the current version is not fully
* supported (i.e: it is deprecated, end-of-life, or untested).
*
* @param envPrefix will be prepended to environment variable names that can be
* used to silence version check warnings.
*/
export function checkNode(): void {
export function checkNode(envPrefix = 'JSII'): void {
const { nodeRelease, knownBroken } = NodeRelease.forThisRuntime();

const defaultCallToAction =
'Should you encounter odd runtime issues, please try using one of the supported release before filing a bug report.';

if (nodeRelease?.endOfLife) {
const qualifier = nodeRelease.endOfLifeDate
? ` on ${nodeRelease.endOfLifeDate.toISOString().slice(0, 10)}`
Expand All @@ -22,28 +28,42 @@ export function checkNode(): void {
`Please upgrade to a supported node version as soon as possible.`,
);
} else if (knownBroken) {
veryVisibleMessage(
bgRed.white.bold,
`Node ${version} is unsupported and has known compatibility issues with this software.`,
);
const silenceVariable = `${envPrefix}_SILENCE_WARNING_KNOWN_BROKEN_NODE_VERSION`;
if (!process.env[silenceVariable])
veryVisibleMessage(
bgRed.white.bold,
`Node ${version} is unsupported and has known compatibility issues with this software.`,
defaultCallToAction,
silenceVariable,
);
} else if (!nodeRelease || nodeRelease.untested) {
veryVisibleMessage(
bgYellow.black,
`This software has not been tested with node ${version}.`,
);
const silenceVariable = `${envPrefix}_SILENCE_WARNING_UNTESTED_NODE_VERSION`;
if (!process.env[silenceVariable]) {
veryVisibleMessage(
bgYellow.black,
`This software has not been tested with node ${version}.`,
defaultCallToAction,
silenceVariable,
);
}
} else if (nodeRelease?.deprecated) {
const deadline = nodeRelease.endOfLifeDate!.toISOString().slice(0, 10);
veryVisibleMessage(
bgYellowBright.black,
`Node ${nodeRelease.majorVersion} is approaching end-of-life and will no longer be supported in new releases after ${deadline}.`,
`Please upgrade to a supported node version as soon as possible.`,
);
const silenceVariable = `${envPrefix}_SILENCE_WARNING_DEPRECATED_NODE_VERSION`;
if (!process.env[silenceVariable]) {
const deadline = nodeRelease.endOfLifeDate!.toISOString().slice(0, 10);
veryVisibleMessage(
bgYellowBright.black,
`Node ${nodeRelease.majorVersion} is approaching end-of-life and will no longer be supported in new releases after ${deadline}.`,
`Please upgrade to a supported node version as soon as possible.`,
silenceVariable,
);
}
}

function veryVisibleMessage(
chalk: Chalk,
message: string,
callToAction = 'You may to encounter runtime issues, and should switch to a supported release.',
callToAction: string,
silenceVariable?: string,
): void {
const lines = [
message,
Expand All @@ -64,6 +84,13 @@ export function checkNode(): void {
release.deprecated ? ' [DEPRECATED]' : ''
}`,
),
// Add blurb on how this message can be silenced (if it can be silenced).
...(silenceVariable
? [
'',
`This warning can be silenced by setting the ${silenceVariable} environment variable.`,
]
: []),
];
const len = Math.max(...lines.map((l) => l.length));
const border = chalk('!'.repeat(len + 8));
Expand Down
9 changes: 8 additions & 1 deletion packages/jsii-config/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ describe('jsii-config', () => {
});

await expect(jsiiConfig('package.json')).rejects.toThrow(
'Unexpected token I in JSON at position 0',
new RegExp(
[
// Error produced by JSON.parse in Node < 19
'Unexpected token I in JSON at position 0',
// Error produced by JSON.parse in Node >= 19
`Unexpected token 'I', "INVALID JSON STRING" is not valid JSON`,
].join('|'),
),
);
});
});
Expand Down

0 comments on commit 880dbcc

Please sign in to comment.