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

Use KeyedCollection instead of Dictionary #130

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

xt0rted
Copy link
Owner

@xt0rted xt0rted commented Dec 4, 2022

When wildcard matching was added it became important for the order of script execution to match the order they're in the config file. This change should make sure that's the case. It also removes the case insensitive matching we were doing since it's been kind of buggy and NPM doesn't do it so people are already used to that behavior.

Closes #92

@xt0rted xt0rted added the enhancement New feature or request label Dec 4, 2022
@xt0rted xt0rted force-pushed the script-loading branch 5 times, most recently from f5ce0bb to b8d1128 Compare December 4, 2022 21:44
Copy link

@aarondandy aarondandy left a comment

Choose a reason for hiding this comment

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

Just some thoughts.

using RunScript.Serialization;

[JsonConverter(typeof(ScriptCollectionConverter))]
public class ScriptCollection : KeyedCollection<string, ScriptMapping>
Copy link

@aarondandy aarondandy Dec 5, 2022

Choose a reason for hiding this comment

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

I wonder if it might be worth setting the key comparer with the base constructor if you need OrdinalIgnoreCase or Invariant?

{
foreach (var script in jsonScripts)
{
scripts.Add(script.Name, script.Value.ToString());

Choose a reason for hiding this comment

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

Maybe it's possible for a null value to end up in script.Value when deserializing.

string[] scripts)
{
var results = new List<ScriptResult>();

foreach (var script in scripts)
{
// The `env` script is special so if it's not explicitly declared we act like it was
if (projectScripts.ContainsKey(script) || string.Equals(script, "env", StringComparison.OrdinalIgnoreCase))
if (projectScripts.Contains(script) || string.Equals(script, "env", StringComparison.Ordinal))

Choose a reason for hiding this comment

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

If you expose the key comparer of projectScripts, you can use that same comparer to compare script with "env" as a way to ensure that you use the same behavior in both places. If env is special and must always be a special ordinal comparison, I think it should be a dedicated (static) method with a descriptive name and maybe a description regarding why it exists. Similar code is found in CommandGroupRunner too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update scripts object from Dictionary<string, string> to KeyedCollection<string, string>
2 participants