Skip to content

Commit 4c08ecd

Browse files
authored
Broaden NPM detection for VS Code extensions (#1801)
Context: #1348 Context: microsoft/vscode#295040 Commit a209393 added logic to ignore NPM dependencies declared in a package.json file if it belonged to a VS Code extension. This was done to ignore warnings for out of date package versions that are built directly into VS Code, however it also limits detection capabilities for all VS Code extension files. A change was made to bump the built in package versions in VS Code in commit microsoft/vscode@e987c52 which should allow us to revert this change and restore broader NPM detection for VS Code extensions.
1 parent 5dd061e commit 4c08ecd

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public NpmComponentDetector(
3838

3939
public override IEnumerable<ComponentType> SupportedComponentTypes { get; } = [ComponentType.Npm];
4040

41-
public override int Version { get; } = 3;
41+
public override int Version { get; } = 4;
4242

4343
protected override async Task OnFileFoundAsync(ProcessRequest processRequest, IDictionary<string, string> detectorArgs, CancellationToken cancellationToken = default)
4444
{
@@ -82,20 +82,6 @@ protected virtual bool ProcessPackageJson(string filePath, ISingleFileComponentR
8282
return false;
8383
}
8484

85-
// Check for VS Code extensions
86-
// See https://code.visualstudio.com/api/working-with-extensions/publishing-extension#visual-studio-code-compatibility
87-
var containsVsCodeEngine = false;
88-
if (packageJson.Engines is not null && packageJson.Engines.ContainsKey("vscode"))
89-
{
90-
containsVsCodeEngine = true;
91-
}
92-
93-
if (containsVsCodeEngine)
94-
{
95-
this.Logger.LogInformation("{NpmPackageName} found at path {NpmPackageLocation} represents a built-in VS Code extension. This package will not be registered.", name, filePath);
96-
return false;
97-
}
98-
9985
var author = this.GetAuthor(packageJson.Author, name, filePath);
10086
var npmComponent = new NpmComponent(name, version, author: author);
10187

test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorTests.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public async Task TestNpmDetector_NodeEngineDoesNotCauseSkippedPackageAsync()
227227
}
228228

229229
[TestMethod]
230-
public async Task TestNpmDetector_VSCodeEngineCausesSkippedPackageAsync()
230+
public async Task TestNpmDetector_VSCodeEnginePackageIsDetectedAsync()
231231
{
232232
var componentName = GetRandomString();
233233
var version = NewRandomVersion();
@@ -239,7 +239,11 @@ public async Task TestNpmDetector_VSCodeEngineCausesSkippedPackageAsync()
239239
.ExecuteDetectorAsync();
240240
scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
241241
var detectedComponents = componentRecorder.GetDetectedComponents();
242-
detectedComponents.Should().BeEmpty();
242+
detectedComponents.Should().ContainSingle();
243+
detectedComponents.Single().Component.Type.Should().Be(ComponentType.Npm);
244+
var detectedNpmComponent = (NpmComponent)detectedComponents.Single().Component;
245+
detectedNpmComponent.Name.Should().Be(componentName);
246+
detectedNpmComponent.Version.Should().Be(version);
243247
}
244248

245249
[TestMethod]
@@ -256,7 +260,11 @@ public async Task TestNpmDetector_EnginesAsArray_VSCodeEngine()
256260
.ExecuteDetectorAsync();
257261
scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
258262
var detectedComponents = componentRecorder.GetDetectedComponents();
259-
detectedComponents.Should().BeEmpty();
263+
detectedComponents.Should().ContainSingle();
264+
detectedComponents.Single().Component.Type.Should().Be(ComponentType.Npm);
265+
var detectedNpmComponent = (NpmComponent)detectedComponents.Single().Component;
266+
detectedNpmComponent.Name.Should().Be(packageName);
267+
detectedNpmComponent.Version.Should().Be(packageVersion);
260268
}
261269

262270
[TestMethod]

0 commit comments

Comments
 (0)