Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nonoroazoro committed Feb 13, 2019
2 parents 75829ea + 1699de7 commit 38752e9
Show file tree
Hide file tree
Showing 10 changed files with 942 additions and 1,266 deletions.
5 changes: 5 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"smartStep": true,
"sourceMaps": true,
"osx": {
"preLaunchTask": "tsc-watch"
// "preLaunchTask": "tsc-watch"
},
}
]
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelogs

## 2.1.2 - February 13, 2019

- Changed: Increase the download speed and accelerate the process of adding and installing VSCode extensions.


## 2.1.1 - February 12, 2019

- Added: Add support for the VSCode exploration builds.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

## Breaking Changes

* From ***version 2.1.1*** onwards:
* From ***version 2.1.2*** onwards:

1. Increase the download speed and accelerate the process of adding and installing VSCode extensions.

1. Add support for different editions of VSCode binaries as the followings:

Expand Down
4 changes: 3 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

## 重要变更

****2.1.1*** 版本开始:
****2.1.2*** 版本开始:

1. 显著加快 VSCode 插件的下载和安装速度;

1. 增加对各种 VSCode 版本的支持,包括:

Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "syncing",
"displayName": "%displayName%",
"description": "%description%",
"version": "2.1.1",
"version": "2.1.2",
"publisher": "nonoroazoro",
"author": {
"email": "xiaochao.k@gmail.com",
Expand Down Expand Up @@ -103,7 +103,6 @@
},
"scripts": {
"vscode:prepublish": "npm run build",
"precommit": "lint-staged",
"postinstall": "node ./node_modules/vscode/bin/install",
"prebuild": "npm run clean && npm run cleanCov",
"build": "cross-env NODE_ENV=production webpack --config ./webpack.config.prod.js --progress",
Expand All @@ -116,12 +115,12 @@
"test:cov": "npm run cleanCov && npm test -- --coverage"
},
"dependencies": {
"@octokit/rest": "^16.1.0",
"@octokit/rest": "^16.15.0",
"date-fns": "^2.0.0-alpha.25",
"extract-zip": "^1.6.7",
"fs-extra": "^7.0.1",
"https-proxy-agent": "^2.2.1",
"jsonc-parser": "^2.0.2",
"jsonc-parser": "^2.0.3",
"jsondiffpatch": "^0.3.11",
"junk": "^2.1.0",
"lodash.isstring": "^4.0.1",
Expand All @@ -131,25 +130,25 @@
},
"devDependencies": {
"@types/extract-zip": "^1.6.2",
"@types/fs-extra": "^5.0.4",
"@types/jest": "^23.3.10",
"@types/fs-extra": "^5.0.5",
"@types/jest": "^24.0.3",
"@types/lodash.isstring": "^4.0.4",
"@types/lodash.pick": "^4.4.4",
"@types/minimatch": "^3.0.3",
"@types/node": "^10.12.10",
"@types/node": "^11.9.3",
"@types/tmp": "0.0.33",
"cross-env": "^5.2.0",
"husky": "^1.2.0",
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"rimraf": "^2.6.2",
"husky": "^1.3.1",
"jest": "^24.1.0",
"lint-staged": "^8.1.3",
"rimraf": "^2.6.3",
"ts-jest": "^23.10.5",
"ts-loader": "^5.3.1",
"tslint": "^5.11.0",
"typescript": "^3.1.6",
"vscode": "^1.1.22",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
"ts-loader": "^5.3.3",
"tslint": "^5.12.1",
"typescript": "^3.3.3",
"vscode": "^1.1.29",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
},
"lint-staged": {
"./src/**/*.ts": [
Expand Down
29 changes: 11 additions & 18 deletions src/core/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IExtension, ISyncedItem } from "../types/SyncingTypes";
import { IExtensionMeta } from "../types/VSCodeWebAPITypes";
import { downloadFile } from "../utils/ajax";
import { getExtensionById, getVSCodeSetting } from "../utils/vscodeAPI";
import { getVSIXDownloadURL, queryExtensions } from "../utils/vscodeWebAPI";
import { getLatestVSIXVersion, queryExtensions } from "../utils/vscodeWebAPI";
import { Environment } from "./Environment";
import { Syncing } from "./Syncing";
import * as Toast from "./Toast";
Expand Down Expand Up @@ -168,14 +168,12 @@ export class Extension
return;
}

// Fallback to normal package in case the extension query service is down.
if (!extension.downloadURL)
{
extension.downloadURL =
`https://${extension.publisher}.gallery.vsassets.io/_apis/public/gallery/`
+ `publisher/${extension.publisher}/extension/${extension.name}/${extension.version}/`
+ `assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`;
}
// Calculates the VSIX download URL.
extension.downloadURL =
`https://${extension.publisher}.gallery.vsassets.io/_apis/public/gallery/`
+ `publisher/${extension.publisher}/extension/${extension.name}/${extension.version}/`
+ `assetbyname/Microsoft.VisualStudio.Services.VSIXPackage?install=true`;

downloadFile(extension.downloadURL, filepath, this._syncing.proxy).then(() =>
{
resolve({ ...extension, vsixFilepath: filepath });
Expand Down Expand Up @@ -341,19 +339,14 @@ export class Extension
const extensionMeta = queriedExtensions.get(ext.id);
if (extensionMeta)
{
const versionMeta = extensionMeta.versions[0];
if (versionMeta)
const latestVersion = getLatestVSIXVersion(extensionMeta);
if (latestVersion != null)
{
const version = versionMeta.version;
const downloadURL = getVSIXDownloadURL(versionMeta);
if (version && downloadURL)
{
ext.version = version;
ext.downloadURL = downloadURL;
}
ext.version = latestVersion;
}
}
}

const localExtension = getExtensionById(ext.id);
if (localExtension)
{
Expand Down
17 changes: 7 additions & 10 deletions src/utils/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export function post(api: string, data: any, headers: any, proxy?: string): Prom
return new Promise((resolve, reject) =>
{
const body: string = JSON.stringify(data);
const { hostname, path, port } = url.parse(api);
const { host, path, port } = url.parse(api);
const options: https.RequestOptions = {
host: hostname,
host,
path,
method: "POST",
headers: {
Expand Down Expand Up @@ -79,11 +79,8 @@ export function downloadFile(uri: string, savepath: string, proxy?: string): Pro
{
return new Promise((resolve, reject) =>
{
const { hostname, path, port } = url.parse(uri);
const options: https.RequestOptions = {
host: hostname,
path
};
const { host, path, port } = url.parse(uri);
const options: https.RequestOptions = { host, path };

if (port)
{
Expand Down Expand Up @@ -131,9 +128,9 @@ export function downloadFile(uri: string, savepath: string, proxy?: string): Pro
}
}).on("error", (err) =>
{
fs.remove(savepath)
.then(() => reject(err))
.catch(() => reject(err));
// Close and remove the temp file.
file.close();
fs.remove(savepath).catch().then(() => reject(err));
});
});
}
22 changes: 16 additions & 6 deletions src/utils/vscodeWebAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ export async function queryExtensions(ids: string[], proxy?: string): Promise<Ca
{
(results[0].extensions || []).forEach((extension: IExtensionMeta) =>
{
// Use extension's id as the key.
result.set(
`${extension.publisher.publisherName}.${extension.extensionName}`,
extension
);
// Use extension's fullname as the key.
result.set(`${extension.publisher.publisherName}.${extension.extensionName}`, extension);
});
}
}
Expand All @@ -60,9 +57,22 @@ export async function queryExtensions(ids: string[], proxy?: string): Promise<Ca
return result;
}

/**
* Gets the latest version of the VSIX file.
*
* @param {IExtensionMeta} extensionMeta The extension's meta object.
*/
export function getLatestVSIXVersion(extensionMeta: IExtensionMeta): string | undefined
{
const versionMeta = extensionMeta.versions[0];
return versionMeta ? versionMeta.version : undefined;
}

/**
* Gets the VSIX download URL.
*
* @deprecated The download speed of this URL is too slow.
*
* @param {IExtensionVersion} version The extension's version object.
*/
export function getVSIXDownloadURL(version: IExtensionVersion): string | undefined
Expand All @@ -76,5 +86,5 @@ export function getVSIXDownloadURL(version: IExtensionVersion): string | undefin
return file.source;
}
}
return undefined;
return;
}
Loading

0 comments on commit 38752e9

Please sign in to comment.