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

Reworking of the config system #340

Closed
wants to merge 1 commit into from
Closed

Reworking of the config system #340

wants to merge 1 commit into from

Conversation

RDIL
Copy link
Member

@RDIL RDIL commented Nov 5, 2023

Fixes #339

Copy link
Member

@LennardF1989 LennardF1989 left a comment

Choose a reason for hiding this comment

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

See notes.

PS. Aren't the unit tests that use configs broken now?

throw new Error(`Tried to lookup config that does not exist: ${config}`)
}

let c = configs[config]()
Copy link
Member

@LennardF1989 LennardF1989 Nov 6, 2023

Choose a reason for hiding this comment

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

So, we're fine this will modify the original object whenever clone is set to false? And if so, what will happen if a plugin gets a config that has already modified by it before*? I'm aware this is how it worked originally, but we didn't have plugins modifying the false (yet), then, only core. And we are/were very careful to make sure we clone when we do that... Seems like a can of worms.

* If intended, we should probably have a guideline how a plugin can keep track if its changes has been applied (eg. by adding a __pluginname: true to the root or something which can then be if-checked before applying.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will modify the original object even if clone is true. It's a matter of do we want to always clone (very slow for big objects like the H1 templates) or only clone when we know the consumer code is going to modify the object being returned.

Copy link
Member

Choose a reason for hiding this comment

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

I think in the end it's not really our responsibility. I do think that in the case of clone == true, we should tap the cloned object, not the source object. Since we always pass clone to the tap, it's up to the plugin to handle it gracefully.

I'm trying to think of situations where one might want to apply different logic based on clone, but can't really think of one right now. Maybe a non-issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

So I've been thinking on this, maybe we just have configs be modified by plugins when they are first (lazily) loaded? I can't think of any plugins that need to modify a config, say, after a specific server event is fired.

import * as databaseHandler from "../../components/databaseHandler"
import * as platformEntitlements from "../../components/platformEntitlements"
import * as databaseHandler from "../../components/databaseHandler.ts"
import * as platformEntitlements from "../../components/platformEntitlements.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Why do these need a .ts extension? Can't we fix that with a tsconfig.json? Haven't actually pulled yet to play with it, just wondering out loud.

Copy link
Member Author

@RDIL RDIL Nov 6, 2023

Choose a reason for hiding this comment

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

Basically had to switch the tests over to ESM because of this code right here which needs top-level await to ensure it's done the thing before the tests run, but not import the module too early, because it could cause core code to be initalized without having proper globals installed, creating a whole new can of worms.

Screenshot 2023-11-06 at 18 24 05

Copy link
Member

Choose a reason for hiding this comment

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

Might have to play with the config a bit, I've had a Vite-based project setup that outputs ESM, but while I could still code in a NodeJS style. Will glance over it again sometime later this week. Maybe there is a better way to bootstrap the whole application for testing purposes...

@RDIL RDIL changed the title #339: Reworking of the config system Reworking of the config system Nov 25, 2023
@RDIL RDIL closed this Jan 15, 2024
@RDIL RDIL deleted the Peacock-339 branch January 15, 2024 00:51
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.

Reworking of the config system
2 participants