Ship editor in ESM format

This commit is contained in:
Alex Dima
2018-03-07 09:38:59 +01:00
parent 6283645114
commit 66091601a5
14 changed files with 769 additions and 59 deletions

View File

@@ -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.