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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/@apphosting/adapter-angular/src/bin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
checkBuildConditions,
validateOutputDirectory,
parseOutputBundleOptions,
outputBundleExists,
} from "../utils.js";
import { getBuildOptions, runBuild } from "@apphosting/common";

Expand All @@ -21,8 +22,10 @@ const { stdout: output } = await runBuild();
if (!output) {
throw new Error("No output from Angular build command, expecting a build manifest file.");
}
const outputBundleOptions = parseOutputBundleOptions(output);
const root = process.cwd();
await generateBuildOutput(root, outputBundleOptions, process.env.FRAMEWORK_VERSION);
if (!outputBundleExists()) {
const outputBundleOptions = parseOutputBundleOptions(output);
const root = process.cwd();
await generateBuildOutput(root, outputBundleOptions, process.env.FRAMEWORK_VERSION);

await validateOutputDirectory(outputBundleOptions);
await validateOutputDirectory(outputBundleOptions);
}
21 changes: 16 additions & 5 deletions packages/@apphosting/adapter-angular/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const SIMPLE_SERVER_FILE_PATH = join(__dirname, "simple-server", "bundled_server.mjs");

export const REQUIRED_BUILDER = "@angular-devkit/build-angular:application";
export const ALLOWED_BUILDERS = [
"@angular-devkit/build-angular:application",
"@analogjs/platform:vite",
];

/**
* Check if the following build conditions are satisfied for the workspace:
Expand All @@ -38,9 +41,9 @@ export async function checkBuildConditions(opts: BuildOptions): Promise<void> {
const output = execSync(`npx nx show project ${opts.projectName}`);
const projectJson = JSON.parse(output.toString());
const builder = projectJson.targets.build.executor;
if (builder !== REQUIRED_BUILDER) {
if (!ALLOWED_BUILDERS.includes(builder)) {
throw new Error(
"Only the Angular application builder is supported. Please refer to https://angular.dev/tools/cli/build-system-migration#for-existing-applications guide to upgrade your builder to the Angular application builder. ",
`Currently, only the following builders are supported: ${ALLOWED_BUILDERS.join(",")}.`,
);
}
return;
Expand Down Expand Up @@ -75,9 +78,9 @@ export async function checkBuildConditions(opts: BuildOptions): Promise<void> {
if (!workspaceProject.targets.has(target)) throw new Error("Could not find build target.");

const { builder } = workspaceProject.targets.get(target)!;
if (builder !== REQUIRED_BUILDER) {
if (!ALLOWED_BUILDERS.includes(builder)) {
throw new Error(
"Only the Angular application builder is supported. Please refer to https://angular.dev/tools/cli/build-system-migration#for-existing-applications guide to upgrade your builder to the Angular application builder. ",
`Currently, only the following builders are supported: ${ALLOWED_BUILDERS.join(",")}.`,
);
}
}
Expand Down Expand Up @@ -226,3 +229,11 @@ export const isMain = (meta: ImportMeta) => {
if (!process.argv[1]) return false;
return process.argv[1] === fileURLToPath(meta.url);
};

export const outputBundleExists = () => {
const outputBundleDir = resolve(".apphosting");
if (existsSync(outputBundleDir)) {
return true;
}
return false;
};
Loading