-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip detection of workspace projects in Yarn detector (#915)
* Potential fix for very large monorepos with yarn berry * Update detector version * Rename YarnLockVersion.V2 to YarnLockVersion.Berry * Update CONTRIBUTING.md * Add functional tests --------- Co-authored-by: OWA Framework <[email protected]>
- Loading branch information
Showing
9 changed files
with
169 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ public void YarnLockParser_CanParseV1LockFiles() | |
[TestMethod] | ||
public void YarnLockParser_CanParseV2LockFiles() | ||
{ | ||
var yarnLockFileVersion = YarnLockVersion.V2; | ||
var yarnLockFileVersion = YarnLockVersion.Berry; | ||
|
||
var parser = new YarnLockParser(this.loggerMock.Object); | ||
|
||
|
@@ -80,23 +80,33 @@ public void YarnLockParser_ParsesEmptyFile() | |
} | ||
|
||
[TestMethod] | ||
public void YarnLockParser_ParsesBlocks() | ||
public void YarnLockParser_V1_ParsesBlocks() | ||
{ | ||
var yarnLockFileVersion = YarnLockVersion.V1; | ||
|
||
var parser = new YarnLockParser(this.loggerMock.Object); | ||
|
||
var blocks = new List<YarnBlock> | ||
{ | ||
this.CreateBlock("a@^1.0.0", "1.0.0", "https://a", new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2" } }), | ||
}), | ||
this.CreateBlock("[email protected]", "2.4.6", "https://b", new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2.4" }, { "a", "^1.0.0" } }), | ||
}), | ||
this.CreateBlock("xyz@2, [email protected]", "2.4.3", "https://xyz", Enumerable.Empty<YarnBlock>()), | ||
this.CreateBlock( | ||
"a@^1.0.0", | ||
"1.0.0", | ||
"https://a", | ||
new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2" } }), | ||
}, | ||
yarnLockFileVersion), | ||
this.CreateBlock( | ||
"[email protected]", | ||
"2.4.6", | ||
"https://b", | ||
new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2.4" }, { "a", "^1.0.0" } }), | ||
}, | ||
yarnLockFileVersion), | ||
this.CreateBlock("xyz@2, [email protected]", "2.4.3", "https://xyz", Enumerable.Empty<YarnBlock>(), yarnLockFileVersion), | ||
}; | ||
|
||
var blockFile = new Mock<IYarnBlockFile>(); | ||
|
@@ -105,14 +115,99 @@ public void YarnLockParser_ParsesBlocks() | |
|
||
var file = parser.Parse(this.recorderMock.Object, blockFile.Object, this.loggerMock.Object); | ||
|
||
file.LockVersion.Should().Be(YarnLockVersion.V1); | ||
file.LockVersion.Should().Be(yarnLockFileVersion); | ||
file.Entries.Should().HaveCount(3); | ||
|
||
foreach (var entry in file.Entries) | ||
{ | ||
var block = blocks.Single(x => x.Values["resolved"] == entry.Resolved); | ||
var block = blocks.Single(x => x.Values[this.GetResolvedEntryName(yarnLockFileVersion)] == entry.Resolved); | ||
|
||
this.AssertBlockMatchesEntry(block, entry); | ||
this.AssertBlockMatchesEntry(block, entry, yarnLockFileVersion); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void YarnLockParser_Berry_ParsesBlocks() | ||
{ | ||
var yarnLockFileVersion = YarnLockVersion.Berry; | ||
|
||
var parser = new YarnLockParser(this.loggerMock.Object); | ||
|
||
var blocks = new List<YarnBlock> | ||
{ | ||
this.CreateBlock( | ||
"a@^1.0.0", | ||
"1.0.0", | ||
"https://a", | ||
new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2" } }), | ||
}, | ||
yarnLockFileVersion), | ||
this.CreateBlock( | ||
"[email protected]", | ||
"2.4.6", | ||
"https://b", | ||
new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2.4" }, { "a", "^1.0.0" } }), | ||
}, | ||
yarnLockFileVersion), | ||
this.CreateBlock("xyz@2, [email protected]", "2.4.3", "https://xyz", Enumerable.Empty<YarnBlock>(), yarnLockFileVersion), | ||
}; | ||
|
||
var blockFile = new Mock<IYarnBlockFile>(); | ||
blockFile.Setup(x => x.YarnLockVersion).Returns(yarnLockFileVersion); | ||
blockFile.Setup(x => x.GetEnumerator()).Returns(blocks.GetEnumerator()); | ||
|
||
var file = parser.Parse(this.recorderMock.Object, blockFile.Object, this.loggerMock.Object); | ||
|
||
file.LockVersion.Should().Be(yarnLockFileVersion); | ||
file.Entries.Should().HaveCount(3); | ||
|
||
foreach (var entry in file.Entries) | ||
{ | ||
var block = blocks.Single(x => x.Values[this.GetResolvedEntryName(yarnLockFileVersion)] == entry.Resolved); | ||
|
||
this.AssertBlockMatchesEntry(block, entry, yarnLockFileVersion); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void YarnLockParser_Berry_SkipsWorkspaceEntries() | ||
{ | ||
var yarnLockFileVersion = YarnLockVersion.Berry; | ||
|
||
var parser = new YarnLockParser(this.loggerMock.Object); | ||
|
||
var blocks = new List<YarnBlock> | ||
{ | ||
this.CreateBlock( | ||
"internal-package@npm:0.0.0, internal-package@workspace:packages/internal-package", | ||
"0.0.0-use.local", | ||
"internal-package@workspace:packages/internal-package", | ||
new List<YarnBlock> | ||
{ | ||
this.CreateDependencyBlock(new Dictionary<string, string> { { "xyz", "2" } }), | ||
}, | ||
yarnLockFileVersion), | ||
this.CreateBlock("xyz@2, [email protected]", "2.4.3", "https://xyz", Enumerable.Empty<YarnBlock>(), yarnLockFileVersion), | ||
}; | ||
|
||
var blockFile = new Mock<IYarnBlockFile>(); | ||
blockFile.Setup(x => x.YarnLockVersion).Returns(yarnLockFileVersion); | ||
blockFile.Setup(x => x.GetEnumerator()).Returns(blocks.GetEnumerator()); | ||
|
||
var file = parser.Parse(this.recorderMock.Object, blockFile.Object, this.loggerMock.Object); | ||
|
||
file.LockVersion.Should().Be(yarnLockFileVersion); | ||
file.Entries.Should().ContainSingle(); | ||
|
||
foreach (var entry in file.Entries) | ||
{ | ||
var block = blocks.Single(x => x.Values[this.GetResolvedEntryName(yarnLockFileVersion)] == entry.Resolved); | ||
|
||
this.AssertBlockMatchesEntry(block, entry, yarnLockFileVersion); | ||
} | ||
} | ||
|
||
|
@@ -161,15 +256,15 @@ private YarnBlock CreateDependencyBlock(IDictionary<string, string> dependencies | |
return block; | ||
} | ||
|
||
private YarnBlock CreateBlock(string title, string version, string resolved, IEnumerable<YarnBlock> dependencies) | ||
private YarnBlock CreateBlock(string title, string version, string resolved, IEnumerable<YarnBlock> dependencies, YarnLockVersion lockfileVersion = YarnLockVersion.V1) | ||
{ | ||
var block = new YarnBlock | ||
{ | ||
Title = title, | ||
Values = | ||
{ | ||
["version"] = version, | ||
["resolved"] = resolved, | ||
[this.GetResolvedEntryName(lockfileVersion)] = resolved, | ||
}, | ||
}; | ||
|
||
|
@@ -181,7 +276,7 @@ private YarnBlock CreateBlock(string title, string version, string resolved, IEn | |
return block; | ||
} | ||
|
||
private void AssertBlockMatchesEntry(YarnBlock block, YarnEntry entry) | ||
private void AssertBlockMatchesEntry(YarnBlock block, YarnEntry entry, YarnLockVersion lockfileVersion = YarnLockVersion.V1) | ||
{ | ||
var componentName = block.Title.Split(',').Select(x => x.Trim()).First().Split('@')[0]; | ||
var blockVersions = block.Title.Split(',').Select(x => x.Trim()).Select(x => x.Split('@')[1]); | ||
|
@@ -194,7 +289,7 @@ private void AssertBlockMatchesEntry(YarnBlock block, YarnEntry entry) | |
} | ||
|
||
entry.Version.Should().Be(block.Values["version"]); | ||
entry.Resolved.Should().Be(block.Values["resolved"]); | ||
entry.Resolved.Should().Be(block.Values[this.GetResolvedEntryName(lockfileVersion)]); | ||
|
||
var dependencies = block.Children.SingleOrDefault(x => x.Title == "dependencies"); | ||
|
||
|
@@ -206,4 +301,9 @@ private void AssertBlockMatchesEntry(YarnBlock block, YarnEntry entry) | |
} | ||
} | ||
} | ||
|
||
private string GetResolvedEntryName(YarnLockVersion lockfileVersion) | ||
{ | ||
return lockfileVersion == YarnLockVersion.Berry ? "resolution" : "resolved"; | ||
} | ||
} |