Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
19 changes: 16 additions & 3 deletions packages/@apphosting/adapter-angular/src/bin/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ describe("build commands", () => {
});

it("expects all output bundle files to be generated", async () => {
const { generateOutputDirectory, validateOutputDirectory } = await importUtils;
const { generateOutputDirectory, validateOutputDirectory, populateMetadata } =
await importUtils;
const files = {
"dist/test/browser/browserfile": "",
"dist/test/server/server.mjs": "",
};
const metadata = populateMetadata("17.3.8");
generateTestFiles(tmpDir, files);
await generateOutputDirectory(tmpDir, outputBundleOptions);
await generateOutputDirectory(tmpDir, outputBundleOptions, "17.3.8");
await validateOutputDirectory(outputBundleOptions);

const expectedFiles = {
Expand All @@ -42,17 +44,23 @@ neededDirs:
staticAssets:
- .apphosting/dist/browser
env: []
metadata:
adapterNpmPackageName: ${metadata.adapterNpmPackageName}
adapterVersion: ${metadata.adapterVersion}
framework: ${metadata.framework}
frameworkVersion: ${metadata.frameworkVersion}
`,
};
validateTestFiles(tmpDir, expectedFiles);
});

it("expects SSR_PORT variable is added to bundle.yaml for Angular v17.3.2", async () => {
const { generateOutputDirectory } = await importUtils;
const { generateOutputDirectory, populateMetadata } = await importUtils;
const files = {
"dist/test/browser/browserfile": "",
"dist/test/server/server.mjs": "",
};
const metadata = populateMetadata("17.3.2");
generateTestFiles(tmpDir, files);
await generateOutputDirectory(tmpDir, outputBundleOptions, "17.3.2");

Expand All @@ -69,6 +77,11 @@ env:
- variable: SSR_PORT
value: "8080"
availability: RUNTIME
metadata:
adapterNpmPackageName: ${metadata.adapterNpmPackageName}
adapterVersion: ${metadata.adapterVersion}
framework: ${metadata.framework}
frameworkVersion: ${metadata.frameworkVersion}
`,
};
validateTestFiles(tmpDir, expectedFiles);
Expand Down
8 changes: 8 additions & 0 deletions packages/@apphosting/adapter-angular/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export enum Availability {
RUNTIME = "RUNTIME",
}

// Metadata schema for bundle.yaml outputted by angular adapter
export interface Metadata {
adapterNpmPackageName: string;
adapterVersion: string;
framework: string;
frameworkVersion?: string;
}

// valid manifest schema
export interface ValidManifest {
errors: string[];
Expand Down
15 changes: 14 additions & 1 deletion packages/@apphosting/adapter-angular/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
Availability,
EnvironmentVariable,
Metadata,
OutputBundleOptions,
OutputPaths,
buildManifestSchema,
Expand All @@ -17,7 +18,7 @@
import { BuildOptions } from "@apphosting/common";

// fs-extra is CJS, readJson can't be imported using shorthand
export const { writeFile, move, readJson, mkdir, copyFile } = fsExtra;
export const { writeFile, move, readJson, mkdir, copyFile, readFileSync } = fsExtra;

const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -142,6 +143,16 @@
return stripAnsi(output.substring(start, end + 1));
}

export function populateMetadata(angularVersion?: string): Metadata {
const packageJson = JSON.parse(readFileSync(`${__dirname}/../package.json`, "utf-8"));
return {
adapterNpmPackageName: packageJson.name.replace(/@/g, "\\$1"),
adapterVersion: packageJson.version,
framework: "angular",
frameworkVersion: angularVersion ? angularVersion : "",
};
}

/**
* Move the base output directory, which contains the server and browser bundle directory, and prerendered routes
* as well as generating bundle.yaml.
Expand Down Expand Up @@ -182,13 +193,15 @@
angularVersion?: string,
): Promise<void> {
const runtimeEnvVars = addBundleYamlEnvVar(angularVersion);
const metadata = populateMetadata(angularVersion);
await writeFile(
outputBundleOptions.bundleYamlPath,
yamlStringify({
runCommand: `node ${normalize(relative(cwd, outputBundleOptions.serverFilePath))}`,
neededDirs: [normalize(relative(cwd, outputBundleOptions.outputDirectory))],
staticAssets: [normalize(relative(cwd, outputBundleOptions.browserDirectory))],
env: runtimeEnvVars,
metadata: metadata,
}),
);
}
Expand Down
Loading