Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
- Improved detection of 'dataconnect.yaml' when not in project root.
- GitHub Action fixes for web frameworks (#6883)
- Fixes issue where PubSub message `publishTime` is set to 1970-01-01T00:00:00 (#7441)
- Display meaningful error message when cannot determine target. (#6594)
31 changes: 25 additions & 6 deletions src/frameworks/angular/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JsonObject } from "@angular-devkit/core";
import type { Target } from "@angular-devkit/architect";
import type { ProjectDefinition } from "@angular-devkit/core/src/workspace";
import type { WorkspaceNodeModulesArchitectHost } from "@angular-devkit/architect/node";
Expand Down Expand Up @@ -177,10 +178,9 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
if (apps.length === 1) project = apps[0];
}

if (!project)
throw new FirebaseError(
"Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable",
);
if (!project) {
throwCannotDetermineTarget();
}

const workspaceProject = workspace.projects.get(project);
if (!workspaceProject) throw new FirebaseError(`No project ${project} found.`);
Expand Down Expand Up @@ -378,7 +378,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
if (!buildOrBrowserTarget) {
throw new FirebaseError(`No build target on ${project}`);
}
const browserTargetOptions = await architectHost.getOptionsForTarget(buildOrBrowserTarget);

const browserTargetOptions = await tryToGetOptionsForTarget(architectHost, buildOrBrowserTarget);
if (!browserTargetOptions) {
const targetString = targetStringFromTarget(buildOrBrowserTarget);
throw new FirebaseError(`Couldn't find options for ${targetString}.`);
Expand All @@ -387,7 +388,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
const baseHref = browserTargetOptions.baseHref || "/";
assertIsString(baseHref);

const buildTargetOptions = buildTarget && (await architectHost.getOptionsForTarget(buildTarget));
const buildTargetOptions =
buildTarget && (await tryToGetOptionsForTarget(architectHost, buildTarget));
const ssr = buildTarget ? !!buildTargetOptions?.ssr : !!serverTarget;

return {
Expand Down Expand Up @@ -561,3 +563,20 @@ export function getAngularVersion(cwd: string): string | undefined {

return angularVersionSemver.toString();
}

/**
* Try to get options for target, throw an error when expected target doesn't exist in the configuration.
*/
export async function tryToGetOptionsForTarget(
architectHost: WorkspaceNodeModulesArchitectHost,
target: Target,
): Promise<JsonObject | null> {
return await architectHost.getOptionsForTarget(target).catch(throwCannotDetermineTarget);
}

function throwCannotDetermineTarget(error?: Error): never {
throw new FirebaseError(
`Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable.`,
{ original: error },
);
}