@@ -7,17 +7,20 @@ import { resolve, normalize, relative, dirname, join } from "path";
77import { stringify as yamlStringify } from "yaml" ;
88import { OutputBundleOptions , OutputPaths , buildManifestSchema } from "./interface.js" ;
99import { createRequire } from "node:module" ;
10+ import { parse as parseYaml } from "yaml" ;
1011import stripAnsi from "strip-ansi" ;
1112import {
1213 BuildOptions ,
1314 OutputBundleConfig ,
1415 EnvVarConfig ,
1516 Metadata ,
1617 Availability ,
18+ updateOrCreateGitignore ,
1719} from "@apphosting/common" ;
1820
1921// fs-extra is CJS, readJson can't be imported using shorthand
20- export const { writeFile, move, readJson, mkdir, copyFile, readFileSync, existsSync } = fsExtra ;
22+ export const { writeFile, move, readJson, mkdir, copyFile, readFileSync, existsSync, ensureDir } =
23+ fsExtra ;
2124
2225const require = createRequire ( import . meta. url ) ;
2326const __filename = fileURLToPath ( import . meta. url ) ;
@@ -135,6 +138,7 @@ export function populateOutputBundleOptions(outputPaths: OutputPaths): OutputBun
135138 }
136139 return {
137140 bundleYamlPath : resolve ( outputBundleDir , "bundle.yaml" ) ,
141+ outputDirectoryBasePath : outputBundleDir ,
138142 serverFilePath : resolve ( baseDirectory , serverRelativePath , "server.mjs" ) ,
139143 browserDirectory : resolve ( baseDirectory , browserRelativePath ) ,
140144 needsServerGenerated,
@@ -210,6 +214,10 @@ export async function generateBuildOutput(
210214 await generateServer ( outputBundleOptions ) ;
211215 }
212216 await generateBundleYaml ( outputBundleOptions , cwd , angularVersion ) ;
217+ // generateBundleYaml creates the output directory (if it does not already exist).
218+ // We need to make sure it is gitignored.
219+ const normalizedBundleDir = normalize ( relative ( cwd , outputBundleOptions . outputDirectoryBasePath ) ) ;
220+ updateOrCreateGitignore ( cwd , [ `/${ normalizedBundleDir } /` ] ) ;
213221}
214222
215223// add environment variable to bundle.yaml if needed for specific versions
@@ -233,7 +241,7 @@ async function generateBundleYaml(
233241 cwd : string ,
234242 angularVersion : string ,
235243) : Promise < void > {
236- await mkdir ( dirname ( opts . bundleYamlPath ) ) ;
244+ await ensureDir ( dirname ( opts . bundleYamlPath ) ) ;
237245 const outputBundle : OutputBundleConfig = {
238246 version : "v1" ,
239247 runConfig : {
@@ -270,10 +278,18 @@ export const isMain = (meta: ImportMeta) => {
270278 return process . argv [ 1 ] === fileURLToPath ( meta . url ) ;
271279} ;
272280
273- export const outputBundleExists = ( ) => {
281+ export const metaFrameworkOutputBundleExists = ( ) => {
274282 const outputBundleDir = resolve ( ".apphosting" ) ;
275- if ( existsSync ( outputBundleDir ) ) {
276- return true ;
283+ const bundleYamlPath = join ( outputBundleDir , "bundle.yaml" ) ;
284+ if ( existsSync ( bundleYamlPath ) ) {
285+ try {
286+ const bundle = parseYaml ( readFileSync ( bundleYamlPath , "utf8" ) ) ;
287+ if ( bundle ?. metadata ?. framework && bundle . metadata . framework !== "angular" ) {
288+ return true ;
289+ }
290+ } catch ( e ) {
291+ logger . debug ( "Failed to parse bundle.yaml, assuming it can be overwritten" , e ) ;
292+ }
277293 }
278294 return false ;
279295} ;
0 commit comments