Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,28 @@ internal static IList<string> GetOrderedPluginDlls(string pluginDirectoryStart)
}

using var doc = JsonDocument.Parse(File.ReadAllText(packagePath));
if (!doc.RootElement.TryGetProperty("dependencies", out var deps))
if (!doc.RootElement.TryGetProperty("plugins", out var plugins))
{
return dllPathsInOrder;
}

var packageNamesInOrder = deps.EnumerateObject().Select(p => p.Name).ToList();
var packageNamesInOrder = plugins.EnumerateObject().Select(p => p.Name).ToList();

foreach (var package in packageNamesInOrder)
{
var packageDistPath = Path.Combine(rootDirectory, NodeModulesDir, package, "dist");
if (Directory.Exists(packageDistPath))
if (!Directory.Exists(packageDistPath))
{
var dlls = Directory.EnumerateFiles(packageDistPath, "*.dll", SearchOption.AllDirectories);
dllPathsInOrder.AddRange(dlls);
throw new InvalidOperationException($"Plugin '{package}' specified in package.json but its dist directory was not found at '{packageDistPath}'.");
}

var dlls = Directory.EnumerateFiles(packageDistPath, "*.dll", SearchOption.AllDirectories).ToList();
if (dlls.Count == 0)
{
throw new InvalidOperationException($"Plugin '{package}' specified in package.json but no DLL files were found in '{packageDistPath}'.");
}

dllPathsInOrder.AddRange(dlls);
}

return dllPathsInOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void GetOrderedPluginDlls()
""name"": ""dummy-project"",
""version"": ""1.0.0"",
""description"": ""Dummy project for testing purposes."",
""dependencies"": { ""plugin-1"": ""^1.0.0"", ""plugin-2"": ""^2.0.0"" }
""plugins"": { ""plugin-1"": ""^1.0.0"", ""plugin-2"": ""^2.0.0"" }
}");

File.WriteAllText(Path.Combine(plugin1Directory, "Plugin1.dll"), "Dummy DLL content");
Expand All @@ -184,5 +184,97 @@ public void GetOrderedPluginDlls()
File.Delete(Path.Combine(plugin2Directory, "Plugin2.dll"));
}
}

[Test]
public void GetOrderedPluginDlls_ThrowsIfPluginDirectoryNotFound()
{
var testRoot = TestContext.CurrentContext.TestDirectory;
var pluginDirectory = Path.Combine(testRoot, "node_modules", "missing-plugin", "dist");
try
{
File.WriteAllText(Path.Combine(testRoot, "package.json"), @"{
""name"": ""dummy-project"",
""version"": ""1.0.0"",
""description"": ""Dummy project for testing purposes."",
""plugins"": { ""missing-plugin"": ""^1.0.0"" }
}");

var ex = Assert.Throws<InvalidOperationException>(() =>
GeneratorHandler.GetOrderedPluginDlls(pluginDirectory));

Assert.That(ex!.Message, Does.Contain("missing-plugin"));
Assert.That(ex.Message, Does.Contain("dist directory was not found"));
}
finally
{
// Cleanup
var packageJsonPath = Path.Combine(testRoot, "package.json");
if (File.Exists(packageJsonPath))
{
File.Delete(packageJsonPath);
}
}
}

[Test]
public void GetOrderedPluginDlls_ThrowsIfPluginDllNotFound()
{
var testRoot = TestContext.CurrentContext.TestDirectory;
var pluginDirectory = Path.Combine(testRoot, "node_modules", "empty-plugin", "dist");
try
{
Directory.CreateDirectory(pluginDirectory);

File.WriteAllText(Path.Combine(testRoot, "package.json"), @"{
""name"": ""dummy-project"",
""version"": ""1.0.0"",
""description"": ""Dummy project for testing purposes."",
""plugins"": { ""empty-plugin"": ""^1.0.0"" }
}");

var ex = Assert.Throws<InvalidOperationException>(() =>
GeneratorHandler.GetOrderedPluginDlls(pluginDirectory));

Assert.That(ex!.Message, Does.Contain("empty-plugin"));
Assert.That(ex.Message, Does.Contain("no DLL files were found"));
}
finally
{
// Cleanup
var packageJsonPath = Path.Combine(testRoot, "package.json");
if (File.Exists(packageJsonPath))
{
File.Delete(packageJsonPath);
}
}
}

[Test]
public void GetOrderedPluginDlls_ReturnsEmptyListWhenNoPluginsProperty()
{
var testRoot = TestContext.CurrentContext.TestDirectory;
try
{
File.WriteAllText(Path.Combine(testRoot, "package.json"), @"{
""name"": ""dummy-project"",
""version"": ""1.0.0"",
""description"": ""Dummy project for testing purposes."",
""dependencies"": { ""some-dep"": ""^1.0.0"" }
}");

var dlls = GeneratorHandler.GetOrderedPluginDlls(testRoot);

Assert.AreEqual(0, dlls.Count);
}
finally
{
// Cleanup
var packageJsonPath = Path.Combine(testRoot, "package.json");
if (File.Exists(packageJsonPath))
{
File.Delete(packageJsonPath);
}
}
}
}
}