diff --git a/projects/igniteui-angular/migrations/common/ServerHost.ts b/projects/igniteui-angular/migrations/common/ServerHost.ts index 18e7aa81ed8..090a90eb58a 100644 --- a/projects/igniteui-angular/migrations/common/ServerHost.ts +++ b/projects/igniteui-angular/migrations/common/ServerHost.ts @@ -1,7 +1,7 @@ -import type { Tree } from '@angular-devkit/schematics'; +import type { Tree } from '@angular-devkit/schematics/index.js'; import * as pathFs from 'path'; -import * as ts from 'typescript/lib/tsserverlibrary'; -import { CUSTOM_TS_PLUGIN_NAME, CUSTOM_TS_PLUGIN_PATH } from './tsUtils'; +import * as ts from 'typescript/lib/tsserverlibrary.js'; +import { CUSTOM_TS_PLUGIN_NAME, CUSTOM_TS_PLUGIN_PATH } from './tsUtils.ts'; import { createRequire } from 'module'; /** @@ -15,7 +15,9 @@ export class ServerHost implements ts.server.ServerHost { /** Cached because Angular schematics encapsulation's customRequire doesn't provide `resolve` */ private nativeRequire = createRequire(__filename); - constructor(public host: Tree) { + public host: Tree; + constructor(host: Tree) { + this.host = host; this.args = ts.sys.args; this.newLine = ts.sys.newLine; this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames; diff --git a/projects/igniteui-angular/migrations/common/UpdateChanges.spec.ts b/projects/igniteui-angular/migrations/common/UpdateChanges.spec.ts index 9d561f24134..00086a33ef0 100644 --- a/projects/igniteui-angular/migrations/common/UpdateChanges.spec.ts +++ b/projects/igniteui-angular/migrations/common/UpdateChanges.spec.ts @@ -1,10 +1,10 @@ -import { UnitTestTree } from '@angular-devkit/schematics/testing'; +import { UnitTestTree } from '@angular-devkit/schematics/testing/index.js'; import * as fs from 'fs'; import * as path from 'path'; -import { ClassChanges, BindingChanges, SelectorChanges, ThemeChanges, ImportsChanges, ElementType, ThemeType, MemberChanges } from './schema'; -import { UpdateChanges, InputPropertyType, BoundPropertyObject } from './UpdateChanges'; -import * as tsUtils from './tsUtils'; -import { setupTestTree } from './setup.spec'; +import { ClassChanges, BindingChanges, SelectorChanges, ThemeChanges, ImportsChanges, ElementType, ThemeType, MemberChanges } from './schema/index.ts'; +import { UpdateChanges, InputPropertyType, BoundPropertyObject } from './UpdateChanges.ts'; +import * as tsUtils from './tsUtils.ts'; +import { setupTestTree } from './setup.spec.ts'; describe('UpdateChanges', () => { let appTree: UnitTestTree; diff --git a/projects/igniteui-angular/migrations/common/UpdateChanges.ts b/projects/igniteui-angular/migrations/common/UpdateChanges.ts index 2336340453a..70adbade4c7 100644 --- a/projects/igniteui-angular/migrations/common/UpdateChanges.ts +++ b/projects/igniteui-angular/migrations/common/UpdateChanges.ts @@ -1,30 +1,31 @@ import * as fs from 'fs'; import * as path from 'path'; import * as ts from 'typescript'; -import * as tss from 'typescript/lib/tsserverlibrary'; +import * as tss from 'typescript/lib/tsserverlibrary.js'; import type { SchematicContext, Tree, FileVisitor } from '@angular-devkit/schematics'; import type { WorkspaceSchema } from '@schematics/angular/utility/workspace-models'; import { ClassChanges, BindingChanges, SelectorChange, SelectorChanges, ThemeChanges, ImportsChanges, MemberChanges, ThemeChange, ThemeType -} from './schema'; +} from './schema/index.ts'; import { getLanguageService, getRenamePositions, getIdentifierPositions, isMemberIgniteUI, NG_LANG_SERVICE_PACKAGE_NAME, NG_CORE_PACKAGE_NAME, findMatches -} from './tsUtils'; +} from './tsUtils.ts'; import { getProjectPaths, getWorkspace, getProjects, escapeRegExp, replaceMatch, getPackageManager, canResolvePackage, tryInstallPackage, tryUninstallPackage, getPackageVersion -} from './util'; -import { ServerHost } from './ServerHost'; -import { serviceContainer } from './project-service-container'; +} from './util.ts'; +import { ServerHost } from './ServerHost.ts'; +import { serviceContainer } from './project-service-container.ts'; const TSCONFIG_PATH = 'tsconfig.json'; -export enum InputPropertyType { - EVAL = 'eval', - STRING = 'string' -} +export const InputPropertyType = { + EVAL: 'eval', + STRING: 'string' +} as const; +export type InputPropertyType = typeof InputPropertyType[keyof typeof InputPropertyType]; declare type TransformFunction = (args: BoundPropertyObject) => void; export interface BoundPropertyObject { value: string; @@ -143,7 +144,14 @@ export class UpdateChanges { * * @param rootPath Root folder for the schematic to read configs, pass __dirname */ - constructor(private rootPath: string, private host: Tree, private context?: SchematicContext) { + private rootPath: string; + private host: Tree; + private context?: SchematicContext; + + constructor(rootPath: string, host: Tree, context?: SchematicContext) { + this.rootPath = rootPath; + this.host = host; + this.context = context; this.workspace = getWorkspace(host); this.sourcePaths = getProjectPaths(this.workspace); @@ -867,7 +875,8 @@ export class UpdateChanges { } } -export enum BindingType { - Output, - Input -} +export const BindingType = { + Output: 'Output', + Input: 'Input' +} as const; +export type BindingType = typeof BindingType[keyof typeof BindingType]; diff --git a/projects/igniteui-angular/migrations/common/filterSourceDirs.ts b/projects/igniteui-angular/migrations/common/filterSourceDirs.ts index bddc648b3bf..b16202c49e5 100644 --- a/projects/igniteui-angular/migrations/common/filterSourceDirs.ts +++ b/projects/igniteui-angular/migrations/common/filterSourceDirs.ts @@ -1,6 +1,6 @@ -import { filter } from '@angular-devkit/schematics'; -import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; -import { getWorkspace, getWorkspacePath, getProjectPaths } from './util'; +import { filter } from '@angular-devkit/schematics/index.js'; +import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics/index.js'; +import { getWorkspace, getWorkspacePath, getProjectPaths } from './util.ts'; /** * @deprecated Temporary diff --git a/projects/igniteui-angular/migrations/common/project-service-container.ts b/projects/igniteui-angular/migrations/common/project-service-container.ts index c85518c208a..51d3966b25d 100644 --- a/projects/igniteui-angular/migrations/common/project-service-container.ts +++ b/projects/igniteui-angular/migrations/common/project-service-container.ts @@ -1,6 +1,6 @@ -import * as tss from 'typescript/lib/tsserverlibrary'; -import { createProjectService } from './tsUtils'; -import { ServerHost } from './ServerHost'; +import * as tss from 'typescript/lib/tsserverlibrary.js'; +import { createProjectService } from './tsUtils.ts'; +import { ServerHost } from './ServerHost.ts'; export class ProjectServiceContainer { private _serverHost: ServerHost; diff --git a/projects/igniteui-angular/migrations/common/schema/index.ts b/projects/igniteui-angular/migrations/common/schema/index.ts index 7db635bada9..eb56927151a 100644 --- a/projects/igniteui-angular/migrations/common/schema/index.ts +++ b/projects/igniteui-angular/migrations/common/schema/index.ts @@ -6,12 +6,14 @@ export interface ThemeChanges { changes: ThemeChange[]; } -export enum ThemeType { - Variable = 'variable', - Property = 'property', - Function = 'function', - Mixin = 'mixin' -} +export const ThemeType = { + Variable: 'variable', + Property: 'property', + Function: 'function', + Mixin: 'mixin' +} as const; +export type ThemeType = typeof ThemeType[keyof typeof ThemeType]; + export interface ThemeChange extends ChangeAction { /** Name of the theme property */ name: string; @@ -92,7 +94,8 @@ export interface ImportsChanges { changes: ImportsChange[]; } -export enum ElementType { - Directive = 'directive', - Component = 'component' -} +export const ElementType = { + Directive: 'directive', + Component: 'component' +} as const; +export type ElementType = typeof ElementType[keyof typeof ElementType]; diff --git a/projects/igniteui-angular/migrations/common/setup.spec.ts b/projects/igniteui-angular/migrations/common/setup.spec.ts index 3c001e78587..16e53c4b4ce 100644 --- a/projects/igniteui-angular/migrations/common/setup.spec.ts +++ b/projects/igniteui-angular/migrations/common/setup.spec.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { EmptyTree } from '@angular-devkit/schematics'; -import { UnitTestTree } from '@angular-devkit/schematics/testing'; -import * as tss from 'typescript/lib/tsserverlibrary'; -import { serviceContainer } from './project-service-container'; +import { EmptyTree } from '@angular-devkit/schematics/index.js'; +import { UnitTestTree } from '@angular-devkit/schematics/testing/index.js'; +import * as tss from 'typescript/lib/tsserverlibrary.js'; +import { serviceContainer } from './project-service-container.ts'; const configJson = { version: 1, diff --git a/projects/igniteui-angular/migrations/common/tsLogger.ts b/projects/igniteui-angular/migrations/common/tsLogger.ts index a332fcafb0b..623a2cda9a0 100644 --- a/projects/igniteui-angular/migrations/common/tsLogger.ts +++ b/projects/igniteui-angular/migrations/common/tsLogger.ts @@ -1,28 +1,30 @@ -import * as ts from 'typescript/lib/tsserverlibrary'; +import * as ts from 'typescript/lib/tsserverlibrary.js'; export class Logger implements ts.server.Logger { - constructor( - private readonly traceToConsole: boolean, - private readonly level: ts.server.LogLevel - ) { } + private readonly traceToConsole: boolean; + private readonly level: ts.server.LogLevel; + constructor(traceToConsole: boolean, level: ts.server.LogLevel) { + this.traceToConsole = traceToConsole; + this.level = level; + } public hasLevel(level: ts.server.LogLevel) { return this.loggingEnabled() && this.level >= level; } - public loggingEnabled() { + loggingEnabled() { return this.traceToConsole; } - public perftrc(s: string) { + perftrc(s: string) { this.msg(s, ts.server.Msg.Perf); } - public info(s: string) { + info(s: string) { this.msg(s, ts.server.Msg.Info); } - public msg(s: string, type: ts.server.Msg = ts.server.Msg.Err) { + msg(s: string, type: ts.server.Msg = ts.server.Msg.Err) { if (!this.traceToConsole) { return; } @@ -41,13 +43,13 @@ export class Logger implements ts.server.Logger { /* These methods are used to log to a file, we will only use the logger to log on the console. */ - public close() { } + close() { } - public startGroup() { } + startGroup() { } - public endGroup() { } + endGroup() { } - public getLogFileName() { + getLogFileName() { return null; } //#endregion diff --git a/projects/igniteui-angular/migrations/common/tsPlugin/TSLanguageService.ts b/projects/igniteui-angular/migrations/common/tsPlugin/TSLanguageService.ts index d491749540e..17217d0eca4 100644 --- a/projects/igniteui-angular/migrations/common/tsPlugin/TSLanguageService.ts +++ b/projects/igniteui-angular/migrations/common/tsPlugin/TSLanguageService.ts @@ -1,4 +1,4 @@ -import * as tss from 'typescript/lib/tsserverlibrary'; +import * as tss from 'typescript/lib/tsserverlibrary.js'; export interface TSLanguageService extends tss.LanguageService { getTypeScriptLanguageService(): tss.LanguageService; diff --git a/projects/igniteui-angular/migrations/common/tsUtils.ts b/projects/igniteui-angular/migrations/common/tsUtils.ts index 1c74a906bdd..bf3a16760bc 100644 --- a/projects/igniteui-angular/migrations/common/tsUtils.ts +++ b/projects/igniteui-angular/migrations/common/tsUtils.ts @@ -1,22 +1,23 @@ import * as ts from 'typescript'; -import * as tss from 'typescript/lib/tsserverlibrary'; -import type { Tree } from '@angular-devkit/schematics'; -import type { MemberChange } from './schema'; -import { escapeRegExp } from './util'; -import { Logger } from './tsLogger'; -import { TSLanguageService } from './tsPlugin/TSLanguageService'; +import * as tss from 'typescript/lib/tsserverlibrary.js'; +import type { Tree } from '@angular-devkit/schematics.js'; +import type { MemberChange } from './schema.ts'; +import { escapeRegExp } from './util.ts'; +import { Logger } from './tsLogger.ts'; +import { TSLanguageService } from './tsPlugin/TSLanguageService.ts'; export const IG_PACKAGE_NAME = 'igniteui-angular'; export const NG_LANG_SERVICE_PACKAGE_NAME = '@angular/language-service'; export const NG_CORE_PACKAGE_NAME = '@angular/core'; -export const CUSTOM_TS_PLUGIN_PATH = './tsPlugin'; +export const CUSTOM_TS_PLUGIN_PATH = './tsPlugin.ts'; export const CUSTOM_TS_PLUGIN_NAME = 'igx-ts-plugin'; -enum SyntaxTokens { - ClosingParenthesis = ')', - MemberAccess = '.', - Question = '?' -} +export const SyntaxTokens = { + ClosingParenthesis: ')', + MemberAccess: '.', + Question: '?' +} as const; +export type SyntaxTokens = typeof SyntaxTokens[keyof typeof SyntaxTokens]; export class MemberInfo implements Pick { public name: string; @@ -101,7 +102,7 @@ export const getRenamePositions = (sourcePath: string, name: string, service: ts const positions = []; // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const imports = source.statements.filter(<(a: ts.Statement) => a is ts.ImportDeclaration>namedImportFilter); + const imports = source.statements.filter(namedImportFilter) as ts.ImportDeclaration[]; if (!imports.length) { return positions; } diff --git a/projects/igniteui-angular/migrations/common/util.ts b/projects/igniteui-angular/migrations/common/util.ts index 9b65508f879..b8ddafec194 100644 --- a/projects/igniteui-angular/migrations/common/util.ts +++ b/projects/igniteui-angular/migrations/common/util.ts @@ -159,12 +159,22 @@ export interface SourceOffset { export class FileChange { + public position: number; + public text: string; + public replaceText = ''; + public type: 'insert' | 'replace' = 'insert'; + constructor( - public position = 0, - public text = '', - public replaceText = '', - public type: 'insert' | 'replace' = 'insert' - ) { } + position = 0, + text = '', + replaceText = '', + type: 'insert' | 'replace' = 'insert' + ) { + this.position = position; + this.text = text; + this.replaceText = replaceText; + this.type = type; + } public apply(content: string) { if (this.type === 'insert') { @@ -250,7 +260,10 @@ class SerializerVisitor implements Visitor { /** * */ - constructor(private getHtmlTagDefinition: (tagName: string) => HtmlTagDefinition) { } + private getHtmlTagDefinition: (tagName: string) => HtmlTagDefinition; + constructor(getHtmlTagDefinition: (tagName: string) => HtmlTagDefinition) { + this.getHtmlTagDefinition = getHtmlTagDefinition; + } public visitElement(element: Element, _context: any): any { if (this.getHtmlTagDefinition(element.name).isVoid) {