diff --git a/package.json b/package.json index dce58f7..e3d3b4b 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "@types/node": "^22.5.2", "@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5", "@types/ts-node": "npm:ts-node@^10.9.2", - "@types/typescript-4.7": "npm:typescript@4.7.x", "changelogen": "^0.5.5", "eslint": "9.x", "globals": "^15.9.0", @@ -77,7 +76,7 @@ "typescript-eslint": "^8.3.0" }, "peerDependencies": { - "typescript": ">=4" + "typescript": ">=5" }, "dependencies": { "minimatch": "^9.0.5" diff --git a/src/harmony/harmony-factory.ts b/src/harmony/harmony-factory.ts deleted file mode 100644 index 3c95f0c..0000000 --- a/src/harmony/harmony-factory.ts +++ /dev/null @@ -1,31 +0,0 @@ -import TS from "typescript"; -import { TsTransformPathsContext } from "../types"; -import { TsFourSeven } from "./versions"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -export interface HarmonyFactory extends TS.NodeFactory {} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utilities -/* ****************************************************************************************************************** */ - -/** Creates a node factory compatible with TS v3+ */ -export function createHarmonyFactory(context: TsTransformPathsContext): HarmonyFactory { - return new Proxy(context.tsFactory ?? context.tsInstance, { - get(target, prop) { - if (TsFourSeven.predicate(context)) { - return TsFourSeven.handler(context, prop); - } else { - // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expression of type 'string | symbol' can't be used to index type 'typeof import("typescript") | NodeFactory'. - return target[prop]; - } - }, - }) as HarmonyFactory; -} - -// endregion diff --git a/src/harmony/index.ts b/src/harmony/index.ts deleted file mode 100644 index 34eee98..0000000 --- a/src/harmony/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./versions"; -export * from "./harmony-factory"; diff --git a/src/harmony/utils.ts b/src/harmony/utils.ts deleted file mode 100644 index 2f0cb8e..0000000 --- a/src/harmony/utils.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* ****************************************************************************************************************** */ -// region: Utility Types -/* ****************************************************************************************************************** */ -// @formatter:off - -// @prettier-ignore -export type DownSampleTsTypes = { - [i in keyof Tuple]: Tuple[i] extends unknown[] - ? DownSampleTsTypes - : DownSampleTsType; -} & { - length: Tuple["length"]; -}; - -// @prettier-ignore -type DownSampleTsType = - T extends Exclude ? Extract[1] : T; - -// @formatter:on -// endregion diff --git a/src/harmony/versions/four-seven.ts b/src/harmony/versions/four-seven.ts deleted file mode 100644 index b09638d..0000000 --- a/src/harmony/versions/four-seven.ts +++ /dev/null @@ -1,125 +0,0 @@ -/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-48 */ -import type { - default as TsCurrentModule, - AssertClause, - ExportDeclaration, - Expression, - ImportClause, - ImportDeclaration, - Modifier, - ModuleBody, - ModuleDeclaration, - ModuleName, - NamedExportBindings, -} from "typescript"; -import type TsFourSevenModule from "typescript-4.7"; -import type { TsTransformPathsContext } from "../../types"; -import type { DownSampleTsTypes } from "../utils"; - -/* ****************************************************************************************************************** */ -// region: Mapping -/* ****************************************************************************************************************** */ - -export type TypeMap = [ - [TsCurrentModule.ImportDeclaration, TsFourSevenModule.ImportDeclaration], - [TsCurrentModule.Modifier, TsFourSevenModule.Modifier], - [TsCurrentModule.ImportClause, TsFourSevenModule.ImportClause], - [TsCurrentModule.Expression, TsFourSevenModule.Expression], - [TsCurrentModule.AssertClause, TsFourSevenModule.AssertClause], - [TsCurrentModule.ExportDeclaration, TsFourSevenModule.ExportDeclaration], - [TsCurrentModule.NamedExportBindings, TsFourSevenModule.NamedExportBindings], - [TsCurrentModule.ModuleDeclaration, TsFourSevenModule.ModuleDeclaration], - [TsCurrentModule.ModuleName, TsFourSevenModule.ModuleName], - [TsCurrentModule.ModuleBody, TsFourSevenModule.ModuleBody], -]; - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utils -/* ****************************************************************************************************************** */ - -export const predicate = ({ tsVersionMajor, tsVersionMinor }: TsTransformPathsContext) => - tsVersionMajor == 4 && tsVersionMinor < 8; - -export function handler(context: TsTransformPathsContext, prop: string | symbol) { - const factory = context.tsFactory as unknown as TsFourSevenModule.NodeFactory; - - switch (prop) { - case "updateImportDeclaration": { - return function ( - node: ImportDeclaration, - _modifiers: readonly Modifier[] | undefined, - importClause: ImportClause | undefined, - moduleSpecifier: Expression, - assertClause: AssertClause | undefined, - ) { - const [dsNode, dsImportClause, dsModuleSpecifier, dsAssertClause] = downSample( - node, - importClause, - moduleSpecifier, - assertClause, - ); - - return factory.updateImportDeclaration( - dsNode, - dsNode.decorators, - dsNode.modifiers, - dsImportClause, - dsModuleSpecifier, - dsAssertClause, - ); - }; - } - case "updateExportDeclaration": { - return function ( - node: ExportDeclaration, - _modifiers: readonly Modifier[] | undefined, - isTypeOnly: boolean, - exportClause: NamedExportBindings | undefined, - moduleSpecifier: Expression | undefined, - assertClause: AssertClause | undefined, - ) { - const [dsNode, dsExportClause, dsModuleSpecifier, dsAssertClause] = downSample( - node, - exportClause, - moduleSpecifier, - assertClause, - ); - - return factory.updateExportDeclaration( - dsNode, - dsNode.decorators, - dsNode.modifiers, - isTypeOnly, - dsExportClause, - dsModuleSpecifier, - dsAssertClause, - ); - }; - } - case "updateModuleDeclaration": { - return function ( - node: ModuleDeclaration, - _modifiers: readonly Modifier[] | undefined, - name: ModuleName, - body: ModuleBody | undefined, - ) { - const [dsNode, dsName, dsBody] = downSample(node, name, body); - - return factory.updateModuleDeclaration(dsNode, dsNode.decorators, dsNode.modifiers, dsName, dsBody); - }; - } - default: { - // @ts-expect-error TS(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' type. - return (...args) => factory[prop](...args); - } - } -} - -export function downSample(...args: T): DownSampleTsTypes { - // @ts-expect-error TS(2322) FIXME: Type 'T' is not assignable to type 'DownSampleTsTypes'. - return args; -} - -// endregion diff --git a/src/harmony/versions/index.ts b/src/harmony/versions/index.ts deleted file mode 100644 index 457660e..0000000 --- a/src/harmony/versions/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as TsFourSeven from "./four-seven"; diff --git a/src/transformer.ts b/src/transformer.ts index e4990f8..55eb957 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -2,7 +2,6 @@ import path from "node:path"; import ts, { CompilerOptions } from "typescript"; import { RunMode, TsNodeState, TsTransformPathsConfig, TsTransformPathsContext, VisitorContext } from "./types"; import { nodeVisitor } from "./visitor"; -import { createHarmonyFactory } from "./harmony"; import { Minimatch } from "minimatch"; import { createSyntheticEmitHost, getTsNodeRegistrationProperties } from "./utils/ts-helpers"; import { TransformerExtras } from "ts-patch"; @@ -139,7 +138,7 @@ export default function transformer( getVisitor() { return nodeVisitor.bind(this); }, - factory: createHarmonyFactory(tsTransformPathsContext), + factory: (tsTransformPathsContext.tsFactory ?? tsTransformPathsContext.tsInstance) as ts.NodeFactory, }; return tsInstance.visitEachChild(sourceFile, visitorContext.getVisitor(), transformationContext); diff --git a/src/types.ts b/src/types.ts index a57e101..4e63dde 100755 --- a/src/types.ts +++ b/src/types.ts @@ -2,8 +2,6 @@ import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript"; import { PluginConfig } from "ts-patch"; import { Minimatch } from "minimatch"; -import { HarmonyFactory } from "./harmony"; - /* ****************************************************************************************************************** */ // region: TS Types /* ****************************************************************************************************************** */ @@ -49,7 +47,7 @@ export interface TsTransformPathsContext { } export interface VisitorContext extends TsTransformPathsContext { - readonly factory: HarmonyFactory; + readonly factory: ts.NodeFactory; readonly sourceFile: ts.SourceFile; readonly isDeclarationFile: boolean; readonly originalSourceFile: ts.SourceFile; diff --git a/test/config.ts b/test/config.ts index d27a7c4..76d32c4 100755 --- a/test/config.ts +++ b/test/config.ts @@ -1,11 +1,7 @@ import ts from "typescript"; -import tsFourSeven from "typescript-4.7"; import path from "node:path"; -export const tsModules = [ - ["4.7.4", tsFourSeven, "typescript-4.7"], - ["Latest", ts, "typescript"], -]; +export const tsModules = [["Latest", ts, "typescript"]]; export const projectsPaths = path.join(__dirname, "./projects"); export const transformerPath = require.resolve("typescript-transform-paths"); diff --git a/test/package.json b/test/package.json index 3d19bc3..ba7913e 100755 --- a/test/package.json +++ b/test/package.json @@ -21,7 +21,6 @@ "ts-patch": "^3.2.1", "tsp2": "npm:ts-patch@2.*.*", "typescript": "^5.5.4", - "typescript-4.7": "npm:typescript@4.7.4", "typescript-transform-paths": "portal:../" }, "workspaces": [ diff --git a/test/prepare.mjs b/test/prepare.mjs index 881e509..730fa36 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -4,7 +4,6 @@ import { symlink } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { patch } from "ts-patch"; -import { patch as patch2 } from "tsp2"; const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules @@ -27,7 +26,6 @@ function patchTsModules() { tspatch(["tsc.js", "typescript.js"], { basedir, dir: basedir }); } - patchTypescript("typescript-4.7", patch2); patchTypescript("typescript", patch); } diff --git a/test/tests/transformer/general.test.ts b/test/tests/transformer/general.test.ts index 3f98796..cbfb124 100755 --- a/test/tests/transformer/general.test.ts +++ b/test/tests/transformer/general.test.ts @@ -50,9 +50,7 @@ describe(`Transformer -> General Tests`, () => { beforeAll(() => { transformed = transformedFiles[file]; expected = { - // @ts-expect-error TS(2345) FIXME: Argument of type 'typeof ts | typeof ts | typeof import("typescript")' is not assignable to parameter of type 'typeof import("typescript")'. js: getExpected(tsInstance, file, originalFiles[file].js, projectRoot), - // @ts-expect-error TS(2345) FIXME: Argument of type 'typeof ts | typeof ts | typeof import("typescript")' is not assignable to parameter of type 'typeof import("typescript")'. dts: getExpected(tsInstance, file, originalFiles[file].dts, projectRoot), }; }); diff --git a/test/yarn.lock b/test/yarn.lock index ec24409..95aebda 100644 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -8069,7 +8069,6 @@ __metadata: ts-patch: "npm:^3.2.1" tsp2: "npm:ts-patch@2.*.*" typescript: "npm:^5.5.4" - typescript-4.7: "npm:typescript@4.7.4" typescript-transform-paths: "portal:../" languageName: unknown linkType: soft @@ -9189,23 +9188,13 @@ __metadata: languageName: node linkType: hard -"typescript-4.7@npm:typescript@4.7.4": - version: 4.7.4 - resolution: "typescript@npm:4.7.4" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/8c1c4007b6ce5b24c49f0e89173ab9e82687cc6ae54418d1140bb63b82d6598d085ac0f993fe3d3d1fbf87a2c76f1f81d394dc76315bc72c7a9f8561c5d8d205 - languageName: node - linkType: hard - "typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A.": version: 0.0.0-use.local resolution: "typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A." dependencies: minimatch: "npm:^9.0.5" peerDependencies: - typescript: ">=4" + typescript: ">=5" languageName: node linkType: soft diff --git a/yarn.lock b/yarn.lock index f598742..7d8d9fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -341,16 +341,6 @@ __metadata: languageName: node linkType: hard -"@types/typescript-4.7@npm:typescript@4.7.x": - version: 4.7.4 - resolution: "typescript@npm:4.7.4" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/8c1c4007b6ce5b24c49f0e89173ab9e82687cc6ae54418d1140bb63b82d6598d085ac0f993fe3d3d1fbf87a2c76f1f81d394dc76315bc72c7a9f8561c5d8d205 - languageName: node - linkType: hard - "@types/unist@npm:*, @types/unist@npm:^3.0.0": version: 3.0.3 resolution: "@types/unist@npm:3.0.3" @@ -2976,7 +2966,6 @@ __metadata: "@types/node": "npm:^22.5.2" "@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5" "@types/ts-node": "npm:ts-node@^10.9.2" - "@types/typescript-4.7": "npm:typescript@4.7.x" changelogen: "npm:^0.5.5" eslint: "npm:9.x" globals: "npm:^15.9.0" @@ -2987,7 +2976,7 @@ __metadata: typescript: "npm:^5.5.4" typescript-eslint: "npm:^8.3.0" peerDependencies: - typescript: ">=4" + typescript: ">=5" languageName: unknown linkType: soft