From 276a33fe1ddf8714e96f4347c7167fca898109f1 Mon Sep 17 00:00:00 2001 From: Taylor Date: Mon, 14 Oct 2024 11:38:19 +1300 Subject: [PATCH 1/2] feat: support typescript 5.6 This is a breaking change and will not work on Typescript versions < 5.6 --- ...lugin-typescript-56-support_2024-10-13-22-44.json | 10 ++++++++++ .../heft-typescript-plugin/src/TypeScriptBuilder.ts | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json diff --git a/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json b/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json new file mode 100644 index 00000000000..9250e00f4ad --- /dev/null +++ b/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-typescript-plugin", + "comment": "Support typescript v5.6", + "type": "patch" + } + ], + "packageName": "@rushstack/heft-typescript-plugin" +} \ No newline at end of file diff --git a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts index f1f4db242a9..e55c01327c7 100644 --- a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts +++ b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts @@ -111,7 +111,7 @@ const OLDEST_SUPPORTED_TS_MAJOR_VERSION: number = 2; const OLDEST_SUPPORTED_TS_MINOR_VERSION: number = 9; const NEWEST_SUPPORTED_TS_MAJOR_VERSION: number = 5; -const NEWEST_SUPPORTED_TS_MINOR_VERSION: number = 4; +const NEWEST_SUPPORTED_TS_MINOR_VERSION: number = 6; interface ITypeScriptTool { ts: ExtendedTypeScript; @@ -1297,12 +1297,16 @@ export class TypeScriptBuilder { } } +type BuilderProgramWithInternals = TTypescript.BuilderProgram & { + state?: { changedFilesSet: Set }; + getState(): { changedFilesSet: Set }; +}; function getFilesToTranspileFromBuilderProgram( builderProgram: TTypescript.BuilderProgram ): Map { - const changedFilesSet: Set = ( - builderProgram as unknown as { getState(): { changedFilesSet: Set } } - ).getState().changedFilesSet; + const program: BuilderProgramWithInternals = builderProgram as unknown as BuilderProgramWithInternals; + const changedFilesSet: Set = (program.state ?? program.getState()).changedFilesSet; + const filesToTranspile: Map = new Map(); for (const fileName of changedFilesSet) { const sourceFile: TTypescript.SourceFile | undefined = builderProgram.getSourceFile(fileName); From aca28b93ef66d233a41c9d1fa4152ef7f6d18f90 Mon Sep 17 00:00:00 2001 From: Taylor Date: Tue, 15 Oct 2024 14:03:11 +1300 Subject: [PATCH 2/2] chore: review comments --- .../heft-typescript-plugin/src/TypeScriptBuilder.ts | 13 +++++++------ .../src/internalTypings/TypeScriptInternals.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts index e55c01327c7..4291e24cbcc 100644 --- a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts +++ b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts @@ -11,7 +11,11 @@ import { JsonFile, type IPackageJson, Path, FileError } from '@rushstack/node-co import type { ITerminal } from '@rushstack/terminal'; import type { IScopedLogger } from '@rushstack/heft'; -import type { ExtendedTypeScript, IExtendedSolutionBuilder } from './internalTypings/TypeScriptInternals'; +import type { + ExtendedBuilderProgram, + ExtendedTypeScript, + IExtendedSolutionBuilder +} from './internalTypings/TypeScriptInternals'; import type { ITypeScriptConfigurationJson } from './TypeScriptPlugin'; import type { PerformanceMeasurer } from './Performance'; import type { @@ -1297,14 +1301,11 @@ export class TypeScriptBuilder { } } -type BuilderProgramWithInternals = TTypescript.BuilderProgram & { - state?: { changedFilesSet: Set }; - getState(): { changedFilesSet: Set }; -}; function getFilesToTranspileFromBuilderProgram( builderProgram: TTypescript.BuilderProgram ): Map { - const program: BuilderProgramWithInternals = builderProgram as unknown as BuilderProgramWithInternals; + const program: ExtendedBuilderProgram = builderProgram as unknown as ExtendedBuilderProgram; + // getState was removed in Typescript 5.6, replaced with state const changedFilesSet: Set = (program.state ?? program.getState()).changedFilesSet; const filesToTranspile: Map = new Map(); diff --git a/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts b/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts index cfcc643e8a3..c330ac96769 100644 --- a/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts +++ b/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts @@ -98,3 +98,14 @@ export interface IExtendedTypeScript { } export type ExtendedTypeScript = typeof TTypescript & IExtendedTypeScript; + +export type ExtendedBuilderProgram = TTypescript.BuilderProgram & { + /** + * Typescript 5.6+ + */ + state?: { changedFilesSet: Set }; + /** + * Typescript < 5.6 + */ + getState(): { changedFilesSet: Set }; +};