Skip to content

Use KeyedCollection instead of Dictionary#130

Draft
xt0rted wants to merge 3 commits intomainfrom
script-loading
Draft

Use KeyedCollection instead of Dictionary#130
xt0rted wants to merge 3 commits intomainfrom
script-loading

Conversation

@xt0rted
Copy link
Copy Markdown
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
Copy Markdown

@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.

Comment thread src/ScriptCollection.cs
using RunScript.Serialization;

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

@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());
Copy link
Copy Markdown

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.

Comment thread src/RunScriptCommand.cs Outdated
{
// 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))
Copy link
Copy Markdown

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