@@ -7,7 +7,7 @@ import { stringify as yamlStringify } from "yaml";
77import { PHASE_PRODUCTION_BUILD , ROUTES_MANIFEST } from "./constants.js" ;
88import { OutputBundleOptions , RoutesManifest } from "./interfaces.js" ;
99import { NextConfigComplete } from "next/dist/server/config-shared.js" ;
10- import { OutputBundleConfig , Metadata } from "@apphosting/common" ;
10+ import { OutputBundleConfig , Metadata , AdapterMetadata } from "@apphosting/common" ;
1111
1212// fs-extra is CJS, readJson can't be imported using shorthand
1313export const { move, exists, writeFile, readJson, readdir, readFileSync, existsSync, mkdir } =
@@ -45,10 +45,10 @@ export async function loadRouteManifest(
4545export async function writeRouteManifest (
4646 standalonePath : string ,
4747 distDir : string ,
48- manifest : RoutesManifest ,
48+ customManifest : RoutesManifest ,
4949) : Promise < void > {
5050 const manifestPath = join ( standalonePath , distDir , ROUTES_MANIFEST ) ;
51- await writeFile ( manifestPath , JSON . stringify ( manifest ) ) ;
51+ await writeFile ( manifestPath , JSON . stringify ( customManifest ) ) ;
5252}
5353
5454export const isMain = ( meta : ImportMeta ) : boolean => {
@@ -98,12 +98,13 @@ export async function generateBuildOutput(
9898 opts : OutputBundleOptions ,
9999 nextBuildDirectory : string ,
100100 nextVersion : string ,
101+ adapterMetadata : AdapterMetadata ,
101102) : Promise < void > {
102103 const staticDirectory = join ( nextBuildDirectory , "static" ) ;
103104 await Promise . all ( [
104105 move ( staticDirectory , opts . outputStaticDirectoryPath , { overwrite : true } ) ,
105106 moveResources ( appDir , opts . outputDirectoryAppPath , opts . bundleYamlPath ) ,
106- generateBundleYaml ( opts , rootDir , nextVersion ) ,
107+ generateBundleYaml ( opts , rootDir , nextVersion , adapterMetadata ) ,
107108 ] ) ;
108109 return ;
109110}
@@ -128,21 +129,17 @@ async function moveResources(
128129 return ;
129130}
130131
131- /**
132- * Create metadata needed for outputting adapter and framework metrics in bundle.yaml.
133- */
134- export function createMetadata ( nextVersion : string ) : Metadata {
132+ export function getAdapterMetadata ( ) : AdapterMetadata {
135133 const directoryName = dirname ( fileURLToPath ( import . meta. url ) ) ;
136134 const packageJsonPath = `${ directoryName } /../package.json` ;
137135 if ( ! existsSync ( packageJsonPath ) ) {
138136 throw new Error ( `Next.js adapter package.json file does not exist at ${ packageJsonPath } ` ) ;
139137 }
140138 const packageJson = JSON . parse ( readFileSync ( packageJsonPath , "utf-8" ) ) ;
139+
141140 return {
142141 adapterPackageName : packageJson . name ,
143142 adapterVersion : packageJson . version ,
144- framework : "nextjs" ,
145- frameworkVersion : nextVersion ,
146143 } ;
147144}
148145
@@ -151,14 +148,19 @@ async function generateBundleYaml(
151148 opts : OutputBundleOptions ,
152149 cwd : string ,
153150 nextVersion : string ,
151+ adapterMetadata : AdapterMetadata ,
154152) : Promise < void > {
155153 await mkdir ( opts . outputDirectoryBasePath ) ;
156154 const outputBundle : OutputBundleConfig = {
157155 version : "v1" ,
158156 runConfig : {
159157 runCommand : `node ${ normalize ( relative ( cwd , opts . serverFilePath ) ) } ` ,
160158 } ,
161- metadata : createMetadata ( nextVersion ) ,
159+ metadata : {
160+ ...adapterMetadata ,
161+ framework : "nextjs" ,
162+ frameworkVersion : nextVersion ,
163+ } ,
162164 } ;
163165 await writeFile ( opts . bundleYamlPath , yamlStringify ( outputBundle ) ) ;
164166 return ;
0 commit comments