1- import { SchematicContext , Tree , FileVisitor } from '@angular-devkit/schematics' ;
2- import { WorkspaceSchema } from '@schematics/angular/utility/workspace-models' ;
3-
41import * as fs from 'fs' ;
52import * as path from 'path' ;
3+ import * as ts from 'typescript' ;
64import * as tss from 'typescript/lib/tsserverlibrary' ;
5+ import { SchematicContext , Tree , FileVisitor } from '@angular-devkit/schematics' ;
6+ import { WorkspaceSchema } from '@schematics/angular/utility/workspace-models' ;
77import {
88 ClassChanges , BindingChanges , SelectorChange ,
99 SelectorChanges , ThemePropertyChanges , ImportsChanges , MemberChanges
1010} from './schema' ;
1111import {
1212 getLanguageService , getRenamePositions , findMatches ,
13- replaceMatch , createProjectService , isMemberIgniteUI
13+ replaceMatch , createProjectService , isMemberIgniteUI , NG_LANG_SERVICE_PACKAGE_NAME
1414} from './tsUtils' ;
15- import { getProjectPaths , getWorkspace , getProjects , escapeRegExp } from './util' ;
15+ import {
16+ getProjectPaths , getWorkspace , getProjects , escapeRegExp ,
17+ getPackageManager , canResolvePackage , tryInstallPackage , tryUninstallPackage
18+ } from './util' ;
1619import { ServerHost } from './ServerHost' ;
1720
1821export enum InputPropertyType {
@@ -82,14 +85,23 @@ export class UpdateChanges {
8285 return this . _sassFiles ;
8386 }
8487
85- private _service : tss . LanguageService ;
86- public get service ( ) : tss . LanguageService {
88+ private _service : ts . LanguageService ;
89+ public get service ( ) : ts . LanguageService {
8790 if ( ! this . _service ) {
8891 this . _service = getLanguageService ( this . tsFiles , this . host ) ;
8992 }
9093 return this . _service ;
9194 }
9295
96+ private _packageManager : 'npm' | 'yarn' ;
97+ private get packageManager ( ) : 'npm' | 'yarn' {
98+ if ( ! this . _packageManager ) {
99+ this . _packageManager = getPackageManager ( this . host ) ;
100+ }
101+
102+ return this . _packageManager ;
103+ }
104+
93105 /**
94106 * Create a new base schematic to apply changes
95107 * @param rootPath Root folder for the schematic to read configs, pass __dirname
@@ -111,16 +123,27 @@ export class UpdateChanges {
111123
112124 /** Apply configured changes to the Host Tree */
113125 public applyChanges ( ) {
126+ const shouldInstallPkg = this . membersChanges && this . membersChanges . changes . length
127+ && ! canResolvePackage ( NG_LANG_SERVICE_PACKAGE_NAME ) ;
128+ if ( shouldInstallPkg ) {
129+ this . context . logger . info ( `Installing temporary migration dependencies via ${ this . packageManager } .` ) ;
130+ tryInstallPackage ( this . context , this . packageManager , NG_LANG_SERVICE_PACKAGE_NAME ) ;
131+ }
132+
114133 this . updateTemplateFiles ( ) ;
115134 this . updateTsFiles ( ) ;
116135 this . updateMembers ( ) ;
117-
118136 /** Sass files */
119137 if ( this . themePropsChanges && this . themePropsChanges . changes . length ) {
120138 for ( const entryPath of this . sassFiles ) {
121139 this . updateThemeProps ( entryPath ) ;
122140 }
123141 }
142+
143+ if ( shouldInstallPkg ) {
144+ this . context . logger . info ( `Cleaning up temporary migration dependencies.` ) ;
145+ tryUninstallPackage ( this . context , this . packageManager , NG_LANG_SERVICE_PACKAGE_NAME ) ;
146+ }
124147 }
125148
126149 /** Add condition function. */
0 commit comments