Skip to content

Commit 605b321

Browse files
edgardmessiasJohnstonCode
authored andcommitted
fix: Show alert to work with code-server (#579)
1 parent bd982c8 commit 605b321

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/vscodeModules.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ import * as vscode from "vscode";
66

77
const appRoot = vscode.env.appRoot;
88

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-
];
9+
function loadVSCodeModule(id: string) {
10+
try {
11+
return require(`${appRoot}/node_modules.asar/${id}`);
12+
} catch (ea) {
13+
// Ignore
14+
}
1415

15-
import * as iconv from "iconv-lite";
16-
import * as jschardet from "jschardet";
16+
const baseDir = path.dirname(process.execPath);
17+
try {
18+
module.paths.unshift(`${baseDir}/node_modules`);
19+
return require(id);
20+
} catch (eb) {
21+
vscode.window.showErrorMessage(`Missing dependency, go to "${baseDir}" and run: npm install ${id}`);
22+
}
23+
}
1724

18-
export { iconv, jschardet };
25+
export const iconv = loadVSCodeModule("iconv-lite") as typeof import("iconv-lite");
26+
export const jschardet = loadVSCodeModule("jschardet") as typeof import("jschardet");

0 commit comments

Comments
 (0)