Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/workbench.web.main.ts
3291 views
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
7
// ####################################
8
// ### ###
9
// ### !!! PLEASE DO NOT MODIFY !!! ###
10
// ### ###
11
// ####################################
12
13
// TODO@esm remove me once we stop supporting our web-esm-bridge
14
15
(function () {
16
17
// #region Types
18
type IGlobalDefine = {
19
(moduleName: string, dependencies: string[], callback: (...args: any[]) => any): any;
20
(moduleName: string, dependencies: string[], definition: any): any;
21
(moduleName: string, callback: (...args: any[]) => any): any;
22
(moduleName: string, definition: any): any;
23
(dependencies: string[], callback: (...args: any[]) => any): any;
24
(dependencies: string[], definition: any): any;
25
};
26
27
interface ILoaderPlugin {
28
load: (pluginParam: string, parentRequire: IRelativeRequire, loadCallback: IPluginLoadCallback, options: IConfigurationOptions) => void;
29
write?: (pluginName: string, moduleName: string, write: IPluginWriteCallback) => void;
30
writeFile?: (pluginName: string, moduleName: string, req: IRelativeRequire, write: IPluginWriteFileCallback, config: IConfigurationOptions) => void;
31
finishBuild?: (write: (filename: string, contents: string) => void) => void;
32
}
33
interface IRelativeRequire {
34
(dependencies: string[], callback: Function, errorback?: (error: Error) => void): void;
35
toUrl(id: string): string;
36
}
37
interface IPluginLoadCallback {
38
(value: any): void;
39
error(err: any): void;
40
}
41
interface IConfigurationOptions {
42
isBuild: boolean | undefined;
43
[key: string]: any;
44
}
45
interface IPluginWriteCallback {
46
(contents: string): void;
47
getEntryPoint(): string;
48
asModule(moduleId: string, contents: string): void;
49
}
50
interface IPluginWriteFileCallback {
51
(filename: string, contents: string): void;
52
getEntryPoint(): string;
53
asModule(moduleId: string, contents: string): void;
54
}
55
56
//#endregion
57
58
const define: IGlobalDefine = (globalThis as any).define;
59
const require: { getConfig?(): any } | undefined = (globalThis as any).require;
60
61
if (!define || !require || typeof require.getConfig !== 'function') {
62
throw new Error('Expected global define() and require() functions. Please only load this module in an AMD context!');
63
}
64
65
let baseUrl = require?.getConfig().baseUrl;
66
if (!baseUrl) {
67
throw new Error('Failed to determine baseUrl for loading AMD modules (tried require.getConfig().baseUrl)');
68
}
69
if (!baseUrl.endsWith('/')) {
70
baseUrl = baseUrl + '/';
71
}
72
globalThis._VSCODE_FILE_ROOT = baseUrl;
73
74
const trustedTypesPolicy: Pick<TrustedTypePolicy<{ createScriptURL(value: string): string }>, 'name' | 'createScriptURL'> | undefined = require.getConfig().trustedTypesPolicy;
75
if (trustedTypesPolicy) {
76
globalThis._VSCODE_WEB_PACKAGE_TTP = trustedTypesPolicy;
77
}
78
79
const promise = new Promise(resolve => {
80
(globalThis as any).__VSCODE_WEB_ESM_PROMISE = resolve;
81
});
82
83
define('vs/web-api', [], (): ILoaderPlugin => {
84
return {
85
load: (_name, _req, _load, _config) => {
86
const script: any = document.createElement('script');
87
script.type = 'module';
88
script.src = trustedTypesPolicy ? trustedTypesPolicy.createScriptURL(`${baseUrl}vs/workbench/workbench.web.main.internal.js`) as any as string : `${baseUrl}vs/workbench/workbench.web.main.internal.js`;
89
document.head.appendChild(script);
90
91
return promise.then(mod => _load(mod));
92
}
93
};
94
});
95
96
define(
97
'vs/workbench/workbench.web.main',
98
['require', 'exports', 'vs/web-api!'],
99
function (_require, exports, webApi) {
100
Object.assign(exports, webApi);
101
}
102
);
103
})();
104
105