-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed webpack dep issue on remote vscode (#1025)
- Loading branch information
1 parent
fbe7296
commit 9a58729
Showing
2 changed files
with
23 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,42 @@ | ||
// Only this file is allowed to import VSCode modules | ||
// tslint:disable: import-blacklist | ||
|
||
import * as path from "path"; | ||
import * as vscode from "vscode"; | ||
import { env, window } from "vscode"; | ||
|
||
const appRoot = vscode.env.appRoot; | ||
declare const __webpack_require__: typeof require; | ||
declare const __non_webpack_require__: typeof require; | ||
|
||
function loadVSCodeModule(id: string) { | ||
function getNodeModule<T>(moduleName: string, showError = true): T | undefined { | ||
const r = | ||
typeof __webpack_require__ === "function" | ||
? __non_webpack_require__ | ||
: require; | ||
try { | ||
return require(`${appRoot}/node_modules.asar/${id}`); | ||
} catch (ea) { | ||
// Ignore | ||
return r(`${env.appRoot}/node_modules.asar/${moduleName}`); | ||
} catch (err) { | ||
// Not in ASAR. | ||
} | ||
|
||
const baseDir = path.dirname(process.execPath); | ||
try { | ||
module.paths.unshift(`${baseDir}/node_modules`); | ||
return require(id); | ||
} catch (eb) { | ||
vscode.window.showErrorMessage( | ||
`Missing dependency, go to "${baseDir}" and run: npm install ${id}` | ||
); | ||
} | ||
} | ||
|
||
function getNodeModule(moduleName: string) { | ||
try { | ||
return require(`${appRoot}/node_modules.asar/${moduleName}`); | ||
} catch (error) { | ||
//Ignore | ||
return r(`${env.appRoot}/node_modules/${moduleName}`); | ||
} catch (err) { | ||
if (showError) { | ||
window.showErrorMessage(`Missing dependency: ${moduleName}`); | ||
} | ||
} | ||
|
||
const baseDir = path.dirname(process.execPath); | ||
|
||
try { | ||
module.paths.unshift(`${baseDir}/node_modules`); | ||
return require(moduleName); | ||
} catch (error) {} | ||
|
||
return undefined; | ||
} | ||
|
||
export const keytar = getNodeModule("keytar") as typeof import("keytar"); | ||
|
||
let iconv_lite = getNodeModule( | ||
"iconv-lite-umd" | ||
"iconv-lite-umd", | ||
false | ||
) as typeof import("iconv-lite-umd"); | ||
if (!iconv_lite) { | ||
iconv_lite = loadVSCodeModule("iconv-lite") as typeof import("iconv-lite"); | ||
iconv_lite = getNodeModule("iconv-lite") as typeof import("iconv-lite"); | ||
} | ||
|
||
export const iconv = iconv_lite; | ||
export const jschardet = loadVSCodeModule( | ||
|
||
export const jschardet = getNodeModule( | ||
"jschardet" | ||
) as typeof import("jschardet"); | ||
export const keytar = loadVSCodeModule("keytar") as typeof import("keytar"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters