Skip to content

Commit

Permalink
[heft-typescript-plugin] feat: support typescript 5.6 (#4972)
Browse files Browse the repository at this point in the history
* feat: support typescript 5.6

This is a breaking change and will not work on Typescript versions < 5.6

* chore: review comments

---------

Co-authored-by: Taylor <ubermous@users.noreply.github.com>
  • Loading branch information
UberMouse and Taylor authored Oct 15, 2024
1 parent 239ad8a commit 8e9a51e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-typescript-plugin",
"comment": "Support typescript v5.6",
"type": "patch"
}
],
"packageName": "@rushstack/heft-typescript-plugin"
}
15 changes: 10 additions & 5 deletions heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -111,7 +115,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;
Expand Down Expand Up @@ -1300,9 +1304,10 @@ export class TypeScriptBuilder {
function getFilesToTranspileFromBuilderProgram(
builderProgram: TTypescript.BuilderProgram
): Map<string, string> {
const changedFilesSet: Set<string> = (
builderProgram as unknown as { getState(): { changedFilesSet: Set<string> } }
).getState().changedFilesSet;
const program: ExtendedBuilderProgram = builderProgram as unknown as ExtendedBuilderProgram;
// getState was removed in Typescript 5.6, replaced with state
const changedFilesSet: Set<string> = (program.state ?? program.getState()).changedFilesSet;

const filesToTranspile: Map<string, string> = new Map();
for (const fileName of changedFilesSet) {
const sourceFile: TTypescript.SourceFile | undefined = builderProgram.getSourceFile(fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,14 @@ export interface IExtendedTypeScript {
}

export type ExtendedTypeScript = typeof TTypescript & IExtendedTypeScript;

export type ExtendedBuilderProgram = TTypescript.BuilderProgram & {
/**
* Typescript 5.6+
*/
state?: { changedFilesSet: Set<string> };
/**
* Typescript < 5.6
*/
getState(): { changedFilesSet: Set<string> };
};

0 comments on commit 8e9a51e

Please sign in to comment.