in cmd/nodejs/firebaseangular/main.go [86:135]
func buildFn(ctx *gcp.Context) error {
appDir := util.ApplicationDirectory(ctx)
nodeDeps, err := nodejs.ReadNodeDependencies(ctx, appDir)
if err != nil {
return err
}
if nodeDeps.LockfilePath == "" {
return gcp.UserErrorf("%w", faherror.MissingLockFileError(appDir))
}
// Ensure that the right version of the application builder is installed.
builderVersion, err := nodejs.Version(nodeDeps, "@angular-devkit/build-angular")
if err != nil {
ctx.Warnf("Error parsing version from lock file, defaulting to package.json version")
builderVersion = nodeDeps.PackageJSON.DevDependencies["@angular-devkit/build-angular"]
}
err = validateVersion(ctx, builderVersion)
if err != nil {
return err
}
// TODO(b/357644160) We should consider adding a validation step to double check that the adapter version works for the framework version.
if version, exists := nodeDeps.PackageJSON.Dependencies["@apphosting/adapter-angular"]; exists {
ctx.Logf("*** You already have @apphosting/adapter-angular@%s listed as a dependency, skipping installation ***", version)
ctx.Logf("*** Your package.json build command will be run as is, please make sure it is set to apphosting-adapter-angular-build if you intend to build your app using the adapter ***")
return nil
}
buildScript, exists := nodeDeps.PackageJSON.Scripts["build"]
if exists && buildScript != "ng build" && buildScript != "apphosting-adapter-angular-build" {
ctx.Warnf("*** You are using a custom build command (your build command is NOT 'ng build'), we will accept it as is but will error if output structure is not as expected ***")
}
al, err := ctx.Layer("npm_modules", gcp.BuildLayer, gcp.CacheLayer)
if err != nil {
return err
}
if err = nodejs.InstallAngularBuildAdaptor(ctx, al, builderVersion); err != nil {
return err
}
// pass angular version as environment variable that will configure the build for version matching
al.BuildEnvironment.Override(frameworkVersion, builderVersion)
// This env var indicates to the package manager buildpack that a different command needs to be run
nodejs.OverrideAngularBuildScript(al)
return nil
}