From 880dbccc883005d10f00a1536561e0fe84b5fda6 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 24 Nov 2022 14:14:23 +0100 Subject: [PATCH] feat(check-node): allow silencing @jsii/check-node warnings (#3841) 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 --- .github/workflows/main.yml | 1 + .mergify/config.yml | 4 ++ packages/@jsii/check-node/src/constants.ts | 2 +- packages/@jsii/check-node/src/index.ts | 59 ++++++++++++++++------ packages/jsii-config/test/index.test.ts | 9 +++- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9399226f2a..7485576407 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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) diff --git a/.mergify/config.yml b/.mergify/config.yml index 2e27db3fa5..802065bdde 100644 --- a/.mergify/config.yml +++ b/.mergify/config.yml @@ -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 .*$ @@ -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 .*$ @@ -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 .*$ @@ -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 .*$ diff --git a/packages/@jsii/check-node/src/constants.ts b/packages/@jsii/check-node/src/constants.ts index f224ba93e7..87e31b18ca 100644 --- a/packages/@jsii/check-node/src/constants.ts +++ b/packages/@jsii/check-node/src/constants.ts @@ -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 }), ]; diff --git a/packages/@jsii/check-node/src/index.ts b/packages/@jsii/check-node/src/index.ts index 51c3f0f368..6ecc4a27d5 100644 --- a/packages/@jsii/check-node/src/index.ts +++ b/packages/@jsii/check-node/src/index.ts @@ -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)}` @@ -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, @@ -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)); diff --git a/packages/jsii-config/test/index.test.ts b/packages/jsii-config/test/index.test.ts index d740462562..02561e2fe6 100644 --- a/packages/jsii-config/test/index.test.ts +++ b/packages/jsii-config/test/index.test.ts @@ -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('|'), + ), ); }); });