This commit is contained in:
StellaOps Bot
2025-12-07 22:49:53 +02:00
parent 11597679ed
commit 7c24ed96ee
204 changed files with 23313 additions and 1430 deletions

View File

@@ -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" })

View File

@@ -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, '/');
}
}

View File

@@ -0,0 +1,18 @@
{
"packages": {
"yarn-pnp-demo@workspace:.": {
"packageLocation": ".",
"packageJson": {
"name": "yarn-pnp-demo",
"version": "1.0.0"
}
},
"cached-lib@npm:1.0.0": {
"packageLocation": ".yarn/cache/cached-lib-1.0.0.zip/node_modules/cached-lib/",
"packageJson": {
"name": "cached-lib",
"version": "1.0.0"
}
}
}
}

View File

@@ -8,7 +8,9 @@
"type": "npm",
"usedByEntrypoint": false,
"metadata": {
"path": ".yarn/cache",
"lockLocator": "cached-lib@npm:1.0.0",
"lockSource": "pnp.data",
"path": ".yarn/cache/cached-lib-1.0.0.zip/node_modules/cached-lib",
"yarnPnp": "true"
},
"evidence": [
@@ -29,6 +31,8 @@
"type": "npm",
"usedByEntrypoint": false,
"metadata": {
"lockLocator": "yarn-pnp-demo@workspace:.",
"lockSource": "pnp.data",
"path": ".",
"yarnPnp": "true"
},
@@ -40,4 +44,4 @@
}
]
}
]
]