@@ -140,11 +140,22 @@ export function validateWorkspace(json: JsonObject) {
140140 return true ;
141141}
142142
143+ function getProjectByCwd ( workspace : experimental . workspace . Workspace ) : string | null {
144+ try {
145+ return workspace . getProjectByPath ( normalize ( process . cwd ( ) ) ) ;
146+ } catch ( e ) {
147+ if ( e instanceof experimental . workspace . AmbiguousProjectPathException ) {
148+ return workspace . getDefaultProjectName ( ) ;
149+ }
150+ throw e ;
151+ }
152+ }
153+
143154export function getPackageManager ( ) : string {
144155 let workspace = getWorkspace ( 'local' ) ;
145156
146157 if ( workspace ) {
147- const project = workspace . getProjectByPath ( normalize ( process . cwd ( ) ) ) ;
158+ const project = getProjectByCwd ( workspace ) ;
148159 if ( project && workspace . getProjectCli ( project ) ) {
149160 const value = workspace . getProjectCli ( project ) [ 'packageManager' ] ;
150161 if ( typeof value == 'string' ) {
@@ -258,7 +269,7 @@ export function getDefaultSchematicCollection(): string {
258269 let workspace = getWorkspace ( 'local' ) ;
259270
260271 if ( workspace ) {
261- const project = workspace . getProjectByPath ( normalize ( process . cwd ( ) ) ) ;
272+ const project = getProjectByCwd ( workspace ) ;
262273 if ( project && workspace . getProjectCli ( project ) ) {
263274 const value = workspace . getProjectCli ( project ) [ 'defaultCollection' ] ;
264275 if ( typeof value == 'string' ) {
@@ -319,7 +330,7 @@ export function getSchematicDefaults(
319330 }
320331 }
321332
322- project = project || workspace . getProjectByPath ( normalize ( process . cwd ( ) ) ) ;
333+ project = project || getProjectByCwd ( workspace ) ;
323334 if ( project && workspace . getProjectSchematics ( project ) ) {
324335 const schematicObject = workspace . getProjectSchematics ( project ) [ fullName ] ;
325336 if ( schematicObject ) {
@@ -339,7 +350,7 @@ export function isWarningEnabled(warning: string): boolean {
339350 let workspace = getWorkspace ( 'local' ) ;
340351
341352 if ( workspace ) {
342- const project = workspace . getProjectByPath ( normalize ( process . cwd ( ) ) ) ;
353+ const project = getProjectByCwd ( workspace ) ;
343354 if ( project && workspace . getProjectCli ( project ) ) {
344355 const warnings = workspace . getProjectCli ( project ) [ 'warnings' ] ;
345356 if ( typeof warnings == 'object' && ! Array . isArray ( warnings ) ) {
0 commit comments