-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
f5ce0bb
to
b8d1128
Compare
There was a problem hiding this 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> |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
src/RunScriptCommand.cs
Outdated
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)) |
There was a problem hiding this comment.
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.
9df2abc
to
acd8f8d
Compare
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