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AAC;IAC/D,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import { readFileSync } from 'node:fs';\nimport { get } from 'node:https';\nimport { join } from 'node:path';\nimport * as chalk from 'chalk';\n\nimport { RELEASE_LINE } from './version';\n\nconst SILENCE_ENV_VAR = 'JSII_SILENCE_SUPPORT_WARNING';\nconst THIRTY_DAYS_IN_MILLIS = 2_592_000_000;\n\n/** @internal */\nexport interface ReleasesDocument {\n /**\n * The release line that occupies the 'Current' stage.\n */\n readonly current: ReleaseLine;\n /**\n * Release lines currently in 'Maintenance' with the date at which they are\n * planned to go into the 'End-of-Support' stage. This date should always be\n * set a minimum of 6 months in the future when a release line is added to the\n * list.\n */\n readonly maintenance: { readonly [release: ReleaseLine]: Date };\n /**\n * Release lines that are currently out-of-support. This is semantically\n * equivalent to being in the `maintenance` list with a past date, but offers\n * slightly faster look-up.\n */\n readonly endOfSupport?: readonly ReleaseLine[];\n}\n\n/**\n * Checks whether the current release line is close to End-of-Support (within\n * 30 days), or already in End-of-Support, and if that is the case, emits a\n * warning to call the user to action.\n *\n * It is possible for users to opt out of these notifications by setting the\n * `JSII_SILENCE_SUPPORT_WARNING` environment variable to any truthy value (that\n * is, any non-empty value).\n */\nexport async function emitSupportPolicyInformation() {\n if (process.env[SILENCE_ENV_VAR]) {\n return;\n }\n\n const data = await getReleasesDocument();\n\n if (data.current == RELEASE_LINE) {\n // Current release is not close to deprecation\n return;\n }\n\n const endOfSupportDate = data.endOfSupport?.includes(RELEASE_LINE) ? new Date(0) : data.maintenance[RELEASE_LINE];\n if (endOfSupportDate == null) {\n // Don't know the status, so don't say anything...\n return;\n }\n\n const now = new Date();\n const inThirtyDays = new Date(now.getTime() + THIRTY_DAYS_IN_MILLIS);\n const alternatives = Object.entries(data.maintenance)\n .flatMap(([release, dateStr]) => {\n const date = new Date(dateStr);\n if (date <= inThirtyDays) {\n return [];\n }\n return [{ release, date }];\n })\n .reduce((acc, { release, date }) => {\n if (acc.length === 0) {\n acc.push('', 'Other actively supported release lines include:');\n }\n acc.push(`- ${release} (planned End-of-Support date: ${date.toISOString()})`);\n return acc;\n }, new Array<string>());\n if (endOfSupportDate <= now) {\n // End-of-Support already!\n veryVisibleMessage(\n chalk.bgRed.white.bold,\n `The ${RELEASE_LINE} release line of jsii has reached End-of-Support.`,\n `We strongly recommend you upgrade to the current release line (${data.current}) at your earliest convenience.`,\n ...alternatives,\n );\n } else if (endOfSupportDate <= inThirtyDays) {\n // End-of-Support within 30 days!\n veryVisibleMessage(\n chalk.bgYellow.black,\n `The ${RELEASE_LINE} release line of jsii will reach End-of-Support soon, on ${endOfSupportDate.toISOString()}.`,\n `We strongly recommend you upgrade to the current release line (${data.current}) at your earliest convenience.`,\n ...alternatives,\n );\n }\n}\n\n/**\n * Downloads the latest `releases.json` document from 'https://raw.githubusercontent.com/aws/jsii-compiler/main/releases.json'\n * if possible, or falls back to the built-in version of that file if that fails in any way.\n */\nasync function getReleasesDocument(): Promise<ReleasesDocument> {\n const downloaded = await new Promise<string | undefined>((ok, ko) => {\n const request = get(\n new URL('https://raw.githubusercontent.com/aws/jsii-compiler/main/releases.json'),\n (response) => {\n if (response.statusCode === 404) {\n return ok(undefined);\n }\n if (response.statusCode !== 200) {\n return ko(`received error response: HTTP ${response.statusCode} - ${response.statusMessage}`);\n }\n response.once('error', ko);\n const chunks = new Array<Buffer>();\n response.on('data', (chunk) => chunks.push(Buffer.from(chunk)));\n response.once('end', () => ok(Buffer.concat(chunks).toString('utf-8')));\n },\n );\n request.once('abort', () => ko('request aborted'));\n request.once('timeout', () => ko('request timed out'));\n request.once('error', ko);\n request.end();\n }).catch((cause) => {\n if (process.env.JSII_DEBUG) {\n console.error(`Could not download releases.json from GitHub: ${cause}`);\n }\n undefined;\n });\n\n return JSON.parse(downloaded ?? readFileSync(join(__dirname, '..', 'releases.json'), 'utf-8'), (key, value) => {\n if (key !== 'maintenance') {\n return value;\n }\n return Object.fromEntries(Object.entries(value).map(([release, date]) => [release, new Date(date as string)]));\n }) as ReleasesDocument;\n}\n\nfunction veryVisibleMessage(formatter: chalk.Chalk, ...lines: readonly string[]): void {\n if (lines.length === 0) {\n throw new Error(`At least one line of message must be provided!`);\n }\n\n const len = Math.max(...lines.map((line) => line.length));\n const border = formatter('!'.repeat(len + 8));\n const spacer = formatter(`!! ${' '.repeat(len)} !!`);\n\n console.error(border);\n console.error(spacer);\n for (const line of lines) {\n console.error(formatter(`!! ${line.padEnd(len, ' ')} !!`));\n }\n console.error(spacer);\n console.error(border);\n}\n\ntype ReleaseLine = `${number}.${number}`;\n"]}
\No newline at end of file