@@ -7,17 +7,20 @@ import { resolve, normalize, relative, dirname, join } from "path";
7
7
import { stringify as yamlStringify } from "yaml" ;
8
8
import { OutputBundleOptions , OutputPaths , buildManifestSchema } from "./interface.js" ;
9
9
import { createRequire } from "node:module" ;
10
+ import { parse as parseYaml } from "yaml" ;
10
11
import stripAnsi from "strip-ansi" ;
11
12
import {
12
13
BuildOptions ,
13
14
OutputBundleConfig ,
14
15
EnvVarConfig ,
15
16
Metadata ,
16
17
Availability ,
18
+ updateOrCreateGitignore ,
17
19
} from "@apphosting/common" ;
18
20
19
21
// 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 ;
21
24
22
25
const require = createRequire ( import . meta. url ) ;
23
26
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -135,6 +138,7 @@ export function populateOutputBundleOptions(outputPaths: OutputPaths): OutputBun
135
138
}
136
139
return {
137
140
bundleYamlPath : resolve ( outputBundleDir , "bundle.yaml" ) ,
141
+ outputDirectoryBasePath : outputBundleDir ,
138
142
serverFilePath : resolve ( baseDirectory , serverRelativePath , "server.mjs" ) ,
139
143
browserDirectory : resolve ( baseDirectory , browserRelativePath ) ,
140
144
needsServerGenerated,
@@ -210,6 +214,10 @@ export async function generateBuildOutput(
210
214
await generateServer ( outputBundleOptions ) ;
211
215
}
212
216
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 } /` ] ) ;
213
221
}
214
222
215
223
// add environment variable to bundle.yaml if needed for specific versions
@@ -233,7 +241,7 @@ async function generateBundleYaml(
233
241
cwd : string ,
234
242
angularVersion : string ,
235
243
) : Promise < void > {
236
- await mkdir ( dirname ( opts . bundleYamlPath ) ) ;
244
+ await ensureDir ( dirname ( opts . bundleYamlPath ) ) ;
237
245
const outputBundle : OutputBundleConfig = {
238
246
version : "v1" ,
239
247
runConfig : {
@@ -270,10 +278,18 @@ export const isMain = (meta: ImportMeta) => {
270
278
return process . argv [ 1 ] === fileURLToPath ( meta . url ) ;
271
279
} ;
272
280
273
- export const outputBundleExists = ( ) => {
281
+ export const metaFrameworkOutputBundleExists = ( ) => {
274
282
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
+ }
277
293
}
278
294
return false ;
279
295
} ;
0 commit comments