MCPcopy Index your code
hub / github.com/jetify-com/devbox / packagesField

Method packagesField

internal/devconfig/configfile/ast.go:67–98  ·  view source on GitHub ↗

packagesField gets the "packages" field, initializing it if necessary. The member value will either be an array of strings or an object. When it's an object, the keys will always be package names and the values will be a string or another object. Examples are: - {"packages": ["go", "hello"]} - {"pa

(migrate bool)

Source from the content-addressed store, hash-verified

65// "hello": ""
66// }
67func (c *configAST) packagesField(migrate bool) *hujson.ObjectMember {
68 rootObject := c.root.Value.(*hujson.Object)
69 i := c.memberIndex(rootObject, "packages")
70 if i != -1 {
71 switch rootObject.Members[i].Value.Value.Kind() {
72 case '[':
73 if migrate {
74 c.migratePackagesArray(&rootObject.Members[i].Value)
75 c.root.Format()
76 }
77 case 'n':
78 // Initialize a null packages field to an empty object.
79 rootObject.Members[i].Value.Value = &hujson.Object{
80 AfterExtra: []byte{'\n'},
81 }
82 c.root.Format()
83 }
84 return &rootObject.Members[i]
85 }
86
87 // Add a packages field to the root config object and initialize it with
88 // an empty object.
89 rootObject.Members = append(rootObject.Members, hujson.ObjectMember{
90 Name: hujson.Value{
91 Value: hujson.String("packages"),
92 BeforeExtra: []byte{'\n'},
93 },
94 Value: hujson.Value{Value: &hujson.Object{}},
95 })
96 c.root.Format()
97 return &rootObject.Members[len(rootObject.Members)-1]
98}
99
100// appendPackage appends a package to the packages field.
101func (c *configAST) appendPackage(name, version string) {

Callers 4

appendPackageMethod · 0.95
removePackageMethod · 0.95
removePatchMethod · 0.95
findPkgObjectMethod · 0.95

Calls 4

memberIndexMethod · 0.95
migratePackagesArrayMethod · 0.95
FormatMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected