Skip to content

Commit dfdd6d2

Browse files
author
Paul van Brenk
committed
Correctly find the name for Scoped packages if they're not yet
installed.
1 parent dc84ac8 commit dfdd6d2

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

Nodejs/Product/Npm/SPI/RootPackage.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
using System;
34
using System.Collections.Generic;
45
using System.Globalization;
56
using System.IO;
@@ -11,11 +12,11 @@ namespace Microsoft.NodejsTools.Npm.SPI
1112
internal class RootPackage : IRootPackage
1213
{
1314
public RootPackage(
14-
string fullPathToRootDirectory,
15-
bool showMissingDevOptionalSubPackages,
16-
Dictionary<string, ModuleInfo> allModules = null,
17-
int depth = 0,
18-
int maxDepth = 1)
15+
string fullPathToRootDirectory,
16+
bool showMissingDevOptionalSubPackages,
17+
Dictionary<string, ModuleInfo> allModules = null,
18+
int depth = 0,
19+
int maxDepth = 1)
1920
{
2021
this.Path = fullPathToRootDirectory;
2122
var packageJsonFile = System.IO.Path.Combine(fullPathToRootDirectory, "package.json");
@@ -47,6 +48,20 @@ public RootPackage(
4748
{
4849
// otherwise we fail to create it completely...
4950
}
51+
52+
if (this.PackageJson != null)
53+
{
54+
this.Name = this.PackageJson.Name;
55+
}
56+
else
57+
{
58+
// this is the root package so the full folder name after node_nodules is the name
59+
// of the package
60+
var index = this.Path.IndexOf(NodejsConstants.NodeModulesFolder, StringComparison.OrdinalIgnoreCase);
61+
var name = this.Path.Substring(index + NodejsConstants.NodeModulesFolder.Length);
62+
63+
this.Name = name.TrimStart('\\', '/');
64+
}
5065
}
5166

5267
public IPackageJson PackageJson { get; }
@@ -55,13 +70,13 @@ public RootPackage(
5570

5671
public string Path { get; }
5772

73+
public string Name { get; }
74+
5875
public IEnumerable<string> Homepages => this.PackageJson?.Homepages ?? Enumerable.Empty<string>();
5976

6077
public bool HasPackageJson => this.PackageJson != null;
6178

62-
public string Name => this.PackageJson?.Name ?? new DirectoryInfo(this.Path).Name;
63-
64-
public SemverVersion Version => this.PackageJson?.Version ?? new SemverVersion();
79+
public SemverVersion Version => this.PackageJson?.Version ?? SemverVersion.UnknownVersion;
6580

6681
public IPerson Author => this.PackageJson?.Author;
6782

0 commit comments

Comments
 (0)