Skip to content

Commit dc28b35

Browse files
committed
1.2 Support sub-folders in namespaced packages
1 parent 619e484 commit dc28b35

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ build/
2929
.vs/
3030
.vscode/
3131
.idea/
32-
# Uncomment if you have tasks that create the project's static files in wwwroot
32+
33+
# Local test files
3334
wwwroot/
3435
unpkg.json
3536

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.0
2+
3+
- Added support for sub-directories in namespaced packages like `dotnet unpkg add @aspnet/signalr/browser`
4+
15
## 1.1.0
26

37
- Added support for namespaced packages like `@aspnet/signalr`

Dist.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,32 @@ public static async Task<DistFile> Get(string package)
3434
private static async Task<HttpResponseMessage> Find(string package)
3535
{
3636
string url;
37-
if (package.Contains("/"))
37+
var parts = package.Split('/');
38+
string sub = null;
39+
40+
if (package.StartsWith('@') && parts.Length > 1)
41+
{
42+
package = $"{parts[0]}/{parts[1]}";
43+
if (parts.Length > 2)
44+
{
45+
sub = string.Join('/', parts.Skip(2));
46+
}
47+
}
48+
else if (parts.Length > 1)
49+
{
50+
package = parts[0];
51+
sub = string.Join('/', parts.Skip(1));
52+
}
53+
54+
if (sub != null)
3855
{
39-
var parts = package.Split('/');
40-
url = $"{parts[0]}/dist/{string.Join('/', parts.Skip(1))}/?meta";
56+
url = $"{package}/dist/{sub}/?meta";
4157
}
4258
else
4359
{
4460
url = $"{package}/dist/?meta";
4561
}
46-
62+
4763
var response = await FollowRedirects(url);
4864

4965
if (response.IsSuccessStatusCode)

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ $ dotnet unpkg add bootswatch/yeti
8686
That just installs the **Yeti** theme within the larger Bootswatch package. If
8787
you just install Bootswatch by itself, you'll get all 20-odd themes.
8888

89+
**New in 1.2**
90+
91+
You can now specify paths with namespaced packages. This is incredibly useful if you want to install [Rx.js](http://reactivex.io/rxjs/)
92+
because it's *huge*, and all you want is the `global` folder:
93+
94+
```
95+
$ dotnet unpkg add @reactivex/rxjs/global
96+
```
97+
And you'll just get the four `<script>`-tag-friendly files that you need, and not the hundreds of Node and Webpack and source files.
98+
8999
### unpkg.json
90100

91101
The `add` command stores the details about the files it downloaded into a file in the current directory, `unpkg.json`. Once that's there, you can just run

dotnet-unpkg.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>1.1.0</Version>
3+
<Version>1.2.0</Version>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.0</TargetFramework>
66
<LangVersion>latest</LangVersion>

0 commit comments

Comments
 (0)