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)
| 65 | // "hello": "" |
| 66 | // } |
| 67 | func (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. |
| 101 | func (c *configAST) appendPackage(name, version string) { |
no test coverage detected