@@ -3,7 +3,7 @@ import * as path from 'path';
33import * as ts from 'typescript' ;
44import * as tss from 'typescript/lib/tsserverlibrary' ;
55import { SchematicContext , Tree , FileVisitor } from '@angular-devkit/schematics' ;
6- import { WorkspaceSchema , WorkspaceProject , ProjectType } from '@schematics/angular/utility/workspace-models' ;
6+ import type { WorkspaceSchema } from '@schematics/angular/utility/workspace-models' ;
77import {
88 ClassChanges , BindingChanges , SelectorChange ,
99 SelectorChanges , ThemeChanges , ImportsChanges , MemberChanges , ThemeChange , ThemeType
@@ -59,17 +59,13 @@ export class UpdateChanges {
5959 // Force Angular service to compile project on initial load w/ configure project
6060 // otherwise if the first compilation occurs on an HTML file the project won't have proper refs
6161 // and no actual angular metadata will be resolved for the rest of the migration
62- const wsProject = this . resolveWorkspaceProject ( ) ;
63- if ( ! wsProject ) {
62+
63+ // TODO: this patter/issue might be obsolete; if so, should be safe to return _projectService directly
64+ const mainRelPath = this . getWorkspaceProjectEntryPath ( ) ;
65+ if ( ! mainRelPath ) {
6466 return null ;
6567 }
66- const mainConfigPath = wsProject . architect ?. build ?. options [ 'main' ] ;
67- let mainRelPath = `src/main.ts` ;
68- if ( mainConfigPath ) {
69- mainRelPath = mainConfigPath . startsWith ( wsProject . root ) ?
70- mainConfigPath :
71- path . join ( wsProject . root , mainConfigPath ) ;
72- }
68+
7369 // patch TSConfig so it includes angularOptions.strictTemplates
7470 // ivy ls requires this in order to function properly on templates
7571 this . patchTsConfig ( ) ;
@@ -82,7 +78,9 @@ export class UpdateChanges {
8278 const project = this . _projectService . findProject ( scriptInfo . containingProjects [ 0 ] . projectName ) ;
8379 project . getLanguageService ( ) . getSemanticDiagnostics ( mainAbsPath ) ;
8480 } catch ( err ) {
85- return this . _projectService ;
81+ this . context . logger . warn (
82+ "An error occurred during TypeScript project service setup. Some migrations relying on language services might not be applied."
83+ ) ;
8684 }
8785 }
8886
@@ -837,22 +835,26 @@ export class UpdateChanges {
837835 return project ;
838836 }
839837
840- private resolveWorkspaceProject ( ) : WorkspaceProject < ProjectType > | null {
841- let wsProject = this . workspace . projects [ 0 ] ;
842- if ( ! wsProject ) {
843- const projectKeys = Object . keys ( this . workspace . projects ) ;
844- if ( ! projectKeys . length ) {
845- this . context
846- . logger
847- . info (
838+ private getWorkspaceProjectEntryPath ( ) : string | null {
839+ const projectKeys = Object . keys ( this . workspace . projects ) ;
840+ if ( ! projectKeys . length ) {
841+ this . context . logger . info (
848842`Could not resolve project from directory ${ this . serverHost . getCurrentDirectory ( ) } . Some migrations may not be applied.` ) ;
849- return null ;
843+ return null ;
844+ }
845+
846+ // grab the first possible main path:
847+ for ( const key of projectKeys ) {
848+ const wsProject = this . workspace . projects [ key ] ;
849+ // intentionally compare against string values of the enum to avoid hard import
850+ if ( wsProject . projectType == "application" && wsProject . architect ?. build ?. options [ 'main' ] ) {
851+ return wsProject . architect . build . options [ 'main' ] ;
852+ } else if ( wsProject . projectType == "library" ) {
853+ // TODO: attempt to resolve from project ng-package.json or tsConfig
850854 }
851- // get the first configured project in the workspace
852- wsProject = this . workspace . projects [ projectKeys [ 0 ] ] ;
853855 }
854856
855- return wsProject ;
857+ return null ;
856858 }
857859}
858860
0 commit comments