Skip to content

Commit bd982c8

Browse files
edgardmessiasJohnstonCode
authored andcommitted
refactor: Refactored usage of vscode modules (#578)
1 parent ba27551 commit bd982c8

File tree

6 files changed

+77
-29
lines changed

6 files changed

+77
-29
lines changed

package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"cz-conventional-changelog": "^2.1.0",
6969
"decache": "^4.5.1",
7070
"glob": "^7.1.4",
71-
"iconv-lite": "^0.4.23",
7271
"istanbul": "^0.4.5",
7372
"mocha": "^6.1.4",
7473
"mocha-junit-reporter": "^1.22.0",

src/svn.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
/**
2-
* Load local first, after load the from VSCode modules
3-
* == 0 - is svn-scm/out/node_modules
4-
* == 1 - is svn-scm/node_modules
5-
* == 2 - is vscode folder
6-
* >= 3 - parent folders of svn-scm
7-
*/
8-
import * as vscode from "vscode";
9-
module.paths.splice(2, 0, `${vscode.env.appRoot}/node_modules.asar`);
10-
module.paths.splice(2, 0, `${vscode.env.appRoot}/node_modules`); // VSCode < 1.21.0
11-
121
import * as cp from "child_process";
132
import { EventEmitter } from "events";
14-
import * as iconv from "iconv-lite";
153
import isUtf8 = require("is-utf8");
16-
import * as jschardet from "jschardet";
174
import * as proc from "process";
185
import { Readable } from "stream";
19-
import { Uri, workspace } from "vscode";
206
import {
217
ConstructorPolicy,
228
ICpOptions,
@@ -28,6 +14,7 @@ import { parseInfoXml } from "./infoParser";
2814
import SvnError from "./svnError";
2915
import { Repository } from "./svnRepository";
3016
import { dispose, IDisposable, toDisposable } from "./util";
17+
import { iconv, jschardet } from "./vscodeModules";
3118

3219
export const svnErrorCodes: { [key: string]: string } = {
3320
AuthorizationFailed: "E170001",
@@ -182,8 +169,8 @@ export class Svn {
182169
if (!iconv.encodingExists(defaultEncoding)) {
183170
this.logOutput(
184171
"svn.default.encoding: Invalid Parameter: '" +
185-
defaultEncoding +
186-
"'.\n"
172+
defaultEncoding +
173+
"'.\n"
187174
);
188175
} else if (!isUtf8(stdout)) {
189176
encoding = defaultEncoding;

src/types/iconv-lite.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/// <reference types='node'/>
7+
8+
declare module "iconv-lite" {
9+
export function decode(buffer: Buffer, encoding: string): string;
10+
11+
export function encode(
12+
content: string | Buffer,
13+
encoding: string,
14+
options?: { addBOM?: boolean }
15+
): Buffer;
16+
17+
export function encodingExists(encoding: string): boolean;
18+
19+
export function decodeStream(encoding: string): NodeJS.ReadWriteStream;
20+
21+
export function encodeStream(
22+
encoding: string,
23+
options?: { addBOM?: boolean }
24+
): NodeJS.ReadWriteStream;
25+
}

src/vscodeModules.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Only this file is allowed to import VSCode modules
2+
// tslint:disable: import-blacklist
3+
4+
import * as path from "path";
5+
import * as vscode from "vscode";
6+
7+
const appRoot = vscode.env.appRoot;
8+
9+
// Try load only in VSCode node_modules, like .vsix files (without dev dependencies)
10+
module.paths = [
11+
path.join(appRoot, "node_modules.asar"),
12+
path.join(appRoot, "node_modules"), // VSCode < 1.21.0
13+
];
14+
15+
import * as iconv from "iconv-lite";
16+
import * as jschardet from "jschardet";
17+
18+
export { iconv, jschardet };

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"]
3636
]
3737
},
38-
"import-blacklist": [true, "fs"]
38+
"import-blacklist": [true, "fs", "iconv-lite", "jschardet"]
3939
},
4040
"rulesDirectory": [],
4141
"linterOptions": {

0 commit comments

Comments
 (0)