Skip to content
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

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

f-f
Copy link
Member

@f-f f-f commented Mar 15, 2024

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)

Comment on lines +103 to +123
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;
}
}
Copy link
Contributor

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.

Copy link
Member Author

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)

@f-f f-f merged commit 9e83d87 into master Mar 15, 2024
3 checks passed
@f-f f-f deleted the camel-case-config branch March 15, 2024 20:22
m15a added a commit to m15a/purescript-choku that referenced this pull request May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixed case configuration for publish location
2 participants