1
+ import type { JsonObject } from "@angular-devkit/core" ;
1
2
import type { Target } from "@angular-devkit/architect" ;
2
3
import type { ProjectDefinition } from "@angular-devkit/core/src/workspace" ;
3
4
import type { WorkspaceNodeModulesArchitectHost } from "@angular-devkit/architect/node" ;
@@ -177,10 +178,9 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
177
178
if ( apps . length === 1 ) project = apps [ 0 ] ;
178
179
}
179
180
180
- if ( ! project )
181
- throw new FirebaseError (
182
- "Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable" ,
183
- ) ;
181
+ if ( ! project ) {
182
+ throwCannotDetermineTarget ( ) ;
183
+ }
184
184
185
185
const workspaceProject = workspace . projects . get ( project ) ;
186
186
if ( ! workspaceProject ) throw new FirebaseError ( `No project ${ project } found.` ) ;
@@ -378,7 +378,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
378
378
if ( ! buildOrBrowserTarget ) {
379
379
throw new FirebaseError ( `No build target on ${ project } ` ) ;
380
380
}
381
- const browserTargetOptions = await architectHost . getOptionsForTarget ( buildOrBrowserTarget ) ;
381
+
382
+ const browserTargetOptions = await tryToGetOptionsForTarget ( architectHost , buildOrBrowserTarget ) ;
382
383
if ( ! browserTargetOptions ) {
383
384
const targetString = targetStringFromTarget ( buildOrBrowserTarget ) ;
384
385
throw new FirebaseError ( `Couldn't find options for ${ targetString } .` ) ;
@@ -387,7 +388,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
387
388
const baseHref = browserTargetOptions . baseHref || "/" ;
388
389
assertIsString ( baseHref ) ;
389
390
390
- const buildTargetOptions = buildTarget && ( await architectHost . getOptionsForTarget ( buildTarget ) ) ;
391
+ const buildTargetOptions =
392
+ buildTarget && ( await tryToGetOptionsForTarget ( architectHost , buildTarget ) ) ;
391
393
const ssr = buildTarget ? ! ! buildTargetOptions ?. ssr : ! ! serverTarget ;
392
394
393
395
return {
@@ -561,3 +563,20 @@ export function getAngularVersion(cwd: string): string | undefined {
561
563
562
564
return angularVersionSemver . toString ( ) ;
563
565
}
566
+
567
+ /**
568
+ * Try to get options for target, throw an error when expected target doesn't exist in the configuration.
569
+ */
570
+ export async function tryToGetOptionsForTarget (
571
+ architectHost : WorkspaceNodeModulesArchitectHost ,
572
+ target : Target ,
573
+ ) : Promise < JsonObject | null > {
574
+ return await architectHost . getOptionsForTarget ( target ) . catch ( throwCannotDetermineTarget ) ;
575
+ }
576
+
577
+ function throwCannotDetermineTarget ( error ?: Error ) : never {
578
+ throw new FirebaseError (
579
+ `Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable.` ,
580
+ { original : error } ,
581
+ ) ;
582
+ }
0 commit comments