up
This commit is contained in:
@@ -57,6 +57,7 @@ internal static class NodePackageCollector
|
||||
|
||||
TraverseTarballs(context, projectInput.Tarballs, packages, visited, yarnPnpPresent, cancellationToken);
|
||||
TraverseYarnPnpCache(context, projectInput.YarnCacheRoots, packages, visited, yarnPnpPresent, cancellationToken);
|
||||
MergePnpPackages(context, packages, visited, cancellationToken);
|
||||
|
||||
AttachImports(context, packages, cancellationToken);
|
||||
|
||||
@@ -149,6 +150,37 @@ internal static class NodePackageCollector
|
||||
}
|
||||
}
|
||||
|
||||
private static void MergePnpPackages(
|
||||
LanguageAnalyzerContext context,
|
||||
List<NodePackage> packages,
|
||||
HashSet<string> visited,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var pnpPackages = NodePnpDataLoader.Load(context, cancellationToken);
|
||||
if (pnpPackages.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var package in pnpPackages)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var key = package.RelativePathNormalized;
|
||||
if (!string.IsNullOrEmpty(key) && !visited.Add(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (packages.Any(p => string.Equals(p.ComponentKey, package.ComponentKey, StringComparison.Ordinal)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
packages.Add(package);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateSourceFiles(string root)
|
||||
{
|
||||
foreach (var extension in new[] { ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx" })
|
||||
|
||||
@@ -84,7 +84,7 @@ internal static class NodePnpDataLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
var relativePath = context.GetRelativePath(packageLocation).Replace(Path.DirectorySeparatorChar, '/');
|
||||
var relativePath = NormalizeRelativePath(context, packageLocation);
|
||||
var absolutePackagePath = Path.GetFullPath(Path.Combine(context.RootPath, packageLocation));
|
||||
var usedByEntrypoint = context.UsageHints.IsPathUsed(absolutePackagePath);
|
||||
var packageJsonLocator = BuildLocator(packageLocation);
|
||||
@@ -252,6 +252,20 @@ internal static class NodePnpDataLoader
|
||||
return (name ?? string.Empty, version ?? string.Empty);
|
||||
}
|
||||
|
||||
private static string NormalizeRelativePath(LanguageAnalyzerContext context, string packageLocation)
|
||||
{
|
||||
var relative = context.GetRelativePath(packageLocation);
|
||||
if (string.IsNullOrWhiteSpace(relative) || relative == ".")
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
return relative
|
||||
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
|
||||
.Replace(Path.DirectorySeparatorChar, '/')
|
||||
.Replace(Path.AltDirectorySeparatorChar, '/');
|
||||
}
|
||||
|
||||
private static string BuildLocator(string packageLocation)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(packageLocation))
|
||||
@@ -276,4 +290,3 @@ internal static class NodePnpDataLoader
|
||||
return relative.Replace(Path.DirectorySeparatorChar, '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user