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

feat: Support jsonc config files #206

Merged
merged 10 commits into from
Dec 1, 2023
Merged

feat: Support jsonc config files #206

merged 10 commits into from
Dec 1, 2023

Conversation

arnauorriols
Copy link
Member

@arnauorriols arnauorriols commented Nov 28, 2023

Resolves #198

deps.ts Show resolved Hide resolved
src/config_file.ts Outdated Show resolved Hide resolved
src/config_file.ts Outdated Show resolved Hide resolved
src/config_file.ts Outdated Show resolved Hide resolved
@arnauorriols
Copy link
Member Author

@magurotuna I've addressed your comments, PTAL.

src/config_file.ts Outdated Show resolved Hide resolved
Comment on lines 84 to 105
diff(args: ConfigArgs): Change[] {
const changes = [];
const otherConfigOutput =
JSON.parse(ConfigFile.create(this.path(), args).toFileContent()).deploy ??
{};
const thisConfigOutput = JSON.parse(this.toFileContent()).deploy ?? {};
// Iterate over the other args as they might include args not yet persisted in the config file
for (const [key, otherValue] of Object.entries(otherConfigArgs)) {
// deno-lint-ignore no-explicit-any
const thisValue = (this.args() as any)[key];
if (otherValue instanceof Array) {
const thisArrayValue = thisValue as typeof otherValue;
if (thisArrayValue.length !== otherValue.length) {
return false;
} else if (!thisArrayValue.every((x, i) => otherValue[i] === x)) {
return false;
for (const [key, otherValue] of Object.entries(otherConfigOutput)) {
const thisValue = thisConfigOutput[key];
if (otherValue instanceof Array && thisValue instanceof Array) {
if (
thisValue.length !== otherValue.length ||
!thisValue.every((x, i) => otherValue[i] === x)
) {
changes.push({ key, removal: thisValue, addition: otherValue });
}
} else if (thisValue !== otherValue) {
return false;
changes.push({ key, removal: thisValue, addition: otherValue });
}
}
return true;
return changes;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of diff function now supports array and primitive types, but iterating over Object.entries might be conveying that this logic is generic enough to cover all the types (including objects), which makes me a little bit confused.
As far as I understand there is no case in reality where otherConfigOutput has unknown keys other than ones defined in ConfigArgs because of what normalize method does, but I'm just wondering if there's a good way to avoid confusion.
(I'll approve it as-is anyway :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like using Object.entries as I prefer the possible false-negatives resulting from it over the false-positives that we would risk if we explicitly checked each property. The reason being that false-negatives are more visible hence easier to detect.

tests/config_file_test/config_file_test.ts Show resolved Hide resolved
Copy link
Member

@magurotuna magurotuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM👍

@arnauorriols arnauorriols merged commit 103fda2 into main Dec 1, 2023
14 checks passed
@arnauorriols arnauorriols deleted the support-jsonc branch December 1, 2023 12:44
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.

support deno.jsonc
2 participants