mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
Ship editor in ESM format
This commit is contained in:
@@ -7,22 +7,19 @@
|
||||
import { globals } from 'vs/base/common/platform';
|
||||
import { logOnceWebWorkerWarning, IWorker, IWorkerCallback, IWorkerFactory } from 'vs/base/common/worker/simpleWorker';
|
||||
|
||||
// Option for hosts to overwrite the worker script url (used in the standalone editor)
|
||||
const getCrossOriginWorkerScriptUrl: (workerId: string, label: string) => string = environment('getWorkerUrl', null);
|
||||
|
||||
function environment(name: string, fallback: any = false): any {
|
||||
if (globals.MonacoEnvironment && globals.MonacoEnvironment.hasOwnProperty(name)) {
|
||||
return globals.MonacoEnvironment[name];
|
||||
function getWorkerUrl(workerId: string, label: string): string {
|
||||
// Option for hosts to overwrite the worker script url (used in the standalone editor)
|
||||
if (globals.MonacoEnvironment && typeof globals.MonacoEnvironment.getWorkerUrl === 'function') {
|
||||
return globals.MonacoEnvironment.getWorkerUrl(workerId, label);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
// ESM-comment-begin
|
||||
if (typeof require === 'function') {
|
||||
return require.toUrl('./' + workerId) + '#' + label;
|
||||
}
|
||||
// ESM-comment-end
|
||||
throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl`);
|
||||
}
|
||||
|
||||
function defaultGetWorkerUrl(workerId: string, label: string): string {
|
||||
return require.toUrl('./' + workerId) + '#' + label;
|
||||
}
|
||||
var getWorkerUrl = getCrossOriginWorkerScriptUrl || defaultGetWorkerUrl;
|
||||
|
||||
/**
|
||||
* A worker that uses HTML5 web workers so that is has
|
||||
* its own global scope and its own thread.
|
||||
|
||||
Reference in New Issue
Block a user