-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch config to camelCase and support automatic migrations #1202
Conversation
export function migrateV1ConfigImpl(doc) { | ||
// see here for more info about the visitor: https://eemeli.org/yaml/#finding-and-modifying-nodes | ||
let hasChanged = false; | ||
Yaml.visit(doc, { | ||
Pair(_idx, pair, _path) { | ||
// A previous version of the config used underscores in the config keys, | ||
// but we standardised on camelCase instead. | ||
// So here we crawl through the keys of each YamlMap and convert all the keys | ||
// to camelCase. | ||
if (pair.key && Yaml.isScalar(pair.key)) { | ||
pair.key.value = pair.key.value.replaceAll(/_./g, function (match) { | ||
hasChanged = true; | ||
return match.charAt(1).toUpperCase(); | ||
}); | ||
} | ||
} | ||
}); | ||
if (hasChanged) { | ||
return doc; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this effectively disables snake_case entirely from the config forever. Moreover, even if someone decided to add a superfluous key to the YAML file in that particular case convention, this script will force it to be camel-case, even if that's not what the user wants. I think that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if someone decided to add a superfluous key to the YAML file in that particular case convention, this script will force it to be camel-case, even if that's not what the user wants
Once we find a way to go at #1165 then I think we could effectively disallow superfluous fields, they only seem to cause confusion (see the comment I left in the Config module)
Now config uses camel case: purescript/spago#1202
This PR moves the config format to be consistently camelCase, to fix #1139
As we figured in #1154, this is a big change for the few projects out there that already use the new spago, so we needed to (a) be backwards compatible, and (b) support automatic migration of the config.
The previous attempt to support this was #1168, but that got convoluted enough that we agreed on a simpler approach - here we manipulate the YAML doc entirely on the JS side, and write it to disk if anything was changed, and the user requested it (otherwise we just warn about the config format being out of date)