1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.emitSupportPolicyInformation = void 0;
|
4 | const node_fs_1 = require("node:fs");
|
5 | const node_https_1 = require("node:https");
|
6 | const node_path_1 = require("node:path");
|
7 | const chalk = require("chalk");
|
8 | const version_1 = require("./version");
|
9 | const SILENCE_ENV_VAR = 'JSII_SILENCE_SUPPORT_WARNING';
|
10 | const THIRTY_DAYS_IN_MILLIS = 2592000000;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | async function emitSupportPolicyInformation() {
|
21 | if (process.env[SILENCE_ENV_VAR]) {
|
22 | return;
|
23 | }
|
24 | const data = await getReleasesDocument();
|
25 | if (data.current == version_1.RELEASE_LINE) {
|
26 |
|
27 | return;
|
28 | }
|
29 | const endOfSupportDate = data.endOfSupport?.includes(version_1.RELEASE_LINE) ? new Date(0) : data.maintenance[version_1.RELEASE_LINE];
|
30 | if (endOfSupportDate == null) {
|
31 |
|
32 | return;
|
33 | }
|
34 | const now = new Date();
|
35 | const inThirtyDays = new Date(now.getTime() + THIRTY_DAYS_IN_MILLIS);
|
36 | const alternatives = Object.entries(data.maintenance)
|
37 | .flatMap(([release, dateStr]) => {
|
38 | const date = new Date(dateStr);
|
39 | if (date <= inThirtyDays) {
|
40 | return [];
|
41 | }
|
42 | return [{ release, date }];
|
43 | })
|
44 | .reduce((acc, { release, date }) => {
|
45 | if (acc.length === 0) {
|
46 | acc.push('', 'Other actively supported release lines include:');
|
47 | }
|
48 | acc.push(`- ${release} (planned End-of-Support date: ${date.toISOString()})`);
|
49 | return acc;
|
50 | }, new Array());
|
51 | if (endOfSupportDate <= now) {
|
52 |
|
53 | veryVisibleMessage(chalk.bgRed.white.bold, `The ${version_1.RELEASE_LINE} release line of jsii has reached End-of-Support.`, `We strongly recommend you upgrade to the current release line (${data.current}) at your earliest convenience.`, ...alternatives);
|
54 | }
|
55 | else if (endOfSupportDate <= inThirtyDays) {
|
56 |
|
57 | veryVisibleMessage(chalk.bgYellow.black, `The ${version_1.RELEASE_LINE} release line of jsii will reach End-of-Support soon, on ${endOfSupportDate.toISOString()}.`, `We strongly recommend you upgrade to the current release line (${data.current}) at your earliest convenience.`, ...alternatives);
|
58 | }
|
59 | }
|
60 | exports.emitSupportPolicyInformation = emitSupportPolicyInformation;
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | async function getReleasesDocument() {
|
66 | const downloaded = await new Promise((ok, ko) => {
|
67 | const request = (0, node_https_1.get)(new URL('https://raw.githubusercontent.com/aws/jsii-compiler/main/releases.json'), (response) => {
|
68 | if (response.statusCode === 404) {
|
69 | return ok(undefined);
|
70 | }
|
71 | if (response.statusCode !== 200) {
|
72 | return ko(`received error response: HTTP ${response.statusCode} - ${response.statusMessage}`);
|
73 | }
|
74 | response.once('error', ko);
|
75 | const chunks = new Array();
|
76 | response.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
77 | response.once('end', () => ok(Buffer.concat(chunks).toString('utf-8')));
|
78 | });
|
79 | request.once('abort', () => ko('request aborted'));
|
80 | request.once('timeout', () => ko('request timed out'));
|
81 | request.once('error', ko);
|
82 | request.end();
|
83 | }).catch((cause) => {
|
84 | if (process.env.JSII_DEBUG) {
|
85 | console.error(`Could not download releases.json from GitHub: ${cause}`);
|
86 | }
|
87 | undefined;
|
88 | });
|
89 | return JSON.parse(downloaded ?? (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'releases.json'), 'utf-8'), (key, value) => {
|
90 | if (key !== 'maintenance') {
|
91 | return value;
|
92 | }
|
93 | return Object.fromEntries(Object.entries(value).map(([release, date]) => [release, new Date(date)]));
|
94 | });
|
95 | }
|
96 | function veryVisibleMessage(formatter, ...lines) {
|
97 | if (lines.length === 0) {
|
98 | throw new Error(`At least one line of message must be provided!`);
|
99 | }
|
100 | const len = Math.max(...lines.map((line) => line.length));
|
101 | const border = formatter('!'.repeat(len + 8));
|
102 | const spacer = formatter(`!! ${' '.repeat(len)} !!`);
|
103 | console.error(border);
|
104 | console.error(spacer);
|
105 | for (const line of lines) {
|
106 | console.error(formatter(`!! ${line.padEnd(len, ' ')} !!`));
|
107 | }
|
108 | console.error(spacer);
|
109 | console.error(border);
|
110 | }
|
111 |
|
\ | No newline at end of file |