From b6c9f4c8875acf50d8c446407f01e1d671a0af6f Mon Sep 17 00:00:00 2001 From: Shan Khan Date: Thu, 13 Dec 2018 15:11:48 +0500 Subject: [PATCH] v3.2.4 (#724) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add support for Coder.com (#714) Checks for extension `coder.coder` to tell if the IDE is Coder + VS Code or just a regular VS Code installation. * add webpack bundling for faster startup * use tsc to compile tests * make tests run * v3.2.3 release * v3.2.4 * Always use VSCODE_PORTABLE env when portable Mac will no longer use Application Support while in portable mode * Token error on HTTP 401 - Display token error on 401, as the current method was displaying generic error for me. Also opens GitHub tokens page on error > Doesn’t listen for 403 errors as this shouldn’t ever happen with current setup, but we could add later - Use error.status instead of error.code to avoid depreciation logging * Fix loading language bundles and add missing dependencies (#736) * add webpack bundling for faster startup * use tsc to compile tests * make tests run * rebase on v3.2.3 * fix loading language bundles --- .vscode/launch.json | 2 +- CHANGELOG.md | 4 ++++ package.json | 30 +++++++++++++++------------- src/commons.ts | 20 +++++++++---------- src/environmentPath.ts | 25 ++++++++++++++---------- src/localize.ts | 10 +++++++--- src/sync.ts | 2 +- webpack.config.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 99 insertions(+), 38 deletions(-) create mode 100644 webpack.config.js diff --git a/.vscode/launch.json b/.vscode/launch.json index 73c6c6b9..35677aff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}"], "stopOnEntry": false, "sourceMaps": true, - "outFiles": ["${workspaceRoot}/out/src/**/*.js"], + "outFiles": ["${workspaceRoot}/out/**/*.js"], "preLaunchTask": "npm" }, { diff --git a/CHANGELOG.md b/CHANGELOG.md index 3208700a..78aa6343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ [![Version](https://vsmarketplacebadge.apphb.com/version/Shan.code-settings-sync.svg)](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync) [![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync) [![Master course](https://img.shields.io/badge/Supported%20by-VSCode%20Power%20User%20Course%20%E2%86%92-gray.svg?colorA=444444&colorB=4F44D6)](https://t.co/8BEMyhpKU5?amp=1) +#### Version - 3.2.3 - 11 Dec, 2018 + +* Startup : Long startup activation time on the first start [#656](https://github.com/shanalikhan/code-settings-sync/issues/656) - Thanks for PR [#717](https://github.com/shanalikhan/code-settings-sync/pull/717) by [@thejewdude](https://github.com/thejewdude) +* Feature : Adding coder.com support [#714](https://github.com/shanalikhan/code-settings-sync/issues/714) - Thanks for PR [#720](https://github.com/shanalikhan/code-settings-sync/pull/720) by [@deansheather](https://github.com/deansheather) #### Version - 3.2.2 - 26 Nov, 2018 diff --git a/package.json b/package.json index f4fe84c2..d11a5457 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "code-settings-sync", "displayName": "Settings Sync", "description": "Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.", - "version": "3.2.2", + "version": "3.2.4", "icon": "images/cloud.png", "publisher": "Shan", "author": { @@ -62,7 +62,7 @@ "activationEvents": [ "*" ], - "main": "./out/src/extension", + "main": "./out/extension.js", "contributes": { "commands": [ { @@ -143,29 +143,33 @@ } }, "scripts": { - "vscode:prepublish": "npm run tslint-check && npm run compile", - "compile": "tsc -p ./", - "watch": "tsc -watch -p ./", + "vscode:prepublish": "npm run tslint-check && webpack --mode production", + "compile": "webpack", + "watch": "webpack --mode development --watch", "postinstall": "node ./node_modules/vscode/bin/install", "tslint-check": "tslint -c ./tslint.json ./src/**/*.ts ./src/*.ts", "format": "prettier --write './src/**/*.ts'", - "test": "npm run vscode:prepublish && node ./node_modules/bin/mocha --recursive" + "test": "npm run tslint-check && tsc -p ./ && mocha --recursive \"./out/test/**/*.js\"" }, "devDependencies": { - "@types/fs-extra": "^5.0.4", - "@types/node": "^10.12.10", "@types/chai": "4.1.7", + "@types/fs-extra": "^5.0.4", "@types/mocha": "^5.2.5", + "@types/node": "^10.12.10", "chai": "^4.2.0", + "clean-webpack-plugin": "^1.0.0", "mocha": "^5.2.0", - "prettier": "^1.15.2", + "prettier": "^1.15.3", + "ts-loader": "^5.3.0", "tslint": "^5.11.0", - "tslint-plugin-prettier": "^2.0.0", - "typescript": "^3.1.2", - "vscode": "^1.1.21" + "tslint-plugin-prettier": "^2.0.1", + "typescript": "^3.2.2", + "vscode": "^1.1.26", + "webpack": "^4.26.1", + "webpack-cli": "^3.1.2" }, "dependencies": { - "@octokit/rest": "^16.0.1", + "@octokit/rest": "^16.2.0", "adm-zip": "^0.4.13", "chokidar": "^2.0.4", "fs-extra": "^7.0.1", diff --git a/src/commons.ts b/src/commons.ts index c48b669a..eae5cdbe 100644 --- a/src/commons.ts +++ b/src/commons.ts @@ -20,19 +20,17 @@ export default class Commons { ): void { if (error) { console.error(error); - if (error.code === 500) { + if (error.status === 500) { message = localize("common.error.connection"); msgBox = false; - } else if (error.code === 4) { + } else if (error.status === 401) { + msgBox = true; + message = localize("common.error.invalidToken"); + } else if (error.status === 4) { message = localize("common.error.canNotSave"); } else if (error.message) { try { message = JSON.parse(error.message).message; - if (message.toLowerCase() === "bad credentials") { - msgBox = true; - message = localize("common.error.invalidToken"); - // vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://github.com/settings/tokens')); - } if (message.toLowerCase() === "not found") { msgBox = true; message = localize("common.error.invalidGistId"); @@ -647,9 +645,11 @@ export default class Commons { outputChannel.appendLine(`--------------------`); outputChannel.appendLine(`Files ${upload ? "Upload" : "Download"}ed:`); - files.filter(item => item.fileName.indexOf(".") > 0).forEach(item => { - outputChannel.appendLine(` ${item.fileName} > ${item.gistName}`); - }); + files + .filter(item => item.fileName.indexOf(".") > 0) + .forEach(item => { + outputChannel.appendLine(` ${item.fileName} > ${item.gistName}`); + }); outputChannel.appendLine(``); outputChannel.appendLine(`Extensions Ignored:`); diff --git a/src/environmentPath.ts b/src/environmentPath.ts index d3d1e17d..f69e7940 100644 --- a/src/environmentPath.ts +++ b/src/environmentPath.ts @@ -17,7 +17,7 @@ export function osTypeFromString(osName: string): OsType { } export class Environment { - public static CURRENT_VERSION: number = 322; + public static CURRENT_VERSION: number = 324; public static getVersion(): string { return ( Environment.CURRENT_VERSION.toString().slice(0, 1) + @@ -31,6 +31,7 @@ export class Environment { public isInsiders: boolean = false; public isOss: boolean = false; public isPortable: boolean = false; + public isCoderCom: boolean = false; public homeDir: string | null = null; public USER_FOLDER: string = null; @@ -66,14 +67,17 @@ export class Environment { this.isInsiders = /insiders/.test(this.context.asAbsolutePath("")); this.isPortable = process.env.VSCODE_PORTABLE ? true : false; this.isOss = /\boss\b/.test(this.context.asAbsolutePath("")); + this.isCoderCom = + vscode.extensions.getExtension("coder.coder") !== undefined; const isXdg = !this.isInsiders && + !this.isCoderCom && process.platform === "linux" && !!process.env.XDG_DATA_HOME; this.homeDir = isXdg ? process.env.XDG_DATA_HOME : process.env[process.platform === "win32" ? "USERPROFILE" : "HOME"]; - const configSuffix = `${isXdg ? "" : "."}vscode${ + const configSuffix = `${isXdg || this.isCoderCom ? "" : "."}vscode${ this.isInsiders ? "-insiders" : this.isOss ? "-oss" : "" }`; @@ -84,10 +88,14 @@ export class Environment { this.PATH = process.env.HOME + "/Library/Application Support"; this.OsType = OsType.Mac; } else if (process.platform === "linux") { - this.PATH = - isXdg && !!process.env.XDG_CONFIG_HOME - ? process.env.XDG_CONFIG_HOME - : os.homedir() + "/.config"; + if (!this.isCoderCom) { + this.PATH = + isXdg && !!process.env.XDG_CONFIG_HOME + ? process.env.XDG_CONFIG_HOME + : os.homedir() + "/.config"; + } else { + this.PATH = "/tmp"; + } this.OsType = OsType.Linux; } else if (process.platform === "win32") { this.PATH = process.env.APPDATA; @@ -99,17 +107,14 @@ export class Environment { } if (this.isPortable) { + this.PATH = process.env.VSCODE_PORTABLE; if (process.platform === "darwin") { - this.PATH = process.env.HOME + "/Library/Application Support"; this.OsType = OsType.Mac; } else if (process.platform === "linux") { - this.PATH = process.env.VSCODE_PORTABLE; this.OsType = OsType.Linux; } else if (process.platform === "win32") { - this.PATH = process.env.VSCODE_PORTABLE; this.OsType = OsType.Windows; } else { - this.PATH = process.env.VSCODE_PORTABLE; this.OsType = OsType.Linux; } } diff --git a/src/localize.ts b/src/localize.ts index 57ca42ce..1c488aeb 100644 --- a/src/localize.ts +++ b/src/localize.ts @@ -1,5 +1,6 @@ import * as fs from "fs-extra"; import * as path from "path"; +import { extensions } from "vscode"; interface IConfig { locale?: string; @@ -49,7 +50,8 @@ export class Localize { const defaultResvoleLanguage = ".nls.json"; let resolvedLanguage: string = ""; // TODO: it should read the extension root path from context - const rootPath = path.join(__dirname, "..", ".."); + const rootPath = extensions.getExtension("Shan.code-settings-sync") + .extensionPath; const file = path.join(rootPath, "package"); const options = this.options; @@ -80,7 +82,9 @@ export class Localize { // then merger the Language pack // just in case the resolveLanguage bundle missing the translation and fallback with default language if (resolvedLanguage !== defaultResvoleLanguage) { - defaultLanguageBundle = require(path.join(file + defaultResvoleLanguage)); + defaultLanguageBundle = JSON.parse( + fs.readFileSync(path.join(file + defaultResvoleLanguage), "utf-8") + ); } const languageFilePath = path.join(file + resolvedLanguage); @@ -88,7 +92,7 @@ export class Localize { const isExistResolvedLanguage = await fs.pathExists(languageFilePath); const ResolvedLanguageBundle = isExistResolvedLanguage - ? require(languageFilePath) + ? JSON.parse(fs.readFileSync(languageFilePath, "utf-8")) : {}; // merger with default language bundle diff --git a/src/sync.ts b/src/sync.ts index c2c6edbd..73b71040 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -528,7 +528,7 @@ export class Sync { const autoUpdate: boolean = vscode.workspace .getConfiguration("extensions") .get("autoUpdate"); - useCli = autoUpdate; + useCli = autoUpdate && !env.isCoderCom; if (useCli) { if (!syncSetting.quietSync) { Commons.outputChannel = vscode.window.createOutputChannel( diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..579fc822 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,44 @@ +//@ts-check +/** @typedef {import('webpack').Configuration} WebpackOptions **/ + +"use strict"; + +const path = require("path"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); + +/** @type WebpackOptions */ +const config = { + mode: "none", + target: "node", + entry: "./src/extension.ts", + output: { + filename: "extension.js", + path: path.resolve(__dirname, "out"), + libraryTarget: "commonjs2", + devtoolModuleFilenameTemplate: "file:///[absolute-resource-path]" + }, + resolve: { + extensions: [".ts", ".js"], + alias: { + deepmerge$: path.resolve(__dirname, "node_modules/deepmerge/dist/umd.js") + } + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + loader: "ts-loader" + } + ] + }, + externals: { + vscode: "commonjs vscode", + fsevents: "commonjs fsevents", + "original-fs": "commonjs original-fs" + }, + devtool: "source-map", + plugins: [new CleanWebpackPlugin(["out"])] +}; + +module.exports = config;