mirror of
https://github.com/coder/code-server.git
synced 2026-05-25 13:47:27 +02:00
Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { join, basename, dirname } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const contents: { [name: string]: string } = {};
|
||||
|
||||
const serverFolder = basename(__dirname) === 'dist' ? dirname(__dirname) : dirname(dirname(__dirname));
|
||||
const TYPESCRIPT_LIB_SOURCE = join(serverFolder, '../../node_modules/typescript/lib');
|
||||
const JQUERY_PATH = join(serverFolder, 'lib/jquery.d.ts');
|
||||
|
||||
export function loadLibrary(name: string) {
|
||||
let content = contents[name];
|
||||
if (typeof content !== 'string') {
|
||||
let libPath;
|
||||
if (name === 'jquery') {
|
||||
libPath = JQUERY_PATH;
|
||||
} else {
|
||||
libPath = join(TYPESCRIPT_LIB_SOURCE, name); // from source
|
||||
}
|
||||
try {
|
||||
content = readFileSync(libPath).toString();
|
||||
} catch (e) {
|
||||
console.log(`Unable to load library ${name} at ${libPath}: ${e.message}`);
|
||||
content = '';
|
||||
}
|
||||
contents[name] = content;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
Reference in New Issue
Block a user