MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / OverrideAppHostingBuildScript

Function OverrideAppHostingBuildScript

pkg/nodejs/nodejs.go:556–588  ·  view source on GitHub ↗

OverrideAppHostingBuildScript overrides the "apphosting:build" script in package.json with the build command from the preprocessed apphosting.yaml.

(ctx *gcp.Context, preprocessedApphostingPath string)

Source from the content-addressed store, hash-verified

554// OverrideAppHostingBuildScript overrides the "apphosting:build" script in package.json
555// with the build command from the preprocessed apphosting.yaml.
556func OverrideAppHostingBuildScript(ctx *gcp.Context, preprocessedApphostingPath string) (*PackageJSON, error) {
557 pjs, err := ReadPackageJSONIfExists(ctx.ApplicationRoot())
558 if err != nil {
559 return nil, err
560 }
561 apphostingSchema, err := apphostingschema.ReadAndValidateFromFile(preprocessedApphostingPath)
562 if err != nil {
563 return nil, err
564 }
565 if apphostingSchema.Scripts.BuildCommand == "" {
566 return pjs, nil
567 }
568 if pjs == nil {
569 pjs = &PackageJSON{}
570 }
571
572 if pjs.Scripts == nil {
573 pjs.Scripts = make(map[string]string)
574 }
575
576 pjs.Scripts[ScriptApphostingBuild] = apphostingSchema.Scripts.BuildCommand
577 marshalledJSON, err := json.Marshal(pjs)
578 if err != nil {
579 return nil, gcp.InternalErrorf("marshaling package.json: %w", err)
580 }
581
582 err = os.WriteFile(filepath.Join(ctx.ApplicationRoot(), "package.json"), marshalledJSON, 0644)
583 if err != nil {
584 return nil, gcp.InternalErrorf("writing package.json: %w", err)
585 }
586
587 return pjs, nil
588}
589
590// IsPackageManagerConfigured checks if the environment is configured to use the specified package manager.
591func IsPackageManagerConfigured(pm string) bool {

Callers 5

BuildFnFunction · 0.92
yarn1InstallModulesFunction · 0.92
pnpmInstallModulesFunction · 0.92
bunInstallModulesFunction · 0.92

Calls 4

ReadAndValidateFromFileFunction · 0.92
ReadPackageJSONIfExistsFunction · 0.85
ApplicationRootMethod · 0.80
WriteFileMethod · 0.80

Tested by 1