Skip to content

Commit 21c8381

Browse files
Switch to download.visualstudio.microsoft.com part 1 (#1646)
This checkin in the first part of the work to switch to using download.visualstudio.microsoft.com. This checkin does two things: 1. It replaces the OmniSharp links with CDN links 2. It adds a new gulp task to update links in package.json. This will allow us to script the insertion process.
1 parent 7bf887a commit 21c8381

File tree

4 files changed

+105
-8
lines changed

4 files changed

+105
-8
lines changed

gulpfile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const platform = require('./out/src/platform');
2020
const util = require('./out/src/common');
2121
const child_process = require('child_process');
2222
const optionsSchemaGenerator = require('./out/src/tools/GenerateOptionsSchema');
23+
const packageDependencyUpdater = require('./out/src/tools/UpdatePackageDependencies');
2324

2425
const Logger = logger.Logger;
2526
const PackageManager = packages.PackageManager;
@@ -44,6 +45,10 @@ gulp.task('generateOptionsSchema', () => {
4445
optionsSchemaGenerator.GenerateOptionsSchema();
4546
});
4647

48+
gulp.task('updatePackageDependencies', () => {
49+
packageDependencyUpdater.updatePackageDependencies();
50+
});
51+
4752
// Install Tasks
4853
function install(platformInfo, packageJSON) {
4954
const packageManager = new PackageManager(platformInfo, packageJSON);

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"runtimeDependencies": [
6969
{
7070
"description": "Mono Runtime (Linux / x86)",
71-
"url": "https://omnisharpdownload.azureedge.net/ext/mono.linux-x86-5.2.0-omnisharp1.zip",
71+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/mono.linux-x86-5.2.0-omnisharp1.zip",
7272
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/mono.linux-x86-5.2.0-omnisharp1.zip",
7373
"installPath": "./bin",
7474
"platforms": [
@@ -85,7 +85,7 @@
8585
},
8686
{
8787
"description": "Mono Runtime (Linux / x64)",
88-
"url": "https://omnisharpdownload.azureedge.net/ext/mono.linux-x86_64-5.2.0-omnisharp1.zip",
88+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/mono.linux-x86_64-5.2.0-omnisharp1.zip",
8989
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/mono.linux-x86_64-5.2.0-omnisharp1.zip",
9090
"installPath": "./bin",
9191
"platforms": [
@@ -102,7 +102,7 @@
102102
},
103103
{
104104
"description": "Mono Runtime (macOS)",
105-
"url": "https://omnisharpdownload.azureedge.net/ext/mono.osx-5.2.0-omnisharp1.zip",
105+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/mono.osx-5.2.0-omnisharp1.zip",
106106
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/mono.osx-5.2.0-omnisharp1.zip",
107107
"installPath": "./bin",
108108
"platforms": [
@@ -116,7 +116,7 @@
116116
},
117117
{
118118
"description": "Mono Framework Assemblies",
119-
"url": "https://omnisharpdownload.azureedge.net/ext/framework-5.2.0-omnisharp1.zip",
119+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/framework-5.2.0-omnisharp1.zip",
120120
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/framework-5.2.0-omnisharp1.zip",
121121
"installPath": "./bin/framework",
122122
"platforms": [
@@ -127,7 +127,7 @@
127127
},
128128
{
129129
"description": "OmniSharp (.NET 4.6 / x86)",
130-
"url": "https://omnisharpdownload.azureedge.net/ext/omnisharp-win-x86-1.22.0.zip",
130+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/omnisharp-win-x86-1.22.0.zip",
131131
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.22.0.zip",
132132
"installPath": "./bin/omnisharp",
133133
"platforms": [
@@ -140,7 +140,7 @@
140140
},
141141
{
142142
"description": "OmniSharp (.NET 4.6 / x64)",
143-
"url": "https://omnisharpdownload.azureedge.net/ext/omnisharp-win-x64-1.22.0.zip",
143+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/omnisharp-win-x64-1.22.0.zip",
144144
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.22.0.zip",
145145
"installPath": "./bin/omnisharp",
146146
"platforms": [
@@ -153,7 +153,7 @@
153153
},
154154
{
155155
"description": "OmniSharp (Mono 4.6)",
156-
"url": "https://omnisharpdownload.azureedge.net/ext/omnisharp-mono-1.22.0.zip",
156+
"url": "https://download.visualstudio.microsoft.com/download/pr/10942097/51c64a0c8945d53601bbf75af88d88f3/omnisharp-mono-1.22.0.zip",
157157
"fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-mono-1.22.0.zip",
158158
"installPath": "./bin/omnisharp",
159159
"platforms": [

src/tools/GenerateOptionsSchema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as os from 'os';
23

34
function AppendFieldsToObject(reference: any, obj: any) {
45

@@ -94,5 +95,9 @@ export function GenerateOptionsSchema() {
9495
packageJSON.contributes.debuggers[1].configurationAttributes.launch = schemaJSON.definitions.LaunchOptions;
9596
packageJSON.contributes.debuggers[1].configurationAttributes.attach = schemaJSON.definitions.AttachOptions;
9697

97-
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2));
98+
let content = JSON.stringify(packageJSON, null, 2);
99+
if (os.platform() === 'win32') {
100+
content = content.replace(/\n/gm, "\r\n");
101+
}
102+
fs.writeFileSync('package.json', content);
98103
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as fs from 'fs';
2+
import * as os from 'os';
3+
import { Package } from '../packages';
4+
5+
interface PackageJSONFile
6+
{
7+
runtimeDependencies : Package[];
8+
}
9+
10+
export function updatePackageDependencies() {
11+
12+
const urlsIndex = process.argv.indexOf("--urls");
13+
const newPrimaryUrls = urlsIndex >= 0 ? process.argv[urlsIndex+1] : undefined;
14+
15+
const fallbackUrlsIndex = process.argv.indexOf("--fallbackUrls");
16+
const newFallbackUrls = fallbackUrlsIndex >= 0 ? process.argv[fallbackUrlsIndex+1] : undefined;
17+
18+
if (newPrimaryUrls === undefined || newPrimaryUrls === "-?" || newPrimaryUrls === "-h") {
19+
console.log("This command will update the URLs for package dependencies in package.json");
20+
console.log();
21+
console.log("Syntax: updatePackageDependencies --urls \"<url1>,<url2>,...\" [--fallbackUrls \"<fallback-url-1>,<fallback-url-2>...\"]");
22+
console.log();
23+
return;
24+
}
25+
26+
if (newPrimaryUrls.length === 0) {
27+
throw new Error("Invalid first argument to updatePackageDependencies. URL string argument expected.");
28+
}
29+
30+
let packageJSON: PackageJSONFile = JSON.parse(fs.readFileSync('package.json').toString());
31+
32+
// map from lowercase filename to Package
33+
const mapFileNameToDependency = {};
34+
35+
// First build the map
36+
packageJSON.runtimeDependencies.forEach(dependency => {
37+
let fileName = getLowercaseFileNameFromUrl(dependency.url);
38+
let existingDependency = mapFileNameToDependency[fileName];
39+
if (existingDependency !== undefined) {
40+
throw new Error(`Multiple dependencies found with filename '${fileName}': '${existingDependency.url}' and '${dependency.url}'.`);
41+
}
42+
mapFileNameToDependency[fileName] = dependency;
43+
});
44+
45+
let findDependencyToUpdate = (url : string): Package => {
46+
let fileName = getLowercaseFileNameFromUrl(url);
47+
let dependency = mapFileNameToDependency[fileName];
48+
if (dependency === undefined) {
49+
throw new Error(`Unable to update item for url '${url}'. No 'runtimeDependency' found with filename '${fileName}'.`);
50+
}
51+
52+
console.log(`Updating ${url}`);
53+
return dependency;
54+
};
55+
56+
newPrimaryUrls.split(',').forEach(urlToUpdate =>{
57+
let depedency = findDependencyToUpdate(urlToUpdate);
58+
depedency.url = urlToUpdate;
59+
});
60+
61+
if (newFallbackUrls !== undefined) {
62+
newFallbackUrls.split(',').forEach(urlToUpdate =>{
63+
let depedency = findDependencyToUpdate(urlToUpdate);
64+
depedency.fallbackUrl = urlToUpdate;
65+
});
66+
}
67+
68+
let content = JSON.stringify(packageJSON, null, 2);
69+
if (os.platform() === 'win32') {
70+
content = content.replace(/\n/gm, "\r\n");
71+
}
72+
fs.writeFileSync('package.json', content);
73+
}
74+
75+
function getLowercaseFileNameFromUrl(url : string) : string {
76+
77+
if (!url.startsWith("https://")) {
78+
throw new Error(`Unexpected URL '${url}'. URL expected to start with 'https://'.`);
79+
}
80+
81+
if (!url.endsWith(".zip")) {
82+
throw new Error(`Unexpected URL '${url}'. URL expected to end with '.zip'.`);
83+
}
84+
85+
let index = url.lastIndexOf("/");
86+
return url.substr(index + 1).toLowerCase();
87+
}

0 commit comments

Comments
 (0)